val_latex 0.1.1
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),timeBudgetis checked as work is done,\multicolumnand\hdotsforcounts 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),\mathopof one, text split by\over, a negative\hdotsforfactor, huge\clineranges.
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 onarray,aligned,alignedat,gatheredand 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/\widetildekeep stretching past three letters;\utildestretches. toLatexround trips reach a fixed point for the new constructs.
Added: TeX and LaTeX #
\ensuremath,\[…\]in a formula,\newenvironment,\NewDocumentCommandand 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,\leqnoon the left,\sb,\sp. \bgroup,\egroup,\long,\show,\message,\errmessage.- MediaWiki names:
\plusmn,\Dagger,\lrarr,\lrArr,\Lrarr.
Added: packages #
tikzcdcommutative diagrams and bussproofsprooftree.- 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,\pupowers (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 asaligned, with a warning; doubled backslashes (\\frac, from JSON) are read as single ones;x^2'is{x^2}'; typedAᵀandeⁱᵖare scripts; typedẋis\dot{x}; typed√2is 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, barecases/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\reflectboxwith 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}gives3.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,
\pdvand\pdv*follow the derivative package. - A blank line in math is a line break, with a warning.
\dotfilland\hrulefilldraw 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.reflectedandImageItem.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 —
parseLatexturns LaTeX math into an immutable syntax tree where every node carries its source span. It never throws for bad input: problems become error nodes andDiagnostics, 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.LatexCataloglists them all. - Macros —
\def,\newcommand,\DeclareMathOperatorand more, with TeX group scoping, shareable across formulas withnewMacroTable(). - TeX layout —
layoutFormulaandrenderLatexfollow the TeXbook's Appendix G and the OpenTypeMATHtable, 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;prepareFormulalays out once and re-breaks for each width. - Right-to-left math — Arabic notation, Arabic-Indic and Persian digits.
- Text with formulas —
MathScannerfinds$…$,$$…$$,\(…\)and\[…\]in text. - Outputs —
toLatex(normalised source) andtoSpeech(spoken math in eight languages, six of them drafts). - Hit testing and selection —
hitTestLayout,selectionUnits. - Background layout —
layoutInBackgroundin a worker isolate. - Third-party notices —
valLatexNoticesandTHIRD_PARTY_NOTICES.mdcredit the work val_latex contains.