val_latex 0.1.1 copy "val_latex: ^0.1.1" to clipboard
val_latex: ^0.1.1 copied to clipboard

LaTeX math typesetting in pure Dart: a TeX parser, macros, TeX layout with line breaking and right-to-left math, OpenType math fonts, and speech output.

0.1.1 #

Robustness #

  • Untrusted input can no longer exhaust memory or hang: macro expansion is limited by the tokens it produces (ParseOptions.maxTokens, default 500,000), timeBudget is checked as work is done, \multicolumn and \hdotsfor counts are limited to the columns that exist, and every length is clamped to TeX's \maxdimen (dimensionTooLarge).
  • A limit reached outside any group leaves an error node, so the formula shows where it stopped.
  • Fixed crashes: a script on an empty symbol (\textcompwordmark_i), \mathop of one, text split by \over, a negative \hdotsfor factor, huge \cline ranges.

Fixed #

  • A backslash before a line end or a tab is a control space, as in TeX; the whole formula used to fail.
  • \\* and \\*[len] no longer draw a star; [t]/[b]/[c] work on array, aligned, alignedat, gathered and tables.
  • Words of other scripts inside a formula (Bengali, Hindi, Arabic, Thai…) stay whole, so they shape correctly.
  • A typed ⋅ is a binary operator (it was spaced as punctuation); typed ·, †, ‡, ⟂, ⊧ and others take unicode-math's classes.
  • \text{…} with a character Latin Modern lacks no longer loses the whole run in pure-Dart output: each character falls back to STIX Two; Cyrillic, Latin Extended and IPA come from STIX Two.
  • Variation selectors and other invisible characters no longer swallow their neighbour or leave gaps.
  • Operators and delimiters taken from STIX Two (\fint, \lBrace, \llangle…) grow and stretch; \widehat/\widetilde keep stretching past three letters; \utilde stretches.
  • toLatex round trips reach a fixed point for the new constructs.

Added: TeX and LaTeX #

  • \ensuremath, \[…\] in a formula, \newenvironment, \NewDocumentCommand and the rest of xparse, \DeclareRobustCommand, \protect, \makeatletter.
  • Lengths (\setlength, \arraycolsep, \jot, \fboxsep…), counters (\setcounter, \theequation, \numberwithin…), \makebox, \framebox, \parbox, minipage, center, \raisebox{-0.5\height}, \newcolumntype, \vline, \boldmath, \fontsize.
  • TeX programming: conditionals (\ifx, \ifnum, \ifcase, \newif…), \csname, \the, count and dimen registers (with TeX's "Arithmetic overflow" past their limits), \numexpr, \loop, \uppercase, \mathchar, \delimiter.
  • plain TeX: \matrix, \pmatrix, \cases, \bordermatrix, \eqalignno, \displaylines, \buildrel, \hbox to, \vbox, \vrule, \noalign, \leqno on the left, \sb, \sp.
  • \bgroup, \egroup, \long, \show, \message, \errmessage.
  • MediaWiki names: \plusmn, \Dagger, \lrarr, \lrArr, \Lrarr.

Added: packages #

  • tikzcd commutative diagrams and bussproofs prooftree.
  • unicode-math alphabets: \symbf, \symbb, \symcal, \mathup… .
  • siunitx: \sisetup, \DeclareSIUnit, \complexnum, \qtyproduct, most options, more units.
  • mathtools small matrices (psmallmatrix…), the derivative package (\odv, \pdv{f}{x,y}), \interval, harpoon accents, \widering, \widebar, \widetriangle, 88 mathabx symbols, empheq delimiters.
  • mhchem: charges inside \frac, \pu powers (mol-1), beta decay (^0_-1e), (v)/(^), \cf, \cesplit.
  • xcolor: the dvips names (NavyBlue…), \definecolor, \colorlet, mixes (red!30!blue), \columncolor.
  • MathJax commands: \bbox, \unicode, \require.
  • Common names: \E, \floor, \arsinh, \arcosh, \artanh.

Added: input as models write it #

  • & alignment with no environment is laid out as aligned, with a warning; doubled backslashes (\\frac, from JSON) are read as single ones; x^2' is {x^2}'; typed Aᵀ and eⁱᵖ are scripts; typed ẋ is \dot{x}; typed √2 is a square root; \left〈.
  • MathScanner: a price before a formula ($5 while $x$) no longer steals its dollar, $a$$b$ is two formulas, Markdown code (fences, indented blocks, HTML comments, unclosed code while streaming) is skipped, blockquotes, bare cases/pmatrix/aligned, doubled \\[…\\], spacedDollars (opt-in), and it is linear time.
  • Every command KaTeX 0.19 and flutter_math_fork define (except the fork's \cursor): KaTeX's Khan Academy colours (\blue{x}, \redA…), \varvdots, the texvc names \bull, \sub, \sube, \supe, amsmath's \tmspace, and graphicx's \reflectbox with KaTeX's \mathreflectbox (content mirrored left to right).
  • Drawn glyphs: ✔ ✗ ❌ ✅ ❗ ➔, the 109 arrows of Miscellaneous Symbols and Arrows (U+2B00–2BFF) the fonts lack (⬈ ⭢ ⭮ ⮐ ⮨ …), Roman numerals, ⅐ ⅑ ⅒, keycaps, ties.

Changed #

  • \num{3+-0.2} gives 3.0(2) and \SI's pre-unit is printed, as in siunitx v3; cmyk colours convert as xcolor does; the capitalised dvips names (Green, Orange…) take xcolor's values (lowercase names stay CSS).
  • With the physics extension off, \pdv and \pdv* follow the derivative package.
  • A blank line in math is a line break, with a warning.
  • \dotfill and \hrulefill draw outside tables.

API #

  • New: ParseOptions.maxTokens, ParseOptions.withStreaming, MathScanner(spacedDollars:), MathLayout.leqno, EquationNumber.left, ArrayNode.position/columnSep/jot, RaiseNode.byHeight…, EncloseNode.padding/ruleWidth, the diagram and proof AST nodes (DiagramNode, ProofTreeNode…), ReflectNode, TextItem.reflected and ImageItem.reflected (renderers draw them mirrored), MathVariant.doubleStruckItalic, and new diagnostic codes.

0.1.0 #

First release.

val_latex typesets LaTeX math in pure Dart. It runs anywhere Dart runs — the VM, Flutter on every platform, servers and the web — and is the shared core of val_latex_flutter.

Added #

  • Parser — parseLatex turns LaTeX math into an immutable syntax tree where every node carries its source span. It never throws for bad input: problems become error nodes and Diagnostics, and unfinished input is incomplete, so streaming text renders as far as it goes.
  • 3,882 commands and 68 environments — LaTeX and AMS math, mathtools, the physics package, mhchem (\ce, \pu), siunitx, diffcoeff, commath, nccmath, empheq, unicode-math names, stmaryrd and wasysym symbols, text tables and lists. LatexCatalog lists them all.
  • Macros — \def, \newcommand, \DeclareMathOperator and more, with TeX group scoping, shareable across formulas with newMacroTable().
  • TeX layout — layoutFormula and renderLatex follow the TeXbook's Appendix G and the OpenType MATH table, and produce a render-agnostic display list.
  • Fonts — Latin Modern Math bundled, STIX Two Math as the fallback; any OpenType math font with MathFont.fromBytes, variable fonts at any axis values.
  • Line breaking — LayoutOptions.maxWidth; prepareFormula lays out once and re-breaks for each width.
  • Right-to-left math — Arabic notation, Arabic-Indic and Persian digits.
  • Text with formulas — MathScanner finds $…$, $$…$$, \(…\) and \[…\] in text.
  • Outputs — toLatex (normalised source) and toSpeech (spoken math in eight languages, six of them drafts).
  • Hit testing and selection — hitTestLayout, selectionUnits.
  • Background layout — layoutInBackground in a worker isolate.
  • Third-party notices — valLatexNotices and THIRD_PARTY_NOTICES.md credit the work val_latex contains.
2
likes
160
points
0
downloads

Documentation

API reference

Publisher

verified publisheruseval.io

Weekly Downloads

LaTeX math typesetting in pure Dart: a TeX parser, macros, TeX layout with line breaking and right-to-left math, OpenType math fonts, and speech output.

Homepage
View/report issues

Topics

#katex #latex #math #tex #llm

License

BSD-3-Clause (license)

Dependencies

characters

More

Packages that depend on val_latex