LaTeXML Documentation

repository·master·Indexed 22 days ago

https://github.com/brucemiller/latexml

A 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.

Tokens
5.5K
Snippets
3
Records
32
Agent score
78%

What's inside LaTeXML

  1. Overview of LaTeXML

    master
    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.
  2. Perform multi-pass processing for complex sites

    master

    When 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: Instructs latexmlpost to 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.
  3. Use the latexmlpost CLI tool

    master

    The latexmlpost command is a post-processing tool for XML files generated by latexml. 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>
  4. Use the latexmlmath CLI to convert math expressions

    master

    The latexmlmath command-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.
  5. Use the latexmlc CLI for LaTeX to XML conversion

    master

    The latexmlc command is a client-side tool for LaTeXML that can perform conversions in three modes: stand-alone (local), via a local socket server (using latexmls), or via a remote web service. It automatically attempts to set up a local server using latexmls if necessary.

    By default, latexmlc performs a stand-alone conversion. You can force stand-alone mode by using the --expire=-1 flag. 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.

  6. Use the latexml CLI to convert TeX/LaTeX to XML

    master

    The latexml command is the main entrypoint for transforming TeX/LaTeX files into XML, TeX, or Box formats. By default, it produces XML output and writes it to stdout unless a destination is specified.

    Basic Usage:

    latexml [options] <texfile>

    Reading from Standard Input: If you provide - as the <texfile>, latexml will read the TeX source from stdin.

    Processing BibTeX: If the input file has a .bib extension, latexml automatically processes it as a BibTeX bibliography. You can also force this mode using the --bibtex flag.

    Output Formats:

    • XML (Default): Use --xml to request XML output.
    • TeX: Use --tex to request TeX output after expansion (useful for debugging).
    • Box: Use --box to request Box output after expansion and digestion (useful for debugging).
    latexml [options] I<texfile>
  7. Configure latexmlc client/server connection

    master

    When 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 to 127.0.0.1 if not specified or if set to localhost).
    • --port: The port number for the connection (defaults to 3334 for local connections and 80 for remote connections).
    • --expire: Controls the server expiration. Setting --expire=-1 requests a stand-alone conversion without using a server.
  8. Control latexmlfind output verbosity

    master

    You can control the amount of information latexmlfind prints 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 --verbose is used, the utility may print the raw XML nodes or more detailed context.
  9. Convert math to various formats with latexmlmath

    master

    Use 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.

    FlagAliasDescription
    --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 is 1.75.
  10. Advanced Presentation MathML options

    master

    When 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 than n characters.
    • --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 for mathvariants (double-struck, fraktur, and script). This provides support for older versions of Firefox and MathPlayer if suitable fonts (like STIX) are available.
  11. Reference: latexml CLI options

    master

    Full 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.
  12. Configure latexmlmath processing options

    master

    Use these flags to control how latexmlmath parses and searches for TeX resources.

    FlagDescription
    --preload=fileLoads an optional module or package (e.g., --preload=LaTeX.pool).
    --includestylesAllows processing of raw .sty files (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 Encode package). 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).