Repository navigation
v0.13.0: Full redesign in TypeScript
LaTeX.js 0.13.0
It's been a long time, but finally here is a new release with many bugfixes - and most importantly, a new architecture: I have rewritten the codebase from LiveScript to TypeScript. The generated HTML is essentially the same as in 0.12.6 (verified by the test suite), but packaging, a few API details and the requirements have changed:
- build uses vite instead of webpack
- docs use VitePress instead of VuePress and update to CodeMirror 6
- parser uses PeggyJS instead of PegJS
- pipeline is GitHub actions instead of CircleCI
- code coverage is done using c8 instead of codecov
- tests are run with vitest instead of mocha soon (which will replace c8 as well)
⚠️ Breaking changes
-
Node.js 22 or newer is required (previously 14).
-
The package is now ESM-first (
"type": "module"), and the files indist/were renamed:Use 0.12.6 0.13.0 ES module ( import)dist/latex.mjsdist/latex.jsCommonJS ( require)dist/latex.jsdist/latex.cjsBrowser <script>(UMD, globallatexjs)dist/latex.jsdist/latex.umd.cjsIf you load LaTeX.js with a
<script>tag or from a CDN URL that points intodist/, update the path.import/requireof"latex.js"keeps working. -
New hyphenation options.
languagePatternswas removed.hyphenatenow takes:true(default): hyphenate with the bundled English patternsfalse: no hyphenation- a function that inserts soft hyphens, for other languages, e.g.
import { hyphenateSync } from 'hyphen/de'
-
heis no longer exported from the library. Import thehepackage yourself if you need it. -
Custom macros now take precedence. Macros passed as
CustomMacrosoverride those of LaTeX.js, the document class and every package. Before, a document class or a\usepackagecould silently override them. Only definitions made in the document itself (e.g.\newcommand) still win over custom macros.
✨ New
- TypeScript type definitions are included, for both ESM and CommonJS consumers.
HtmlOptionsandHyphenatorare exported as types. - The CLI can now hyphenate any language the
hyphenpackage supports via-l/--language(en-us,en-gb,de,fr, …), not justenandde. - Custom macro classes are documented in more detail: methods whose names start with
_are helpers and not macros, andstatic symbols(aMapfrom macro name to string) defines macros without arguments that output text.
⚡ Performance and size
- The bundle is about 260 kB smaller because the
lodashandhedependencies were removed. - Parsing is faster. The grammar was restructured so that each control sequence is parsed once instead of up to six times, and comments are no longer looked for at every whitespace position.
- Creating an
HtmlGeneratoris cheaper. The hyphenator is cached, lengths are copy-on-write, and the formatter for\todayis created only once. This helps most in the playground and when converting many files with the CLI.
🐛 Fixes and improvements
- Math: now rendered with KaTeX 0.16. Output is slightly more compact (dimensions are rounded to 4 decimal places), and math no longer gets an extra wrapping
<div>. picture: a zero-length\vectornow draws its arrowhead in the direction of its slope. Very short arrows no longer show the line sticking out from under the head.<latex-js>web component:- works in the UMD/CommonJS builds
- no longer crashes when imported in Node
- resolves the
macrosattribute relative tobaseURL - cleans up its observer when it is removed from the page
- Counters: counter formats defined by the document classes are now resolved dynamically.
- Labels: using
\labelwith no\@currentlabelset no longer causes problems.
📖 Website
- https://latex.js.org was moved to VitePress, with a new playground based on CodeMirror 6 and with a new zoom feature