I am working on a LaTeX pretty printer that parses a LaTeX document and then re-renders the source. (I know that this is not possible in all cases, but it should be possible a lot of the time.)
In the spirit of Prettier, I want the code formatter to be opinionated, and I am trying to decide which macros should have their arguments automatically wrapped in a group {}. For example, \mathbb R
should be converted to \mathbb{R}
, and \frac23
should be converted to \frac{2}{3}
.
My question is: (a) Are there LaTeX macros where passing in a group will cause unexpected behavior? and (b) are there macros where it is considered "best practice" not to wrap the arguments in a group?
A follow-up question would be: what would you put on a list of "special" macros that are commonly used. This can include LaTeX macros that don't follow standard conventions (of [...]
and {...}
style arguments), or commonly-used macros that would need special handling (like almost everything in a tikz environment...).
To rein in the scope, I am not trying to parse complicated TeX programming or macro definitions themselves.
\sffamily
should be used as is, and not e.g. like\sffamily{text}
.$\left(1\right)$
works but$\left{(}1\right{)}$
doesn't.\left
and\right
are exactly the types of exceptions I'm looking for. I have no idea how they work, but I would imagine the macro is something like\left(#1\right)
? And so the "argument" is really what's between the two...