Coming from the programming language side, I am used to the very regular syntax of these languages. E.g. in Python a function call has to be like below:


This makes understanding the code easy.

In LaTeX, I see much more free usages of syntax.


or like


which I find confusing. So far to me it seems writers of these \command s can define whatever syntax they want for their commands. Is that right?

So, what are the rules of command syntax in latex?

  • 3
    Actually you can make any syntax (google for xii.tex , which is plain tex but could be latex:-) but the examples you quote are all following strictly the standard latex syntax. mandatory arguments in {} and optional arguments in [] – David Carlisle Jan 20 '14 at 11:20
  • 5
    related: tex.stackexchange.com/questions/84685/… – David Carlisle Jan 20 '14 at 11:23
  • Keyvals are all very well and good, and as David says in the linked answer are available for LaTeX programmers, but experience suggests that in day-to-day use there are some places where the optional/star approach in LaTeX is much more convenient. (See the experimental xcoffins, where the keyval interface doesn't seem anything like as useful/popular as the standard LaTeX optional argument one.) – Joseph Wright Jan 20 '14 at 11:31
  • 4
    LaTeX is built on top of TeX, which has a syntax that is based on pattern-matching. Most commands don't use any explicit patterns but you can define commands that are based on complex patterns. For example, \def\joinInMatrimony#1 and #2{#1 and~#2 are now married.}. Using the pattern matching-based definitions you can implement more convenient and robust APIs, like e.g. TikZ's key-value interface. – user10274 Jan 20 '14 at 11:46
  • Several packages introduce their own syntax on top of LaTeX. – John Kormylo Jan 23 '14 at 4:52

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.