# FDocumentLatex

- Human documentation: [https://docs.univer.ai/reference/facade/document-latex](https://docs.univer.ai/reference/facade/document-latex)

- Agent Markdown: [https://docs.univer.ai/reference/facade/document-latex.md](https://docs.univer.ai/reference/facade/document-latex.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0-rc.0`

- Source: [facade/document-latex.mdx](https://github.com/dream-num/documentation/blob/dev/content/reference/facade/document-latex.mdx)

---

Facade object for a single LaTeX formula in a Univer document.

## Access

Access through:

* [`FDocumentTextRange.replaceWithLatex()`](https://docs.univer.ai/reference/facade/document-text-range.md#replacewithlatex)
* [`FDocumentTextRange.insertLatexBefore()`](https://docs.univer.ai/reference/facade/document-text-range.md#insertlatexbefore)
* [`FDocumentTextRange.insertLatexAfter()`](https://docs.univer.ai/reference/facade/document-text-range.md#insertlatexafter)
* [`FDocumentParagraph.appendLatex()`](https://docs.univer.ai/reference/facade/document-paragraph.md#appendlatex)
* [`FDocumentParagraph.prependLatex()`](https://docs.univer.ai/reference/facade/document-paragraph.md#prependlatex)
* [`FDocument.getLatexFormulas()`](https://docs.univer.ai/reference/facade/document.md#getlatexformulas)
* [`FDocument.getLatexFormula()`](https://docs.univer.ai/reference/facade/document.md#getlatexformula)
* [`FDocument.getLatexFormulaAt()`](https://docs.univer.ai/reference/facade/document.md#getlatexformulaat)

## Example

```ts
const univerAPI = FUniver.newAPI(univer)
const document = univerAPI.getActiveDocument()
if (!document) throw new Error('No active document')
const formula = document.getLatexFormulas()[0]
if (!formula) throw new Error('No LaTeX formula')
console.log(formula.getLatex())
console.log(formula.getConfig())
if (!formula.update({ latex: '\\frac{a}{b}' })) throw new Error('Cannot update LaTeX formula')
```

## Setup

Register [`@univerjs-pro/docs-latex`](https://docs.univer.ai/reference/packages/plugins/univerjs-pro/docs-latex.md) or a preset that includes it. In plugin mode, import `@univerjs-pro/docs-latex/facade`. Additional methods below require their listed plugin packages. See [Facade setup](https://docs.univer.ai/guides/docs/getting-started/facade.md).

## `@univerjs-pro/docs-latex`

### `FDocumentLatex.describe`

Returns an agent-friendly description of this formula.

```typescript
describe(): IDocsLatexInfo | null
```

**Returns**

The formula id, range, source, and config, or `null` if it no longer exists.

**Examples**

```ts
const univerAPI = FUniver.newAPI(univer)
const document = univerAPI.getActiveDocument()
if (!document) throw new Error('No active document')
const formula = document.getLatexFormulas()[0]
if (!formula) throw new Error('No LaTeX formula')
console.log(formula.describe())
```

**Types:** [`IDocsLatexInfo`](https://unpkg.com/@univerjs-pro/docs-latex@1.0.0-rc.0/lib/types/facade/types.d.ts)

**Package:** [`@univerjs-pro/docs-latex`](https://docs.univer.ai/reference/packages/plugins/univerjs-pro/docs-latex.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-latex@1.0.0-rc.0/lib/types/facade/f-document-latex.d.ts)

### `FDocumentLatex.getConfig`

Returns the normalized formula configuration.

```typescript
getConfig(): IDocsLatexFormulaConfig
```

**Returns**

The formula source and visual properties.

**Examples**

```ts
const univerAPI = FUniver.newAPI(univer)
const document = univerAPI.getActiveDocument()
if (!document) throw new Error('No active document')
const formula = document.getLatexFormulas()[0]
if (!formula) throw new Error('No LaTeX formula')
console.log(formula.getConfig().kind)
```

**Types:** [`IDocsLatexFormulaConfig`](https://unpkg.com/@univerjs-pro/docs-latex@1.0.0-rc.0/lib/types/common/type.d.ts)

**Package:** [`@univerjs-pro/docs-latex`](https://docs.univer.ai/reference/packages/plugins/univerjs-pro/docs-latex.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-latex@1.0.0-rc.0/lib/types/facade/f-document-latex.d.ts)

### `FDocumentLatex.getId`

Returns the LaTeX formula range id.

```typescript
getId(): string
```

**Returns**

The custom range id that identifies this formula.

**Examples**

```ts
const univerAPI = FUniver.newAPI(univer)
const document = univerAPI.getActiveDocument()
if (!document) throw new Error('No active document')
const formula = document.getLatexFormulas()[0]
if (!formula) throw new Error('No LaTeX formula')
console.log(formula.getId())
```

**Package:** [`@univerjs-pro/docs-latex`](https://docs.univer.ai/reference/packages/plugins/univerjs-pro/docs-latex.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-latex@1.0.0-rc.0/lib/types/facade/f-document-latex.d.ts)

### `FDocumentLatex.getLatex`

Returns the editable LaTeX source for this formula.

```typescript
getLatex(): string
```

**Returns**

The LaTeX source, or an empty string if the formula range is gone.

**Examples**

```ts
const univerAPI = FUniver.newAPI(univer)
const document = univerAPI.getActiveDocument()
if (!document) throw new Error('No active document')
const formula = document.getLatexFormulas()[0]
if (!formula) throw new Error('No LaTeX formula')
console.log(formula.getLatex())
```

**Package:** [`@univerjs-pro/docs-latex`](https://docs.univer.ai/reference/packages/plugins/univerjs-pro/docs-latex.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-latex@1.0.0-rc.0/lib/types/facade/f-document-latex.d.ts)

### `FDocumentLatex.getRange`

Returns this formula's document data-stream range.

```typescript
getRange(): IDocsLatexRange | null
```

**Returns**

The formula range, or `null` if it no longer exists.

**Examples**

```ts
const univerAPI = FUniver.newAPI(univer)
const document = univerAPI.getActiveDocument()
if (!document) throw new Error('No active document')
const formula = document.getLatexFormulas()[0]
if (!formula) throw new Error('No LaTeX formula')
console.log(formula.getRange())
```

**Types:** [`IDocsLatexRange`](https://unpkg.com/@univerjs-pro/docs-latex@1.0.0-rc.0/lib/types/facade/types.d.ts)

**Package:** [`@univerjs-pro/docs-latex`](https://docs.univer.ai/reference/packages/plugins/univerjs-pro/docs-latex.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-latex@1.0.0-rc.0/lib/types/facade/f-document-latex.d.ts)

### `FDocumentLatex.remove`

Removes this formula and its source text from the document.

```typescript
remove(): boolean
```

**Returns**

Whether the remove command succeeded.

**Examples**

```ts
const univerAPI = FUniver.newAPI(univer)
const document = univerAPI.getActiveDocument()
if (!document) throw new Error('No active document')

const formula = document.getLatexFormulas()[0]
if (!formula) throw new Error('No LaTeX formula')
if (!formula.remove()) throw new Error('Failed to remove LaTeX formula')
```

**Package:** [`@univerjs-pro/docs-latex`](https://docs.univer.ai/reference/packages/plugins/univerjs-pro/docs-latex.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-latex@1.0.0-rc.0/lib/types/facade/f-document-latex.d.ts)

### `FDocumentLatex.replaceWithText`

Replaces this formula with plain text.

```typescript
replaceWithText(text: string): boolean
```

**Parameters**

* `text` — Required. Plain replacement text.

**Returns**

Whether the replace command succeeded.

**Examples**

```ts
const univerAPI = FUniver.newAPI(univer)
const document = univerAPI.getActiveDocument()
if (!document) throw new Error('No active document')

const formula = document.getLatexFormulas()[0]
if (!formula) throw new Error('No LaTeX formula')
if (!formula.replaceWithText('F = ma')) throw new Error('Failed to replace LaTeX formula')
```

**Package:** [`@univerjs-pro/docs-latex`](https://docs.univer.ai/reference/packages/plugins/univerjs-pro/docs-latex.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-latex@1.0.0-rc.0/lib/types/facade/f-document-latex.d.ts)

### `FDocumentLatex.update`

Updates this formula's source and optional visual properties.

```typescript
update(options: IDocsLatexUpdateFacadeOptions): boolean
```

**Parameters**

* `options` — Required. The replacement LaTeX source and property patch.

**Returns**

Whether the update command succeeded.

**Examples**

```ts
const univerAPI = FUniver.newAPI(univer)
const document = univerAPI.getActiveDocument()
if (!document) throw new Error('No active document')
const formula = document.getLatexFormulas()[0]
if (!formula) throw new Error('No LaTeX formula')
if (!formula.update({ latex: '\\frac{a}{b}' })) throw new Error('Cannot update LaTeX formula')
```

**Types:** [`IDocsLatexUpdateFacadeOptions`](https://unpkg.com/@univerjs-pro/docs-latex@1.0.0-rc.0/lib/types/facade/types.d.ts)

**Package:** [`@univerjs-pro/docs-latex`](https://docs.univer.ai/reference/packages/plugins/univerjs-pro/docs-latex.md) · [Type definitions](https://unpkg.com/@univerjs-pro/docs-latex@1.0.0-rc.0/lib/types/facade/f-document-latex.d.ts)
