LaTeX Formula
LaTeX formula 機能は、編集可能な formula source を Docs model に保存し、browser editor で描画します。
プラグインモード
インストール
Shell
pnpm add @univerjs-pro/docs-latex @univerjs-pro/docs-latex-uiShell
npm install @univerjs-pro/docs-latex @univerjs-pro/docs-latex-uiShell
yarn add @univerjs-pro/docs-latex @univerjs-pro/docs-latex-uiShell
bun add @univerjs-pro/docs-latex @univerjs-pro/docs-latex-ui使い方
TypeScript
import { UniverDocsLatexPlugin } from '@univerjs-pro/docs-latex'import { UniverDocsLatexUIPlugin } from '@univerjs-pro/docs-latex-ui'import DocsLatexUIJaJP from '@univerjs-pro/docs-latex-ui/locale/ja-JP'import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import '@univerjs-pro/docs-latex-ui/lib/index.css'import '@univerjs-pro/docs-latex/facade'const univer = new Univer({ locale: LocaleType.JA_JP, locales: { [LocaleType.JA_JP]: mergeLocales( DocsLatexUIJaJP, ), },})univer.registerPlugin(UniverDocsLatexPlugin)univer.registerPlugin(UniverDocsLatexUIPlugin)Univer の商用ライセンスを利用している場合は、クライアントで License を使用する を参照してください。
モバイル対応
まずモバイルエディターを設定します。このページのプラグインモードの初期化コードで、以下のデスクトップ登録を同じパッケージのモバイル版に置き換え、文書を開く前に完了してください。モデル、スタイル、言語ファイル、Facade は維持し、両方を同時に登録しないでください。
| パッケージ | デスクトップの登録 | モバイルの登録 |
|---|---|---|
@univerjs-pro/docs-latex-ui | UniverDocsLatexUIPlugin | UniverDocsLatexMobileUIPlugin |
Facade API
LaTeX API を呼び出す前に facade entry を import します。
TypeScript
import '@univerjs-pro/docs-latex/facade'現在の document に formula を挿入します。
TypeScript
const doc = univerAPI.getActiveDocument()const formula = doc?.insertLatexFormula({ latex: 'E=mc^2', index: 12,})Formula を読み取り、更新します。
TypeScript
const formulas = doc?.getLatexFormulas() ?? []const firstFormula = doc?.findLatexFormulaByText('mc')firstFormula?.update({ latex: '\\frac{a}{b}',})range id または document data-stream offset でも検索できます。
TypeScript
const byId = doc?.getLatexFormula('formula-range-id')const atOffset = doc?.getLatexFormulaAt(42)console.log(byId?.describe(), atOffset?.getLatex())このガイドはいかがですか?