# Italic

> Mark selected text or the next typed characters as italic.

Italic adds the `italic` mark. Use it for emphasis, book titles, or terms from another language.

## Try it

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

## Install

```sh
cargo add gpdoc-plugin-italic
```

## Example

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

```rust
use gpdoc::{EditorConfig, PluginViewExt};
use gpdoc_plugin_italic::{italic, italic_format};
use gpdoc_plugin_paragraph::paragraph;


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

Type `*emphasis*` in a paragraph. The editor removes the asterisks and displays *emphasis* in italics.

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

### `setItalic`

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

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

### `toggleItalic`

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

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

### `unsetItalic`

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

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

## Keyboard shortcuts

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

Typing `*emphasis*` or `_emphasis_` applies italic.