3

I'm trying to generate a svg image of a reaction mechanism. However I keep receiving the error:

! Undefined control sequence.
\pgfsys@svg@newline ->\Hnewline 

when running the command make4ht -u "Bromothymol_blue".tex where Bromothymol_blue is the name of the latex document. Here is the code:

\documentclass{article}
\thispagestyle{empty}
\usepackage{chemfig}
\usepackage{mol2chemfig}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mhchem}
\usepackage{tex4ht}
\begin{document}
    \schemestart
    \chemname{\tiny\chemfig{-[:160]-[:100](-[:40]Br)(-[:220,,,,draw=none]\mcfcringle{1.3})-[:160](-[:100,,,1]OH)-[:220](-[:160](-[:100])-[:220])-[:280]-[:340](-[:40])-[:280]@{C}(-[:204]-[:274](-[:154,,,,draw=none]\mcfcringle{1.3})-[:214](-[:274](-[:214])-[:334])-[:154](-[:214,,,2]HO)-[:94](-[:154]Br)-[:34](-[:94])-[:334])-[:288]-[:240](-[:0,,,,draw=none]\mcfcringle{1.3})-[:300]--[:60]-[:120](-[:180])-[:72]S(=[:336]O)(=[:60]O)-[:144]O(-[:216])}}{Yellow}
    \begin{tikzpicture}[overlay,remember picture]
    \draw[red](C) circle (0.1) +(120:0.1) ..controls +(120:0.5) and +(0:0.5).. +(155:2) node[left,align=right] {Conjugation\\stops\\here};
    \end{tikzpicture}
    \arrow{<=>[\small\ce{+OH-}][\small\ce{H+},\;\ce{H2O}]}
    \chemname{\tiny\chemfig{
            % 15
            -[:300]% 14
            (
            -[::60]% 16
            )
            -[::300]% 12
            -[::300]% 11
            (
            -[::300]\mcfright{O}{^{\mcfminus}}% 17
            )
            -[::60]% 10
            (
            -[::300]Br% 18
            )
            -[::60]% 9
            (
            -[::300]% 19
            )
            -[::60]% 8
            (
            -[::60]% 13
            -[::60]% -> 12
            )
            (
            -[::120,,,,draw=none]\mcfcringle{1.3}% (o)
            )
            -[::300]% 7
            (
            -[::70]% 20
            -[::320]% 21
            (
            -[::310]S% 26
            (
            -[::110]\mcfright{O}{^{\mcfminus}}% 28
            )
            (
            =[::50]O% 29
            )
            =[::350]O% 27
            )
            (
            -[::120,,,,draw=none]\mcfcringle{1.3}% (o)
            )
            -[::60]% 22
            -[::60]% 23
            -[::60]% 24
            -[::60]% 25
            -[::60]% -> 20
            )
            =[::300]% 6
            -[::60]% 1
            (
            -[::60]% 35
            )
            -[::300,,,,drh]% 2
            (
            -[::60]Br% 34
            )
            -[::300]% 3
            (
            =[::60]O% 33
            )
            -[::300]% 4
            (
            -[::300,,,,drh]% 5
            -[::300]% -> 6
            )
            -[::60]% 30
            (
            -[::300]% 31
            )
            -[::60]% 32
    }}{Blue}
    \schemestop
\end{document}

I tried to follow the solution from Latex to HTML conversion (basic explanation). I use TeXstudio and used the user command make4ht -u %.tex

Please note that I know the code works with pdftlatex and that is not what I am trying to do. I am trying to generate a html output with an svg using tex4ht. Also I am quite new to this so please try and explain as much as possible in your answer. Thanks!

4

You encountered an old bug in PGF. It was fixed by a recent update, so you shouldn't get this error in up-to date TL 2018 or pretest of TL 2019.

But the real problem is that this source file doesn't work wit the default tex4ht anyway. It produces just some arrows. Fortunately, some alternative ways for TikZ support for tex4ht exist. First one is to use TikZ externalization, the second is to use an alternative tex4ht driver. The second alternative is easier to use. You need to install the alternative driver and modify your source file slightly:

\documentclass{article}
\thispagestyle{empty}
\ifdefined\HCode
    \def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\fi 

\usepackage{chemfig}
\usepackage{mol2chemfig}

\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{mhchem}
%\usepackage{tex4ht}
\begin{document}
    \schemestart
    \chemname{\tiny\chemfig{-[:160]-[:100](-[:40]Br)(-[:220,,,,draw=none]\mcfcringle{1.3})-[:160](-[:100,,,1]OH)-[:220](-[:160](-[:100])-[:220])-[:280]-[:340](-[:40])-[:280]@{C}(-[:204]-[:274](-[:154,,,,draw=none]\mcfcringle{1.3})-[:214](-[:274](-[:214])-[:334])-[:154](-[:214,,,2]HO)-[:94](-[:154]Br)-[:34](-[:94])-[:334])-[:288]-[:240](-[:0,,,,draw=none]\mcfcringle{1.3})-[:300]--[:60]-[:120](-[:180])-[:72]S(=[:336]O)(=[:60]O)-[:144]O(-[:216])}}{Yellow}
    \begin{tikzpicture}[overlay,remember picture]
    \draw[red](C) circle (0.1) +(120:0.1) ..controls +(120:0.5) and +(0:0.5).. +(155:2) node[left,align=right] {Conjugation\\stops\\here};
    \end{tikzpicture}
    \arrow{<=>[\small\ce{+OH-}][\small\ce{H+},\;\ce{H2O}]}
    \chemname{\tiny\chemfig{
            % 15
            -[:300]% 14
            (
            -[::60]% 16
            )
            -[::300]% 12
            -[::300]% 11
            (
            -[::300]\mcfright{O}{^{\mcfminus}}% 17
            )
            -[::60]% 10
            (
            -[::300]Br% 18
            )
            -[::60]% 9
            (
            -[::300]% 19
            )
            -[::60]% 8
            (
            -[::60]% 13
            -[::60]% -> 12
            )
            (
            -[::120,,,,draw=none]\mcfcringle{1.3}% (o)
            )
            -[::300]% 7
            (
            -[::70]% 20
            -[::320]% 21
            (
            -[::310]S% 26
            (
            -[::110]\mcfright{O}{^{\mcfminus}}% 28
            )
            (
            =[::50]O% 29
            )
            =[::350]O% 27
            )
            (
            -[::120,,,,draw=none]\mcfcringle{1.3}% (o)
            )
            -[::60]% 22
            -[::60]% 23
            -[::60]% 24
            -[::60]% 25
            -[::60]% -> 20
            )
            =[::300]% 6
            -[::60]% 1
            (
            -[::60]% 35
            )
            -[::300,,,,drh]% 2
            (
            -[::60]Br% 34
            )
            -[::300]% 3
            (
            =[::60]O% 33
            )
            -[::300]% 4
            (
            -[::300,,,,drh]% 5
            -[::300]% -> 6
            )
            -[::60]% 30
            (
            -[::300]% 31
            )
            -[::60]% 32
    }}{Blue}
    \schemestop
\end{document}

This is the result in browser:

enter image description here

  • 1
    It appears that the circles within the benzene ring have been offput to the side. Is it possible to fix this? – sab hoque Apr 3 at 12:02
  • It appears that one svg file outputs correctly while the other with 0x at the end (<filename>0x.svg) is not outputted correctly and is the one included in the html output. Nonetheless I can use the correct one. Thanks so much – sab hoque Apr 3 at 12:11
  • 1
    @sabhoque unfortunately not. I've tried also pgfsys-dvisvgm and pgfsys-dvips drivers with tex4ht and they always produce shifted circles. I am not an expert on PGF and the graphic drivers, so I don't understand what is the issue. – michal.h21 Apr 9 at 6:45
  • 1
    @sabhoque I've updated the driver, it seems to fix the issue – michal.h21 Apr 11 at 9:03
  • 1
    @sabhoque make4ht -u -l Bromothymol_blue.tex – michal.h21 Apr 21 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.