make4ht

repository·master·Indexed 41 days ago

https://github.com/michal-h21/make4ht

A build system for TeX4ht, the TeX-to-XML converter. It provides a command-line interface to drive the conversion process more efficiently than the standard htlatex script, offering improved directory management, build modes, and extension capabilities via Lua scripts.

Tokens
7.4K
Snippets
24
Records
35
Agent score
1%

What's inside make4ht

  1. Use built-in compilation modes

    master

    make4ht provides built-in modes to change the compilation behavior:

    • draft mode: Invokes ext{LaTeX} only once instead of the default three times. This is useful for quick iterations where cross-references are not critical. Use -um draft.
    • clean mode: Executes the Make:clean() command to remove all generated and temporary files from the current directory. No compilation occurs in this mode. Use -m clean.
    # Fast draft compilation
    $ make4ht -um draft filename.tex
    
    # Clean up generated files (using -a info to see what was removed)
    $ make4ht -m clean -a info filename.tex
  2. Use build files to customize the compilation process

    master

    Build files are Lua scripts that allow you to adjust the build process, such as requesting external applications (BibTeX, Makeindex), passing options, or post-processing files.

    make4ht automatically looks for a file named filename.mk4 (where filename is your input file). You can specify a custom build file using the -e or --build-file flag.

    -- Sample filename.mk4
    Make:htlatex()
    Make:match("html$", "tidy -m -xml -utf8 -q -i ${filename}")
  3. Handle filenames with spaces and non-ASCII characters

    master

    When working with input files, be aware of the following constraints:

    • Spaces: tex4ht cannot handle filenames containing spaces. make4ht automatically mitigates this by replacing spaces in input filenames with underscores. Consequently, generated XML filenames will also use underscores instead of spaces.
    • Non-ASCII characters: If you are generating odt output, avoid using accented or non-ASCII characters in filenames, as the odt output format does not support them.
  4. Access and modify the `mode` variable

    master

    The mode variable contains the value of the --mode command line option. You can use it to execute different build sequences conditionally (e.g., a faster 'draft' mode vs. a full production mode).

    if mode == "draft" then
      Make:htlatex{}
    else
      Make:htlatex{}
      Make:htlatex{}
      Make:htlatex{}
    end
  5. Configure output directories and handling

    master

    You can specify where generated files are placed using the -d or --output-dir option. make4ht will automatically create the directory if it does not exist. Paths can be relative or absolute.

    To ensure proper directory structure preservation (especially for images), use the make4ht output directory routines rather than passing arguments directly to htlatex style strings.

    Recommended usage: make4ht -d <dir> <filename>

    Advanced separation: You can separate auxiliary files from final output files using the -B or --build-dir option. This puts .aux, .4tc, and other temporary files in the build directory, while keeping .html and .css in the output directory.

    # Create output in a specific directory
    $ make4ht -d outputdir filename.tex
    
    # Separate auxiliary files into a 'build' directory
    $ make4ht -B build -d outputdir filename.tex
  6. Adjust the logging level

    master

    By default, make4ht is quiet, showing only status, warnings, and errors. If a compilation fails, you can increase the verbosity using the --loglevel or -a option. Useful levels for debugging include info and debug.

    $ make4ht -a debug faulty.tex
  7. Install make4ht on Unix systems

    master

    To install make4ht on Unix-like systems, use the provided Makefile. By default, it installs to /usr/local/bin. You can specify a custom installation directory using the BIN_DIR variable.

    make
    make install
    
    # To install to a custom directory:
    make install BIN_DIR=~/.local/bin/
  8. Configure global build settings with a configuration file

    master

    You can globally modify build settings using a make4ht configuration file. This allows you to declare new commands, load default filters, specify build sequences, and enable/disable extensions globally.

    File Locations:

    • $HOME/.config/make4ht/config.lua (Global)
    • .make4ht in the current or parent directory (Project-specific, up to $HOME).

    Available Commands in Config Files:

    • Make:enable_extension(name): Requires a specific extension.
    • Make:disable_extension(name): Disables a specific extension.
    • Make:add(name, command): Adds a new command.
    • settings_add { ... }: Adds global settings.
    Make:add("biber", "biber ${input}")
    Make:enable_extension "common_domfilters"
    settings_add {
      tex4ht_sty_par ="=mathml"
    }
  9. Enable or disable extensions via CLI

    master

    You can modify the build process without a build file by using extensions. Extensions are enabled or disabled by appending +EXTENSION or -EXTENSION to the output format name using the -f flag.

    Example: To use the tidy extension with html5 format: $ make4ht -f html5+tidy filename.tex

    Note: In xhtml and html5 formats, the common_domfilters extension is enabled by default. To disable it, use html5-common_domfilters.

    $ make4ht -f html5+tidy filename.tex
    $ make4ht -f html5-common_domfilters filename.tex
  10. Install make4ht on Windows

    master

    On Windows, you can install make4ht by creating a batch file and placing it in a directory that is included in your system PATH. The batch file should invoke texlua with the full path to the make4ht script and pass through all arguments using %*.

    texlua "C:\full\path\to\make4ht" %*