You can find the complete compound labeling mechanism of XyMTeX in the file chemist.sty
:
\@ifundefined{chapter}{\newcounter{compd}}{\newcounter{compd}[chapter]}
\def\thecompd{\arabic{compd}}
\def\compd{\leavevmode\refstepcounter{compd}{\large\bf \thecompd}}
\def\nocompd{\refstepcounter{compd}}
\def\compdlabel#1{\compd \label{#1}}
\def\nocompdlabel#1{\nocompd \label{#1}}
\@ifundefined{bf}{\def\bf{\normalfont\bfseries}}{}
\def\cref#1{{\bf \ref{#1}}}
Let's go through it:
\@ifundefined{chapter}{\newcounter{compd}}{\newcounter{compd}[chapter]}
This defines a counter compd
which if a macro \chapter
exists is added to the counter chapter
's reset list.
\def\thecompd{\arabic{compd}}
This redefines \thecompd
from \@arabic \c@compd
to \arabic{compd}
which is basically redundant.
\def\compd{\leavevmode\refstepcounter{compd}{\large\bf \thecompd}}
This defines a macro \compd
which steps said counter and prints the number in bold and large. The environment XyMcompd
which you mention in your question uses this macro if the corresponding argument is not empty.
\def\nocompd{\refstepcounter{compd}}
This defines a macro \nocompd
which steps said counter but doesn't print the number.
\def\compdlabel#1{\compd \label{#1}}
This defines a macro \compdlabel
with a mandatory argument which steps the counter, prints the number and adds a label using the argument.
\def\nocompdlabel#1{\nocompd \label{#1}}
The same but doesn't print the number.
\@ifundefined{bf}{\def\bf{\normalfont\bfseries}}{}
This checks if \bf
is undefined and if it is defines it to be \normalfont\bfseries
.
\def\cref#1{{\bf \ref{#1}}}
This defines \cref
to take an argument to refer to a label and prints it in bold.
Here is some slightly modified code which copies this:
\documentclass{article}
\newcounter{compound}
\newcommand*\compoundformat[1]{\textbf{\large#1}}
\newcommand*\compound{\leavevmode\refstepcounter{compound}\compoundformat{\thecompound}}
\newcommand*\nocompound{\refstepcounter{compound}}
\newcommand*\compoundlabel[1]{\compound\label{#1}}
\newcommand*\nocompoundlabel[1]{\nocompound\label{#1}}
\newcommand*\compoundref[1]{\compoundformat{\ref{#1}}}
\begin{document}
foo \compound\ bar and \compoundlabel{ethanol} and later \compoundref{ethanol}.
\end{document}
As comparison the corresponding code with XyMTeX:
\documentclass{article}
\usepackage{xymtex}
\begin{document}
foo \compd\ bar and \compdlabel{ethanol} and later \cref{ethanol}.
\end{document}
XyMTeX
-- it seems to be a very special TeX format. Perhaps you should provide us with a starter document\cref
is a command most likely fromcleveref
packagesty
files) (and its documentation is 780 pages strong!) for typesetting of all aspects concerning chemistry.chemnum
package. I am not familar with XyMTeX's mechanism so it's hard to say how easy it will be to rebuild its\cref
…