I have a fairly basic questions (I guess), but can't find a clear answer.

I have an existing command \ox{#1,#2} from a package (chemmacros) which has two arguments which are separated by commas. I want to change the command (i.e. \renewcommand), but I don't know how to handle the comma-separated arguments.

By basic idea would be:


But this doesn't work.

Does anyone have a suggestion how to separate the arguments?

  • 2
    You can specify delimiters of arguments with \def, e.g. \makeatletter\def\ox#1{\@ox[#1]}\def\@ox[#1,#2]{#1($\mathrm{#2}$)}\makeatother. Note that this doesn't work if your argument contains [ or ] -- in this case you would have to specify other delimiters.
    – Skillmon
    Jul 5, 2017 at 8:29

2 Answers 2


Here's a simple version:


\DeclareDocumentCommand { \ox } { m }
        \clist_set:Nn \l_tmpa_clist { #1 }
        \clist_item:Nn \l_tmpa_clist { 1 }
        ($\mathrm{\clist_item:Nn \l_tmpa_clist {2}}$)

  • 1
    You can even avoid setting the clist: \clist_item:nn { #1 } { 1 } (or {2}) will do.
    – egreg
    Jul 5, 2017 at 8:47

Here are three ways of doing this:


Using xparse and SplitArgument to extract the values and then
pass them to a second helper macro:

\NewDocumentCommand\oxone{>{ \SplitArgument{1}{,} } m }{\realoxone#1}

Using a plain def to extract the values using a helper macro:


Using a pgf loop to extract the values into ox1, ox2, ...:

  \foreach \x [count=\n] in {#1} {
      \csxdef{ox\n}{\x}% save value n as ox<n>
  \csuse{ox1}($\mathrm{\csuse{ox2}}$)% use values


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .