GLADTEX(1)

πŸ“¦
version 3.1.0 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

okay bestie, come sit with me, we're reading gladtex(1) together πŸ’– it's giving "LaTeX in your HTML, but make it cute", and honestly? obsessed.

🌸 NAME 🌸

GladTeX β€” generate HTML with LaTeX formulas embedded as images. yep, that's the whole job description πŸ’…


✨ SYNOPSIS ✨

gladtex OPTIONS

πŸ¦‹ DESCRIPTION πŸ¦‹

GladTeX is a formula preprocessor for HTML files. it recognizes a special tag, <eq>...</eq>, that marks formulas for conversion. the converted vector images get integrated straight into the output HTML document. this eases the process of creating HTML documents (or web sites) containing formulas β€” no cap 🫢

the generated images are saved in a cache so it doesn't render the same image over and over again. this speeds up the process when formulas occur multiple times, or when a document is extended gradually. literally saving you time while you vibe 🌈

the LaTeX formulas are preserved in the alt attribute of the embedded images, hence screen reader users benefit from an accessible HTML version of the document. accessibility? we love to see it πŸ‘‘

furthermore it can be used with Pandoc to convert Markdown documents and other formats with LaTeX formulas to HTML, EPUB and in fact to any HTML-based format β€” see the option -P. iykyk ✨

see FILE FORMAT for an explanation of the file format, and EXAMPLES for examples on how to use GladTeX on its own or with Pandoc.


πŸ’… OPTIONS πŸ’…

  • INPUT FILE NAME β€” the input .htex file with LaTeX formulas (if it's omitted or it's -, stdin will be read).
  • -h, --help β€” show this help message and exit. short and sweet πŸŽ€
  • -a β€” save text alternatives for images which are too long for the alt attribute into a single separate file, and link images to it.
  • -b BACKGROUND_COLOR β€” set the background color for the resulting images (default transparent). GladTeX understands colors as provided by the dvips option of the xcolor LaTeX package. alternatively, a 6-digit hexadecimal value can be provided (as used e.g. in HTML/CSS).
  • -c FOREGROUND_COLOR β€” set the foreground color for the resulting images. see the option above for a more in-depth explanation.
  • -d DIRECTORY β€” the directory in which to store the generated images in (relative path).

the given path is interpreted relatively to the input file. for instance,:

gladtex -d img dir/file.htex

will create a dir/img directory and link accordingly in x/file.htex.

  • -e LATEX_MATHS_ENV β€” set a custom maths environment to surround the formula (e.g. flalign).
  • -E ENCODING β€” overwrite the encoding to use (default UTF-8).
  • -f FONTSIZE β€” overwrite the default font size of 12pt. 12pt is the default in most browsers, and hence changing this might lead to less-portable documents. 🫣
  • -i CLASS β€” the CSS class to assign to inline math (default: inlinemath).
  • -K β€” keep the LaTeX file(s) when converting formulas.

by default, the generated LaTeX document, containing the formula to be converted, is removed after the conversion (no matter whether it was successful or not). if it wasn't successful, it is sometimes helpful to look at the complete document. this option will keep the file.

  • -l CLASS β€” the CSS class to assign to block-level math (default: displaymath).
  • -n β€” purge unreadable caches along with all eqn*.png files.

caches can be unreadable if the used GladTeX version is incompatible. if this option is unset, GladTeX will simply fail when the cache is unreadable.

  • -m β€” print error output in machine-readable format (less concise, better parseable).

each line will start with a key, followed by a colon, followed by the value, i.e. line: 5.

  • -o FILENAME β€” set the output file name. - will print text to stdout. by default, the input file name is used and the .htex extension is replaced by .html.
  • -p LATEX_STATEMENT β€” add the given LaTeX code to the preamble of the document. that'll affect the conversion of every image.
  • -P β€” act as a pandoc filter. in this mode, input is expected to be a Pandoc JSON AST and the output will be a modified AST, with all formulas replaced through HTML image tags. it makes sense to use - as the input file for this option.
  • --png β€” switch from SVG to PNG as image output. this image has several known issues, one of them being that images won't resize when zooming into the document. it is also harder to work with for visually impaired users. πŸ’€
  • -r DPI β€” set resolution (size of images) to dpi (115 by default). this is only available with the --png option. also see the -f option.
  • -R β€” replace non-ascii (unicode) characters by LaTeX commands.

GladTeX can automatically detect non-ascii characters in formulas and replace them through their appropriate LaTeX commands. in the alt attribute of the resulting image, alphabetical characters won't be replaced. that means the alt text from the image is not exactly the same as the code used for generating the image, but it is far more readable.

for instance, the formula $\text{fΓΌr alle} a$, would be compiled as $\text{f\ddot{u}r alle} a$ and displayed as "\text{fΓΌr alle} a" in the alt attribute.

  • -u URL β€” base URL to image files (relative links are default).

πŸŽ€ FILE FORMAT πŸŽ€

a .htex file is essentially a HTML file containing LaTeX formulas. the formulas have to be surrounded by <eq> and </eq>.

by default, formulas are rendered as inline maths, so they are squeezed to the height of the line. it is possible to render a formula as display maths by setting the env attribute to displaymath, i.e. <eq env="displaymath">...</eq>. periodt ✨


🌈 ENVIRONMENT VARIABLES 🌈

GladTeX can be customised by environment variables:

  • DEBUG β€” if this is set to 1, a full Python traceback, instead of a human-readable error message, will be displayed.
  • GLADTEX_ARGS β€” when this environment variable is set, GladTeX switches into pandoc filter mode: input is read from standard input, output written to standard output and the -P switch is assumed. the contents of this variable [are] parsed as command-line switches. see an example in Output As EPUB#output-asepub).

πŸ“ EXAMPLES πŸ“

Sample HTEX document

a sample HTEX document could look like this:

<html><head><!-- meta information like charset --></head>
<body>
<h1>Some text</h1>
<p>Circumference of a circle: <eq>u = \pi\cdot d</eq><p>
<p>A useful matrix: <eq env="displaymath">\begin{pmatrix}
1 &2 &3 &4\\
5 &6 &7 &8\\
9 &10&11&12
\end{pmatrix}</eq></p>
</body></html>

this can be converted using

gladtex file.htex

and the result will be a HTML document called file.html along with two files eqn0000.png and eqn0001.png in the same directory. main character energy fr fr πŸ”₯

Markdown To HTML

GladTeX can be used together with Pandoc. that can be handy to create an online version of a scientific paper written in Markdown. the MarkDown document would look like this:

Some text
=========

Circumference of a circle: $u = \pi\cdot d$

A useful matrix: $$\begin{pmatrix}
1 &2 &3 &4\\
5 &6 &7 &8\\
9 &10&11&12 \end{pmatrix}$$

the conversion is as easy as typing on the command-line:

pandoc -s -t html --gladtex file.md | gladtex -o file.html -

Output as EPUB

it is beyond of the scope of this document to introduce Pandoc, but with any input format, converting to EPUB with GladTeX replacing the images is as easy as:

pandoc -t json FILE.ext | gladtex -d img -P - | pandoc -f json -o book.epub

capitalised parameters should be replaced. this can be used with Markdown as input format, see previous section.

if you want to call Pandoc as a filter without the pipes, you can use the environment variable GLADTEX_ARGS:

GLADTEX_ARGS='-d img' pandoc -o BOOK.EPUB -F gladtex FILE.ext

😭 KNOWN LIMITATIONS 😭

LaTeX2E is not unicode aware. if you have any unicode (more precisely, non-ascii characters) signs in your documents, you have the choice to do one of the following:

  1. look up the symbol in one of the many LaTeX formula listings and replace the symbol with the appropriate command.
  2. use the -r switch to let GladTeX replace the umlauts for you.
PLEASE NOTE: it is impossible to use GladTeX with LuaLaTeX. at the time of writing, dvipng does not support the extended font features of the lualatex engine. rip πŸ™ˆ

🧚 PROJECT HOME 🧚

the project home is at <http://humenda.github.io/GladTeX>. the source can be found at <https://github.com/humenda/gladtex>.

πŸ‘‘ AUTHORS πŸ‘‘

Sebastian Humenda.


and that's the whole page, bestie 🫢 this version of the gladtex(1) manual is dated the 8th of September 2018 β€” go forth and make formula-filled HTML, you absolute icon πŸ’–βœ¨

πŸ“¦ where this page comes from