1

After a blog post by Joseph Wright, I wanted to use mhchem in chemfig. All went well, until I decided to include acronyms by the acro package. With the following MWE, the acronym is defined as used, but not included in the acronym list.

\documentclass{article}
\usepackage{acro}
\usepackage{chemfig}
\usepackage[version=4]{mhchem}

\DeclareAcronym{boc}{short=Boc,long=\textit{tert}-butyloxycarbonyl}

% From http://www.texdev.net/2012/08/25/exploring-chemfig-customising-appearance/
\makeatletter
\def\CF@node@content{%
  \expandafter\expandafter\expandafter%\expandafter\expandafter%
  \printatom\expandafter\expandafter\expandafter%\expandafter\expandafter%
  {\csname atom@\number\CF@cnt@atomnumber\endcsname}%
  \ensuremath{\CF@node@strut}%
}
\makeatother
\renewcommand*{\printatom}[1]{{\ce{#1}}}

\begin{document}

\sffamily

\acifused{boc}{Boc is used}{Boc is not used}

\chemfig{\acs{boc}HN-R-NH2}

\acifused{boc}{Boc is used}{Boc is not used}

\printacronyms

\end{document}

Acronym not in acronym list

When the code from the blog post is removed, all works fine again, but I really liked being able to use \ce from within \chemfig. Also, it made \chemfig use the sans-serif text font instead of the serif math font, which was something I wanted.

I tried using five \expandafters around the \printatom macro. This did fix the acronym issue, and the font still is the same as the surrounding sans-serif text font, but parsing by \ce is no longer done correctly. Note the non-subscript 2:

Contents not parsed by mhchem

Any suggestions how to get both acro and mhchem to work inside of chemfig would be highly appreciated.

1

Due to your redefinition the \acs command is processed more than once, but as the first processing -- this is an educated guess -- are only done to measure the content the write commands from acro aren't executed and so it doesn't write the needed \acro@used@once to the aux-file but only \acro@used@twice from the actual typesetting.

You would get a similar behaviour also if you used acro inside align (tested) and probably tabularx and other environment which process their content twice. So imho it is a bug: acro should check this case.

You should notify the author, as a workaround you can try the following. Be aware that from the point of view of acro this key has been used twice. So a special style for "single" occurances will not work.

\documentclass{article}
\usepackage{acro}
\usepackage{chemfig,amsmath}
\usepackage[version=4]{mhchem}

\DeclareAcronym{boc}{short=Boc,long=\textit{tert}-butyloxycarbonyl}

%% From http://www.texdev.net/2012/08/25/exploring-chemfig-customising-appearance/
\makeatletter
\def\CF@node@content{%
  \expandafter\expandafter\expandafter%\expandafter\expandafter%
  \printatom\expandafter\expandafter\expandafter%\expandafter\expandafter%
  {\csname atom@\number\CF@cnt@atomnumber\endcsname}%
  \ensuremath{\CF@node@strut}%
}


\ExplSyntaxOn
\cs_set_protected:Npn \acro@used@twice #1#2#3#4
  {
    \bool_if:cF {g__acro_#1_in_list_bool}
    {\acro@used@once {#1}{#2}{#3}{#4}}
    \cs_gset_nopar:cpn {acro@#1@twice} {#1}
    \tl_if_empty:nF {#2#3#4}
      { \seq_gput_right:cn {g__acro_#1_pages_seq} { {#2}{#3}{#4} } }
  }

\ExplSyntaxOff

\makeatother
\renewcommand*{\printatom}[1]{{\ce{#1}}}

\begin{document}


\sffamily

\acifused{boc}{Boc is used}{Boc is not used}

\chemfig{\acs{boc}HN-R-NH2}

\acifused{boc}{Boc is used}{Boc is not used}

\printacronyms

\end{document}
  • This is related: texwelt.de/wissen/fragen/1820/… – clemens Apr 30 '17 at 1:23
  • @clemens yes, but imho instead of patching all sorts of commands it would be easier to extend/improve my work around: if a previous once command is missing the twice version should simply fall back to the once version. – Ulrike Fischer Apr 30 '17 at 6:33
  • I've discovered that when you use \ac instead of \acs or \acl inside such an environment you only get the short form printed out. That also seems like a bug, which the above workaround does not fix. I've created a bug report here. – cp.fe.cp Apr 30 '17 at 20:27

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.