# Why is tex designed to render spaces around brackets?

When I wrote following lines:

\section{Introduction}{
Content in introduction ...
}


Unwanted space comes before Content as warned.

I understand it's due to some technical decision in tex. But I wonder the reasons behind this decision.

At the beginning of text tags in HTML, literal spaces do not get rendered. I actually prefer behavior like this, because it makes my handcrafted code more readable.

By the way, can I have tex ignore spaces between { and Content of this code?

• You don't need to put the contents of the introduction between braces to begin with. Sep 26, 2013 at 14:03
• @egreg But some brackets can't be omitted, like in \institute{}. Sep 26, 2013 at 14:13
• Use a comment character: {% then start a newline. If you skip the 'philosophical' reasons, it is just a matter of getting used to how TeX works --- and knowing when and where and why braces are needed. (Why in this case relates to the number of arguments a command like \section needs, not 'why' whitespace is important in macros.) I would also imagine any workaround would be a lot more trouble than it's worth to implement, and probably quite fragile to boot.
– jon
Sep 26, 2013 at 14:41
• @jon Thanks, the {% works. But I don't understand the behavior here. Does that mean % in first line comments out spaces in second line? Sep 26, 2013 at 15:26
• If it helps to think of it that way: the comment character, %, tells TeX to treat the rest of the line as a comment, and spaces are skipped at the start of an input line. (Line ends, however, is one place where spurious spaces can creep in.)
– jon
Sep 26, 2013 at 17:01

Commands that expect an argument can be defined to ignore white space (typically use of \ignorespaces and/or \unskip) (eg \footnotetext{ a} is the same as \footnotetext{a} the fact that spaces are not ignored around {} in running text is a general feature so \LaTeX{} is... is a common way of making the space appear.

HTML is different as it is a fixed tag set and special parsing rules are added for each element. XML does not drop white space for example. So the situation in TeX is similar to that in XHTML: The parser does not drop space but the definition of particular commands may be such that it ignores the space tokens.

• Have you checked whether the OP's claim is even correct? I, for one, can't reproduce his claim about an extra, unwanted space showing up if I expand his code snippet into an MWE.
– Mico
Sep 26, 2013 at 21:41
• @Mico good catch:-) Sep 27, 2013 at 0:23

Ignoring the spaces after \section{Introduction} is standard LaTeX behavior, with or without braces. Spaces do not appear in the output before "Content" in the following minimal example:

\documentclass{article}
\begin{document}
\section{Introduction}{
Content in introduction ...
}
\end{document}


This uses the article document class, but most of the common classes behave the same.

So the problem occurs because of something else in your document. I suspect an odd definition of \section, either in your document or in your document class.

• Welcome Dan, er, @user37136 (you can change this if you like.) :) Sep 26, 2013 at 21:26

The \section command has one mandatory argument, the section title (and an optional argument, but this is irrelevant here).

The text of the section goes after the title and not inside braces:

 \section{Introduction}

This is silly text, but shows how one should do.

The introduction has more than one paragraph; paragraphs
are separated by a blank line.

Enough for the introduction.

\section{Main results}

Here we'll show the wonderful results we got.

...


LaTeX is not HTML and has no concept of tags similar to HTML ones, though some constructs (the environments) can remind of them.