# Superscript

> Display selected characters above the text baseline.

Superscript adds the `superscript` mark. Use it for an exponent such as the `2` in x² or for a footnote number.

## Try it

[Try the superscript editor example](https://gpdoc.dev/docs/plugins/formatting/superscript/#superscript-example)

## Install

```sh
cargo add gpdoc-plugin-superscript
```

## Example

Register the superscript formatter in the [Quickstart editor configuration](/docs/quickstart/#configure-the-editor). `superscript()` uses this formatter by default.

```rust
use gpdoc::{EditorConfig, PluginViewExt};
use gpdoc_plugin_superscript::{superscript, superscript_format};
use gpdoc_plugin_paragraph::paragraph;


let config = EditorConfig::builder()
    .plugin(paragraph())
    .plugin(superscript().with_view(superscript_format))
    .build()
    .expect("configure editor");
```

Type `x2`, select the digit, and use the superscript shortcut below. The formatter raises the digit above the baseline.

## Commands

These commands take no arguments. Select text to change its formatting, or place the caret where you want to start typing. `editor.run` returns `Result<CommandOutcome, Error>`. A handled command returns `Applied(AppliedChange)`. Set and toggle return `NotApplicable` if no text can take the mark.

### `setSuperscript`

Apply superscript to the selection or to the next characters typed at the caret.

```rust
editor.run(gpdoc_plugin_superscript::Set)?;
```

### `toggleSuperscript`

Switch superscript off when the whole eligible selection has the mark. On a mixed selection, apply it throughout.

```rust
editor.run(gpdoc_plugin_superscript::Toggle)?;
```

### `unsetSuperscript`

Clear superscript from the selection or turn it off for subsequent typing.

```rust
editor.run(gpdoc_plugin_superscript::Unset)?;
```

## Keyboard shortcuts

Toggle superscript with **Command + .** on macOS or **Ctrl + .** on Windows and Linux.