# \textbf has wider space than \bf with own command

How come the \textbf command results in a wider space between words, than the deprecated \bf when using this own command?

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\makeatletter
\newcommand*{\textlabel}[2]{
\edef\@currentlabel{#1}
\phantomsection
#1\label{#2}
}
\makeatother

\begin{description}
\item[item] \textbf{\textlabel{First text}{ref1}} \\
Description!
\item[item] {\bf \textlabel{Second text}{ref2}} \\
Description!
\end{description}
\end{document}


Output:

-
add comment

## 1 Answer

You have three spurious spaces in your definition of \textlabel. If you remove them by masking the end-of-lines, the result is the same:

\makeatletter
\newcommand*{\textlabel}[2]{% <- Here
\edef\@currentlabel{#1}% <- Here
\phantomsection
#1\label{#2}% <- Here
}
\makeatother


Why don't the spaces show up in the second case? Because \textbf starts a paragraph by itself, while \bf doesn't. So in the second case the spaces are ignored because TeX is still not typesetting a paragraph.

The correct command to use with a syntax similar to \bf is \bfseries: it's a declaration, so it needs a pair of braces or it can be issued in an environment. But it's preferable to use \textbf in running text: you can see a difference between

{\bf stuff} boldfaced


and

\textbf{stuff} boldfaced


because in the second case LaTeX adds the "italic correction" that compensates for the "f" bumping into the interword space.

-
Perhaps add a hint that \bfseries features the same behaviour as the obsolete \bf. –  lockstep May 13 '12 at 22:50
@lockstep But the \bfseries needs including a package right? –  cherrung May 13 '12 at 22:53
@egreg Awesome. Learned something new again. This actually just happened today, because I had comments after each line and wanted to make the comments look nice, but having a space between the code and the '%' comment symbol. Silly me. –  cherrung May 13 '12 at 22:53
@lockstep I wouldn't recommend using \bfseries in that situation. –  egreg May 13 '12 at 22:53
@egreg But would you recommend \bf? (My hint was mainly about that the OP's problem is not due to using an obsolete command.) –  lockstep May 13 '12 at 22:55
show 2 more comments