Wondering if you can accomplish all of these variations in LaTeX by defining a custom command:


So it could be used like this:


Either one would work. How to define the command so this sort of thing would work?

  • 1
    Noticed the packages I mentioned yesterday: xparse can do this, see the g specifier
    – daleif
    Mar 23, 2018 at 12:27
  • 1
    while technically possible, you should not do this in latex. LaTeX has clear syntactic guidelines that {} delimited arguments should be mandatory, if you want optional arguments as here, then they should be [] delimited. Mar 23, 2018 at 12:59

1 Answer 1


You can implement more or less any syntax in tex, but latex has clear guidelines that optional arguments should be [] delimited. \newcommand only defines commands with at most one option, so to have two you would need to define it in two steps but xparse allows it to be declared directly as having two options so for example the following (complete) example test document:





which produces

  • Wondering, does this output actually mean it is a key-value object that can be iterated over like in a property list, or is size=1cm just a string.
    – Lance
    Mar 24, 2018 at 4:07
  • @LancePollard it means whatever you define \mycmd to make it mean. To TeX there are no strings or objects or anything else lor=red,t is just a list of 9 character tokens. Mar 24, 2018 at 8:14

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.