The scope of LaTeX commands
Three issues are raised by your question. First the easy one arguments
. When you say \emph{text goes here} you are calling a macro that has been defined with one argument, possibly something like this:
\def\emph#1{\textit{#1}}
In this case most macros will affect the enclosing text only.
When you get commands like \noindent
\small
etc they normally continue until redefined again. This is just a convention, commands don't need to be defined this way. It is a convention started with Knuth. Think of them as globals
in other programming languages or as cascading
in CSS.
When you use {}
you are grouping
or scoping the command(s). The grouping mechanism can be thought of a bit like scope in other programming languages, with the
exception that in TeX the mechanism is much more powerful. Most assignments made inside a group are local to that group unless explicitly indicated otherwise, and outside the group old values are restored (pretty much like in Pascal). If we type the following example:
\def\anumber{42}
\anumber % -> 42
{
\def\anumber{43}
\def\b{2}
\anumber % -> 43
}
\anumber % -> 42
The macro anumber
will have a different values within the group than outside it. There are a lot of commands associated with grouping and differentiating between local and global definitions.
The \noindent
control sequence is not a macro, but a primitive. It is not something that remains in effect for an entire paragraph. It instructs TeX to leave (internal) vertical mode and enter horizontal mode. (I sort of described TeX's vertical and horizontal modes in a blog post.)
More relevant to your question, there's no good way to distinguish which control sequences have arguments. The LaTeX 3 team has taken some pains to provide a consistent naming convention that lets the user know how many arguments and what type are expected. See the expl3
documentation for details.
To complicate matters, there are many LaTeX macros which, strictly speaking, do not take any arguments, but do in reality. For example, according to TeX, the \emph
macro takes no arguments. To see this, we can ask TeX to show the implementation of a macro using the \show
primitive:
*\show\emph
> \emph=macro:
->\protect \emph .
<*> \show\emph
This is a little tricky to read at first, but in the first line, I've asked TeX to show me the definition of \emph
(the *
is TeX's prompt). TeX responded by telling me that \emph
is a macro which takes no arguments and expands to \protect \emph
. (There's actually a space in the name of the latter control sequence, which is why there are two spaces between \emph
and the period.)
As an example of a macro which takes arguments, we can define \def\foo#1{asdf}
which takes a single argument. When we ask TeX for the definition, it responds as follows.
*\show\foo
> \foo=macro:
#1->asdf.
<*> \show\foo
Here, it's showing us that it takes a single argument (denoted #1
) and then expands to asdf
(note that we didn't actually use the argument).
What this means is that we can't even interrogate TeX to ask it which macros require arguments and which do not. (Technically speaking, the problem of deciding if a given macro requires an argument is undecidable. The proof is a simple reduction to the Halting problem.)
Unfortunately, this means that differentiating control sequences that require arguments from those that remain in effect until some point in the future (like the end of a group, or the end of a paragraph) from those that perform some discrete action right then is just a matter of experience and reading documentation. Hopefully LaTeX 3 will improve the situation.