I'm not proficient in LaTeX enough to solve the following. I have a macro that takes two parameters, creates a nice box, puts the first argument in bold, and the second argument in an emphasized text:

\noindent{\\[0pt] \rule{0pt}{0.5ex}%
\hspace*{1em}\fbox{\parbox[t]{0.92\columnwidth}{{\bfseries Step #1.\ }\emph{#2}}}}
    \vspace*{1.1ex} }

I call this macro 10-15 times in text (that many steps I have). In order to be able to refer to the page where this macro is expanded, I would now like to place a label. If I change the last line to:

    \vspace*{1.1ex} \label{step:mode:#1} }

errors start to pop up. I get this, on a completely unrelated line:

! Missing \endcsname inserted.
<to be read again> 
l.160 ...aults Occur\relax }{figure.caption.52}{}}

This line probably comes from some auxiliary file.

How to properly expand the first argument and use it as an argument to label? First argument does not have spaces, and will never have them.

  • What errors are popping up? – Werner Dec 2 '11 at 15:07
  • I found the problem. It turns out that I indeed called the macro passing something with other macro invocations as the first argument. That was causing problems. Sorry for the trouble. For the curious, the call was \Step{R\textsuperscript{+}4.a}{blah, blah}. – Nikola Knezevic Dec 2 '11 at 15:25

You may redefine \textsuperscript while setting the label. Here \@firstofone would be a good redefinition. This command simply reads the argument and uses it, as it is.

An additional \csname phantomsection\endcsname may also be a good idea to have working links with package hyperref:

\usepackage{lipsum}% for demonstration only
\usepackage{hyperref}% to show, that this works

    \csname phantomsection\endcsname
    \hspace*{1em}\fbox{\parbox[t]{\dimexpr \linewidth-2em-2\fboxsep-2\fboxrule\relax}{%
        {\bfseries Step #1.\ }\emph{#2}}}}\par

\Step{R\textsuperscript{+}4.a}{blah, blah}
See R\textsuperscript{+}4.b on page \pageref{R+4.b}.

\Step{R\textsuperscript{+}4.b}{blah, blah}
See R\textsuperscript{+}4.a on page \pageref{R+4.a}.


The \csname phantomsection\endcsname would simply be \relax, if hyperref is not used, so it's almost nothing.

  • Wow, this is great, and exactly what I was looking for. – Nikola Knezevic Dec 2 '11 at 15:57

I'd do in a different way:

  {\textbf{Step #1.}\ \emph{#2}}}\label{step:mode:#1}\\*[1.1ex]}

In this way the \fbox will be centered on the line and have equal space before and after it (correct the spacings, if you don't like them as they are now).

Pay attention that spaces are allowed in labels, but not accented characters or commands. So \Step{R\textsuperscript{+}4.a}{blah, blah} will surely give problems. You can solve it by saying

  {\textbf{Step #2.}\ \emph{#3}}}\label{step:mode:#1}\\*[1.1ex]}

and call this problematic entry as

\Step[R+4.a]{R\textsuperscript{+}4.a}{blah, blah}

referring then to

  • I ended up coding something like this at the end. Since I have a minority of calls where I have textsuperscript, I just created another macro. Thanks. – Nikola Knezevic Dec 2 '11 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.