# What internal command(s) does \hspace call?

I know that (by \hspace vs. \hspace*) the command \hspace* calls the internal commands

\vrule width 0pt \nobreak \hskip 1cm \hskip 0pt plus 0pt minus 0pt


but which command(s) does \hspace use? Is there a way to see the implementation of \hspace?

• Could you say what you are aiming to achieve? Depending on the code you might find \hspace or the primitive \hskip code being used for arbitrary spacing. – Joseph Wright Oct 7 '14 at 12:35
• Yes basically I want to learn how to program in LaTeX, then I want to know what the commands (at least the basic) do! – Valerin Oct 7 '14 at 12:47
• Ah, an (English) language thing: 'what commands calls \hspace' can be interpreted as meaning 'Which commands use \hspace internally?' while you mean 'How is \hspace implemented?' or similar. – Joseph Wright Oct 7 '14 at 12:57

You can use \show or \meaning to see individual commands but I usually have latex.ltx in my emacs (editor) buffer, you can find your copy with kpsewhich (or just look in the log of any latex file for the file path to article.cls etc)

On my system

\$ kpsewhich latex.ltx
/usr/local/texlive/2014/texmf-dist/tex/latex/base/latex.ltx


At line 1308 you see

\DeclareRobustCommand\hspace{\@ifstar\@hspacer\@hspace}
\def\@hspace#1{\hskip #1\relax}
\def\@hspacer#1{\vrule \@width\z@\nobreak
\hskip #1\hskip \z@skip}


searching in the file will show that \hspace does not appear except in those lines so no command defined in the format uses \hspace in its definition.

You can also see a typeset pdf version of the same by going

texdoc source2e

• If they're defined by \def, why do they appear as long? Is it possible that amsmath redefines them? – yo' Oct 7 '14 at 13:12
• @tohecz The only one that is long is the one defined with \DeclareRobustCommand – David Carlisle Oct 7 '14 at 13:52
\makeatletter
\show\hspace
% \hspace=macro: ->\protect \hspace  .
\expandafter\show\csname hspace \endcsname
% \hspace =\long macro: ->\@ifstar \@hspacer \@hspace .
\show\@hspace
% > \@hspace=macro: #1->\hskip #1\relax .


So it's \hskip that gets called. The \expandafter\show\csname trick has been explained before.

• You could also do \let\protect\show\hspace to get to the \@hspace step. – Joseph Wright Oct 7 '14 at 13:28
• @JosephWright that's what I usually do, but best to mention to do that in a local group, otherwise latex will behave a little strangely:-) – David Carlisle Oct 7 '14 at 13:54
• @DavidCarlisle I thought about adding the grouping, but most of the time this is best done in a 'demo' file that you then stop processing so missed it out – Joseph Wright Oct 7 '14 at 14:08
• \usepackage{xpatch} and \xshowcmd\hspace. – egreg Oct 7 '14 at 14:56