11

To structure my sourcecode, I often use spaces for padding:

\newcommand{\st}[1]{%
  \begin{tabular}{lr}
    \emph{Student} & \emph{Score}\\
    #1
  \end{tabular}%
}

Can this ever cause problems? Like putting no % at the end some lines.

Moriambar
  • 11,466
u17
  • 4,976

2 Answers2

16

Usually, spaces at the beginning of a line are ignored by TeX. However, this is not the case when writing in a verbatim like context. Tabulators at the beginning of a line are ignored as well.

Whitespace characters like NO-BREAK SPACE (U+00A0) behave in a different way. To use them properly, a modern engine like LuaLaTeX in conjunction with fontspec is needed.

Please be aware, that the end of a line is nothing more than a (space) for LaTeX, if in M-mode (middle of a line), so you have to be careful in the definition of your own commands.

\documentclass{article}
\newcommand\testa{h
    ello}
\newcommand\testb{h%
     ello}
\begin{document}
\testa \par \testb

\begin{verbatim}
  h
 a
   ll
o
\end{verbatim}
\end{document}
Johannes_B
  • 24,235
  • 10
  • 93
  • 248
  • 1
    Does the same apply for tabs or other whitespace characters? – ComFreek Nov 27 '13 at 15:33
  • @ComFreek Good question, I added the information to the answer. Can somebody please varify the behaviour for »other whitespace character«? I somehow would have guessed a different behaviour. – Johannes_B Nov 27 '13 at 17:11
  • I'm not really sure about U+00A0, which in the normal setting of LuaLaTeX and XeLaTeX has category code 12 when fontspec is loaded. – egreg Nov 27 '13 at 17:12
  • @egreg I tried it out myself, but as I said, i don't think this should happen. Am i missing something? – Johannes_B Nov 27 '13 at 17:14
  • @Johannes_B Try loading fontspec – egreg Nov 27 '13 at 17:17
  • Thanks @egreg for pointing me in the right direction. I made the according changes. – Johannes_B Nov 27 '13 at 17:23
  • @Johannes_B "the end of a line is nothing more than a space" — This is not entirely correct. It depends on which state TeX currently is in. If TeX is in state N (new line) then the end-of-line is converted to \setminuspar\nonumber whereas if TeX is in state M (mid-line) the end-of-line is converted to a space. – Henri Menke Sep 12 '14 at 21:34
  • @HenriMenke I am going to add something tomorrow. Thanks for hint. – Johannes_B Sep 12 '14 at 21:36
5

The comment environment (comment package) should start in a new line without a space before. From the manual:

The opening and closing commands should appear on a line of their own. No starting spaces, nothing after it.

Otherwise it won't work and cause strange errors.

Keks Dose
  • 30,892