LaTeXML Documentation
repository·master·Indexed 22 days ago
https://github.com/brucemiller/latexmlA converter that transforms TeX and LaTeX source files into structured output formats including XML, HTML, MathML, ePub, and JATS. This documentation covers the latexml CLI for general conversion, latexmlc for client/server processing, latexmlfind for searching objects within LaTeXML XML files, and latexmlmath for converting mathematical expressions into MathML, OpenMath, UnicodeMath, XMath, and images.
What's inside LaTeXML
- LaTeXML is a converter designed to transform TeX and LaTeX documents into various structured formats, including XML, HTML, MathML, ePub, and JATS. It is primarily used for converting mathematical and scientific documents into web-friendly or machine-readable formats.
Perform multi-pass processing for complex sites
masterWhen generating a website with multiple documents, use two-pass processing to allow documents to cross-reference each other (IDs, titles, URLs, etc.) and to create a unified index and bibliography.
--prescan: Instructslatexmlpostto first scan documents to extract and store cross-referencing data.--dbfile=<file>: Specifies the filename for the cross-referencing data used during the two-pass process.--sitedirectory=<dir>: Specifies the base directory of the website. Pathnames in the database are stored relative to this directory to ensure portability.
Use the latexmlpost CLI tool
masterThe
latexmlpostcommand is a post-processing tool for XML files generated bylatexml. It is used to perform common tasks such as converting mathematics to images or MathML, processing graphics for the web, and splitting large documents into multiple files.Basic usage:
latexmlpost [options] <xmlfile>If
<xmlfile>is-, the tool reads the XML from standard input.latexmlpost [options] I<xmlfile>Use the latexmlmath CLI to convert math expressions
masterThe
latexmlmathcommand-line tool transforms TeX/LaTeX mathematical expressions into various formats including MathML (Presentation and Content), OpenMath, UnicodeMath, XMath, and images (PNG, SVG).Input Handling:
- If you provide a TeX string as an argument, it is processed directly.
- If you provide
-as the input, the tool reads the TeX from standard input (stdin). - Shell Escaping: Because TeX uses many special characters (like
\or*), you must often quote or slashify your input to prevent the shell from interpreting them. For example, use\\to ensure a single backslash reaches the tool. - Handling Minus Signs: If your math expression starts with a minus sign (e.g.,
-a + b), the shell might interpret it as an option. Use--to signal the end of options, or wrap the expression in curly braces{}.
Output Handling:
- If no conversion option is specified, the tool defaults to outputting Presentation MathML to standard output (stdout).
- If any output destination is set to
-, the result is printed to stdout.
Use the latexmlc CLI for LaTeX to XML conversion
masterThe
latexmlccommand is a client-side tool for LaTeXML that can perform conversions in three modes: stand-alone (local), via a local socket server (usinglatexmls), or via a remote web service. It automatically attempts to set up a local server usinglatexmlsif necessary.By default,
latexmlcperforms a stand-alone conversion. You can force stand-alone mode by using the--expire=-1flag. To use the client/server model, you can specify a remote address and port.Input can be provided as a file path or via STDIN by using
-as the source.Use the latexml CLI to convert TeX/LaTeX to XML
masterThe
latexmlcommand is the main entrypoint for transforming TeX/LaTeX files into XML, TeX, or Box formats. By default, it produces XML output and writes it tostdoutunless a destination is specified.Basic Usage:
latexml [options] <texfile>Reading from Standard Input: If you provide
-as the<texfile>,latexmlwill read the TeX source fromstdin.Processing BibTeX: If the input file has a
.bibextension,latexmlautomatically processes it as a BibTeX bibliography. You can also force this mode using the--bibtexflag.Output Formats:
- XML (Default): Use
--xmlto request XML output. - TeX: Use
--texto request TeX output after expansion (useful for debugging). - Box: Use
--boxto request Box output after expansion and digestion (useful for debugging).
latexml [options] I<texfile>- XML (Default): Use
Configure latexmlc client/server connection
masterWhen communicating with a remote LaTeXML web service or a local daemon, use the following flags to specify the connection details:
--address: The hostname or IP address of the server (defaults to127.0.0.1if not specified or if set tolocalhost).--port: The port number for the connection (defaults to3334for local connections and80for remote connections).--expire: Controls the server expiration. Setting--expire=-1requests a stand-alone conversion without using a server.
Control latexmlfind output verbosity
masterYou can control the amount of information
latexmlfindprints to the terminal using the following flags:--quiet: Suppresses messages. This flag can be repeated to increase silence.--verbose: Increases the amount of information provided. This flag can be repeated to increase verbosity (e.g., to see the exact XPath used or to get more detailed output when errors occur).
Output Behavior:
- By default, matches are printed to
stdout. - The utility uses UTF-8 encoding for output.
- If
--verboseis used, the utility may print the raw XML nodes or more detailed context.
Convert math to various formats with latexmlmath
masterUse the following flags to specify the desired output format. For most formats, providing a filename will save the output to that file; using
-will print it to stdout.Flag Alias Description --mathimage=fileConverts to PNG images (supports .png,.gif,.jpg,.jpeg,.svg).--mathsvg=fileConverts to SVG images. --presentationmathml=file--pmml=fileConverts to Presentation MathML (Default). --contentmathml=file--cmml=fileConverts to Content MathML (Partially implemented). --openmath=file--om=fileConverts to OpenMath (Partially implemented). --unicodemath=fileConverts to UnicodeMath (unstructured Unicode string). --XMath=fileOutputs LaTeXML's internal format. Image Options:
--magnification=factor: Specifies the magnification factor for math images. Default is1.75.
Advanced Presentation MathML options
masterWhen generating Presentation MathML (
--pmml), you can use these specific flags to control the output structure and character encoding:--linelength=n: (Experimental) Line-breaks the generated Presentation MathML so that it is no longer thanncharacters.--plane1: Converts the content of Presentation MathML token elements to the appropriate Unicode Plane-1 codepoints according to the selected font, when applicable.--hackplane1: Converts the content of Presentation MathML token elements to the appropriate Unicode Plane-1 codepoints formathvariants(double-struck, fraktur, and script). This provides support for older versions of Firefox and MathPlayer if suitable fonts (like STIX) are available.
Reference: latexml CLI options
masterFull list of available command-line options for
latexml:--destination=file sets destination file (default stdout). --output=file [obsolete synonym for --destination] --preload=module requests loading of an optional module; can be repeated --preamble=file sets a preamble file which will effectively be prepended to the main file. --postamble=file sets a postamble file which will effectively be appended to the main file. --includestyles allows latexml to load raw *.sty file; by default it avoids this. --path=dir adds to the paths searched for files, modules, etc; --log=file specifies log file (default is file named after job name) --documentid=id assigns an id to the document root. --quiet suppress messages (can repeat) --verbose more informative output (can repeat) --strict makes latexml less forgiving of errors --bibtex processes as a BibTeX bibliography. --xml requests xml output (default). --tex requests TeX output after expansion. --box requests box output after expansion and digestion. --noparse suppresses parsing math --nocomments omit comments from the output --inputencoding=enc specify the input encoding. --VERSION shows version number. --debug=package enables debugging output for the named package. --help shows this help message.Configure latexmlmath processing options
masterUse these flags to control how
latexmlmathparses and searches for TeX resources.Flag Description --preload=fileLoads an optional module or package (e.g., --preload=LaTeX.pool).--includestylesAllows processing of raw .styfiles (normally ignored).--path=dirAdds a directory to the search path for files, modules, and style files (can be repeated). --noparseDisables parsing of math (not useful for cMML or OpenMath). --strictEnables strict mode; undefined control sequences or invalid constructs become fatal errors instead of warnings. --inputencoding=encSpecifies the input encoding (must be known to Perl's Encodepackage). Output is always UTF-8.--documentid=idAssigns an ID to the root element of the XML document. --debug=packageEnables debugging for a specific package (omit the LaTeXML::prefix).--quietReduces verbosity (can be repeated). --verboseIncreases verbosity (can be repeated).