1

I am quite new to LaTeX and as I was reading the LaTeX Wikibook I came upon the following general definition for a command in LaTeX here:

\commandname[option1,option2,...]{argument1}{argument2}...

However, later on in the Wikibook the syntax for creating a new command is given as:

\newcommand{name}[num][default]{definition}

Now given the general definition for a command in LaTeX I would have instead expected the following syntax for creating a new command:

 \newcommand[num,default]{name}{definition}

A bit later on in the same section on creating macros in the LaTeX wikibook the syntax for creating a new environment is given as:

\newenvironment{name}[num][default]{before}{after}

Again, given the general definition I would have expected this instead:

 \newenvironment[num,default]{name}{before}{after}

I would appreciate it greatly if somebody could clarify this inconsistency for me.

  • 2
    Welcome to TeX.SX! The nice thing about TeX is that it has almost no syntax of itself. The syntax is defined by you (or in this case, by LaTeX). Commands defined with \newcommand will invariably have the syntax \cmd{<arg1>}{<arg2>}... or \cmd[<opt>]{<arg1>}{<arg2>}.... Commands defined with xparse have much more flexibility, and you can also define the commands by hand to have virtually any syntax you want. – Phelype Oleinik Oct 19 '19 at 14:59
  • 7
    Welcome to TeX.SX! I don't find the LaTeX Wikibook a very reliable guide. Some commands accept comma separated options, but the vast majority doesn't. And a command can have multiple optional arguments, one case is indeed [math]\newcommand[/math]. – egreg Oct 19 '19 at 15:00
  • 3
    The only somewhat consistent convention is to use [] for optional arguments and {} for mandatory ones. Third type is () for coordinates, but those are pretty rare in the LaTeX format itself (picture-mode). There are some classes and packages however that break this general rule and add optional braced arguments, so not even those are safe. And the concept of key=value optional arguments is relatively young, so the older the macro the less likely they are used. – Skillmon likes topanswers.xyz Oct 19 '19 at 15:05
  • Also, while it is possible in theory to use optional arguments in fully expandable macros, a key=value syntax will most likely never be fully expandable, so there might be macros which take normal and possibly multiple optional arguments in the distant future, when key=value has otherwise fully took over. – Skillmon likes topanswers.xyz Oct 19 '19 at 15:10
  • Could you explain what key=value means? – The Riddler Oct 19 '19 at 15:11

Your Answer

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

Browse other questions tagged or ask your own question.