3

I have observed a Command \setbondstyle undefined error while using the mol2chemfig package with the following mwe:

\documentclass[preview,border=7pt,active,tightpage]{standalone}
\usepackage{booktabs}
%\usepackage{chemfig}
\usepackage{mol2chemfig} 
\usepackage{filecontents} 
\usepackage[scaled]{helvet}

\begin{filecontents}{anthracene_aromatic_rings.tex}
\chemfig{                          % 5
              -[:210,0.96]% 1
              -[:270,0.96]% 2
                             (
                     -[:210.9]% 8
                     -[:150.4]% 12
                        -[:90]% 11
                      -[:29.6]% 7
                     -[:329.1]% -> 1
    -[:209.1,0.99,,,draw=none]\mcfcringle{1.28}% (o)
                             )
                             (
       -[:30,0.96,,,draw=none]\mcfcringle{1.25}% (o)
                             )
              -[:330,0.96]% 6
               -[:30,0.96]% 4
               -[:90,0.96]% 3
                             (
                  -[:150,0.96]% -> 5
                             )
                  -[:30.9]% 9
                             (
    -[:270.2,0.99,,,draw=none]\mcfcringle{1.29}% (o)
                             )
                 -[:330.4]% 13
                   -[:270]% 14
                 -[:209.6]% 10
                             (
                     -[:149.1]% -> 4
                             )
}
\end{filecontents}


\begin{filecontents}{methane.tex}
\chemfig{           H% 2
    -[:210]% 1
              (
        -[:210]H% 3
              )
              (
        -[:300]H% 5
              )
    -[:120]H% 4
}
\end{filecontents}


% sans serif font
\renewcommand\familydefault{\sfdefault} 

% define formulae
\def\anthracene{\mathrm{C_{14}H_{10}}}
\def\methane{\mathrm{CH_{4}}}

\begin{document}

\begin{center}
\begin{tabular}[]{lp{1.5cm}}
\toprule
\textbf{Formula} & \textbf{Structure}\\
\midrule%
%$\methane$ & \begin{minipage}{1cm} \input{methane.tex} \end{minipage} \\ [2mm]%
$\anthracene$ & \begin{minipage}{1cm} \input{anthracene_aromatic_rings.tex} \end{minipage} \\ [2mm]%
\bottomrule
\end{tabular}
\end{center}
\end{document}

A successful compile is observed if one comments \usepackage{mol2chemfig} and the line in the table for anthracene (which calls some of the macros contained in mol2chemfig).

I verified my chemfig package installation (managed through console) and removed a copy of chemfig.sty that was in my texmf tree.

For installation of mol2chemfig, I simply downloaded the mol2chemfig.sty and placed it in my texmf tree manually, doing FNDB after depositing files.

Could there be an accessory file that I do not have in which \setbondstyle is defined?

Perhaps I should be calling a supplementary package?

  • 1
    \setbondstyle is a deprecated chemfig command but mol2chemfig stores the bondstyle in a tikz key, so this is going to break. Suggest you contact the mol2chemfig author or rewrite your code to avoid using mol2chemfig. – Ross Aug 2 at 17:38
  • 2
    Would using the version of chemfig that mol2chemfig was developed with be a solution? – John Chris Aug 2 at 19:10
  • @JohnChris - yes, that should work. – Michael Palmer Aug 3 at 14:43
4

I am the mol2chemfig author and apologize for not having fixed this yet, even though it was pointed out to me a while ago. As a quick fix, you can just comment out or delete the entire block

\let\mcf@setbondstyle\setbondstyle
\renewcommand{\setbondstyle}[1]{%
    \mcf@setbondstyle{#1}%
    \tikzset{mcfbond/.style={#1}}%
}

inside mol2chemfig.sty.

Edit: OK, so there are additional problems here that I cannot solve. In the newer versions of chemfig, the former \CF@atom@sep and \CF@cycle@inraduiscoeff have been replaced with \CF_atomsep and \CF_cycleradiuscoeff, but simply making those substitutions in mol2fchemfig does not work. There may be some catcode trickery involved that is beyond me. I will ask the chemfig author for help with this and hopefully have an update soon. In the meantime, the only solution seems to be to use an ancient version of chemfig.

Second edit: I just tested this on my system, and it worked.

1) I downloaded the old version (1.2d) of chemfig.tex which I posted at https://pastebin.com/uJWRDXuj earlier and saved it as cf-pastebin.tex into an empty directory.

2) Into the same directory, I saved a copy of mol2chemfig.sty under the name mol2chemfigfix.sty. I edited the first couple of lines of that file to use cf-pastebin.tex directly:

% auxiliary package for mol2chemfig
\ProvidesPackage{mol2chemfigfix} % use the modified mol2chemfig package

\RequirePackage{xcolor, twoopt, ifmtarg, tikz} % load tikz as a prereq for chemfig
\input{cf-pastebin.tex}  % load this directly, don't mess with chemfig.sty

\def\printatom#1{\ensuremath{\mathrm{#1}}}% \printatom pour LaTeX.
\expandafter\def\csname CF\string_begintikzpicture\endcsname{\begin{tikzpicture}}%
\expandafter\def\csname CF\string_endtikzpicture\endcsname{\end{tikzpicture}}%

\usetikzlibrary{decorations}

I then used the following MWE (also saved into the same directory):

\documentclass[border=2pt]{standalone}
\usepackage{mol2chemfigfix} 

% minimal example that exercises all \CF@... macros used by mol2chemfig

\begin{document}
\chemfig{
              -[:210,0.96]% 1
              -[:270,0.96]% 2
                             (
                     -[:210.9]% 8
                     -[:150.4](-[:210]
                               -[:150,,,,drhs]
                              )
                        -[:90]% 11
                      -[:29.6]% 7
                     -[:329.1]% -> 1
    -[:209.1,0.99,,,draw=none]\mcfcringle{1.28}% (o)
                             )
}
\end{document}

This gives no errors and produces the expected output. Since it does not invoke chemfig.sty at all, I hope this will work for you also.

  • 1
    Thanks! On trying this and then attempting to compile the mwe above I'm seeing: Undefined control sequence. <argument> \CF@atom@sep *1.28*0.66667*\CF@cycle@inraduiscoeff. The \mcfcringle definition code is presenting an issue. – John Chris Aug 2 at 23:08
  • 1
    @JohnChris - please see updated answer. – Michael Palmer Aug 3 at 14:24
  • 1
    Thanks, @Michael Palmer. How ancient? Are you able to provide a version number or url? – John Chris Aug 3 at 14:47
  • 1
    @JohnChris - On my system, I have chemfig v1.2d, which works. I just posted the content of that version of chemfig.tex to pastebin.com/uJWRDXuj . Note that chemfig.sty is just a hook to load chemfig.tex, which contains the actual package code. If you arrange for chemfig.sty to find the old version of chemfig.tex, it should work. – Michael Palmer Aug 3 at 14:56
  • 1
    I placed the v1.2d chemfig.tex at ...\Programs\MiKTeX 2.9\tex\generic\chemfig on my system, changing the filename of the up to date file so that it would not be found. When I compile the mwe I get: ! Undefined control sequence. <argument> \CFname .3 \ProvidesPackage\CFname [\CFdate\space v\CFver\space Draw molecule with a... – John Chris Aug 3 at 17:02

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.