Skip to content

v0.13.0: Full redesign in TypeScript

Choose a tag to compare

@michael-brade michael-brade released this 18 Nov 23:39
· 143 commits to master since this release

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 in dist/ were renamed:

    Use 0.12.6 0.13.0
    ES module (import) dist/latex.mjs dist/latex.js
    CommonJS (require) dist/latex.js dist/latex.cjs
    Browser <script> (UMD, global latexjs) dist/latex.js dist/latex.umd.cjs

    If you load LaTeX.js with a <script> tag or from a CDN URL that points into dist/, update the path. import/require of "latex.js" keeps working.

  • New hyphenation options. languagePatterns was removed. hyphenate now takes:

    • true (default): hyphenate with the bundled English patterns
    • false: no hyphenation
    • a function that inserts soft hyphens, for other languages, e.g. import { hyphenateSync } from 'hyphen/de'
  • he is no longer exported from the library. Import the he package yourself if you need it.

  • Custom macros now take precedence. Macros passed as CustomMacros override those of LaTeX.js, the document class and every package. Before, a document class or a \usepackage could 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. HtmlOptions and Hyphenator are exported as types.
  • The CLI can now hyphenate any language the hyphen package supports via -l/--language (en-us, en-gb, de, fr, …), not just en and de.
  • Custom macro classes are documented in more detail: methods whose names start with _ are helpers and not macros, and static symbols (a Map from macro name to string) defines macros without arguments that output text.

⚡ Performance and size

  • The bundle is about 260 kB smaller because the lodash and he dependencies 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 HtmlGenerator is cheaper. The hyphenator is cached, lengths are copy-on-write, and the formatter for \today is 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 \vector now 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 macros attribute relative to baseURL
    • 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 \label with no \@currentlabel set 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