Table of Contents

Class OdfFormulaDocument

Namespace
OdfKit.Formula
Assembly
OdfKit.dll

Adds MathML annotation helpers to formula documents. 提供 OdfFormulaDocument 的 MathML 標註協助方法。

public class OdfFormulaDocument : OdfDocument, IDisposable, IAsyncDisposable
Inheritance
OdfFormulaDocument
Implements
Derived
Inherited Members

Constructors

OdfFormulaDocument(OdfPackage)

Initializes a new instance of the OdfFormulaDocument class with the specified ODF package. 使用指定的 ODF 封裝初始化 OdfFormulaDocument 類別的新執行個體。

public OdfFormulaDocument(OdfPackage package)

Parameters

package OdfPackage

OdfFormulaDocument(OdfPackage, string)

Initializes a new instance of the OdfFormulaDocument class with the specified ODF package and sub-path. 使用指定的 ODF 封裝與子路徑初始化 OdfFormulaDocument 類別的新執行個體。

public OdfFormulaDocument(OdfPackage package, string subPath)

Parameters

package OdfPackage

The ODF package. / ODF 封裝。

subPath string

The sub-path within the package. / 封裝內的子路徑。

Properties

FormulaNode

Gets the main formula node. 取得主要公式節點。

public OdfNode FormulaNode { get; }

Property Value

OdfNode

MathMlXml

Gets or sets the full MathML XML string. 取得或設定完整 MathML XML 字串。

public string MathMlXml { get; set; }

Property Value

string

Remarks

讀取時會序列化目前的 MathML 根節點;寫入時會沿用 SetMathMl(string) 的安全解析與根節點檢查。

MathNode

Gets the current MathML root node. 取得目前的 MathML 根節點。

public OdfNode MathNode { get; }

Property Value

OdfNode

MathText

Performs math text. 取得 MathML 呈現內容(presentation MathML)的純文字摘要,不含

public string MathText { get; }

Property Value

string

MathTokens

Gets a summary of the recognizable tokens in the current MathML row. 取得目前 MathML row 中可辨識的 token 摘要。

public IReadOnlyList<OdfMathToken> MathTokens { get; }

Property Value

IReadOnlyList<OdfMathToken>

Methods

Builder()

Creates a new ODF formula document fluent builder. 建立新的 ODF 公式文件 Fluent builder。

public static OdfFormulaBuilder Builder()

Returns

OdfFormulaBuilder

A new OdfFormulaBuilder instance. / 新的 OdfFormulaBuilder 執行個體。

Create()

Creates a new ODF formula document. 建立新的 ODF 公式文件。

public static OdfFormulaDocument Create()

Returns

OdfFormulaDocument

A new OdfFormulaDocument instance. / 新的 OdfFormulaDocument 執行個體。

FindAnnotation(string)

Finds MathML annotation content for the specified encoding (math:semantics/math:annotation). 尋找指定編碼的 MathML 標註內容(math:semanticsmath:annotation)。

public string? FindAnnotation(string encoding)

Parameters

encoding string

The annotation encoding, such as application/x-tex or StarMath 5.0. / 標註編碼,例如 application/x-texStarMath 5.0

Returns

string

The annotation content, or null when the formula is not wrapped in math:semantics or no matching annotation exists. / 標註內容;若公式未以 math:semantics 包裹或不存在對應編碼的標註則為 null

Exceptions

ArgumentException

When encoding is blank. / 當 encoding 為空白時擲出。

FromBuilder(Action<OdfMathBuilder>)

Creates and loads an OdfFormulaDocument by using an OdfMathBuilder composition delegate. 使用 OdfMathBuilder 組合委派建立並載入 OdfFormulaDocument

public static OdfFormulaDocument FromBuilder(Action<OdfMathBuilder> build)

Parameters

build Action<OdfMathBuilder>

The delegate used to compose the MathML token tree. / 用於組合 MathML token 樹狀結構的委派。

Returns

OdfFormulaDocument

The OdfFormulaDocument instance loaded with the composed result. / 已載入組合結果的 OdfFormulaDocument 執行個體。

Exceptions

ArgumentNullException

When build is null. / 當 buildnull 時擲出。

FromLatex(string)

Creates and loads an OdfFormulaDocument from the specified LaTeX formula string. 從指定的 LaTeX 公式字串建立並載入 OdfFormulaDocument

public static OdfFormulaDocument FromLatex(string latex)

Parameters

latex string

The LaTeX formula string. / LaTeX 公式字串。

Returns

OdfFormulaDocument

The OdfFormulaDocument instance loaded with the LaTeX formula. / 已載入 LaTeX 公式的 OdfFormulaDocument 執行個體。

Exceptions

ArgumentNullException

When latex is null. / 當 latexnull 時擲出。

ArgumentException

When the LaTeX formula syntax is invalid. / 當 LaTeX 公式語法錯誤時擲出。

GetDefaultContentXml()

Gets the default content XML string. 取得預設的內容 XML 字串。

protected override string GetDefaultContentXml()

Returns

string

The default content XML string. / 預設的內容 XML 字串。

GetDefaultStylesXml()

Gets the default styles XML string. 取得預設的樣式 XML 字串。

protected override string GetDefaultStylesXml()

Returns

string

The default styles XML string. / 預設的樣式 XML 字串。

GetMathML()

Gets the MathML XML string. 取得 MathML 的 XML 字串。

public string GetMathML()

Returns

string

The MathML XML string. / MathML XML 字串。

GetMathTokens()

Gets the recognizable token summary list in the current MathML row. 取得目前 MathML row 中可辨識的 token 摘要清單。

public IReadOnlyList<OdfMathToken> GetMathTokens()

Returns

IReadOnlyList<OdfMathToken>

The MathML token list. / MathML token 清單。

Load(Stream)

Loads an ODF formula document from the specified stream. 從指定資料流載入 ODF 公式文件。

public static OdfFormulaDocument Load(Stream stream)

Parameters

stream Stream

Returns

OdfFormulaDocument

The loaded OdfFormulaDocument instance. / 載入完成的 OdfFormulaDocument 執行個體。

Exceptions

InvalidOperationException

When the specified document is not an ODF formula. / 當指定文件不是 ODF 公式時擲出。

Load(Stream, string?)

Full overload of Load that accepts stream and fileName. Load 完整多載:接受 stream 與 fileName。

public static OdfFormulaDocument Load(Stream stream, string? fileName)

Parameters

stream Stream
fileName string

Returns

OdfFormulaDocument

Load(string)

Loads an ODF formula document from the specified path. 從指定路徑載入 ODF 公式文件。

public static OdfFormulaDocument Load(string path)

Parameters

path string

The ODF formula document path. / ODF 公式文件路徑。

Returns

OdfFormulaDocument

The loaded OdfFormulaDocument instance. / 載入完成的 OdfFormulaDocument 執行個體。

Exceptions

InvalidOperationException

When the specified document is not an ODF formula. / 當指定文件不是 ODF 公式時擲出。

LoadAsync(Stream)

Asynchronously loads an ODF formula document from the specified stream. 非同步從指定資料流載入 ODF 公式文件。

public static Task<OdfFormulaDocument> LoadAsync(Stream stream)

Parameters

stream Stream

Returns

Task<OdfFormulaDocument>

A task representing the asynchronous load operation, whose result is the loaded OdfFormulaDocument. / 代表非同步載入作業的工作,其結果為載入完成的 OdfFormulaDocument

LoadAsync(Stream, string?)

Short overload of LoadAsync that accepts stream and fileName; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 stream 與 fileName;其餘可選參數使用預設值並轉呼叫最長 LoadAsync 多載。

public static Task<OdfFormulaDocument> LoadAsync(Stream stream, string? fileName)

Parameters

stream Stream
fileName string

Returns

Task<OdfFormulaDocument>

LoadAsync(Stream, string?, CancellationToken)

Short overload of LoadAsync that accepts stream, fileName, and cancellationToken; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 stream、fileName 與 cancellationToken;其餘可選參數使用預設值並轉呼叫最長 LoadAsync 多載。

public static Task<OdfFormulaDocument> LoadAsync(Stream stream, string? fileName, CancellationToken cancellationToken)

Parameters

stream Stream
fileName string
cancellationToken CancellationToken

Returns

Task<OdfFormulaDocument>

LoadAsync(Stream, CancellationToken)

Asynchronously loads the document from a stream with a cancellation token. 以取消語彙基元非同步從資料流載入文件。

public static Task<OdfFormulaDocument> LoadAsync(Stream stream, CancellationToken cancellationToken)

Parameters

stream Stream

The document stream. / 文件資料流。

cancellationToken CancellationToken

The cancellation token. / 取消語彙基元。

Returns

Task<OdfFormulaDocument>

A task whose result is the loaded document. / 代表非同步載入作業的工作,其結果為載入完成的文件。

LoadAsync(string)

Asynchronously loads an ODF formula document from the specified path. 非同步從指定路徑載入 ODF 公式文件。

public static Task<OdfFormulaDocument> LoadAsync(string path)

Parameters

path string

Returns

Task<OdfFormulaDocument>

A task representing the asynchronous load operation, whose result is the loaded OdfFormulaDocument. / 代表非同步載入作業的工作,其結果為載入完成的 OdfFormulaDocument

LoadAsync(string, CancellationToken)

Short overload of LoadAsync that accepts path and cancellationToken; remaining optional parameters use defaults and forward to the full overload. 便利多載:提供 path 與 cancellationToken;其餘可選參數使用預設值並轉呼叫最長 LoadAsync 多載。

public static Task<OdfFormulaDocument> LoadAsync(string path, CancellationToken cancellationToken)

Parameters

path string
cancellationToken CancellationToken

Returns

Task<OdfFormulaDocument>

LoadFromLatex(string)

Compiles the specified LaTeX formula string to MathML and loads it into the current formula document. 將指定的 LaTeX 公式字串編譯為 MathML 並載入到目前的公式文件中。

public void LoadFromLatex(string latex)

Parameters

latex string

The LaTeX formula string. / LaTeX 公式字串。

Exceptions

ArgumentNullException

When latex is null. / 當 latexnull 時擲出。

ArgumentException

When the LaTeX formula syntax is invalid. / 當 LaTeX 公式語法錯誤時擲出。

MergeContentNodes(OdfDocument, OdfMergeOptions, Dictionary<string, string>)

Merges content nodes from the source document into this document. 合併來源文件的內容節點至此文件。

protected override void MergeContentNodes(OdfDocument sourceDoc, OdfMergeOptions options, Dictionary<string, string> renameMap)

Parameters

sourceDoc OdfDocument

The source document. / 來源文件。

options OdfMergeOptions

The merge options. / 合併選項。

renameMap Dictionary<string, string>

The style rename map. / 樣式重新命名對照表。

Exceptions

ArgumentException

When the source document is not an OdfFormulaDocument. / 當來源文件不是 OdfFormulaDocument 時擲出。

ReplaceFirst(OdfMathTokenKind, OdfMathToken)

Replaces the first token of the specified kind in the current formula tree. 將目前公式樹中第一個符合種類的 token 替換為指定 token。

public bool ReplaceFirst(OdfMathTokenKind kind, OdfMathToken replacement)

Parameters

kind OdfMathTokenKind

The target token kind. / 目標 token 種類。

replacement OdfMathToken

The replacement token. / 替換後的新 token。

Returns

bool

true if a token was replaced; false when no target token was found. / 若成功替換則為 true;找不到目標時為 false

Exceptions

ArgumentNullException

When replacement is null. / 當 replacementnull 時擲出。

SetAnnotation(string, string?)

Sets or removes the MathML annotation (math:annotation) for the specified encoding. 設定或移除指定編碼的 MathML 標註(math:annotation)。

public void SetAnnotation(string encoding, string? content)

Parameters

encoding string

The annotation encoding, such as application/x-tex. / 標註編碼,例如 application/x-tex

content string

The annotation content; pass null to remove an existing annotation. / 標註內容;傳入 null 表示移除既有標註。

Remarks

Annotations can carry the original source, such as the LaTeX or StarMath string used to create the formula, so later processing can restore it exactly instead of only rebuilding it on a best-effort basis. 標註可附帶原始來源,例如建立公式時使用的 LaTeX 或 StarMath 字串,使後續可精確還原而非僅 best-effort 重建。

Exceptions

ArgumentException

When encoding is blank. / 當 encoding 為空白時擲出。

SetIdentifierEquation(string, string)

Builds a simple MathML equation stating that one identifier equals another. 建立以識別名稱等於另一個識別名稱的簡單 MathML 等式。

public OdfNode SetIdentifierEquation(string leftIdentifier, string rightIdentifier)

Parameters

leftIdentifier string

The identifier on the left side of the equals sign. / 等號左側識別名稱。

rightIdentifier string

The identifier on the right side of the equals sign. / 等號右側識別名稱。

Returns

OdfNode

The imported MathML root node. / 匯入後的 MathML 根節點。

SetMathMl(string)

Replaces the formula content with the specified MathML XML. 以指定 MathML XML 取代公式內容。

public OdfNode SetMathMl(string mathMlXml)

Parameters

mathMlXml string

The well-formed MathML XML. / 格式正確的 MathML XML。

Returns

OdfNode

The imported MathML root node. / 匯入後的 MathML 根節點。

Exceptions

ArgumentException

When the MathML XML is empty or its root node is not a MathML math element. / 當 MathML XML 為空或根節點不是 MathML math 時擲出。

SetMathRow(params OdfMathToken[])

Builds a MathML row from a set of semantic tokens. 以一組語意 token 建立 MathML row。

public OdfNode SetMathRow(params OdfMathToken[] tokens)

Parameters

tokens OdfMathToken[]

The MathML tokens to write into the row. / 要寫入 row 的 MathML token。

Returns

OdfNode

The imported MathML root node. / 匯入後的 MathML 根節點。

Exceptions

ArgumentException

When tokens is empty. / 當 tokens 為空時擲出。

ArgumentNullException

When any token is null. / 當任一 token 為 null 時擲出。

ToLatex()

Converts the current MathML formula content back to a LaTeX formula string. 將目前 MathML 公式內容反向轉換為 LaTeX 公式字串。若公式以 LoadFromLatex(string)FromLatex(string) 建立(或曾以 SetAnnotation(string, string?) 附加 application/x-tex 標註),會優先傳回該原始 LaTeX 來源以達成精確往返;否則改採 best-effort 由 MathML token 重建(因 LaTeX 與 MathML 並非一對一對應,部分語意可能無法完整保留)。

public string ToLatex()

Returns

string

The LaTeX formula string. / LaTeX 公式字串。