The structured library errors derive from TexformError (which extends Error) and carry a kind discriminator, so one instanceof TexformError check catches all of them:
TexformErrorTexformParseError— an operation needed a complete tree but parsing produced none.TexformEditError— an invalidDocumentedit.TexformConfigError— invalid construction or per-call configuration input.TexformTransformError— a transform-engine failure.
Parser.parse reports malformed LaTeX through its result object rather than throwing; invalid configuration still throws TexformConfigError. Passing TransformEngine.transform a document that hasErrors() throws TexformTransformError with kind: "transform", not the base class.
There is no target-counting helper here. Python's count_targets, which tallies command, environment, and character occurrences in a formula, is Python-only. To approximate it, parse the source and walk the Document with findCommands / findEnvironments or the Node navigation methods.
listPackagesfunction#
listPackages(): PackageInfo[]List all built-in knowledge packages with record counts.
The returned names are the identifiers accepted by the packages option of
KnowledgeBase: ams, base, bboldx,
boldsymbol, braket, physics, textmacros.
PackageInfo[] — One PackageInfo per built-in package.
import { listPackages } from 'texform';
listPackages(); // [ { name: 'ams', commands: 35, environments: 28 }, ... ]PackageInfointerface#
Summary of one built-in knowledge package, returned by listPackages.
| Field | Type | Description |
|---|---|---|
name | string | The package identifier, accepted by the |
commands | number | Number of command records in the package. |
environments | number | Number of environment records in the package. |
TexformErrorexceptionextends Error#
Base class for every error the library throws.
TexformError extends the built-in Error, so a single catch with an
instanceof TexformError check catches all library errors. The
TexformError.kind discriminator identifies which subsystem raised it.
kindattribute#
"parse" | "edit" | "conformance" | "config" | "transform" | "internal"Discriminator naming the subsystem that raised the error: "parse",
"edit", "config", "transform", or "internal".
TexformParseErrorexceptionextends TexformError#
Thrown when source could not be parsed into a complete tree.
TransformEngine.normalize throws this on input that cannot produce a
complete tree, and Document construction and editing methods throw it for invalid source strings. Note that Parser.parse itself never throws — it
returns a ParseResult instead.
TexformEditErrorexceptionextends TexformError#
Thrown by Document editing methods on an invalid edit: editing a read-only (error) tree, detaching or removing the root, an out-of-bounds index, or mixing nodes across documents.
TexformConfigErrorexceptionextends TexformError#
Thrown on invalid construction or per-call configuration: unknown package or profile names, unknown or snake_case keys, arrays in object positions, and wrong scalar types. Messages include a camelCase field path.
TexformTransformErrorexceptionextends TexformError#
Thrown on a transform-engine failure, such as an eliminated-form contract violation, or passing TransformEngine.transform a document that Document.hasErrors or that is bound to a different KnowledgeBase instance.
TexformConformanceErrorexceptionextends TexformEditError#
Thrown when a construction, edit, or syntax import violates the knowledge base or the document's structure.
listRulesfunction#
listRules(): RuleInfo[]List all built-in rewrite rules, sorted by key.
The keys are the identifiers accepted by the disableRules option of
TransformEngine and reported in RewriteReport rules. A rule
runs only when the engine's profile selects its level and the knowledge base
enables one of its packages.
RuleInfo[] — One RuleInfo per built-in rule.
import { listRules } from 'texform';
listRules().find((rule) => rule.key === 'base/over-to-frac');
// { key: 'base/over-to-frac', level: 'authoring', fidelity: 'render', summary: '...', enabledByPackages: ['base'] }RuleInfointerface#
Summary of one built-in rewrite rule, returned by listRules.
| Field | Type | Description |
|---|---|---|
key | string | Stable rule key, such as |
level | Rule | The first profile that accepts the rule's output. |
fidelity | Rule | Worst-case equivalence guarantee of the rule. |
summary | string | One-line description of what the rule does. |
enabledByPackages | string[ | Packages that make the rule loadable when any one of them is enabled. |
RuleFidelitytype#
"math" | "reading" | "render"A rewrite rule's worst-case equivalence guarantee over its declared input
domain, ordered least to most faithful: math (mathematical meaning is
preserved, rendering may change), reading (notation content, reading order,
and structural roles are preserved), render (rendering is equivalent under
the reference renderer).