1

This question already has an answer here:

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

marked as duplicate by egreg spacing Jan 5 '17 at 0:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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! – user31729 Jan 4 '17 at 23:58
  • So, how is \labelText defined? – Werner Jan 4 '17 at 23:58
  • 1
    Add % after \refstepcounter{mylabelcounter} – egreg Jan 5 '17 at 0:09
  • Yes, it was one of my answers ;-) tex.stackexchange.com/questions/271062/… -- Corrected it – user31729 Jan 5 '17 at 0:13
  • 1
    Also at the end of the \string line, although it's not essential. – egreg Jan 5 '17 at 0:13

Browse other questions tagged or ask your own question.