FDocumentLatex
Facade object for a single LaTeX formula in a Univer document.
Access
Access through:
FDocumentTextRange.replaceWithLatex()FDocumentTextRange.insertLatexBefore()FDocumentTextRange.insertLatexAfter()FDocumentParagraph.appendLatex()FDocumentParagraph.prependLatex()FDocument.getLatexFormulas()FDocument.getLatexFormula()FDocument.getLatexFormulaAt()
Example
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 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.
@univerjs-pro/docs-latex
FDocumentLatex.describe
Returns an agent-friendly description of this formula.
describe(): IDocsLatexInfo | nullReturns
The formula id, range, source, and config, or null if it no longer exists.
Examples
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
Package: @univerjs-pro/docs-latex · Type definitions
FDocumentLatex.getConfig
Returns the normalized formula configuration.
getConfig(): IDocsLatexFormulaConfigReturns
The formula source and visual properties.
Examples
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
Package: @univerjs-pro/docs-latex · Type definitions
FDocumentLatex.getId
Returns the LaTeX formula range id.
getId(): stringReturns
The custom range id that identifies this formula.
Examples
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 · Type definitions
FDocumentLatex.getLatex
Returns the editable LaTeX source for this formula.
getLatex(): stringReturns
The LaTeX source, or an empty string if the formula range is gone.
Examples
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 · Type definitions
FDocumentLatex.getRange
Returns this formula's document data-stream range.
getRange(): IDocsLatexRange | nullReturns
The formula range, or null if it no longer exists.
Examples
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
Package: @univerjs-pro/docs-latex · Type definitions
FDocumentLatex.remove
Removes this formula and its source text from the document.
remove(): booleanReturns
Whether the remove command succeeded.
Examples
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 · Type definitions
FDocumentLatex.replaceWithText
Replaces this formula with plain text.
replaceWithText(text: string): booleanParameters
text— Required. Plain replacement text.
Returns
Whether the replace command succeeded.
Examples
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 · Type definitions
FDocumentLatex.update
Updates this formula's source and optional visual properties.
update(options: IDocsLatexUpdateFacadeOptions): booleanParameters
options— Required. The replacement LaTeX source and property patch.
Returns
Whether the update command succeeded.
Examples
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
Package: @univerjs-pro/docs-latex · Type definitions
你觉得这篇文档如何?