To avoid typing subscripts and extra parentheses and brackets, I want to define a command, say \disk
, that may be used with a comma-separated list of either 2 or 3 arguments, like this:
$\disk{r,x}$
$\disk{r,x,d}$
that will produce, respectively, the same output as would directly typing:
$D_{r}(x)$
$D_{r}(x;d)$
[The r
, x
, and d
could, of course, by any letter or number, etc. For example, I might use \disk{\epsilon, 0, D}
, etc.]
Using xparse
or otherwise, how might this be done?
Although I am aware that the two different outputs could be obtained by using an optional argument, that would require typing the 3rd, optional argument inside brackets; and in any case even for the case of only two arguments, I want to speed up typing by using just the comma-separated list {x, d}
rather than {x}{d}
.
Best Answer
We can do this at TeX primitive level without any
xparse
or another package. Note, there are only two lines of code.If you need to do something like this
$\disk{\epsilon,(1,2),\rho}$
then add one line of code: