# LatexDocument

Parsed LaTeX document with lossless syntax and bounded profile semantics.

Class 

`OfficeIMO.Latex`

**Namespace**

`OfficeIMO.Latex`

**Assembly**

`OfficeIMO.Latex`

**Source revision**

`ba882f6b0d07` with working tree changes

**Source**

[LatexDocument.cs:115](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L115)

**Modifiers**

sealed

Parsed LaTeX document with lossless syntax and bounded profile semantics.

## Inheritance

- object
- LatexDocument

## Usage

Explore 6 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

### Returned or exposed by 6

- Method [LatexDocument.Load](/api/latex/officeimo-latex-latexdocument/#method-load-string-officeimo-latex-latexparseoptions-text-encoding)
- Method [LatexDocument.LoadAsync](/api/latex/officeimo-latex-latexdocument/#method-loadasync-string-officeimo-latex-latexparseoptions-text-encoding-threading-cancellationtoken)
- Method [LatexDocument.Parse](/api/latex/officeimo-latex-latexdocument/#method-parse-string-officeimo-latex-latexparseoptions)
- Method [LatexParseResult.RequireValue](/api/latex/officeimo-latex-latexparseresult/#method-requirevalue)
- Property [LatexParseResult.Document](/api/latex/officeimo-latex-latexparseresult/#property-document)
- Property [LatexParseResult.Value](/api/latex/officeimo-latex-latexparseresult/#property-value)

Filter members 

Show inherited

## Methods

`public LatexMacroExpansionResult ExpandSimpleMacros(string value)` [#](#method-expandsimplemacros-string)

[LatexDocument.cs:150](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L150)

Explicitly expands structurally safe simple definitions when enabled by parse options.

Parameters

**value string required**

Returns

`LatexMacroExpansionResult`

Load 2 overloads

`public static LatexDocument Load(string path, LatexParseOptions? options = null, Encoding? encoding = null)` [#](#method-load-string-officeimo-latex-latexparseoptions-text-encoding)

[LatexDocument.cs:135](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L135)

Loads decoded text using Unicode BOM detection when no encoding is specified.

Parameters

**path string required**

**options OfficeIMO.Latex.LatexParseOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

Returns

`LatexDocument`

`public static LatexDocument Load(Stream stream, LatexParseOptions? options = null, Encoding? encoding = null)` [#](#method-load-io-stream-officeimo-latex-latexparseoptions-text-encoding)

[LatexDocument.IO.cs:10](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.IO.cs#L10)

Loads and parses a LaTeX document from a caller-owned stream.

Parameters

**stream System.IO.Stream required**

**options OfficeIMO.Latex.LatexParseOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

Returns

`LatexDocument`

LoadAsync 2 overloads

`public static async Task<LatexDocument> LoadAsync(string path, LatexParseOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default)` [#](#method-loadasync-string-officeimo-latex-latexparseoptions-text-encoding-threading-cancellationtoken)

Asynchronously loads and parses a LaTeX file.

Parameters

**path string required**

**options OfficeIMO.Latex.LatexParseOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

`Task<LatexDocument>`

`public static async Task<LatexDocument> LoadAsync(Stream stream, LatexParseOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default)` [#](#method-loadasync-io-stream-officeimo-latex-latexparseoptions-text-encoding-threading-cancellationtoken)

Asynchronously loads and parses a LaTeX document from a caller-owned stream.

Parameters

**stream System.IO.Stream required**

**options OfficeIMO.Latex.LatexParseOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

`Task<LatexDocument>`

LoadResult 3 overloads

`public static LatexParseResult LoadResult(string path, LatexParseOptions? options = null, Encoding? encoding = null)` [#](#method-loadresult-string-officeimo-latex-latexparseoptions-text-encoding)

[LatexDocument.cs:139](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L139)

Loads decoded text with syntax and recovery diagnostics using Unicode BOM detection when no encoding is specified.

Parameters

**path string required**

**options OfficeIMO.Latex.LatexParseOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

Returns

`LatexParseResult`

`public static LatexParseResult LoadResult(Stream stream, LatexParseOptions? options = null, Encoding? encoding = null)` [#](#method-loadresult-io-stream-officeimo-latex-latexparseoptions-text-encoding)

[LatexDocument.IO.cs:14](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.IO.cs#L14)

Loads a LaTeX document from a caller-owned stream with syntax and recovery diagnostics.

Parameters

**stream System.IO.Stream required**

**options OfficeIMO.Latex.LatexParseOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

Returns

`LatexParseResult`

`public static LatexParseResult LoadResult(Stream stream, LatexParseOptions? options, Encoding? encoding, CancellationToken cancellationToken)` [#](#method-loadresult-io-stream-officeimo-latex-latexparseoptions-text-encoding-threading-cancellationtoken)

[LatexDocument.IO.cs:19](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.IO.cs#L19)

Loads a caller-owned stream with byte and character limits and cooperative cancellation.

Parameters

**stream System.IO.Stream required**

**options OfficeIMO.Latex.LatexParseOptions? required**

**encoding System.Text.Encoding? required**

**cancellationToken System.Threading.CancellationToken required**

Returns

`LatexParseResult`

LoadResultAsync 2 overloads

`public static async Task<LatexParseResult> LoadResultAsync(string path, LatexParseOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default)` [#](#method-loadresultasync-string-officeimo-latex-latexparseoptions-text-encoding-threading-cancellationtoken)

Asynchronously loads a LaTeX file with syntax and recovery diagnostics.

Parameters

**path string required**

**options OfficeIMO.Latex.LatexParseOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

`Task<LatexParseResult>`

`public static async Task<LatexParseResult> LoadResultAsync(Stream stream, LatexParseOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default)` [#](#method-loadresultasync-io-stream-officeimo-latex-latexparseoptions-text-encoding-threading-cancellationtoken)

Asynchronously loads a LaTeX stream with syntax and recovery diagnostics.

Parameters

**stream System.IO.Stream required**

**options OfficeIMO.Latex.LatexParseOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

`Task<LatexParseResult>`

Parse 2 overloads

`public static LatexDocument Parse(string source, LatexParseOptions? options = null)` [#](#method-parse-string-officeimo-latex-latexparseoptions)

[LatexDocument.cs:115](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L115)

Parses LaTeX source into the typed document model without executing it.

Parameters

**source string required**

**options OfficeIMO.Latex.LatexParseOptions? = null optional**

Returns

`LatexDocument`

`public static LatexDocument Parse(string source, LatexParseOptions? options, CancellationToken cancellationToken)` [#](#method-parse-string-officeimo-latex-latexparseoptions-threading-cancellationtoken)

[LatexDocument.cs:125](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L125)

Parses LaTeX source into the typed model without executing it and cooperatively observes cancellation.

Parameters

**source string required**

**options OfficeIMO.Latex.LatexParseOptions? required**

**cancellationToken System.Threading.CancellationToken required**

Returns

`LatexDocument`

ParseResult 2 overloads

`public static LatexParseResult ParseResult(string source, LatexParseOptions? options = null)` [#](#method-parseresult-string-officeimo-latex-latexparseoptions)

[LatexDocument.cs:119](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L119)

Parses LaTeX source with syntax and recovery diagnostics without executing it.

Parameters

**source string required**

**options OfficeIMO.Latex.LatexParseOptions? = null optional**

Returns

`LatexParseResult`

`public static LatexParseResult ParseResult(string source, LatexParseOptions? options, CancellationToken cancellationToken)` [#](#method-parseresult-string-officeimo-latex-latexparseoptions-threading-cancellationtoken)

[LatexDocument.cs:131](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L131)

Parses LaTeX source with diagnostics and cooperatively observes cancellation.

Parameters

**source string required**

**options OfficeIMO.Latex.LatexParseOptions? required**

**cancellationToken System.Threading.CancellationToken required**

Returns

`LatexParseResult`

Save 2 overloads

`public void Save(string path, LatexWriterOptions? options = null, Encoding? encoding = null)` [#](#method-save-string-officeimo-latex-latexwriteroptions-text-encoding)

[LatexDocument.IO.cs:134](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.IO.cs#L134)

Saves the current document text to a file.

Parameters

**path string required**

**options OfficeIMO.Latex.LatexWriterOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

`public void Save(Stream stream, LatexWriterOptions? options = null, Encoding? encoding = null)` [#](#method-save-io-stream-officeimo-latex-latexwriteroptions-text-encoding)

[LatexDocument.IO.cs:140](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.IO.cs#L140)

Writes the current document text to a caller-owned stream.

Parameters

**stream System.IO.Stream required**

**options OfficeIMO.Latex.LatexWriterOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

SaveAsync 2 overloads

`public async Task SaveAsync(string path, LatexWriterOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default)` [#](#method-saveasync-string-officeimo-latex-latexwriteroptions-text-encoding-threading-cancellationtoken)

Asynchronously saves the current document text to a file.

Parameters

**path string required**

**options OfficeIMO.Latex.LatexWriterOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

`Task`

`public Task SaveAsync(Stream stream, LatexWriterOptions? options = null, Encoding? encoding = null, CancellationToken cancellationToken = default)` [#](#method-saveasync-io-stream-officeimo-latex-latexwriteroptions-text-encoding-threading-cancellationtoken)

[LatexDocument.IO.cs:161](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.IO.cs#L161)

Asynchronously writes the current document text to a caller-owned stream.

Parameters

**stream System.IO.Stream required**

**options OfficeIMO.Latex.LatexWriterOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

**cancellationToken System.Threading.CancellationToken = default optional**

Returns

`Task`

`public byte[] ToBytes(LatexWriterOptions? options = null, Encoding? encoding = null)` [#](#method-tobytes-officeimo-latex-latexwriteroptions-text-encoding)

[LatexDocument.IO.cs:130](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.IO.cs#L130)

Encodes the current document text.

Parameters

**options OfficeIMO.Latex.LatexWriterOptions? = null optional**

**encoding System.Text.Encoding? = null optional**

Returns

`byte[]`

ToLatex 2 overloads

`public string ToLatex()` [#](#method-tolatex)

[LatexDocument.cs:145](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L145)

Writes in preserve mode.

Returns

`string`

`public string ToLatex(LatexWriterOptions? options)` [#](#method-tolatex-officeimo-latex-latexwriteroptions)

[LatexDocument.cs:147](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L147)

Writes using explicit options.

Parameters

**options OfficeIMO.Latex.LatexWriterOptions? required**

Returns

`string`

## Inherited Methods

`public virtual bool Equals(object? obj)` [#](#method-equals-object)

Inherited from object

Parameters

**obj object? required**

Returns

`bool`

`public virtual int GetHashCode()` [#](#method-gethashcode)

Inherited from object

Returns

`int`

`public Type GetType()` [#](#method-gettype)

Inherited from object

Returns

`Type`

`public virtual string? ToString()` [#](#method-tostring)

Inherited from object

Returns

`string?`

## Properties

`public LatexSourceText Source { get; }` [#](#property-source)

[LatexDocument.cs:57](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L57)

Original decoded source.

`public LatexSyntaxTree SyntaxTree { get; }` [#](#property-syntaxtree)

[LatexDocument.cs:59](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L59)

Lossless syntax tree.

`public LatexDocumentProfile Profile { get; }` [#](#property-profile)

[LatexDocument.cs:61](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L61)

Selected bounded profile.

`public IReadOnlyList<LatexToken> Tokens { get; }` [#](#property-tokens)

[LatexDocument.cs:63](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L63)

All exact tokens.

`public IReadOnlyList<LatexDiagnostic> Diagnostics { get; }` [#](#property-diagnostics)

[LatexDocument.cs:66](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L66)

Parser and recovery diagnostics.

`public IReadOnlyList<LatexCommand> Commands { get; }` [#](#property-commands)

[LatexDocument.cs:68](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L68)

Commands including unknown commands.

`public IReadOnlyList<LatexEnvironment> Environments { get; }` [#](#property-environments)

[LatexDocument.cs:70](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L70)

Nested environments.

`public IReadOnlyList<LatexMath> Math { get; }` [#](#property-math)

[LatexDocument.cs:72](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L72)

Inline and display math regions.

`public IReadOnlyList<LatexHeading> Headings { get; }` [#](#property-headings)

[LatexDocument.cs:74](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L74)

Part/chapter/section headings.

`public IReadOnlyList<LatexParagraph> Paragraphs { get; }` [#](#property-paragraphs)

[LatexDocument.cs:76](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L76)

Paragraph source regions in the document body.

`public IReadOnlyList<LatexList> Lists { get; }` [#](#property-lists)

[LatexDocument.cs:78](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L78)

Itemize, enumerate, and description lists.

`public IReadOnlyList<LatexFigure> Figures { get; }` [#](#property-figures)

[LatexDocument.cs:80](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L80)

Figure environments and included graphics.

`public IReadOnlyList<LatexTable> Tables { get; }` [#](#property-tables)

[LatexDocument.cs:82](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L82)

Tabular environments.

`public IReadOnlyList<LatexCitation> Citations { get; }` [#](#property-citations)

[LatexDocument.cs:84](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L84)

Citation commands.

`public IReadOnlyList<LatexReference> References { get; }` [#](#property-references)

[LatexDocument.cs:86](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L86)

Cross-reference commands.

`public IReadOnlyList<LatexLabel> Labels { get; }` [#](#property-labels)

[LatexDocument.cs:88](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L88)

Label declarations.

`public IReadOnlyList<LatexTheorem> Theorems { get; }` [#](#property-theorems)

[LatexDocument.cs:90](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L90)

Theorem-like environments.

`public IReadOnlyList<LatexFootnote> Footnotes { get; }` [#](#property-footnotes)

[LatexDocument.cs:92](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L92)

Source-backed footnote commands with editable bodies and optional explicit marks, in source order.

`public IReadOnlyList<LatexMacroDefinition> MacroDefinitions { get; }` [#](#property-macrodefinitions)

[LatexDocument.cs:94](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L94)

Document-local new/renew/provide command definitions.

`public LatexCommand? DocumentClassCommand { get; }` [#](#property-documentclasscommand)

[LatexDocument.cs:96](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L96)

Document class command, when present.

`public LatexEnvironment? Body { get; }` [#](#property-body)

[LatexDocument.cs:98](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L98)

Main document environment, when present.

`public string? DocumentClassName { get; }` [#](#property-documentclassname)

[LatexDocument.cs:100](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L100)

Document class name.

`public bool IsRecognizedProfile { get; }` [#](#property-isrecognizedprofile)

[LatexDocument.cs:102](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L102)

True for article, report, or book documents with a document environment.

`public bool IsModified { get; }` [#](#property-ismodified)

[LatexDocument.cs:107](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Latex/LatexDocument.cs#L107)

True when an editable semantic region changed.

<!-- PowerForge markdown artifact sha256:37B6F6398C6F03A1D3BF6D9ECFF16D23443CDA5CD3858B7F1BC1090DF085B34B -->
