2

I'm using the \nameref package and I need to obtain a labelled text within round brackets, but it adds some space before the right bracket, while it doesn't add space after the left bracket. Here is the MWE:

\documentclass[a4paper, 12pt]{article}


\usepackage{nameref}

\newcounter{mylabelcounter}

\makeatletter
\newcommand{\labelText}[2]{%
#1\refstepcounter{mylabelcounter}
\immediate\write\@auxout{%
  %\string\newlabel{#2}{{1}{\thepage}{{#1}}{mylabelcounter.\number\value{mylabelcounter}}{}}
  \string\newlabel{#2}{{1}{\thepage}{{\unexpanded{#1}}}{mylabelcounter.\number\value{mylabelcounter}}{}}
}%
}
\makeatother


\begin{document}


(\labelText{A}{label:textA})

\end{document}

How can I do to avoid the unwanted addition of space before the right bracket?

N.B. adding \hspace{-xpt} doesnt't works as the space added isn't fixed but depends on the type of letter.

Thank you!

Edit: I added the MWE

qwertxyz
  • 542
  • Well, I've gave an answer once defining something like \labelText, perhaps I've missed some % character, but it could be some totally different code -- and that's the point: Which code are you using? Please post the minimal version of your document that shows this issue! –  Jan 04 '17 at 23:58
  • So, how is \labelText defined? – Werner Jan 04 '17 at 23:58
  • 2
    Add % after \refstepcounter{mylabelcounter} – egreg Jan 05 '17 at 00:09
  • Yes, it was one of my answers ;-) http://tex.stackexchange.com/questions/271062/labeling-a-text-and-referencing-it-later -- Corrected it –  Jan 05 '17 at 00:13
  • 1
    Also at the end of the \string line, although it's not essential. – egreg Jan 05 '17 at 00:13
  • @egreg: Yes, ... and the O.P. used just that version of my answers with this approach that had the missing % ... –  Jan 05 '17 at 00:16
  • Yes, it is possible that I used that version from your answer :) – qwertxyz Jan 05 '17 at 00:18

0 Answers0