# Underline

> Draw a line beneath selected text or the next typed characters.

Underline adds the `underline` mark. It can mark a label in a worksheet or a term to review.

## Try it

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

## Install

```sh
cargo add gpdoc-plugin-underline
```

## Example

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

```rust
use gpdoc::{EditorConfig, PluginViewExt};
use gpdoc_plugin_underline::{underline, underline_format};
use gpdoc_plugin_paragraph::paragraph;


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

Select a word and press **Command + U** on macOS or **Ctrl + U** on Windows and Linux. A line appears beneath the word.

## 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.

### `setUnderline`

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

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

### `toggleUnderline`

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

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

### `unsetUnderline`

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

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

## Keyboard shortcuts

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