[Tex/LaTex] the difference between square brackets and curly brackets in a command invocation

parsingsyntaxtex-core

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.

Best Answer

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.