Wednesday, March 31, 2010

LaTeX: Nested optional arguments

Latex allows you to make commands with an optional argument.  For example,


\newcommand{\Line}[1][G]{\overline{{#1}}}

Now $\Line$ will draw a G with a line above it, and $\Line[H]$ will draw
an H with a line above.  Nesting these can cause problems though.  For instance,
$\Line[\Line]$ works, but $\Line[\Line[H]]$ doesn't.  The solution is to always
wrap the optional argument in an extra set of curly braces: $\Line[{\Line[H]}]$.


3 comments:

  1. Anonymous6:23 AM

    That was what I've been looking for, thank you!

    ReplyDelete
  2. Anonymous2:57 PM

    Thanks!!!

    ReplyDelete
  3. Anonymous8:37 AM

    Thanks!!

    ReplyDelete