Skip to content

Latest commit

 

History

History
50 lines (31 loc) · 3.28 KB

File metadata and controls

50 lines (31 loc) · 3.28 KB

OfficeIMO.Latex

OfficeIMO.Latex is a dependency-free, source-preserving LaTeX2e interoperability engine. It implements the bounded OfficeIMO document profile; it is not a TeX compiler and never executes commands, loads packages, or invokes an external runtime.

The native parser retains every input character, exposes tokens, groups, commands, environments, math, comments, and common document semantics, and writes unchanged input exactly.

using OfficeIMO.Latex;

LatexParseResult result = LatexDocument.Parse(source);
LatexDocument document = result.Document;

LatexHeading first = document.Headings[0];
first.Command.GetRequiredArgument(0)!.Content = "Updated section";

string updated = document.ToLatex();

The profile recognizes article/report/book structure, paragraphs, lists, figures, tabular data, labels/references, citations, theorem-like environments, and inline/display math. Unknown commands and environments remain source-backed instead of disappearing.

\verb and verbatim-like environments are opaque tokenizer nodes: braces, percent signs, commands, and environment-looking text inside them are never reparsed as LaTeX structure. The default set includes verbatim, Verbatim, lstlisting, minted, and comment; add producer-specific names through LatexParseOptions.VerbatimEnvironmentNames. Unterminated opaque constructs produce structural diagnostics.

Stream and file loading is bounded by MaximumInputBytes and MaximumInputLength; token count and nesting depth are bounded separately. Async load/save APIs accept cancellation tokens. UTF-8 output is emitted without an unexpected byte-order mark.

Simple document-local macros can be expanded only when explicitly enabled:

LatexDocument document = LatexDocument.Parse(
    source,
    new LatexParseOptions {
        MacroExpansion = LatexMacroExpansion.SafeSimpleDefinitions
    }).Document;

LatexMacroExpansionResult expansion = document.ExpandSimpleMacros(@"\project{OfficeIMO}");

This is deliberately not general TeX expansion. Replacement control words must be another transitively safe document-local simple macro or an explicitly allow-listed formatting/reference command; file I/O, packages, shell escape, dynamic control sequences, category-code changes, bibliography tools, and TeX typesetting remain outside the product. The operation is bounded string substitution, not a sanitizer: invocation arguments and expanded output must still be treated as untrusted if another system will compile the TeX.

Macro expansion has independent input and output budgets. Configure MaximumExpansionInputLength for the invocation source and MaximumExpansionLength for the produced text; a long invocation that contracts to a short value is not rejected merely because the output limit is small.

See the LaTeX support matrix for the exact boundary.

Targets: netstandard2.0, net8.0, net10.0, and net472 on Windows.

Dependency footprint

  • External: None; no TeX runtime, compiler, or parser package.
  • OfficeIMO: OfficeIMO.Core. Parsing, source preservation, bounded macro expansion, and writing are first-party.

See the complete OfficeIMO package map for related formats and conversion paths.