11

In (La)TeX source code definitions are sometimes written with a space after \def and with a space after the control-sequence being defined. For example, these two lines come from miniltx.tex:

\long\def \@gobbletwo #1#2{}
...
\long\def\@firstoftwo#1#2{#1}

As far as I can tell, the extra one or two spaces make no difference to the definition. I assume they're meant to document some behavior. What is that behavior, or what is the purpose of the spaces?

  • 1
    There, the only purpose I can see is aligning two lines for better readability. Other than that, there's no difference at all between leaving spaces or not leaving spaces. It's true that I see different spacing sometimes with no purpose of alinging and that annoys me too. – Manuel Aug 17 '15 at 19:18
  • It made sense to eliminate all unnecessary spaces when your computer terminal was a mechanical typewriter with a speed of about 10 characters per second. The first release of LaTeX was at about the same time as IBM released Mk III of its Selectric "golf-ball" terminal. If "legacy code" works well, the best option is not to mess about with it without a very good reason! – alephzero Aug 17 '15 at 22:44
  • @Manuel -- that's what makes xii.tex so readable: everything is perfectly aligned in one code block! – jon Aug 18 '15 at 3:43
11

Since the spaces after the command sequence names are ignored in

\long\def \@gobbletwo #1#2{}

this line is equivalent to the version without spaces:

\long\def\@gobbletwo#1#2{}

Mixing these styles without reason is just bad coding style.

Spaces could be used for enhanced readability or vertical code alignments, e.g.:

\long\def\@gobble     #1{}
\long\def\@gobbletwo  #1#2{}
\long\def\@gobblefour #1#2#3#4{}
\long\def\@firstofone #1{#1}
\long\def\@firstoftwo #1#2{#1}
\long\def\@secondoftwo#1#2{#2}
  • David Carlisle did miniltx, and I assume he had a purpose besides alignment, because I see the extra spaces elsewhere, like \long\def \IfFileExists#1#2#3{%. I wonder what he had in mind. – Dan Levin Aug 17 '15 at 19:25
  • 1
    @DanLevin Probably copied from the LaTeX kernel, which was written over many years and isn't exactly stylistically consistent! – Joseph Wright Aug 17 '15 at 19:27
  • 3
    David's code is free of bug, of course ;-). However, this does not mean, that it applies to the code formatting, which is not consistent indeed. But the comment lines at the top of miniltx.tex only say, that he has contributed some changes, the original code comes from the LaTeX3 project. Maybe he can claim others for the inconsistencies in the formatting. :-) – Heiko Oberdiek Aug 17 '15 at 19:39
10

miniltx was a few minutes work, I just copied things from the latex.ltx source of the latex format until an example using \includegraphics worked in plain TeX.

So you need to look at the source of latex.ltx which was written by several people over several years.

In this case

%
% \begin{macro}{\@gobble}
% \begin{macro}{\@gobbletwo}
% \begin{macro}{\@gobblefour}
% \changes{v1.2n}{1995/05/26}{(CAR) Added \cs{long}s}
%    The |\@gobble| macro is used to get rid of its argument.
%    \begin{macrocode}
\long\def \@gobble #1{}
\long\def \@gobbletwo #1#2{}
\long\def \@gobblefour #1#2#3#4{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@firstofone}
% \begin{macro}{\@firstoftwo}
% \begin{macro}{\@secondoftwo}
%    Some argument-grabbers.
%    \begin{macrocode}
\long\def\@firstofone#1{#1}
\long\def\@firstoftwo#1#2{#1}
\long\def\@secondoftwo#1#2{#2}
%    \end{macrocode}

Which leads one to suspect that the extra space (which has no effect at all) was added by Chris (CAR). It's one way to make the source perhaps more readable. Much of the original latex2.09 source was written in a very compressed style with "interesting" linebreaks and indentation. So quite a bit of ignored white space was added while converting the sources to the documented doc/docstrip format.

It might be noted that using stylistic white space to lay out the source code has to be done with some care when using traditional TeX settings. A major feature of the expl3 coding style is that essentially all white space is ignored, which makes it much easier to do this sort of thing (and more explicit that it is purely a coding style with no affect on the actual run time behaviour)

  • Thanks, David. I was concerned that I might be missing some deeper meaning. I'm almost disappointed there isn't any ;-) – Dan Levin Aug 19 '15 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.