The structured library exceptions derive from TexformError, so one except texform.TexformError catches them:
TexformErrorParseError— an operation needed a complete tree but parsing produced none.EditError— an invalidDocumentedit.ConfigError— invalid construction or per-call configuration input.TransformError— a transform-engine failure.
Parser.parse reports malformed LaTeX through its result dict rather than raising; invalid configuration still raises ConfigError. Two categories are easy to misattribute. Attaching a node that belongs to another document raises EditError (node belongs to a different document), rejected before either tree is touched, and passing TransformEngine.transform a document that has_errors() raises TransformError — the precondition belongs to the engine, not to the earlier parse.
list_packagesfunction#
list_packages() -> list[PackageInfo]List the built-in knowledge packages with their record counts.
The returned names are the package identifiers accepted by the packages
argument of KnowledgeBase.
list[PackageInfo] — A list of PackageInfo dicts, each {"name": str, "commands": int, "environments": int}.
texform.list_packages() # [{'name': 'ams', 'commands': 35, 'environments': 28}, ...]count_targetsfunction#
count_targets( src: str, config: ParseConfig | None = None, knowledge_base: KnowledgeBase | None = None,) -> dict[str, int]Count command, environment, and character targets in a LaTeX formula.
This is a Python-only helper for corpus analysis. The JavaScript binding does not provide an equivalent function. It parses the source and reports aggregate counts rather than returning a tree, so it requires a complete parse.
| Parameter | Type | Default | Description |
|---|---|---|---|
src | str | — | The LaTeX source string. |
config | Parse | None | A |
knowledge_base | Knowledge | None | Shared knowledge, or |
dict[str, int] — A dict mapping a prefixed target key to its occurrence count. Keys are prefixed by kind: cmd: for commands, env: for environments, and char: for named character commands such as \alpha.
ParseError—If the source does not parse into a complete tree.
texform.count_targets(r"\frac{x}{y} + \alpha") # {'cmd:frac': 1, 'char:alpha': 1}PackageInfodict type#
Summary of one built-in knowledge package.
| Field | Type | Description |
|---|---|---|
name | str | The package identifier accepted by the |
commands | int | The number of command records in the package. |
environments | int | The number of environment records in the package. |
TexformErrorexceptionextends Exception#
Base class for every exception the library raises.
Catching TexformError catches all of them. Note that Parser.parse
does not raise on malformed input; it reports failures through its result
dict instead.
ParseErrorexceptionextends TexformError#
Raised when source could not be parsed into a complete tree.
Besides the cases below, Document.create_*, parse_fragment, and the set_* editing methods raise it when a source string is invalid.
TransformEngine.normalize raises this on input that cannot produce a
complete tree, and count_targets raises it when the source does not parse
into a complete tree. The exception then carries the diagnostics and the
partial document for inspection.
EditErrorexceptionextends TexformError#
Raised by a Document editing method on an invalid edit.
Triggers include editing a read-only (error) tree, detaching or removing the root node, an out-of-bounds index, a wrong container shape, and attaching a node that belongs to another document. The edit is rejected before it can corrupt the tree.
ConfigErrorexceptionextends TexformError#
Raised on invalid construction or per-call configuration input.
Triggers include an unknown knowledge package name or transform profile, a
config argument that is not the matching complete-config class (including
a dict passed as config), unknown override keys, wrong scalar types
(string or int instead of bool, float instead of int), a list where an object
is expected, and a config class instance used as a nested override value.
TransformErrorexceptionextends TexformError#
Raised on a transform-engine failure.
Triggers include an eliminated-form contract violation, passing
TransformEngine.transform a document that has_errors(), or one
bound to a different knowledge-base instance.
ConformanceErrorexceptionextends EditError#
Raised when a construction, edit, or syntax import violates the knowledge base or the document's structure.
list_rulesfunction#
list_rules() -> list[RuleInfo]List the built-in rewrite rules, sorted by key.
The returned keys are the rule identifiers accepted by the
disable_rules argument of TransformEngine and reported in rewrite
statistics. A rule runs only when the engine's profile selects its level and
the knowledge base enables one of its packages.
list[RuleInfo] — A list of RuleInfo dicts, each {"key": str, "level": str, "fidelity": str, "summary": str, "enabled_by_packages": list[str]}.
[rule for rule in texform.list_rules() if rule["key"] == "base/over-to-frac"]
# [{'key': 'base/over-to-frac', 'level': 'authoring', 'fidelity': 'render', ...}]RuleInfodict type#
Summary of one built-in rewrite rule.
| Field | Type | Description |
|---|---|---|
key | str | The stable rule key, such as |
level | Rule | The first profile that accepts the rule's output. |
fidelity | Rule | The rule's worst-case equivalence guarantee. |
summary | str | A one-line description of what the rule does. |
enabled_by_packages | list[ | Packages that make the rule loadable when any one of them is enabled. |
RuleFidelitytype#
Literal['math', 'reading', 'render']A rewrite rule's worst-case equivalence guarantee, least to most faithful:
"math" (meaning preserved, rendering may change), "reading" (notation
content, reading order, and structural roles preserved), or "render"
(rendering equivalent under the reference renderer).
RuleLeveltype#
Literal['authoring', 'faithful', 'corpus', 'equiv']The first profile that accepts a rewrite rule's output as a suitable product.