-
Book Overview & Buying
-
Table Of Contents
LaTeX Beginner's Guide
We will use \newcommand another time, this time with an optional parameter concerning the formatting and a mandatory argument for the keyword:
Modify the previous example to get this code:
\documentclass{article}
\newcommand{\keyword}[2][\bfseries]{{#1#2}}
\begin{document}
\keyword{Grouping} by curly braces limits the
\keyword{scope} of \keyword[\itshape]{declarations}.
\end{document}Typeset and check out the result:

Let's look again at the bold marked line in the code. By using [\bfseries], we introduced an optional parameter. We refer to it with #1. Its default value is \bfseries. Since we used a declaration this time, we added a pair of braces to ensure that only the keyword is affected by the declaration.
Later in the document, we gave [\itshape] to \keyword, changing the default formatting to italics.
Here's the definition of the \newcommand:
\newcommand{command}[arguments][optional]{definition}
|
|
The name... |