O'Reilly logo

LaTeX Beginners Guide by Stefan Kottwitz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – marking keywords with optional formatting

We will use \newcommand another time, this time with an optional parameter concerning the formatting and a mandatory argument for the keyword:

  1. 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}
  2. Typeset and check out the result:
    Time for action – marking keywords with optional formatting

What just happened?

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required