18

Pardon the naive beginner question.

In a command like: \textcolor[HTML]{4C7045}{dark green text}, or \documentclass[12pt]{article}, or \begin{figure}[htb], why are some arguments surrounded by [] and some by {}?

The above examples are all for LaTeX, but this doesn't seem to be LaTeX-specific.

  • 4
    This really is LaTeX-specific: the [] optional convention really doesn't apply to plain, ConTeXt or other formats. – Joseph Wright Jun 2 '14 at 8:41
  • Is \newcommand from LaTeX, then? How is it defined? – immibis Jun 2 '14 at 8:42
  • 1
    @immbis Yes, \newcommand is LaTeX-specific: it's wrapper around the \def primitive and depending on the exact set up does various things (optional arguments, for example, require more than one TeX macro for implementation). – Joseph Wright Jun 2 '14 at 8:46
  • There is also <n>; used, for example, in beamer. – gerrit Jun 2 '14 at 14:41
13

In TeX (and LaTeX and ConTeXt) braces ({}) are used as grouping characters.

In LaTeX, brackets ([]) are conventionally used for optional arguments, whereas braces are used for mandatory arguments.

In ConTeXt, braces are used for text that is to be typeset, whereas brackets are used for 'setup' text such as option lists.

  • 1
    Nota bene: xargs (and probably others) make it easy to screw the conventions in LaTeX. – Raphael Jun 2 '14 at 19:30
  • @Raphael Of course: the answer doe say 'conventionally'. Notice that xparse, written by the team, does allow the creation of non-standard input syntaxes but the idea is that it's primarily for creating standard ones: \foo*[<opt>]{<mandatory-1>}. – Joseph Wright Jun 4 '14 at 9:10
9

In general everything between [...] is optional and everything between {...} is mandatory. However, it depends to the author of the macros what will be optional and what will be mandatory. There are a lot of other possibilities.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.