# LaTeX 수식

- Human documentation: [https://docs.univer.ai/ko-KR/guides/docs/features/latex](https://docs.univer.ai/ko-KR/guides/docs/features/latex)

- Agent Markdown: [https://docs.univer.ai/ko-KR/guides/docs/features/latex.md](https://docs.univer.ai/ko-KR/guides/docs/features/latex.md)

- Requested language: `ko-KR`

- Content language: `ko-KR`

- Documentation version: `1.0.4`

- Source: [docs/features/latex.ko-KR.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/docs/features/latex.ko-KR.mdx)

---

#### Package metadata

```json
{
  "mobile": true,
  "plugins": [
    {
      "client": "@univerjs-pro/docs-latex",
      "facade": "@univerjs-pro/docs-latex/facade"
    },
    {
      "client": "@univerjs-pro/docs-latex-ui",
      "locale": "@univerjs-pro/docs-latex-ui/locale/en-US",
      "style": "@univerjs-pro/docs-latex-ui/lib/index.css"
    }
  ],
  "license": true,
  "server": false
}
```

LaTeX 수식 기능을 사용하면 편집 가능한 수식 소스를 문서 모델에 저장하고 브라우저 편집기에서 렌더링할 수 있습니다.

## 플러그인 모드

### 설치

#### npm

```bash
npm install @univerjs-pro/docs-latex @univerjs-pro/docs-latex-ui
```

#### pnpm

```bash
pnpm add @univerjs-pro/docs-latex @univerjs-pro/docs-latex-ui
```

#### yarn

```bash
yarn add @univerjs-pro/docs-latex @univerjs-pro/docs-latex-ui
```

#### bun

```bash
bun add @univerjs-pro/docs-latex @univerjs-pro/docs-latex-ui
```

### 사용법

```typescript
import { UniverDocsLatexPlugin } from '@univerjs-pro/docs-latex' // [!code ++]
import { UniverDocsLatexUIPlugin } from '@univerjs-pro/docs-latex-ui' // [!code ++]
import DocsLatexUIEnUS from '@univerjs-pro/docs-latex-ui/locale/en-US' // [!code ++]
import { LocaleType, mergeLocales, Univer } from '@univerjs/core'

import '@univerjs-pro/docs-latex-ui/lib/index.css' // [!code ++]
import '@univerjs-pro/docs-latex/facade' // [!code ++]

const univer = new Univer({
  locale: LocaleType.EN_US,
  locales: {
    [LocaleType.EN_US]: mergeLocales(
      DocsLatexUIEnUS, // [!code ++]
    ),
  },
})

univer.registerPlugin(UniverDocsLatexPlugin) // [!code ++]
univer.registerPlugin(UniverDocsLatexUIPlugin) // [!code ++]
```

Univer 상용 라이선스가 있다면 구성 방법은 [클라이언트에서 라이선스 사용하기](https://docs.univer.ai/ko-KR/server/license.md#in-plugin-mode)를 참고하세요.

## 모바일 지원

먼저 [모바일 에디터](https://docs.univer.ai/ko-KR/guides/docs/getting-started/installation.md#mobile-support)를 구성하세요. 이 페이지의 플러그인 모드 초기화 코드에서 아래 데스크톱 등록을 같은 패키지의 모바일 버전으로 바꾸고 **문서를 열기 전에** 완료하세요. 모델 플러그인, 스타일, 언어 파일과 Facade 가져오기는 유지하며 두 버전을 동시에 등록하지 마세요.

| 패키지                           | 데스크톱 등록                   | 모바일 등록                          |
| ----------------------------- | ------------------------- | ------------------------------- |
| `@univerjs-pro/docs-latex-ui` | `UniverDocsLatexUIPlugin` | `UniverDocsLatexMobileUIPlugin` |

## Facade API

LaTeX API를 호출하기 전에 facade 진입점을 가져오세요.

```typescript
import '@univerjs-pro/docs-latex/facade'
```

활성 문서에 수식을 삽입합니다.

```typescript
const doc = univerAPI.getActiveDocument()

const formula = doc?.insertLatexFormula({
  latex: 'E=mc^2',
  index: 12,
})
```

수식을 읽고 업데이트합니다.

```typescript
const formulas = doc?.getLatexFormulas() ?? []
const firstFormula = doc?.findLatexFormulaByText('mc')

firstFormula?.update({
  latex: '\\frac{a}{b}',
})
```

범위 ID 또는 문서 데이터 스트림 오프셋으로 조회할 수도 있습니다.

```typescript
const byId = doc?.getLatexFormula('formula-range-id')
const atOffset = doc?.getLatexFormulaAt(42)

console.log(byId?.describe(), atOffset?.getLatex())
```
