3

I realized that I sometimes write :

\begin{figure}
   ...
   \label{fig:foo}
   \caption{Bla}
\end{figure}

instead of:

\begin{figure}
   ...
   \caption{Bla}
   \label{fig:foo}
\end{figure}

Which results in wrong reference numbers.

Is there an easy way to catch all these errors?

  • 1
    Not really; LaTeX is just doing what you tell it to do (labeling the last element that had an associated number generated). There's no way for it to know that you mean something other than what you code. – Paul Gessler Mar 10 '14 at 17:40
2

If your editor supports regular expressions this expression should find all wrong label+caption statements

\\label\{.*\}\r*\n*\\caption\{.*\}

  • Thanks for your suggestion. I used pcregrep instead. – Maxime Mar 11 '14 at 13:07
3

I would suggest to insert systematically the \label command inside the argument of \caption to avoid that sort of “errors”:

\caption{\label{fig:foo}Bla}
0

Based on Oliver's answer, I used:

pcregrep -M "\\\label{.*}\r*\n*\\\caption{.*}" */*.tex

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.