Amend \showlabels optional argument to support one-arg macro.

Also add `\showlabeltype` macro.

This should end up as version 1.9, with a version bump to acknowledge
that this is a non-trivial change in functionality.
4 files changed, 56 insertions(+), 16 deletions(-)

M Makefile
M showlabels.dtx.in
M showlabels.html
M t/t19.tex
M Makefile +2 -2
@@ 6,13 6,13 @@ 
 # and check that the bundle does match the suggestions at
 # <https://ctan.org/help/upload-pkg>.
 
-VERSION=1.8.1-SNAPSHOT
+VERSION=1.9-SNAPSHOT
 RELEASEDATE=2016 June 9
 #  following must be yyyy/mm/dd
 RELEASEDATEN=2016/06/09
 DIST=showlabels-$(VERSION)
 
-COPYRIGHTYEARS=1999, 2001-09, 2013-16
+COPYRIGHTYEARS=1999, 2001-09, 2013-21
 
 DISTFILES=showlabels.ins showlabels.dtx showlabels.html showlabels.pdf \
 	lppl.txt style.css

          
M showlabels.dtx.in +36 -6
@@ 154,8 154,8 @@ 
 % \begin{quote}
 % |\renewcommand{\showlabelfont}{\small\slshape\color{green}}|
 % \end{quote}
-% in the preamble of your document, as long as you have loaded the
-% \Lpackage{color} package.
+% in the preamble of your document (as long as you have loaded the
+% \Lpackage{color} package, of course).
 %
 % Alternatively, the |\showlabels| command has an optional argument containing
 % formatting commands, which allows you to format |\cite| labels, for

          
@@ 163,6 163,12 @@ 
 % \begin{quote}
 % |\showlabels[\color{green}]{cite}|
 % \end{quote}
+% The optional formatting command can be either a font-changing
+% command, as illustrated here, \emph{or} a command which takes a
+% single argument, such as
+% \begin{quote}
+% |\showlabels[\fbox]{cite}|
+% \end{quote}
 %
 % If, finally, you want complete control over the labels, you can
 % instead override |\showlabelsetlabel|, which initially expands to

          
@@ 174,13 180,25 @@ 
 % \null\qquad |{\begin{turn}{60}\showlabelfont #1\end{turn}}|\\
 % \end{quote}
 % then you end up with your labels at a jaunty angle in the margin.
-% Finally, you can change the definition of the
-% |\showlabelrefline| rule from its default,
-% in order to change how the inline rule (see below) is displayed.
+%
+% The command |\showlabeltype| will expand to the current label type
+% (ie, `label' or `cite', etc), so it would be possible for
+% |\showlabelsetlabel| to conditionalise on that, if you felt that
+% were necessary.\footnote{The support for an one-argument command in
+% $\backslash$\texttt{showlabels}, and the presence of the
+% $\backslash$\texttt{showlabeltype} macro, were added in version 1.9.}
+%
+% If instead you want to adjust how inline markings are displayed, you
+% can change the definition of the
+% |\showlabelrefline| rule from its default.
 % For example, defining this to be
+% \begin{quote}
 % |\color{red}\hrule width 0.1em height 1.5ex depth 0pt |
+% \end{quote}
 % produces a fattish red line, and defining it to be
+% \begin{quote}
 % |\hrule width 0pt height 1.5ex depth 0pt|
+% \end{quote}
 % suppresses the line but still positions the text between the lines.
 %
 % \subsection*{Compatibility with other packages, and other problems}

          
@@ 468,7 486,7 @@ 
 % If you want slightly more general control over the labels, you can
 % instead override |\showlabelsetlabel|.
 %    \begin{macrocode}
-\providecommand{\showlabelsetlabel}[1]{{\normalfont\showlabelfont\SL@fmt@ #1}}
+\providecommand{\showlabelsetlabel}[1]{{\normalfont\showlabelfont\SL@fmt@{#1}}}
 %    \end{macrocode}
 %
 % For the benefit of |\SL@prlabelname|, define |\SL@gobblethree| to do nothing

          
@@ 596,10 614,22 @@ 
 % it immediately, within the called macros.  We call |\@sanitize| in
 % order to cope with eg |\index{Poincar\'e}| (see discussion of
 % |\SL@prlabelname| above).
+%
+% We declare |\showlabeltype| to be the `current' label type.  It
+% would be good to put this inside a group, so that it's only visible
+% locally, but we would then have to be careful exactly when we closed
+% the group: if we put it inside the group that's opened for
+% |\@sanitize|, it would be closed too early to have an effect; if we
+% open another group for |\showlabeltype|, then we'd have to close it
+% \emph{after} |\SL@orig@@next|, where we risk colliding with whatever
+% comes after it (and see above).  It might be possible to be cleverer
+% about this, but it's at least harmeless to have the command defined
+% globally.
 %    \begin{macrocode}
 \DeclareRobustCommand\SL@showlabels[1]{%
   \@bsphack
   \expandafter\let\expandafter\SL@orig@@next\csname SL@orig#1\endcsname
+  \def\showlabeltype{#1}%
   \begingroup\@sanitize
   \@ifstar
     {\SL@showlabelsplainstar}

          
M showlabels.html +10 -3
@@ 105,9 105,16 @@ either version 1.3 of this licence or (a
 
 <h3>History</h3>
 <dl>
-<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><span class='attention'><strong>1.9, YYYY MMM DD</strong></span></dt>
+<dd><ul>
+  <li>Robustness fix: macros in arguments are now handled, so that
+  (after <code>\showlabel{index}</code>),
+  <code>\index{Poincar\'e}</code> doesn't cause an error.</li>
+  <li>The <code>\showlabel[optarg]{command}</code> optional argument
+  can now take a one-argument command.</li>
+  <li>The macro <code>\showlabeltype</code> expands to the current
+  label type, for possible use in <code>\showlabelsetlabel</code>.</li>
+</ul></dd>
 
 <dt><strong>1.8, 2016 June 9</strong></dt>
 <dd>The <code>ntheorem</code> package exposed an apparently

          
M t/t19.tex +8 -5
@@ 1,6 1,7 @@ 
 %%% Testing: \index with macros; like t4, but not inline
 % Compare t4
 \documentclass{article}
+\usepackage{color}
 
 \parindent0pt
 \parskip\bigskipamount

          
@@ 15,8 16,9 @@ 
 
 \usepackage{showlabels}
 \showlabels{cite}
-\showlabels{begin}
-\showlabels{ref}
+\showlabels[\color{green}]{begin}
+\def\reflabel#1{\fbox{#1} (\showlabeltype)}
+\showlabels[\reflabel]{ref}
 \showlabels{index}
 \makeindex
 

          
@@ 30,14 32,15 @@ We talk about Poincar\'e\index{Poincar\'
 
 This is \label{s:s1_b text} some text.
 
-And an equation:
+And an equation (environments labelled in green):
 \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}.
+\item Eq.\ref{e:e a_1} (which should be labelled in a \texttt{fbox}
+  plus type), and
+\item Citation \cite{nobody_bar\'e}.
 \end{itemize}
 \end{document}