Robustness fix: cope with \index{Poincar\'e}
5 files changed, 82 insertions(+), 12 deletions(-)

M Makefile
M showlabels.dtx.in
M showlabels.html
A => t/t19.tex
M t/t4.tex
M Makefile +5 -1
@@ 2,7 2,11 @@ 
 #
 # Just for packaging -- not distributed
 
-VERSION=1.8
+# FIXME: add the usual step-by-step instructions for distribution,
+# and check that the bundle does match the suggestions at
+# <https://ctan.org/help/upload-pkg>.
+
+VERSION=1.8.1-SNAPSHOT
 RELEASEDATE=2016 June 9
 #  following must be yyyy/mm/dd
 RELEASEDATEN=2016/06/09

          
M showlabels.dtx.in +18 -5
@@ 479,8 479,14 @@ 
 %
 % \begin{macro}{\SL@prlabelname}
 % Expansion is label name with all catcodes `other' (Appendix~D trickery
-% abounds!).  Use |\r@#1|, rather then just |\#1| to avoid defining any new
-% control sequences.
+% abounds!).  Use |\r@#1| (defined by |\ref|), rather then just |\#1|
+% to avoid defining any new control sequences.
+%
+% Note that this catcode magic, and the |\@sanitize| in
+% |\SL@showlabels| below, are doing much the same job, and indeed are
+% almost redundant with each other.  But this |\SL@prlabelname|
+% doesn't cope with eg |\index{Poincar\'e}|, and the |\@sanitize|
+% below doesn't cope with |\section{\label{a_b}Foo}| (see tests t4 and t19).
 %    \begin{macrocode}
 \def\SL@prlabelname#1{%
 \expandafter\expandafter\expandafter\SL@gobblethree

          
@@ 585,9 591,16 @@ 
 % We actually handle three distinct cases here, for |\foo{label}|,
 % |\foo[opt]{label}| and |\foo*{label}| (the last is to handle the
 % \Lpackage{hyperref} package's |\ref*{label}| variant; see test case t14).
+%
+% We open a group in order to call |\@sanitize|; we're able to close
+% it immediately, within the called macros.  We call |\@sanitize| in
+% order to cope with eg |\index{Poincar\'e}| (see discussion of
+% |\SL@prlabelname| above).
 %    \begin{macrocode}
 \DeclareRobustCommand\SL@showlabels[1]{%
+  \@bsphack
   \expandafter\let\expandafter\SL@orig@@next\csname SL@orig#1\endcsname
+  \begingroup\@sanitize
   \@ifstar
     {\SL@showlabelsplainstar}
     {\@ifnextchar[

          
@@ 595,19 608,19 @@ 
        {\SL@showlabelsplain}}
 }
 \def\SL@showlabelsopt[#1]#2{%
-  \@bsphack
+  \endgroup
   \SL@setlabel{#2}\relax
   \ifhmode \spacefactor\@savsf \ifdim\@savsk>\z@ \hskip1sp \fi\fi
   \SL@orig@@next[#1]{#2}%
 }
 \def\SL@showlabelsplain#1{%
-  \@bsphack
+  \endgroup
   \SL@setlabel{#1}\relax
   \ifhmode \spacefactor\@savsf \ifdim\@savsk>\z@ \hskip1sp \fi\fi
   \SL@orig@@next{#1}%
 }
 \def\SL@showlabelsplainstar#1{%
-  \@bsphack
+  \endgroup
   \SL@setlabel{#1}\relax
   \ifhmode \spacefactor\@savsf \ifdim\@savsk>\z@ \hskip1sp \fi\fi
   \SL@orig@@next*{#1}%

          
M showlabels.html +12 -3
@@ 30,8 30,6 @@ whenever either the <code>\label</code> 
 equation is automatically numbered.  It is compatible with the
 <code>amsmath</code> and <code>hyperref</code> packages.</p>
 
-<p>It is similar to, but does a little more than, the showkeys package.</p>
-
 <p>You invoke this package with the command
 <code>\usepackage{showlabels}</code> in the preamble.  You can control
 where the labels appear – in the margins or in the interline gaps –

          
@@ 58,6 56,13 @@ conflict in either case).  The package c
 in the wrong margins, near the top of a page – see the documentation
 for a discussion of this.</p>
 
+<p>The <code>{showlabels}</code> package has a large overlap in
+functionality with David Carlisle's <code>{showkeys}</code>, although
+the latter will only handle <code>\label</code> and <code>\cite</code> keys.  If
+<code>{showlabels}</code> fails in some particular situation, you might
+want to try using <code>{showkeys}</code>, but please do mention the
+problem, typically by email to me.</p>
+
 <h3>Download and installation</h3>
 
 <ol>

          
@@ 100,7 105,11 @@ either version 1.3 of this licence or (a
 
 <h3>History</h3>
 <dl>
-<dt><span class='attention'><strong>1.8, 2016 June 9</strong></span></dt>
+<dt><span class='attention'><strong>1.8.X, YYYY MMM DD</strong></span></dt>
+<dd>Robustness fix: macros in arguments are now handled, so that
+<code>\index{Poincar\'e}</code> doesn't cause an error.</dd>
+
+<dt><strong>1.8, 2016 June 9</strong></dt>
 <dd>The <code>ntheorem</code> package exposed an apparently
 long-standing incompleteness in the handling of <code>amsmath</code>
 documents.

          
A => t/t19.tex +43 -0
@@ 0,0 1,43 @@ 
+%%% Testing: \index with macros; like t4, but not inline
+% Compare t4
+\documentclass{article}
+
+\parindent0pt
+\parskip\bigskipamount
+
+% Setup for using this with XeLaTeX --
+% the underscores look odd with a non-tt TeX font, but are OK
+% with native fonts.
+%\usepackage{fontspec}
+%\setromanfont{Optima}
+%\setsansfont{Optima}
+%\setmonofont[Scale=0.8]{Monaco}
+
+\usepackage{showlabels}
+\showlabels{cite}
+\showlabels{begin}
+\showlabels{ref}
+\showlabels{index}
+\makeindex
+
+\begin{document}
+\section{\label{s:s1_a sect}This is a section}
+
+The labels in this file have underscores and spaces in them, and
+should be formatted without error.
+
+We talk about Poincar\'e\index{Poincar\'e}.
+
+This is \label{s:s1_b text} some text.
+
+And an equation:
+\begin{equation}
+\label{e:e a_1} % label with space and underscore
+E=mc^2,
+\end{equation}
+which we can refer to as
+\begin{itemize}
+\item Eq.\ref{e:e a_1}, and
+\item \cite{nobody_bar\'e}.
+\end{itemize}
+\end{document}

          
M t/t4.tex +4 -3
@@ 1,5 1,5 @@ 
-%%% Testing:[inline] option, and \showlabelfont, and labels with space
-%%% and underscore.
+%%% Testing:[inline] option, and \showlabelfont, and labels with space and underscore.
+% Compare t19
 \documentclass{article}
 
 \parindent0pt

          
@@ 17,6 17,7 @@ 
 \showlabels{cite}
 \showlabels{begin}
 \showlabels{ref}
+\showlabels{index}
 \renewcommand{\showlabelfont}{\small\sffamily\color{blue}}
 
 \usepackage{color}

          
@@ 33,7 34,7 @@ as the showlabelfont, these underscores 
 fonts.
 
 Each of the begin, ref and cite commands in the file should have an
-inline label attached to it.
+inline label attached to it.  As should Poincar\'e\index{Poincar\'e}.
 
 This is \label{s:s1_b text} some text, with an equation.
 \begin{equation}