make4ht icon indicating copy to clipboard operation
make4ht copied to clipboard

Package 'tikz-cd': incompatibility with equations

Open iabarus opened this issue 1 year ago • 1 comments

LaTeX

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz-cd}
\begin{document}
\[
    \begin{tikzcd}[arrows=to]
        \cdots \rar & H_n(A \cap B) \rar & H_n(A) \oplus H_n(B) \rar & H_n(X) \rar 
    \end{tikzcd}
\]
\end{document}

make4ht

make4ht file.tex 'mathjax'

iabarus avatar Jul 24 '23 15:07 iabarus

The problem here is that when you enclose TikZ environment in math, it won't get parsed by LaTeX and it will end verbatim in the output HTML. It is not something that can be fixed easily without modification of your source file.

What I would do is this: define a new environment which switches to the math mode by default, and then redefine it in the TeX4ht config file to start picture before switching to math. In this way, you will enforce creation of the picture.

Here is the TeX file:

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz-cd}
\newenvironment{pictenv}{\[}{\]}
\begin{document}
\begin{pictenv}
    \begin{tikzcd}[arrows=to]
        \cdots \rar & H_n(A \cap B) \rar & H_n(A) \oplus H_n(B) \rar & H_n(X) \rar & \hphantom{0}\\
        \hphantom{\cdots} \rar 
        & H_{n-1}(A \cap B) \rar 
        & \makebox[\widthof{$H_n(A) \oplus H_n(B)$}][c]{$\cdots\hfill \cdots$} \rar
        &  H_0(X) \rar & 0
    \end{tikzcd}
\end{pictenv}
\end{document}

The configuration file can look like this:

\Preamble{xhtml}
\renewenvironment{pictenv}{\Picture*{}$$}{$$\EndPicture}{}{}
\begin{document}
\EndPreamble

The \Picture*{}...\EndPicture code should force the image creation.

michal-h21 avatar Jul 24 '23 16:07 michal-h21