我想使用 chemfig 绘制聚合物,使用 ConTeXt。在 chemfig 的文档中,我们找到了一个解决方案,它定义了一个宏,该宏在 LaTeX 上运行良好,但与 ConTeXt 不兼容(我使用 mkIV 版本)。有人知道如何转换宏以使其兼容吗?谢谢。
答案1
这是从手册移植到 ConTeXt 的示例chemfig
。因为我使用的是另一种字体,所以所有分隔符的大小都不对,但应该很容易调整它们。
\usemodule[chemfig]
\def\setpolymerdelim#1#2{%
\def\delimleft{#1}%
\def\delimright{#2}%
}
\def\makebraces[#1,#2]#3#4#5{%
\edef\delimhalfdim{\the\dimexpr(#1+#2)/2}%
\edef\delimvshift{\the\dimexpr(#1-#2)/2}%
\chemmove{%
\node[at=(#4),yshift=(\delimvshift)]%
{$\expandafter\left\delimleft\vrule height \delimhalfdim depth \delimhalfdim width 0pt\right.$};%
\node[at=(#5),yshift=(\delimvshift)]%
{$\left.\vrule height \delimhalfdim depth \delimhalfdim width 0pt \expandafter\right\delimright_{\rlap{#3}}$};%
}%
}
\setpolymerdelim()
\starttext
Polyéthylène:
\chemfig{\vphantom{CH_2}-[@{op,.75}]CH_2-CH_2-[@{cl,0.25}]}
\makebraces[5pt,5pt]{\!\!n}{op}{cl}
\blank[big]
Polyvinyl chloride:
\chemfig{\vphantom{CH_2}-[@{op,.75}]CH_2-CH(-[6]Cl)-[@{cl,0.25}]}
\makebraces[5pt,25pt]{\!\!\!n}{op}{cl}
\blank[big]
Nylon 6:
\chemfig{\phantom{N}-[@{op,.75}]{N}(-[2]H)-C(=[2]O)-{(}CH_2{)_5}-[@{cl,0.25}]}
\makebraces[30pt,5pt]{}{op}{cl}
\blank[big]
Polycaprolactame:\setatomsep{2em}
\chemfig{[:-30]-[@{left,.75}]N(-[6]H)-[:30](=[2]O)--[:30]--[:30]--[@{right,0.25}:30]}
\makebraces[5pt,25pt]{\!\!\!n}{left}{right}
\blank[big]
\setpolymerdelim[]
Polyphénylène sulfide:
\chemfig{\vphantom{S}-[@{op,.75}]S-(**6(---(-[@{cl,0.25}])---))}
\makebraces[15pt,15pt]{}{op}{cl}
\blank[big]
\chemfig{-CH_2-CH([6]-CO-NH-CH_2-NH-CO-CH([4]-CH_2-)([0]-[@{downleft,0.8},2]CH_2
-CH([2]-CO-NH_2)-[@{downright,0.3},2]CH_2-[,1.5]C?H-))-[@{upleft,0.8},2]CH_2
-CH([6]-CO-NH_2)-[@{upright,0.3},2]CH_2-[,1.5]CH([6]-CO-NH-CH_2-NH-C?O)-}
\makebraces[5pt,40pt]{n}{upleft}{upright}
\makebraces[38pt,7pt]{n}{downleft}{downright}
\stoptext