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.

Apparently it seems to raise a warning »LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.« if I want to use a mathematical equation in a figure's caption and I use the onlyamsmath and the hyperref packages in the document's preamble as follows:

\documentclass{scrartcl}

\usepackage{amsmath}
\usepackage[all,error]{onlyamsmath}
\usepackage{hyperref}

\begin{document}

Reference~\ref{fig:foobar}.

\begin{figure}[htb!]
  \caption{Foo Bar $f=2$}
  \label{fig:foobar}
\end{figure}

\end{document}

I have currently no clue why this happens and what I should change ...

share|improve this question
7  
The warning is perfectly normal at the first run, because LaTeX doesn't yet know what number the label fig:foobar refers to. It will be issued every time LaTeX finds a new label or some reference has changed. A new run of LaTeX will fix the "problem". –  egreg Jun 15 '12 at 12:58
    
For more complicated documents even three, four,... compilation runs can be necessary. –  Stephen Jun 15 '12 at 17:19
    
I think you may have found a bug. The .aux file is unchanged from run 1 to run 2 of LaTeX, but the warning keeps coming up no matter how many times I run it. Disabling either onlyamsmath or hyperref makes the problem go away, so I imagine the problem is a conflict between those two packages (both of which do some scary low-level stuff). –  Zack Jun 17 '12 at 17:31
    
See my answer tex.stackexchange.com/a/78757/10777 how to remove the $ feature from amsmath which is the source of many problems. –  jofel Oct 23 '12 at 9:12

3 Answers 3

up vote 5 down vote accepted

The right solution, in my opinion, is not using onlyamsmath at all: it makes more damages than it solves.

However, if you really prefer using it, then accustom yourself to write

\(a=b\)

for all formulas, instead of $a=b$. And remember to load also the fixltx2e package, otherwise formulas in captions will result in disasters when trying to use \listoffigures or \listoftables.

\documentclass{scrartcl}

\usepackage{fixltx2e}    
\usepackage{amsmath}
\usepackage[all,error]{onlyamsmath}
\usepackage{hyperref}

\begin{document}

Reference~\ref{fig:foobar}.

\begin{figure}[htb!]
  \caption{Foo Bar \(f=2\)}
  \label{fig:foobar}
\end{figure}

\end{document}
share|improve this answer

This is solved when you use the LaTeX inline math environment \( ... \) instead of the commonly used (though plain TeX directive) $ ... $.

share|improve this answer
    
True, since the problem is in the catcode of $ (as I explained in my answer). –  mbork Jun 17 '12 at 17:49
    
Unfortunately this doesn't really solve the problem: look at the generated .aux file. –  egreg Jun 17 '12 at 18:02
    
@egreg: Gee wizz - just as long as you don't create a contents for your floats. –  Werner Jun 17 '12 at 18:08

The explanation is quite simple - but only once you know it;). Actually, I've been able to run into a similar issue without hyperref, but I suspect the problem is the same.

When you run LaTeX on a source file, first the aux file is read and after that the \AtBeginDocument commands are executed. And since onlyamsmath says

\AtBeginDocument{\catcode‘\$=13 }

it means that labels etc. are read under normal catcode regime of $, and checked during compilation with $'s catcode set to "active". Therefore for all labels using this character LaTeX will always complain. (And what makes the problem tricky is that the character codes of everything in the aux file stay the same, i.e. the aux file itself stays identical in the sense of diff.

The remedy to this problem is thus quite simple: just say

\catcode`\$=13

somewhere in your preamble (best right before edit: not before, but after, since onlyamsmath uses $ with its normal catcode too! \usepackage{onlyamsmath}, or at least take care so that between this line and loading of that package you never actually use the dollar sign).

share|improve this answer

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.