# Show IEEElabels with showlabel?

I'm using IEEEtrantools to typeset equations (here's an excellent tutorial).

The package offers, among other things the IEEEeqnarray environment to typeset equations. That environment has an issue with labels, so one must use

\newcommand{\IEEElabel}[1]{\begingroup\addtocounter{equation}{-1}\refstepcounter{equation}\label{#1}\endgroup}


instead of \label.

The problem is to show IEEElabels with showlabel (or some other way?).

Here's an MWE:

\documentclass{article}

\usepackage{polyglossia} % support for languages

% fonts:
\defaultfontfeatures{Scale=MatchLowercase,Mapping=tex-text} % without this XeLaTeX won't turn "--" into dashes
\setmainfont{Arial}
\setsansfont{Arial}
\setmonofont{DejaVu Sans Mono}

% math:
\usepackage{IEEEtrantools} % for advanced typesetting like multiline equations, and the likes.
\usepackage{unicode-math} % to use unicode in the formulas -- to improve readability of sources
\setmathfont{Asana-Math.otf}

% showlabels?
\usepackage[inline]{showlabels}

\begin{document}

\begin{IEEEeqnarray}{rCl}
e^{i π} + 1 = 0
\IEEElabel{eq:test}
\end{IEEEeqnarray}

\end{document}


Edit:

Here's a snippet with amsmath, mathtools. When I use them -- I get no labels, when I don't -- the labels are there.

\documentclass{article}

\usepackage{polyglossia} % support for languages

% fonts:
\defaultfontfeatures{Scale=MatchLowercase,Mapping=tex-text} % without this XeLaTeX won't turn "--" into dashes
\setmainfont{Arial}
\setsansfont{Arial}
\setmonofont{DejaVu Sans Mono}

% math:
\usepackage{amsmath, mathtools}
\usepackage{IEEEtrantools} % for advanced typesetting like multiline equations, and the likes.
\usepackage{unicode-math} % to use unicode in the formulas -- to improve readability of sources
\setmathfont{Asana-Math.otf}

% showlabels?
\usepackage[inline]{showlabels}

% define a general showlabels patch for equation numbering commands
\makeatletter
\def\eqnnumpatch#1{
\expandafter\let\csname SL@#1\expandafter\endcsname\csname #1\endcsname
\expandafter\def\csname #1\endcsname{%
\csname SL@#1\endcsname     %% produce original equation number %%
\ifx\SL@labelname\relax
% do nothing
\else
\SL@eqnlrtext{\SL@labelname}%     %% produce label annotation %%
\fi
\global\let\SL@labelname\relax
}
}
\makeatother

% patch the two macros relevant for the IEEEeqnarray environment
\eqnnumpatch{theequationdis}
\eqnnumpatch{theIEEEsubequationdis}

\begin{document}

\begin{IEEEeqnarray}{rCl}
e^{i π} + 1 & = & 0
\label{eq:test}
\end{IEEEeqnarray}

\end{document}


I have the same IEEEtrantools and showlabel. Here're the full two logs: no math, with math.

-
It seems that the inline option is failing with IEEEeqalign. Without it the example works. – egreg Feb 27 at 15:11
@egreg: You right -- that's it! – Adobe Feb 27 at 15:23

The showlabels package redefines the \label macro to produce label annotations. However, within the redefined \label macro, it distinguishes between text mode, where the label annotation is produced directly, and math mode, where typesetting of the label annotation is put off until the actual equation number, i.e. (1), (2), etc., is typeset. The latter is done by also patching the \@eqnnum macro, which is used by LaTeX to typeset equation numbers, or alternatively \maketag@@@, which is defined by amsmath for the same purpose. The patched equation numbering macros then produce a label annotation by restoring the label name, which was stored in \SL@labelname by the showlabels-patched \label macro.

Unfortunately for you, IEEEeqnarray uses yet another set of macros to produce equation numbers, namely \theequationdis for regular equations and \theIEEEsubequationdis for subequations (which can be found out by looking into IEEEtrantools.sty). For this reason, label annotations won't show up out of the box. The obvious solution to your problem would be to patch these two commands in the same way as \@eqnnum, thus transparently integrating the showlabels functionality also into IEEEeqnarray.

If we look into showlabels.sty, we can see that the \@eqnnum macro is redefined in the following segment:

\let\SL@eqnnum=\@eqnnum
\def\@eqnnum{%
\SL@eqnnum
\ifx\SL@labelname\relax
% do nothing
\else
\SL@eqnlrtext{\SL@labelname}%
\fi
\global\let\SL@labelname\relax
}


The important thing to note here is how the redefined macro checks whether \SL@labelname has been set, and if so passes it to showlabel's \SL@eqnlrtext which produces the actual annotation. In the following MWE, I defined \eqnnumpatch which takes the csname of a macro and then patches it in the same way as shown above with \@eqnnum in the showlabel package. This macro is then used to patch the aforementioned equation numbering macros of IEEEtrantools:

\documentclass{article}

\usepackage{IEEEtrantools}
\usepackage[inline]{showlabels}

\makeatletter
%% 1) define a general showlabels patch for equation numbering commands
\def\eqnnumpatch#1{
\expandafter\let\csname SL@#1\expandafter\endcsname\csname #1\endcsname
\expandafter\def\csname #1\endcsname{%
\csname SL@#1\endcsname     %% produce original equation number %%
\ifx\SL@labelname\relax
% do nothing
\else
\SL@eqnlrtext{\SL@labelname}%     %% produce label annotation %%
\fi
\global\let\SL@labelname\relax
}
}
%% 2) fix showlabel's definition of \SL@inlinetext
\newif\ifSL@inline
\ifx\SL@setlabel\SL@inlinetext\SL@inlinetrue\fi    %% inline set? %%
\def\SL@inlinetext#1{%
\ifmmode                               %% remove \ifSL@AMS switch %%
\xdef\SL@labelname{\SL@prlabelname{#1}}%
\else
\SL@interlinetextright{\SL@prlabelname{#1}}%
\fi
}
\ifSL@inline
\let\SL@setlabel\SL@inlinetext %% correctly redefine \SL@setlabel %%
\fi
\makeatother

%% 3) patch the two macros relevant for the IEEEeqnarray environment
\eqnnumpatch{theequationdis}
\eqnnumpatch{theIEEEsubequationdis}

%% 4) test it
\begin{document}

\begin{IEEEeqnarray}{rCl}
e^{i p} + 1 = 0 \label{eq:first}\\
E = mc^2 \IEEEyessubnumber\label{eq:second}
\end{IEEEeqnarray}

\end{document}


Everything XeLaTeX related was omitted for the sake of brevity.

### edit:

This of course also works when using the \IEEElabel macro as defined in your question instead of \label. However, I wasn't able to reproduce your numbering issue, and as you didn't specify the exact problem with the equation counter and it appears to be unrelated to the actual IEEEtrantools+showlabels issue, I chose not to include it in the answer. Perhaps you should make sure that your version of IEEEtrantools is up to date.

### edit:

My original answer did not work with showlabel's inline option. This is due to the fact that the \SL@inlinetext macro is defined to do nothing in math mode if amsmath is used, obviously relying on the fact that the AMS environments store label names in \df@label. This problem has been fixed in the MWE shown above (cf. everything between comment fix showlabel's definition of \SL@inlinetext and \makeatother).

-
It looks like amsmath and/or mathtools break Your solution. – Adobe Feb 27 at 12:57
@Adobe could you be a bit more specific, please? When I add \usepackage{amsmath,mathtools} to the preamble, there is no apparent change in behaviour. Make sure you include amsmath/mathtools before you call \setmathfont. Are you using showlabels v1.6.5 <2009/05/29> and IEEEtrantools v1.3 <2012/12/27>? – benwilfut Feb 27 at 13:18
Also, amsmath has to be included prior to showlabels. Otherwise the \maketag@@@ macro will not be patched, and showlabels will not work in the equation, align, split, ... environments. This is pointed out in the showlabels manual. – benwilfut Feb 27 at 13:44
Please see the updated question -- I've added an MWE with amsmath and mathtools -- which doesn't work for me. – Adobe Feb 27 at 14:52
@Adobe: Sorry, I forgot to check my solution with the inline option. I fixed the issue in my answer. – benwilfut Feb 27 at 17:23