LinuxCommandLibrary

gladtex

Convert LaTeX to XML for MathML

TLDR

Convert to HTML

$ gladtex [path/to/input.htex]
copy

Save the converted file to a specific [o]utput file
$ gladtex [path/to/input.htex] -o [path/to/output.html]
copy

Save the generated images to a specific [d]irectory
$ gladtex [path/to/input.htex] -d [path/to/image_output_directory]
copy

Set image [r]esolution (in dpi, default is 100)
$ gladtex [path/to/input.htex] -r [resolution]
copy

[k]eep LaTeX files after conversion
$ gladtex [path/to/input.htex] -k
copy

Set [b]ackground and [f]oreground color of the images
$ gladtex [path/to/input.htex] -b [background_color] -f [foreground_color]
copy

Convert Markdown to HTML using pandoc and gladtex
$ pandoc [[-s|--standalone]] [[-t|--to]] html --gladtex [path/to/input.md] | gladtex -o [path/to/output.html]
copy

SYNOPSIS

gladtex [OPTION]... [FILE]...

PARAMETERS

-h, --help
    Display help message and exit.

-d, --dumptex
    Dump extracted LaTeX code to stdout.

-t DIR, --tmpdir=DIR
    Set directory for temporary files (default: alt/)

-s, --split
    Split display math ($$...$$) into inline equations.

-r, --restore
    Reverse: restore LaTeX from images (requires img2tex)

-x, --cleanup
    Remove temporary files only, no processing.

-a, --alttext
    Add alt="..." attribute to images using original LaTeX.

-g, --svg
    Generate SVG images instead of PNG (requires dvisvgm)

-e ENGINE, --engine=ENGINE
    Use rendering engine: dvisvgm, mathjax, mathoid, mathpix.

DESCRIPTION

GladTeX is a Perl-based command-line utility that enables the embedding of high-quality mathematical equations in HTML documents by converting LaTeX markup into images.

It scans input HTML files for LaTeX math expressions delimited by constructs like \( ... \), \[ ... \], \begin{equation} ... \end{equation}, or $$ ... $$. The tool extracts these expressions, compiles them using LaTeX to produce DVI files, converts them to PNG images (or SVG with options) via dvipng, and replaces the original math with <img> tags linking to the generated images in an alt/ subdirectory.

This addresses the limitation of web browsers lacking native LaTeX rendering, producing crisp, scalable images suitable for print or web. GladTeX supports batch processing of multiple files, temporary file management, and reverse operations to restore original LaTeX from images. Modern versions include support for alternative rendering engines like MathJax or SVG output for better web compatibility.

Dependencies include a LaTeX distribution (e.g., TeX Live) and dvipng. Output HTML remains standards-compliant, with optional alt text for accessibility.

CAVEATS

Requires full LaTeX suite and dvipng; large equations may produce oversized images; SVG mode needs additional tools; not suitable for dynamic content.

DEPENDENCIES

Needs TeX Live/TeX distribution, dvipng, Perl; optional: dvisvgm, Node.js for MathJax/Mathoid.

OUTPUT STRUCTURE

Creates alt/ dir with numbered images (eqno.png); updates HTML with <img src="alt/eqno.png">.

HISTORY

Developed by Alexey Tourbin in 2003 as a Perl script to solve LaTeX-in-HTML rendering issues. Maintained sporadically; version 2016+ adds SVG/MathJax support. Widely used in static site generators for math-heavy docs.

SEE ALSO

latex(1), dvipng(1), dvisvgm(1), img2tex(1)

Copied to clipboard