1

I am trying to combine two packages in to a new command. The problem I have come across is when trying to add an optional parameter.

I want to be able to have 2 parameters with the second parameter being invoked if I use it but otherwise LaTeX should just use the first one.

I think I need something in "[???]" below but I don't know what.

\usepackage{mhchem} 
\usepackage{chemnum}
\newcommand{\cecount}[2][???]{\ce{#2} (\cmpd{#1})}

\begin{document}

Reaction of compounds \ce{H2} and \ce{O2} makes \cecount[AAA]{H2O}.  
Another compound is \cecount{X}.
Reaction of compounds Na and Cl makes \cecount[B]{NaCl}. 
Compound \refcmpd{AAA} dissolves compound \refcmpd{B}.
But I can also refer to \refcmpd{X}

\end{document}

This gives me an error of (??) when trying to use the \refcmpd{X} command.

cgnieder
  • 66,645
Tmr90
  • 31

0 Answers0