The excellent TeX by Topic has already been mentioned, and I'd start there if you are a programmer looking for enlightenment. What you need to bear in mind is that TeX works with tokens with category codes. In the case of grouping, usually {
and }
are tokens with category codes 1 (begin group) and 2 (end group), respectively. So TeX will start a group when it reads {
and finish it when it reads }
.
For a simple macro such as
\newcommand*\example[1]{Stuff with #1}
the argument will be either a single token or a single group. Thus
\example{stuff}
will absorb 'stuff' as #1, but
\example stuff
will only pick up the 's' of 'stuff', as 's' is a single token.
LaTeX introduces the idea of optional arguments inside [
... ]
. As pointed out by Andrew, this isn't done by grouping, and so can give odd results. You can get around this: see how xparse manages optional arguments for example. LaTeX also uses (
... )
for co-ordinate arguments, but again with no grouping.
As I said, category codes are important. ConTeXt uses [
and ]
for grouping rather than {
and }
. So it's not the character you need to worry about, but the token (including the category code). This is a rather TeX-specific concept, so looking at TeX by Topic and The TeXbook is a good way to get to grips with it.
tex
program itself. Indeed the all three actions parse/evaluate/output are intermixed in TeX and the results of any of these stages can (and often does) influence the behavior of the others.