### Draft vs. Full Build Example
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
This example illustrates how to conditionally perform a quick preview build ('draft' mode) or a full build including bibliography processing.
```lua
if mode == "draft" then
-- Quick preview build
Make:htlatex {}
Make:tex4ht {}
Make:t4ht {}
else
-- Full build with bibliography
Make:htlatex {}
Make:biber {}
Make:htlatex {}
Make:htlatex {}
Make:tex4ht {}
Make:t4ht {}
end
```
--------------------------------
### Multi-Compilation Build Example
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
This example demonstrates a multi-compilation build process for complex documents, ensuring stability by recompiling multiple times.
```lua
local status = 0
for i = 1, 3 do
status = Make:htlatex {}
if status ~= 0 then break end
end
if status == 0 then
Make:tex4ht {}
Make:t4ht {}
end
```
--------------------------------
### Bibliography-Aware Build Example
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
This snippet shows a build process that correctly handles bibliographies by performing multiple compilation steps.
```lua
Make:htlatex {}
Make:biber {}
Make:htlatex {}
Make:htlatex {}
Make:tex4ht {}
Make:t4ht {}
```
--------------------------------
### Mathematics Rendering Configuration
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/configuration-files.md
Configure mathematics rendering options. This example shows how to enable MathML with a MathJax fallback. Another example demonstrates SVG rendering with caching for equations.
```tex
\Preamble{xhtml,mathml,mathjax}
% Use MathML with MathJax fallback
\begin{document}
\EndPreamble
```
```tex
\Preamble{xhtml,pic-m,pic-equation,svg}
\begin{document}
\EndPreamble
```
--------------------------------
### Make htlatex with Input and Arguments
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
Example of calling Make:htlatex with specific input and additional LaTeX arguments, such as '-interaction=nonstopmode'.
```lua
Make:htlatex {
input = "myfile",
latex_args = "-interaction=nonstopmode"
}
```
--------------------------------
### Modern Responsive Website Configuration
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/css-and-javascript.md
This example configures a modern responsive website with linked stylesheets, inline critical CSS, media queries for different screen sizes, and a JavaScript snippet for theme initialization.
```tex
\Preamble{xhtml,fn-in,mathml}
% Link stylesheets
\Configure{AddCss}{styles.css}
\Configure{AddJs}{app.js}
% Inline critical styles
\Css{
html {
box-sizing: border-box;
scroll-behavior: smooth;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
font-family: system-ui, sans-serif;
line-height: 1.6;
color: #333;
}
}
% Responsive design
\CssMediaQueryStart{screen}{min-width: 768px}
\Css{
body { font-size: 16px; }
.container { max-width: 900px; margin: 0 auto; }
}
\CssMediaQueryEnd
\CssMediaQueryStart{screen}{max-width: 767px}
\Css{
body { font-size: 14px; }
nav { display: none; }
}
\CssMediaQueryEnd
% Dark mode
\CssMediaQueryStart{}{prefers-color-scheme: dark}
\Css{
body { background: #1a1a1a; color: #f0f0f0; }
a { color: #64b5f6; }
}
\CssMediaQueryEnd
\begin{document}
\JavaScript
// Initialize theme
document.addEventListener("DOMContentLoaded", function() {
var savedTheme = localStorage.getItem("theme");
if (savedTheme) {
document.documentElement.setAttribute("data-theme", savedTheme);
}
});
\EndJavaScript
\EndPreamble
```
--------------------------------
### Integrate with Custom Workflows
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-command.md
Configure make4ht for automated builds or CI by specifying output directory, format, and verbosity level. This example outputs to 'output/', uses HTML5, and shows warnings.
```bash
make4ht -d output -f html5 -a warning filename.tex "info"
```
--------------------------------
### E-Book Configuration with JavaScript
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/css-and-javascript.md
This example configures an e-book with a responsive viewport meta tag and optimized CSS. It includes a JavaScript snippet to detect e-reader user agents and adjust font size accordingly.
```tex
\Preamble{xhtml,javascript,fn-in}
% Set viewport for e-readers
\Configure{@HEAD}
{\HCode{\Hnewline}}
% E-book optimized styling
\Css{
body { font-size: 1em; line-height: 1.5; }
img { max-width: 100%; }
h1 { page-break-before: always; }
}
\begin{document}
\JavaScript
// Detect e-reader environment
var isEbook = /\b(Kindle|Kobo|nook|Tolino|Sony Reader)\b/i.test(navigator.userAgent);
if (isEbook) {
document.body.style.fontSize = "larger";
}
\EndJavaScript
\EndPreamble
```
--------------------------------
### Format-Specific Configuration Files for make4ht
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/advanced-features.md
This example shows how to invoke make4ht with different configuration files for various output formats (HTML5, EPUB3, ODT). Each config file specifies preamble and options tailored to the target format.
```bash
# Different configs for different formats
make4ht -c config-html5.cfg -f html5 doc.tex
make4ht -c config-epub.cfg -f epub3 doc.tex
make4ht -c config-odt.cfg -f odt doc.tex
```
```tex
% Config files:
% config-html5.cfg
\Preamble{xhtml,fn-in,mathjax}
...
% config-epub.cfg
\Preamble{xhtml,fn-in,mathml}
...
% config-odt.cfg
\Preamble{xhtml}
...
```
--------------------------------
### Conditional Bibliography Processing Example
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
This example shows conditional bibliography processing based on a 'mode' variable, offering a quick build for 'draft' and a full build with bibtex for other modes.
```lua
if mode == "draft" then
Make:htlatex {}
else
Make:htlatex {}
Make:bibtex {}
Make:htlatex {}
Make:htlatex {}
end
```
--------------------------------
### Configure Custom List Environment
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-configuration-commands.md
Use \ConfigureList to define custom list environments. This example configures a list named \texttt{mylist} with specific tags for the list and its items.
```tex
\ConfigureList{mylist}
{\HCode{
}}
{\HCode{
}}
{\HCode{
}}
{\HCode{
}}
```
--------------------------------
### Academic Paper Configuration
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/css-and-javascript.md
This example configures an academic paper with specific CSS for article layout, headings, abstract, and tables. It includes necessary preamble options for math rendering.
```tex
\Preamble{xhtml,mathml,mathjax}
\Css{
article {
max-width: 8.5in;
margin: 0 auto;
padding: 0.5in;
font-family: "Georgia", serif;
}
h1 { font-size: 2em; text-align: center; }
h2 { font-size: 1.5em; margin-top: 1em; }
.abstract {
border: 1px solid #ccc;
padding: 1em;
background: #f9f9f9;
margin: 1em 0;
}
table {
border-collapse: collapse;
width: 100%;
margin: 1em 0;
}
th, td {
border: 1px solid #ddd;
padding: 0.5em;
text-align: left;
}
}
\begin{document}
\EndPreamble
```
--------------------------------
### Configure Quote Environment
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-configuration-commands.md
Use \ConfigureEnv to define how a specific LaTeX environment is rendered. This example sets the \texttt{quote} environment to use \texttt{
} and \texttt{
}.
```tex
\ConfigureEnv{quote}
{\HCode{
}}
{\HCode{
}}
{}{}
```
--------------------------------
### GitHub Actions CI Workflow for Building Documentation
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/advanced-features.md
This snippet shows a GitHub Actions workflow to automate the building of documentation using tex4ht. It installs dependencies, builds the documentation, and uploads the output as an artifact.
```yaml
name: Build Documentation
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: apt-get install -y texlive texlive-latex-extra
- name: Build with make4ht
run: make4ht -d output -f html5 doc.tex
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: documentation
path: output/
```
--------------------------------
### Pass LaTeX Compiler Options
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-command.md
Specify options for the LaTeX engine by using the fourth quoted argument. This example sets the interaction mode to 'nonstopmode'.
```bash
make4ht filename.tex "" "" "" "-interaction=nonstopmode"
```
--------------------------------
### tex4ht Start and End Block Elements
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-configuration-commands.md
Commands to start and end block-level elements, applying configured tags and properties. Additional dynamic attributes can be provided when starting the block.
```tex
\BlockElementStart{maketitle}{id="page-header"}
..content..
\BlockElementEnd{maketitle}
```
--------------------------------
### Add Custom CSS
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/README.md
A tex4ht configuration file that includes custom CSS for styling the output. This example sets a maximum width for the body and centers the content.
```tex
\Preamble{xhtml}
\Css{body { max-width: 70ch; margin: 0 auto; }}
\begin{document}
\EndPreamble
```
--------------------------------
### Configure Document Head Hook
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-configuration-commands.md
Use \Configure to insert code into specific configuration hooks. This example inserts a meta tag into the \{@HEAD\} hook.
```tex
\Configure{@HEAD}
{\HCode{\Hnewline}}
```
--------------------------------
### Configuring Environment Tags for Paragraphs
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-conversion-process.md
Properly configure environment tags to control paragraph handling in the output. This example shows how to use '\Configure{environment}' to wrap content in '
' tags and manage paragraphs.
```tex
% Use proper paragraph control
\Configure{environment}
{\ifvmode\IgnorePar\fi\EndP\HCode{
}\par\ShowPar}
{\ifvmode\IgnorePar\fi\EndP\HCode{
}}
```
--------------------------------
### Custom Command Rendering
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/configuration-files.md
Define how custom LaTeX commands are rendered in the output. This example shows how to wrap content from a custom command \mycommand with specific HTML span tags.
```tex
\Preamble{xhtml}
\Configure{mycommand}
{\HCode{}}
{\HCode{}}
\begin{document}
\EndPreamble
```
--------------------------------
### Configuring Chapter Markup with \HCode
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-conversion-process.md
Shows how \HCode is used within LaTeX configuration files to insert specific HTML/XML markup into the output. This example configures chapter tags.
```tex
\Configure{chapter}
{\HCode{}\IgnorePar}
{\HCode{}}
```
--------------------------------
### Conditional Configuration Based on Option
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-configuration-commands.md
Use \ifOption to conditionally apply configurations based on whether a tex4ht option is active. This example configures \texttt{picture} handling differently for \texttt{svg} and non-\texttt{svg} options.
```tex
\ifOption{svg}
{\Configure{picture}{\HCode{}}}
{\Configure{picture}{\HCode{Theorem: }}
{\HCode{
}}
{}
\ConfigureEnv{lemma}
{\HCode{
Lemma: }}
{\HCode{
}}
{}
\ConfigureEnv{proof}
{\HCode{
Proof: }}
{\HCode{
}}
{}
\Css{
.theorem, .lemma, .proof {
border-left: 4px solid blue;
padding-left: 1em;
margin: 1em 0;
}
}
```
--------------------------------
### Generate Documentation/Wiki-Like Output
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/advanced-features.md
Creates static site output suitable for documentation or wikis. Includes CSS links and Jekyll frontmatter comments for site generation.
```bash
make4ht -f html5+staticsite filename.tex "3,sec-filename"
```
```tex
\Preamble{xhtml,3,sec-filename}
\Configure{@HEAD}
{\HCode{\Hnewline}}
% Add Jekyll frontmatter comments
\Configure{@/BODY}
{\HCode{}}
\begin{document}
\EndPreamble
```
--------------------------------
### Step-by-Step Verification of tex4ht Build Process
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/advanced-features.md
This sequence of commands outlines a manual step-by-step verification process for a tex4ht build. It includes LaTeX compilation, checking the DVI output, running tex4ht, and inspecting the final HTML.
```bash
# Step 1: LaTeX compilation
pdflatex doc.tex
# Step 2: Check DVI
file doc.dvi
# Step 3: tex4ht processing
tex4ht doc
# Step 4: Check output
head doc.html
```
--------------------------------
### Configure Blog Post Article and Header
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Maps the 'article' environment to HTML article tags and 'maketitle' to a header with a 'post-header' class for blog posts.
```tex
\ConfigureEnv{article}
{\HCode{}}
{\HCode{}}
{}
\Configure{maketitle}
{\HCode{}}
{\HCode{}}
\Css{
article { max-width: 60ch; margin: 0 auto; }
header.post-header { margin-bottom: 2em; }
}
```
--------------------------------
### Environment-Specific Configurations
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/configuration-files.md
Customize the HTML rendering of specific LaTeX environments like 'verbatim' or 'quote'. This involves defining the start and end tags for the environment's HTML representation.
```tex
\Preamble{xhtml}
% Configure code samples
\ConfigureEnv{verbatim}
{\HCode{
}}
{}{}
\begin{document}
\EndPreamble
```
--------------------------------
### Use Custom Configuration File
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-command.md
Specifies a custom configuration file (e.g., mycfg.cfg) for the build process using the -c option.
```bash
make4ht -c mycfg.cfg filename.tex
```
--------------------------------
### Configure Display Math Alternatives
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Offers two configurations for the 'equation*' environment: one for inline display math using a span and another for block display math using a div, both with the 'display-math' class.
```tex
% Display equations inline
\Configure{equation*}
{\HCode{}}
{\HCode{}}
% Or as block elements
\Configure{equation*}
{\HCode{
}}
{\HCode{
}}
```
--------------------------------
### Configure Equation Environments for MathML and Picture Rendering
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Provides two configurations for the 'equation' environment: one for MathML output and another for picture-based rendering, both using a 'div' with class 'equation'.
```tex
% For MathML output
\Configure{equation}
{\HCode{
}}
{\HCode{
}}
% For picture-based rendering
\Configure{equation}
{\HCode{
}\IgnorePar}
{\IgnorePar\HCode{
}\ShowPar}
```
--------------------------------
### Viewing First 50 Lines of HTML Output
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-conversion-process.md
Inspect the generated HTML file to understand its structure by viewing the first 50 lines using the 'cat' and 'head' commands.
```bash
cat filename.html | head -50
```
--------------------------------
### tex4ht New Logical Block Definition
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-configuration-commands.md
Creates a new logical block with a specified identifier, used for semantic HTML5 structuring. Examples show defining blocks for text emphasis and document titles.
```tex
\NewLogicalBlock{textit}
\NewLogicalBlock{maketitle}
```
--------------------------------
### Set Global Configuration Variables
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
Illustrates setting global variables like 'current_file' and 'output_format' that persist across Make command calls.
```lua
-- These persist across Make command calls
current_file = "output.html"
output_format = "html5"
```
--------------------------------
### Defining Configuration Hooks for Commands
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-conversion-process.md
Define hooks within configuration commands to insert custom code before and after original command logic. This example shows how to insert HTML tags around a chapter title.
```tex
\Configure{chapter}
{\HCode{
}} % Hook 1: before chapter
{\HCode{
}} % Hook 2: after chapter
```
--------------------------------
### Sequential Build Steps
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
Executes the standard make4ht build steps sequentially: LaTeX compilation, tex4ht processing, and t4ht image/CSS generation.
```lua
Make:htlatex {} -- Step 1: Compile with LaTeX
Make:tex4ht {} -- Step 2: Extract to XML
Make:t4ht {} -- Step 3: Generate images
```
--------------------------------
### Define Options in Configuration File
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-options.md
Specify tex4ht conversion options within a LaTeX preamble using the \Preamble command. The first option must be an output format like xhtml or html5.
```tex
\Preamble{xhtml,fn-in,pic-m,svg}
...
\begin{document}
\EndPreamble
```
--------------------------------
### CSS Media Queries with \CssMediaQueryStart and \CssMediaQueryEnd
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/css-and-javascript.md
Use \CssMediaQueryStart and \CssMediaQueryEnd to define CSS media queries for responsive design. This allows styles to adapt to different screen sizes or media types.
```tex
\Preamble{xhtml}
\CssMediaQueryStart{screen}{max-width: 600px}
\Css{body { font-size: 14px; }}
\Css{h1 { font-size: 1.5em; }}
\CssMediaQueryEnd
\CssMediaQueryStart{print}{all}
\Css{body { color: black; background: white; }}
\Css{a { color: black; text-decoration: underline; }}
\CssMediaQueryEnd
\begin{document}
\EndPreamble
```
```css
@media screen and (max-width: 600px) {
body { font-size: 14px; }
h1 { font-size: 1.5em; }
}
@media print {
body { color: black; background: white; }
a { color: black; text-decoration: underline; }
}
```
--------------------------------
### tex4ht Configuration File Wrapper
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-configuration-commands.md
Use \Preamble{xhtml,...options}...\EndPreamble to wrap configuration code. The first option must be 'xhtml' or 'html5'.
```tex
\Preamble{xhtml,...options}...
\EndPreamble
```
--------------------------------
### Minimal tex4ht Configuration
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/configuration-files.md
The simplest valid configuration enables XHTML output without any additional customization. It requires the \Preamble command and the \EndPreamble marker.
```tex
\Preamble{xhtml}
\begin{document}
\EndPreamble
```
--------------------------------
### Apply Format Extensions with Make4ht
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/output-formats.md
Use format extensions with make4ht by appending them to the format flag using '+' for inclusion or '-' for exclusion. For example, to use the tidy HTML validator or cache math SVGs.
```bash
make4ht -f html5+tidy filename.tex # Use tidy HTML validator
make4ht -f html5+dvisvgm_hashes filename.tex # Cache math SVG
make4ht -f html5-staticsite filename.tex # Disable static site generation
```
--------------------------------
### Custom Configuration File
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/README.md
Uses a specified configuration file (e.g., config.cfg) to customize the conversion process. This allows for fine-grained control over output and features.
```bash
# Use custom config file
make4ht -c config.cfg filename.tex
```
--------------------------------
### Load tex4ht Configuration File
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-configuration-commands.md
Use \Hinput{filename} to load a configuration file with the .4ht extension.
```tex
\Hinput{filename}
```
--------------------------------
### Minimal Build File Structure
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
A basic make4ht build file consists of Lua code, typically invoking Make:htlatex.
```lua
-- This is a comment
Make:htlatex {}
```
--------------------------------
### Configure Figure and Caption Environments
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Configures 'figure' environment for figures and 'caption' command for captions, rendering them as HTML5 figure and figcaption elements. Includes CSS for styling.
```tex
\ConfigureEnv{figure}
{\HCode{}\IgnorePar}
{\IgnorePar\HCode{}\ShowPar}
{}
\Configure{caption}
{\HCode{}}
{\HCode{}}
\Css{
figure { margin: 1em 0; text-align: center; }
figcaption { font-style: italic; font-size: 0.9em; }
}
```
--------------------------------
### Configure Environment for Preformatted Text with CSS Class
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Maps the 'verse' environment to HTML pre tags with a 'verse' CSS class for preformatted text.
```tex
\ConfigureEnv{verse}
{\HCode{
}}
{\HCode{
}}
{}{}
\Css{
pre.verse {
font-family: serif;
white-space: pre-wrap;
}
}
```
--------------------------------
### Configure Multi-Column Layout Environment
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Maps the 'multicols' environment to a div with a 'columns' CSS class for multi-column layouts.
```tex
\ConfigureEnv{multicols}
{\HCode{
}}
{\HCode{
}}
{}{}
\Css{
.columns {
column-count: 2;
column-gap: 2em;
}
@media (max-width: 600px) {
.columns { column-count: 1; }
}
}
```
--------------------------------
### Combine Make4ht Options with Formats
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/output-formats.md
Pass specific options to formats by providing them as a comma-separated string after the format flag. This allows for fine-tuning output like image handling or bibliography processing.
```bash
# HTML5 with specific options
make4ht -f html5 filename.tex "pic-m,svg,mathjax"
# ODT with bibliography degraded for Word
make4ht -f odt filename.tex "bib-,endnotes"
```
--------------------------------
### Testing tex4ht Configuration Separately
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/advanced-features.md
This command allows you to test a specific tex4ht configuration file, such as 'compat.tex', using pdflatex. It helps isolate and verify configuration settings before integrating them into the main build.
```bash
pdflatex -halt-on-error '\input' compat.tex
```
--------------------------------
### Optimize for E-Book Output
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/advanced-features.md
Uses tex4ebook to create EPUB3 files, optimizing content for e-readers. Configures viewport settings and applies CSS for responsive e-book display.
```bash
tex4ebook -f epub3 filename.tex "mathml,2"
```
```tex
\Preamble{xhtml,mathml,fn-in}
% Viewport for e-readers
\Configure{@HEAD}
{\HCode{\Hnewline}}
% Optimize for e-reader screens
\Css{
body {
font-size: 1em;
line-height: 1.5;
margin: 0;
padding: 0.5em;
}
img {
max-width: 100%;
height: auto;
}
h1 { page-break-before: always; }
}
\begin{document}
\EndPreamble
```
--------------------------------
### Conditional Math Configuration (Pictures vs. MathML)
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Conditionally configures math output based on the 'pic-m' option, switching between image-based math and MathML.
```tex
\ifOption{pic-m}
{
% Math as pictures
\Configure{$
{\HCode{}
}
{
% MathML output
\Configure{$}{\HCode{}}
}
```
--------------------------------
### Styling Environments with \ConfigureEnv
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/css-and-javascript.md
Use \ConfigureEnv to wrap environments like \texttt{quote} in custom HTML tags with classes. This enables styling of entire blocks of content.
```tex
\Preamble{xhtml}
\ConfigureEnv{quote}
{\HCode{
}}
{\HCode{
}}
{}{}
\Css{blockquote.pullquote {
border-left: 4px solid blue;
padding-left: 1em;
font-style: italic;
}}
\begin{document}
\EndPreamble
```
--------------------------------
### Configure graphicx Package for Images
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Sets up HTML image tags for the graphicx package's \includegraphics command.
```tex
\Configure{includegraphics}
{\HCode{}}
```
--------------------------------
### Configure hyperref Package for Links
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Sets up HTML anchor tags for the hyperref package's \href command.
```tex
\Configure{href}
{\HCode{}}
{\HCode{}}
```
--------------------------------
### Configure Presentation Slide Environment
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Maps the 'frame' environment to section tags with a 'slide' CSS class for presentation slides.
```tex
\ConfigureEnv{frame}
{\HCode{}\IgnorePar\ShowPar}
{\IgnorePar\HCode{}\ShowPar}
{}{}
\Css{
section.slide {
border: 1px solid #ccc;
padding: 2em;
margin: 1em 0;
page-break-inside: avoid;
}
}
```
--------------------------------
### Generate Simple Web Document
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/README.md
Command to generate a simple web document from a LaTeX file using a custom configuration file. This command produces an HTML file and a CSS file.
```bash
make4ht -c web.cfg article.tex
# Generates: article.html, article-css.css
```
--------------------------------
### Execute tex4ht Post-Processor
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
Runs the tex4ht post-processor on the DVI file.
```lua
Make:tex4ht {}
```
--------------------------------
### Basic make4ht Command Syntax
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-command.md
The fundamental structure for invoking make4ht. It includes the main command, optional global flags, the input LaTeX file, and optional arguments for different processing stages.
```bash
make4ht [OPTIONS] filename.tex ["tex4ht-options"] ["tex4ht-post-options"] ["t4ht-options"] ["latex-options"]
```
--------------------------------
### Use Custom Lua Build File
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-command.md
Employs a custom Lua build file (e.g., custom.mk4) for advanced build script customization using the -e option.
```bash
make4ht -e custom.mk4 filename.tex
```
--------------------------------
### Loading tex4ht.sty in LaTeX
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-conversion-process.md
Demonstrates how to load the tex4ht.sty package in a LaTeX document to enable conversion support. The package should be loaded early.
```tex
\documentclass{article}
% tex4ht.sty is loaded first
\usepackage[options]{tex4ht}
\begin{document}
...
\end{document}
```
--------------------------------
### Generate E-Book with Math
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/README.md
Command to generate an e-book in EPUB3 format with MathML and MathJax support. This is useful for academic or technical documents containing mathematical equations.
```bash
tex4ebook -f epub3 book.tex "mathml,mathjax"
# Generates: book.epub3
```
--------------------------------
### Configure Verbatim and Code Environments
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Configures 'verbatim' environment for preformatted code blocks and 'verb' command for inline code. Includes CSS for styling code blocks.
```tex
\ConfigureEnv{verbatim}
{\HCode{
}}
{\HCode{
}}
{}
\Configure{verb}
{\HCode{}\NoFonts}
{\EndNoFonts\HCode{}}
\Css{
pre { background: #f5f5f5; padding: 1em; overflow-x: auto; }
code { font-family: monospace; }
}
```
--------------------------------
### Generate EPUB and AZW3 Simultaneously
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/output-formats.md
Convert a TeX file to both EPUB3 and AZW3 formats by running the tex4ebook command twice with different format flags.
```bash
# Convert once, produce both EPUB and AZW3
tex4ebook -f epub3 mybook.tex
tex4ebook -f azw3 mybook.tex
```
--------------------------------
### Access Environment Variables
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
Demonstrates how to access environment variables like TEXMFHOME and TMPDIR/TEMP within make4ht build files.
```lua
local texmf = os.getenv("TEXMFHOME")
local temp = os.getenv("TMPDIR") or os.getenv("TEMP")
```
--------------------------------
### Configure Cross-Links Navigation
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Sets up HTML navigation for previous, next, and up links using the \Configure{crosslinks} hook.
```tex
% Six hooks for cross-linking
\Configure{crosslinks}
{\HCode{}} % End nav
```
--------------------------------
### Requesting Configuration Files with make4ht
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/configuration-files.md
Use the -c option with make4ht to specify configuration files. This can be a basename, a relative path, or an absolute path.
```bash
make4ht -c mycfg.cfg myfile.tex
```
```bash
make4ht -c config.cfg file.tex
```
```bash
make4ht -c configs/custom.cfg file.tex
```
```bash
make4ht -c /path/to/config.cfg file.tex
```
--------------------------------
### Enable Debug Output for Troubleshooting
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-command.md
Use the '-a debug' option to enable detailed debug output, which is recommended for diagnosing issues and reporting bugs.
```bash
make4ht -a debug filename.tex
```
--------------------------------
### Configure List Environments
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Configures standard list environments (itemize, enumerate, description) to render as their corresponding HTML tags (ul, ol, dl).
```tex
\ConfigureList{itemize}
{\HCode{
}}
```
--------------------------------
### Configure Sectioning Commands
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Configures 'chapter', 'section', and 'subsection' commands to render as section elements with corresponding classes. Uses IgnorePar/ShowPar for proper paragraph handling.
```tex
\Configure{chapter}
{\HCode{}\IgnorePar}
{\IgnorePar\HCode{}\ShowPar}
\Configure{section}
{\HCode{}\IgnorePar}
{\IgnorePar\HCode{}\ShowPar}
\Configure{subsection}
{\HCode{}\IgnorePar}
{\IgnorePar\HCode{}\ShowPar}
```
--------------------------------
### Post-process with Tidy
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-command.md
Applies the Tidy HTML cleaner after the primary conversion to HTML5. The format is specified as 'html5+tidy'.
```bash
make4ht -f html5+tidy filename.tex
```
--------------------------------
### Standard Build Process Invocation
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
Invokes the standard tex4ht build steps: LaTeX compilation, tex4ht processing, and t4ht processing.
```lua
Make:htlatex {}
Make:tex4ht {}
Make:t4ht {}
```
--------------------------------
### Error Handling for Build Steps
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
Checks the return status of the Make:htlatex command. If it fails (non-zero status), prints an error message and returns the status, preventing further execution.
```lua
local status = Make:htlatex {}
if status ~= 0 then
print("LaTeX compilation failed!")
return status
end
Make:tex4ht {}
Make:t4ht {}
```
--------------------------------
### HTML5 to PDF Conversion Pipeline
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/output-formats.md
Convert HTML5 output to PDF using an external tool like wkhtmltopdf after the initial TeX to HTML5 conversion.
```bash
# HTML5 -> PDF (external tool)
make4ht -f html5 doc.tex
wkhtmltopdf doc.html doc.pdf
```
--------------------------------
### Configure color Package for Text Color
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Sets up HTML span tags with inline styles for the color package.
```tex
\Configure{color}
{\HCode{}}
{\HCode{}}
```
--------------------------------
### Read File Content
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
Demonstrates standard Lua file I/O to open a file in read mode, read its entire content, and close the file handle.
```lua
local f = io.open("filename.txt", "r")
if f then
local content = f:read("*all")
f:close()
end
```
--------------------------------
### Define and Use Custom Command
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
Defines a custom 'myhtlatex' command that recompiles if checksums change, with a limit on compilations. It then invokes this custom command.
```lua
local htlatex = require "make4ht-htlatex"
local md5 = require "md5"
local function get_checksum(main_file, extensions)
local checksum = ""
local extensions = extensions or {"aux", "4tc", "xref"}
for _, ext in ipairs(extensions) do
local f = io.open(main_file .. "." .. ext, "r")
if f then
local content = f:read("*all")
f:close()
checksum = md5.sumhexa(checksum .. content)
end
end
return checksum
end
Make:add("myhtlatex", function(par)
local checksum = get_checksum(par.input)
local status = htlatex.htlatex(par)
if status ~= 0 then return status end
local newchecksum = get_checksum(par.input)
local compilation_count = 1
local max_compilations = 3
while checksum ~= newchecksum do
if compilation_count > max_compilations then return status end
status = htlatex.htlatex(par)
if status ~= 0 then return status end
checksum = newchecksum
newchecksum = get_checksum(par.input)
compilation_count = compilation_count + 1
end
return status
end)
Make:myhtlatex {}
```
--------------------------------
### Create Multi-Column Layouts with CSS
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/advanced-features.md
Implements multi-column layouts using CSS for different screen sizes. Defines a 'columns' class for two-column layouts on larger screens and single-column on smaller ones.
```tex
\Preamble{xhtml}
\ConfigureEnv{multicols}
{\HCode{
}}
{\HCode{
}}
{}{}
\CssMediaQueryStart{screen}{min-width: 768px}
\Css{.columns { column-count: 2; column-gap: 2em; }}
\CssMediaQueryEnd
\CssMediaQueryStart{screen}{max-width: 767px}
\Css{.columns { column-count: 1; }}
\CssMediaQueryEnd
\begin{document}
\EndPreamble
```
--------------------------------
### Generate Presentation Slides with JavaScript
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/advanced-features.md
Converts documents into presentation slides with basic JavaScript navigation. Configures slide frames and applies CSS for presentation layout.
```bash
make4ht -f html5 filename.tex "2,javascript"
```
```tex
\Preamble{xhtml,javascript}
\ConfigureEnv{frame}
{\HCode{}\IgnorePar\ShowPar}
{\IgnorePar\HCode{}\ShowPar}
{}{}
\Css{
section.slide {
page-break-inside: avoid;
border: 1px solid #ccc;
margin: 1em 0;
padding: 2em;
clear: both;
}
}
\begin{document}
\JavaScript
// Slide navigation
document.addEventListener("keydown", function(e) {
if (e.key === "ArrowRight") {
window.location = location.pathname + "?slide=" + (currentSlide + 1);
}
});
\EndJavaScript
\EndPreamble
```
--------------------------------
### Running tex4ht for Post-Processing
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-conversion-process.md
The command to initiate the tex4ht post-processing stage, which parses the DVI file and generates intermediate output like XML or HTML.
```bash
tex4ht filename
```
--------------------------------
### HTML5 to EPUB Conversion Pipeline
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/output-formats.md
Convert HTML5 output to EPUB3 using an external tool like Pandoc after the initial TeX to HTML5 conversion.
```bash
# HTML5 -> EPUB (Pandoc)
make4ht -f html5 doc.tex
pandoc -f html -t epub3 doc.html -o doc.epub3
```
--------------------------------
### Enable Frames Layout
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-command.md
Configures the output to use a frames layout, often with multiple columns, by passing 'frames' as a tex4ht option.
```bash
make4ht filename.tex "frames"
```
--------------------------------
### Configure Technical Documentation Description List
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Maps the 'description' environment to definition lists (dl, dt, dd) with specific CSS classes for technical documentation.
```tex
\ConfigureEnv{description}
{\HCode{
}}
{\HCode{
}}
{\HCode{
}}
{\HCode{
}}
\Css{
dl.reference dt { font-weight: bold; margin-top: 1em; }
dl.reference dd { margin-left: 2em; margin-bottom: 0.5em; }
}
```
--------------------------------
### Enabling Draft Mode for Faster Builds
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/tex4ht-conversion-process.md
Use the '-m draft' option with make4ht to skip non-essential compilation steps, significantly speeding up build times for large documents.
```bash
make4ht -m draft filename.tex # Skip non-essential steps
```
--------------------------------
### Correct Paragraph Nesting with IgnorePar and ShowPar
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Demonstrates the correct usage of \IgnorePar and \ShowPar to manage paragraph nesting and prevent improper tag generation.
```tex
% Wrong: paragraph tags may nest improperly
\ConfigureEnv{example}{\HCode{
}}{\HCode{
}}{}
% Right: explicit paragraph control
\ConfigureEnv{example}
{\ifvmode\IgnorePar\fi\EndP\HCode{
}\par\ShowPar}
{\ifvmode\IgnorePar\fi\EndP\HCode{
}}
{}{}
```
--------------------------------
### Generate HTML5 Output with make4ht
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/output-formats.md
Generate HTML5 output, which is the default format. You can specify it explicitly or let make4ht use it by default.
```bash
make4ht filename.tex # Default: html5
```
```bash
make4ht -f html5 filename.tex # Explicit
```
--------------------------------
### Return Non-Zero for Failure
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
Explains the return value convention for build files, where returning a non-zero value indicates failure to make4ht.
```lua
if failed_condition then
return 1 -- Indicate failure to make4ht
end
-- Implicit return 0 on success
```
--------------------------------
### Render Math with MathJax and MathML Fallback
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/advanced-features.md
Enables MathJax for rendering mathematical content in HTML and provides a MathML fallback. Configure CSS for math element styling.
```bash
make4ht filename.tex "mathml,mathjax"
```
```tex
\Preamble{xhtml,mathml,mathjax}
\Css{.math { font-size: 1.1em; }}
\begin{document}
\EndPreamble
```
--------------------------------
### Graphics Configuration
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/configuration-files.md
Configure graphics extensions and dimensions. \DeclareGraphicsExtensions specifies supported image formats, while \Configure{Gin-dim} can be used to set dynamic dimensions based on page width.
```tex
\Preamble{xhtml}
% Declare supported image formats (order matters)
\DeclareGraphicsExtensions{.svg,.png,.jpg}
% Configure graphics dimensions
\makeatletter
\ExplSyntaxOn
\Configure{Gin-dim}{style="width:\fp_eval:n{round(\Gin@req@width/\textwidth*100,2)}\%"}
\ExplSyntaxOff
\makeatother
\begin{document}
\EndPreamble
```
--------------------------------
### Makefile for Automated Document Builds with make4ht
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/advanced-features.md
This Makefile defines rules for building HTML and PDF outputs from LaTeX sources using make4ht. It includes targets for building, cleaning intermediate files, and converting HTML to PDF using wkhtmltopdf.
```makefile
# Makefile for automated builds
SOURCES = doc.tex
TARGETS = $(SOURCES:.tex=.html)
all: $(TARGETS)
%.html: %.tex
make4ht -d output -f html5 $<
%.pdf: %.html
wkhtmltopdf $< $@
clean:
rm -rf output/
rm -f *.aux *.lg *.xref *.4tc
.PHONY: all clean
```
--------------------------------
### Require make4ht-htlatex Library
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/make4ht-build-files.md
Demonstrates how to require and use the 'make4ht-htlatex' Lua module for executing LaTeX with error handling.
```lua
local htlatex = require "make4ht-htlatex"
local status = htlatex.htlatex({input = "filename"})
```
--------------------------------
### Configure Bold Text Command with Class
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Configures the 'textbf' command to render bold text using a tag with a 'bold' class. Includes CSS for font weight.
```tex
\Configure{textbf}
{\HCode{}\NoFonts}
{\EndNoFonts\HCode{}}
\Css{strong.bold { font-weight: bold; }}
```
--------------------------------
### Debug Environment Mapping with Start/End Comments
Source: https://github.com/michal-h21/tex4ht-doc/blob/master/_autodocs/environment-configuration.md
Adds HTML comments around the 'myenv' environment to aid in debugging generated HTML output.
```tex
\ConfigureEnv{myenv}
{\HCode{}