My LaTeX document contains the following lines:
\documentclass{article}
\usepackage{etoolbox}
\newcommand{\defineSpecies}[2]{\csdef{spec@#1}{#2}}
\newrobustcmd{\spec}[1]{%
\ifcsname spec@#1\endcsname
\csuse{spec@#1}
\else
\GenericError{}{Undefined species `#1'}{}{}
\fi
}
\defineSpecies{h216o}{H$_2^{~16}$O}
\begin{document}
\spec{h216o}. \spec{h216o} molecule
\end{document}
When compiling this document, an extra space (denoted with a red box) is put before the dot in the PDF file:
Could you please help me to redefine \spec{}
that
(a) it does not provide the red space before the dot, but
(b) it includes the blue space before the world molecule.
Please focus on repairing this command instead of suggesting packages, like mchem
.