PGF 装饰不起作用

PGF 装饰不起作用

我尝试使用以下习惯pgfdecoration来绘制使用时双键长度不同的键chemfig。代码来自以下链接:如何改变 chemfig 中双键的键长?。但是,我无法运行代码,因为最近安装MikTeX并执行代码时会抛出以下错误消息:Undefined control sequence. ...]--[::-60,,,,,rsdbond={120}{120}]-[::-60]}。我尝试从控制台更新pgf和,但无济于事。chemfigMikTeX

有人知道我缺少什么包以及如何成功执行此代码(见下文)。

\documentclass{article}
\usepackage{chemfig}
\usetikzlibrary{decorations}
\makeatletter
\newdimen\mystartshorten
\newdimen\myendshorten
\mystartshorten0pt
\myendshorten0pt
\pgfdeclaredecoration{sdbond}{initial}{
  \state{initial}[width=\pgfdecoratedremainingdistance,next state=final]
  {
    {
      \pgftransformyshift{\CF@double@sep}
      \pgfpathmoveto{\pgfqpoint{\mystartshorten}{0pt}}
      {
        \pgftransformxshift{\pgfdecoratedremainingdistance}
        \pgfpathlineto{\pgfqpoint{-\myendshorten}{0pt}}
      }
    }
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfqpoint{\pgfdecoratedremainingdistance}{0pt}}
  }
  \state{final}
  {}
}
\tikzset{
  lsdbond/.code 2 args={%
    \tikzset{decorate, decoration=sdbond}%
    \pgfmathsetlength\mystartshorten{\CF@double@sep*cot((#1)/2)}%
    \pgfmathsetlength\myendshorten{\CF@double@sep*cot((#2)/2}%
  },
  rsdbond/.code 2 args={%
    \tikzset{decorate, decoration={sdbond, mirror}}%
    \pgfmathsetlength\mystartshorten{\CF@double@sep*cot((#1)/2)}%
    \pgfmathsetlength\myendshorten{\CF@double@sep*cot((#2)/2}%
  }
}
\setchemfig{
    double bond sep=0.4em,
    atom sep=2em,
}
\makeatother
\begin{document}
\chemfig{[:60]--[::-60,,,,,rsdbond={120}{120}]-[::-60]}
\chemfig{[:90]--[::-90,,,,,rsdbond={90}{60}]-[::-120]}
\end{document}

答案1

“受保护”字符已从 更改为@_您需要按照 chemfig 手册第 10 节中指示的步骤进行操作。以下是我在更新的 TeXLive2019 安装中得到的结果:

\documentclass{article}
\usepackage{chemfig}
\usetikzlibrary{decorations}
\catcode`\_11
\newdimen\mystartshorten
\newdimen\myendshorten
\mystartshorten0pt
\myendshorten0pt
\pgfdeclaredecoration{sdbond}{initial}{
  \state{initial}[width=\pgfdecoratedremainingdistance,next state=final]
  {
    {
      \pgftransformyshift{\CF_doublesep}
      \pgfpathmoveto{\pgfqpoint{\mystartshorten}{0pt}}
      {
        \pgftransformxshift{\pgfdecoratedremainingdistance}
        \pgfpathlineto{\pgfqpoint{-\myendshorten}{0pt}}
      }
    }
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfqpoint{\pgfdecoratedremainingdistance}{0pt}}
  }
  \state{final}
  {}
}
\tikzset{
  lsdbond/.code 2 args={%
    \tikzset{decorate, decoration=sdbond}%
    \pgfmathsetlength\mystartshorten{\CF_doublesep*cot((#1)/2)}%
    \pgfmathsetlength\myendshorten{\CF_doublesep*cot((#2)/2}%
  },
  rsdbond/.code 2 args={%
    \tikzset{decorate, decoration={sdbond, mirror}}%
    \pgfmathsetlength\mystartshorten{\CF_doublesep*cot((#1)/2)}%
    \pgfmathsetlength\myendshorten{\CF_doublesep*cot((#2)/2}%
  }
}
\setchemfig{
    double bond sep=0.4em,
    atom sep=2em,
}
\catcode`\_8
\begin{document}
\chemfig{[:60]--[::-60,,,,,rsdbond={120}{120}]-[::-60]}
\chemfig{[:90]--[::-90,,,,,rsdbond={90}{60}]-[::-120]}
\end{document}

在此处输入图片描述

相关内容