5

I've used the wonderful LTXexample environment defined by showexpl to illustrate some LaTeX basics. However, the following code confuses it: the reference remains ?? no matter how many times I recompile...

\documentclass{article}
\usepackage{showexpl}
\begin{document}

\begin{LTXexample}[frame=none]
  \begin{enumerate}
  \item No need to manually number items here!
  \item\label{second} Number two added automatically
  \item Third item
  \end{enumerate}
  And here is a reference to item number \ref{second}
\end{LTXexample}

\end{document}

I've managed references inside LTXexample in equation environments, so this is something specific to enumerate... Any ideas how to fix it? (I can't even cheat and just put "2" because the code is shown side-by-side with it...)

UPDATE: I emailed the author of showexpl but I've had no reply. Does anyone feel like delving into the code to see if it's obvious how to fix this?

Seamus
  • 73,242

2 Answers2

4

It is not a bug. It is deliberate. showexpl sets quite a lot commands to \@gobble in \SX@@preset. The SX@1-label is from LTXexample itself, not from the \label{second}. You can reactivate \label:

\documentclass{article}
\usepackage{showexpl}
\begin{document}
\let\orilabel\label
\begin{LTXexample}[frame=none,preset=\let\label\orilabel]
  \begin{enumerate}
  \item No need to manually number items here!
  \item\label{second} Number two added automatically
  \item Third item
  \end{enumerate}
  And here is a reference to item number \ref{second}
\end{LTXexample}

\end{document}
Ulrike Fischer
  • 327,261
  • Wow! Can you also explain why showexpl does this to the \label? I just can't see what this feature is good for. – Hendrik Vogt Dec 15 '10 at 18:21
  • I don't know. Perhaps it breaks in some cases. Or Rolf did so that you can use \label{second} in another example without conflict. Or perhaps he copied simply the list of commands from latex.ltx: \label is deactivated in other commands too. Btw: The list contains a tipo \let\tableofcontens\relax. – Ulrike Fischer Dec 15 '10 at 18:34
  • Why does this make labels break for enumerate, but not for equation? That seems weird... – Seamus Dec 16 '10 at 09:53
  • It breaks for the original equation too. This changes if you load amsmath: amsmath has to process quite often the content of an equation twice. So it stores the original \label definition and restores it in the equation and so isn't affected if \label is changed somewhere in the document. – Ulrike Fischer Dec 16 '10 at 11:03
1

Looks like a bug somewhere in showxmpl to me. If you look in the .aux file, rather than the expected label you see

\newlabel{SX@1}{{}{1}}

So if you hack the .aux to read

    \newlabel{second}{{2}{1}}

then things will work but of course you'll have to re-do this every LaTeX run.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036