LaTeX 수식
LaTeX 수식 기능을 사용하면 편집 가능한 수식 소스를 문서 모델에 저장하고 브라우저 편집기에서 렌더링할 수 있습니다.
플러그인 모드
설치
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 DocsLatexUIEnUS from '@univerjs-pro/docs-latex-ui/locale/en-US'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.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( DocsLatexUIEnUS, ), },})univer.registerPlugin(UniverDocsLatexPlugin)univer.registerPlugin(UniverDocsLatexUIPlugin)Univer 상용 라이선스가 있다면 구성 방법은 클라이언트에서 라이선스 사용하기를 참고하세요.
모바일 지원
먼저 모바일 에디터를 구성하세요. 이 페이지의 플러그인 모드 초기화 코드에서 아래 데스크톱 등록을 같은 패키지의 모바일 버전으로 바꾸고 문서를 열기 전에 완료하세요. 모델 플러그인, 스타일, 언어 파일과 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())이 가이드는 어떠셨나요?