# Chemcompounds package and subfloat comportement ?

I would like to use chemcompounds package which allows you to keep track of the chemical compounds you go citing on, and give them a number order if nothing is specified. I would like to use it within the subfloat environment modified so that no (a)(b) appears. But the comportement of chemcompounds is rare and doesn't numbers in the right way if first inserted inside the subfloat environment.

I put an example to be more clear.

\documentclass{article}
\usepackage{graphics}
\usepackage{subfig}
\usepackage{caption}
\usepackage{chemcompounds}

\begin{document}

\begin{figure}[!ht]
\captionsetup[subfigure]{labelformat=empty}
\centering
\subfloat[\compound{wikoB}]{\rule{3cm}{2cm}}
\caption{Wiko A and B}
\label{wikoAandB}
\end{figure}

Here are Wiko A \compound{wikoA} and B \compound{wikoB} see fig.\ref{wikoAandB}
Of course Wiko C and D are present \compound{wikoC,wikoD}

As well as Wiko E and F \compound{wikoE,wikoF}  that you can see below. See fig. \ref{wikoEandF}

\begin{figure}[!ht]
\captionsetup[subfigure]{labelformat=empty}
\centering
\subfloat[\compound{wikoF}]{\rule{3cm}{2cm}}
\caption{Wiko E and F}
\label{wikoEandF}
\end{figure}

\end{document}


Any clue?

• The chemcompounds way would be to use \compound+ instead of \compound, see here – clemens Mar 25 '12 at 14:18

The subfig resp. the caption package will do a so called single-line-check for every caption to test if it will fit into a single line or not. This way \compound will be evaluated twice, and for a reason I don't have evaluated yet the \compound macro doesn't like this.

A workaround would be telling the caption package to ignore \compound inside the single-line-check. Please note that this is not a solution but a (dirty) hack since this will cause the single-line-check to evaluate a wrong width. Therefore I will to further investigation tomorrow and maybe could offer a better solution afterwards.

Addendum: There is a patch inside the caption package to adapt \footnotemark. Unfortunately this has effected \compound in a negative way - this bug will be fixed in caption v3.2. Furthermore I have replaced the hack with a proper patch in this example code:


\documentclass{article}
\usepackage{graphics}
\usepackage{caption}
\usepackage{subfig}
\usepackage{chemcompounds}

% Patch: Make \compound work inside (figure & table) captions
% Not neccessary for caption package version >= 3.2, but will not make any harm
\makeatletter
\let\caption@prepareslc@ORI\caption@prepareslc
\renewcommand\caption@prepareslc{%
\let\caption@g@stepcounter\stepcounter
\caption@prepareslc@ORI
\let\compound@ORI\compound
\def\compound{\let\stepcounter\caption@g@stepcounter\compound@ORI}%
}
\makeatother

\begin{document}

\begin{figure}[!ht]
\captionsetup[subfigure]{labelformat=empty}
\centering
\subfloat[\compound{wikoB}]{\rule{3cm}{2cm}}
\caption{Wiko A and B}
\label{wikoAandB}
\end{figure}

Here are Wiko A \compound{wikoA} and B \compound{wikoB} see fig.\ref{wikoAandB}
Of course Wiko C and D are present \compound{wikoC,wikoD}

As well as Wiko E and F \compound{wikoE,wikoF}  that you can see below. See fig. \ref{wikoEandF}

\begin{figure}[!ht]
\captionsetup[subfigure]{labelformat=empty}
\centering
\subfloat[\compound{wikoF}]{\rule{3cm}{2cm}}
\caption{Wiko E and F}
\label{wikoEandF}
\end{figure}

\end{document}


Addendum: The version 3.2 of the caption package was released in August 2011 so simply updating the TeX distribution should help -- especially the patch above should not be necessary anymore.

• Saying \renewcommand\@createcompound[2][]{} instead of \let\@compound\@gobble seems better. Try both alternatives with \subfloat[\compound{wikoA} 1 1 1 1 1 1 1 1 1 1 1 1]; with mine the last 1 is correctly left aligned, while with yours it's centered. – egreg Jul 7 '11 at 9:17
• @egreg I must be missing something but I dont see difference. Anyway both ar working ! Thank you – oo1on Jul 7 '11 at 10:45
• @oolon: They work the same because you put in the subcaption only the number of the compound. It would be different if that was accompanied by other text. – egreg Jul 7 '11 at 10:56
• I have just replaced my hack with a proper solution. – Axel Sommerfeldt Jul 7 '11 at 13:36