Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using the chemstyle package to handle automatic numbering of compounds. It apparently uses the chemcompounds package to handle this. In the documentation for the latter, it explains compounds can be 'created' implicitly, just by referring to a label that doesn't yet exist: \compound{label}.

Generally this works great, but when I try to do it inside a caption, it seems to forget the compound straight away. For example, I have two figures side-by-side, I refer to different compounds in each caption, but they get assigned the same compound number. When I create a new compound in the text following, it gets the number assigned to the first compound in the figures... so basically as soon as the caption ends the package forgets all the compounds.

I should mention I'm aware it is possible to work around this (eg. by making sure things are referred to in text before captions), but I'm looking for a foolproof solution. After all I'm using LaTeX for this so I don't have to worry about misnumbered compounds constantly.

share|improve this question
1  
Welcome to TeX.SE. It is always best to compose a MWE that illustrates the problem including the \documentclass so that those trying to help don't have to recreate it. –  Peter Grill Oct 19 '11 at 0:03
    
I'm not familiar with the chemstyle package, but the problem you describe with the use of the \compound command inside captions sounds like it could be solved by inserting a \protect command before the \compound command. –  Mico Oct 19 '11 at 1:15
    
In moving arguments such like in \caption one should use the variant \compound+ (and maybe define the label before using the “invisible” variant \compound*). –  cgnieder Mar 23 '12 at 9:42
add comment

2 Answers 2

Are you using the caption package as well? If yes, this bug was fixed in version 3.2 so updating your TeX distribution will help.

For example this MWE will work fine when compiled using caption package v3.2, but gives "1" every time when compiled using caption package v3.1m:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption,chemstyle}
\begin{document}
\begin{figure}[ht]
\includegraphics[height=1cm]{foo}
\caption{Compound number \compound{foo}.}
\end{figure}
\begin{figure}[ht]
\includegraphics[height=1cm]{bar}
\caption{Compound number \compound{bar}.}
\end{figure}

This should be three: \compound{foobar}
\end{document}

(Peter, sorry for "stealing" your MWE ;-))

Also take a look at question Chemcompounds package and subfloat comportement ? which contains a patch for the caption package if updating is not an option.

share|improve this answer
add comment

Without a full MWE it is difficult to provide much help. I tried the following and it does not seem to exhibit the problem you report:

enter image description here

If this example does not help, perhaps you can modify this so that it reproduces the problem you mention:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{chemstyle}
\begin{document}
\begin{figure}[ht]
\includegraphics[height=1cm]{foo}
\caption{Compound number \compound{foo}.}
\end{figure}
\begin{figure}[ht]
\includegraphics[height=1cm]{bar}
\caption{Compound number \compound{bar}.}
\end{figure}

This should be three: \compound{foobar}
\end{document}
share|improve this answer
    
When I compile your MWE, I get compound number 1 appearing three times. I'm using TeXShop and pdflatex... No idea if that helps but don't know what else it could be. –  JMS Oct 19 '11 at 2:23
    
Interesting, I also get 1 appearing three times, with chemcompounds.sty 2006/12/01 v1.1.3. What version are you using? –  Jake Oct 19 '11 at 2:31
    
Oh, and if I load chemcompounds directly, without loading chemstyle, the example works. chemstyle.sty 2011/01/05 v2.0k. –  Jake Oct 19 '11 at 2:36
    
I too am using TeXShop with pfdlatex (TeXLive 2011). I updated all the packages yesterday so not sure if that has anything to do with it. I also have chemstyle.sty 2011/01/05 v2.0k –  Peter Grill Oct 19 '11 at 3:12
    
I am using an older version... chemstyle.sty 2008/08/18 v1.3c. How does one force TexShop to use updated packages? When I put new versions in ~/Library/texmf/tex/latex/, latex still seems to load the older version (that comes packaged?) –  JMS Oct 19 '11 at 3:33
show 6 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.