1

I keep getting this Text right underneath the heading of my document, just "cosxx12."

When I delete the following lines

\begin{figure}
  \includegraphics[width=100mm]{expxcosx.png}
  \caption{$e^x$ vs. $\cos x$}
  \label{fig:Graph e^x vs. \cos x}
\end{figure}

The text disappears. I have no idea what is going on. What can I do to remove this?

Werner
  • 603,163
  • How about not using \cos in your \label, but instead just cos. Also, don't use spaces... – Werner Jan 15 '17 at 05:11
  • hm I will try and do that....no spaces in the label? Now I am getting an invalid root error and nothing is compiling at all, is that possibly related? – operatorerror Jan 15 '17 at 05:17
  • Yes, delete your .aux and retry to compile. – Werner Jan 15 '17 at 05:28
  • @Werner oops got it that did it. So I guess there isn't a good way to format math within the label? – operatorerror Jan 15 '17 at 05:30
  • Why would you want to? A label is a document-internal identifier of something, that can later be referenced. Give it a good name, not an equation. – rubenvb Jan 15 '17 at 09:25

1 Answers1

1

Don't use strange things in your \labels. In this case, math content. Here's what happens using a relevant example (following along with Understanding how references and labels work):

\documentclass{article}

\begin{document}

\begin{figure}
  \caption{$e^x \cos x$}
  \label{fig:e^x \cos x}
\end{figure}

\end{document}

After the first compilation, one would think there's something like \newlabel{fig:e^x \cos x}{{<fig>}{<page>}} in the .aux. However, this is not the case:

\newlabel{fig:e^x \mathop {\mathgroup \symoperators cos}\nolimits x}{{1}{1}}

\cos is fully-expanded, causing all sorts of problems. As such, avoid math-related content in your labels as a general rule, since they may be shorthand for bigger hidden things.

In fact, \cos even expands in the \caption (which may be used in \listoffigures) and therefore might be problematic. In this case its not, but it may help using \protect\cos in moving arguments like \caption.

Werner
  • 603,163