2

This MWE

\documentclass{article}
\ifdefined\HCode 
\def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\fi 
\usepackage{amsmath}
\usepackage[edges]{forest}

\begin{document}

\begin{forest}
for tree={
    draw, rounded corners, fill=blue!20,
    minimum height=1.5cm, minimum width=2cm,
    align=center, base=b,
    s sep=1cm, l sep=.5cm,
    if level<=2{edge=-latex}{edge=red},
}
[differential\\equation
    [\begin{minipage}{2cm}     
     first order
     \vspace{-8pt}
     {\begin{align*} 
       f(x,y,(y')^n)&=0
     \end{align*} 
     }
     \end{minipage}
     ,calign=last
   ]
]
\end{forest}

\end{document}

When compiled using

make4ht  -ulm default -a debug foo4.tex "htm" "-cunihtf -utf8"

Gives this HTML

enter image description here

But when compiling using mathjax mode

 make4ht  -ulm default -a debug foo4.tex "mathjax,htm" "-cunihtf -utf8"

Gives this html

enter image description here

The math is missing.

I tried with and without \def\pgfsysdriver{pgfsys-dvisvgm4ht.def} as I was not sure if this is needed for mathjax, but it made no difference. Same result was generated. Math is missing in mathjax mode.

Does this mean one should compile the Tikz/Forest diagram to standalone image and include that as an image in HTML instead of doing it all inline as in the above example?

TL 2022

which tex4ht 
/usr/local/texlive/2022/bin/x86_64-linux/tex4ht
make4ht --version 
make4ht version v0.3l
5
  • If I see that correct, your MathJax routine creates a svg graphic and even the text is transformed to a (vector) image. Just a guess but since forest first typesets stuff to measure it before it actually is put on the page I could see this somehow causing trouble in the transformation. Commented Nov 22, 2022 at 19:38
  • (Off-Topic: Instead of a minipage you could just use text width=2cm which for LaTeX even does the same.) Commented Nov 22, 2022 at 19:39
  • Instead of a minipage you could just use text width=2cm I must be doing something wrong, but now it does not compile. Here is what I tried \begin{forest} for tree={ draw, rounded corners, fill=blue!20, minimum height=1.5cm, minimum width=2cm, align=center, base=b, s sep=1cm, l sep=.5cm, if level<=2{edge=-latex}{edge=red}, } [differential\\equation [text width=2cm, first order {\begin{align*} f(x,y,(y')^n)&=0 \end{align*} } ,calign=last ] ] \end{forest} I am new using forest.
    – Nasser
    Commented Nov 22, 2022 at 19:45
  • I thought I needed minipage since this will be paragraph with math in it and it is easier to make it its own page.
    – Nasser
    Commented Nov 22, 2022 at 19:47
  • The first part (up to a ,) after [ is always the content: [{\begin{align*}…\end{align*}}, text width=2cm, first order, calign=last] (This node will be wider than 2cm because it will add the inner xsep to both sides.) Commented Nov 22, 2022 at 21:34

1 Answer 1

2

This one is quite complicated. Most math environments are redefined in the MathJax mode in the way that they cannot be used in pictures. Other than externalization, the only way I can think of is to redefine environments back to their original meaning at the beginning of the forest environment. The example for the align* environment can look like this:

\Preamble{xhtml}
\makeatletter
\AddToHook{env/forest/begin}{%
  \renewenvironment{align*}
  {\start@align \@ne \st@rredtrue \m@ne}
  {\math@cr \black@ \totwidth@ \egroup \ifingather@ \restorealignstate@ \egroup \nonumber \ifnum 0=`{\fi \iffalse }\fi \else $$\fi \ignorespacesafterend}
}
\makeatother
\begin{document}
\EndPreamble

The \AddToHook{env/forest/begin} executes code at the begiinig of the forest environment. The change is local, so the align* environment will still work with MathJax outside of forest.

This is the result:

enter image description here

2
  • hello Michal. I found a big problem. But since it is now using tikzpicture and not forest,. I thought it will be better to post separate question so not to clutter this one?
    – Nasser
    Commented Nov 28, 2022 at 2:22
  • fyi, I've posted separate question at tex.stackexchange.com/questions/666705/…
    – Nasser
    Commented Nov 28, 2022 at 2:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .