## Chapter 9FAQ and Troubleshooting

In general, don’t postpone your conversion to the last moment. As you will most likely want to produce ebook or HTML versions of LaTeX documents these days, you should try the conversion of your document from the beginning.

It is much easier to fix errors as soon as they appear. Often, one issue can cause many issues that follows, and it can be really hard to find the culprit.

Compile your document using TeX4ht every time you add a new package, as the included code can break other packages or even LaTeX kernel. You may also find that you will need a different definitions for some commands for the HTML conversion, as the version suitable for PDF produce some artifacts from drawing commands. These issues are also best to fix as soon as possible.

If you cannot find the solution for your error yourself, you can report it to one of the following channels:

### 9.2 Compilation Errors

Packages that cause issues TeX4ht can sometimes clash with other packages. If you don’t need features the problematic package provides (typically, they modify stuff that makes sense in the PDF output, but not in HTML, like page headers, fancy section titles, etc.), an easiest fix is to disable their loading when TeX4ht is active.

Fragile commands Some commands may cause compilation errors when used in \section or \caption arguments. These errors usually show when the document preamble stops and auxilary files are loaded. They can be quite hard to debug.

Consider the following example:

It produces a fatal error:

You can get more context for this error using the -a debug option for make4ht:

The error itself is pretty cryptic, but you can see that the cause is in

The issue is that some commands needs to be protected when used in parameters of \section or \caption commands. There are two possible fixes. First is to use the \protect command:

Other fix is to use the writetoc configuration:

In this configuration, we redefine \begin and \end commands to print their verbatim contents when they are used. They will be then written to the auxilary file thanks to this configuration. Redefinitions that happen in writetoc are active only when stuff is written to the auxilary files, so you don’t need to worry that it will break normal handling of environments.

Last tip for dealing with errors that involve auxilary files is to delete temporary files if the error is fatal. In that case the temporary file will not be overwritten with a fixed version, resulting in fatal error even if you fixed the original issue. It is recommended to remove at least the .aux and .xref files, but you may need to remove also .4tc and .4ct files. To simplify this process, you can use the clean mode of make4ht:

It will remove all temporary files, but also generated HTML files and images.

### 9.3 DOM Processing Errors

TeX4ht post-process generated HTML and XML files using Lua filters. They fixes various issues that are not possible fix on the TeX level, and also add some additional features. For example, the MathML output relies on filters to produce valid code.

These filters use the LuaXML library for the processing. When the generated HTML or XML file is not well-formed, you may get the following warning:

This means that DOM parsing failed and filters cannot be applied. This will result in incorrect file.

Incorrect handling of paragraphs Common cause of this issue is incorect handling of paragraphs in commands that produce block level elements such as <div> or <section> elements.

Say that you have a following code in your document:

And that you configure the test environment to to produce a custom <div> element:

This configuration will break the LuaXML parsing, as it produces invalid HTML code:

The issue is that <p> elements are mismatched. It is necessary that closing </p> tag is inserted before <div> tag. You can use commands introduced in section Paragraph Handling (7.3.4 ) for this task. The correct configuration can look like this:

The \EndP inserts closing </p> tag. But new paragraph still could be started before <div> if we are in the vertical mode, so we need to use also the \ifvmode\IgnorePar\fi command. This will prevent starting of the new paragraph too early. But we want to start a new paragraph after <div>, so we need to use explicit \par after \HCode. Similar paragraph treatment is needed also for the closing of the environment. The resulting HTML with this configuration is correct:

### 9.4 Math Issues

#### 9.4.1 Problems With MathML

Single delimiters Use of single delimiters like $\langle$ may result in invalid MathML code. TeX4ht can try to fix that using the mathml- option.

Use of \hbox in math environments

Don’t use the \hbox command inside math environments. The following code results in DOM error and wrong rendering by MathML processors. You can fix this by using \mbox instead.