4

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 02 '19 at 17:38
  • 2
    Would using the version of chemfig that mol2chemfig was developed with be a solution? – John Chris Aug 02 '19 at 19:10
  • @JohnChris - yes, that should work. – Michael Palmer Aug 03 '19 at 14:43

2 Answers2

5

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 02 '19 at 23:08
  • 1
    @JohnChris - please see updated answer. – Michael Palmer Aug 03 '19 at 14:24
  • 1
    Thanks, @Michael Palmer. How ancient? Are you able to provide a version number or url? – John Chris Aug 03 '19 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 https://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 03 '19 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 03 '19 at 17:02
  • 1
    @JohnChris - please see updated answer. – Michael Palmer Aug 03 '19 at 18:15
  • @MichaelPalmer Upvote your answer. But help you to contibuite for this site: https://py-chemist.com/mol_2_chemfig/home. Yet I have not understood as export a draw in LaTeX. It is very complicated to draw a chemical scheme. – Sebastiano Aug 03 '19 at 22:32
  • @Sebastiano - I am not sure exactly what you are asking. – Michael Palmer Aug 03 '19 at 22:39
  • @MichaelPalmer If you're also participating in the construction of the online tool that I have given you. – Sebastiano Aug 03 '19 at 22:41
  • Thanks again! I can confirm that the proposed solution works. – John Chris Aug 05 '19 at 19:26
  • @MichaelPalmer Is there any chance of a new version of mol2chemfig.sty solving this without the need for this sort of hacking appearing soon? – jonalv Dec 02 '19 at 14:17
  • My mistake. In fact there seem to be one: https://ctan.org/tex-archive/graphics/mol2chemfig/latex – jonalv Dec 02 '19 at 14:59
  • 1
    @jonalv - yes, I uploaded an update a couple of days ago - I hope it will work now, but there are several versions of chemfig floating around, so if you experience any incompatibilities, please let me know. – Michael Palmer Dec 03 '19 at 15:38
0

I have a problem with the chemfig and mol2chemfig packages. When I try to set the bond length using the statement \setatomsep{2.25 em} I get the following error message:

`Undefined control sequence. \setatomsep`.

I tried to fix the problem following the steps provided by @Michel Palmer, but I did not manage to solve the problem: the MWE gives a lot of errors, the first one is Undefined control sequence. So, I am wondering, in which directory do I have to save files cf-pastebin.tex, mol2chemfigfix.sty? Maybe I did not place those files in the right directory...

javadr
  • 2,404