渲染 svg 时出错

渲染 svg 时出错

我正在尝试生成反应机制的 svg 图像。但是我一直收到错误:

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

运行命令时,make4ht -u "Bromothymol_blue".tex其中Bromothymol_blue是 latex 文档的名称。代码如下:

\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}

我尝试按照以下解决方案进行操作Latex 到 HTML 的转换(基本解释)。我使用 TeXstudio 并使用用户命令make4ht -u %.tex

请注意,我知道代码适用于 pdftlatex,但这不是我想要做的。我正在尝试使用 tex4ht 生成带有 svg 的 html 输出。另外,我对此还很陌生,所以请尽量在您的回答中解释清楚。谢谢!

答案1

你遇到了一个老漏洞在 PGF 中。最近的更新已修复此问题,因此您在最新的 TL 2018 或 TL 2019 预测试中不会遇到此错误。

但真正的问题是,这个源文件无论如何都不能使用默认值tex4ht。它只产生一些箭头。幸运的是,tex4ht存在一些支持 TikZ 的替代方法。第一种方法是使用 TikZ 外部化,第二种方法是使用替代tex4ht驱动程序。第二种方法更容易使用。您需要安装替代司机并稍微修改源文件:

\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}

这是浏览器中的结果:

在此处输入图片描述

相关内容