6

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?

Valerin
  • 183
  • 1
    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 07 '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 07 '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 07 '14 at 12:57

2 Answers2

6

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
David Carlisle
  • 757,742
5
\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.

yo'
  • 51,322