# Subscript

> Display selected characters below the text baseline.

Subscript adds the `subscript` mark. Use it for parts of a formula such as the `2` in H₂O.

## Try it

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

## Install

```sh
cargo add gpdoc-plugin-subscript
```

## Example

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

```rust
use gpdoc::{EditorConfig, PluginViewExt};
use gpdoc_plugin_subscript::{subscript, subscript_format};
use gpdoc_plugin_paragraph::paragraph;


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

Type `H2O`, select the digit, and use the subscript shortcut below. The formatter lowers the digit below 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.

### `setSubscript`

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

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

### `toggleSubscript`

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

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

### `unsetSubscript`

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

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

## Keyboard shortcuts

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