JavaScriptUtilities

Utilities

Python

List knowledge packages and the error classes.

The structured library errors derive from TexformError (which extends Error) and carry a kind discriminator, so one instanceof TexformError check catches all of them:

  • TexformError
    • TexformParseError — an operation needed a complete tree but parsing produced none.
    • TexformEditError — an invalid Document edit.
    • 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.

Returns
PackageInfo[] —

One PackageInfo per built-in package.

TypeScript
import { listPackages } from 'texform';

listPackages(); // [ { name: 'ams', commands: 35, environments: 28 }, ... ]

PackageInfointerface#

Summary of one built-in knowledge package, returned by listPackages.

FieldTypeDescription
namestring

The package identifier, accepted by the packages option.

commandsnumber

Number of command records in the package.

environmentsnumber

Number of environment records in the package.

See also

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.

diagnosticsattribute#

ParseDiagnostic[]

The diagnostics describing why parsing could not produce a complete tree.

documentattribute#

Document | null

The partial Document that was recovered, or null if none.

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.

See also

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.

pathattribute#

string

The tree path where the violation was found.

ruleattribute#

string

A stable machine-readable rule code.

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.

Returns
RuleInfo[] —

One RuleInfo per built-in rule.

TypeScript
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.

FieldTypeDescription
keystring

Stable rule key, such as "base/over-to-frac", accepted by disableRules.

levelRuleLevel

The first profile that accepts the rule's output.

fidelityRuleFidelity

Worst-case equivalence guarantee of the rule.

summarystring

One-line description of what the rule does.

enabledByPackagesstring[]

Packages that make the rule loadable when any one of them is enabled.

See also

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).