I am trying to use the following custom pgfdecoration
to draw bonds with varying length of the double bond while using chemfig
. The code was obtained from the following link: How to alter the bond length of a double bond in chemfig?. However, I am unable to run the code after recently installing MikTeX
and executing the code throws the following error message: Undefined control sequence. ...]--[::-60,,,,,rsdbond={120}{120}]-[::-60]}
. I have tried updating pgf
and chemfig
from the MikTeX
console but to no avail.
Does someone know what package I am missing and how to successfully execute this code (see below).
\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}
@
to_
, see e.g. here for a related problem. You'll need to go through the steps indicated in section 10 of the chemfig manual. – user194703 Sep 20 '19 at 18:01\makeatletter
to\catcode`\_11
,\makeatother
to\catcode`\_8
, and\CF@double@sep
to\CF_doublesep
. – user194703 Sep 20 '19 at 18:08\makeatletter
and\makeatother
statements to what you suggested. I also looked at thechemfig
manual, and tried implementing the test code in Section 6 on page 29 for creating delocalized double bonds. But I still get the same error as mentioned earlierUndefined control sequence...
. The code inchemfig
manual, however, still uses@
instead of_
. – scorpionwars Sep 20 '19 at 18:24