# Chemical numbering

The XyMTeX package defines the environment XyMcompd{name} that results in a counter \cref{name} pointing to the compound "name". I would like to know what are the basic steps for this macro \cref and how complex it will be to rebuild it without the package XyMTeX.

Thanks for your help

Bernhard

• I am not familiar with XyMTeX -- it seems to be a very special TeX format. Perhaps you should provide us with a starter document – user31729 Dec 13 '15 at 21:11
• On the other hand: \cref is a command most likely from cleveref package – user31729 Dec 13 '15 at 21:17
• @ChristianHupfer XyMTeX is a collection of 27 packages (counting the sty files) (and its documentation is 780 pages strong!) for typesetting of all aspects concerning chemistry. – clemens Dec 13 '15 at 23:59
• If you're interested in a package for numbering of chemical compounds have a look at the 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 – clemens Dec 14 '15 at 0:01
• For comparison, \eqref is defined as (condensed) \newcommand{\eqref}[1]{\textup{\hbox{\m@th\normalfont(\ignorespaces\ref{#1}\unskip\@@italiccorr}}} – John Kormylo Dec 14 '15 at 3:28

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}


• thank you very much for this. I will come back to it. I try to make this latexml compatible as well which seems challenge by its own. However the SVG structure to not show well in latexml and we have to solve that first. Afterwards I have already some code which might work, with an environment so draw the structure and a newfloat to make the labels work. thanks again – Bernhard Kleine Dec 15 '15 at 21:35

I used the code from XyMTeX, and the structures are labeled, however the references are still missing which I do not understand since they are inside a float which should give the proper reference at least for the \mevalonate macro.

@Clemens BTW Using your code and the \compoundlabel and \compoundref pair resulted in the same warnings: Latex failed to resolve 2 reference(s)

\documentclass[12pt,a4paper]{book}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx,float,hyperref,calc,caption,mwe}
\newfloat{Mycomp}{hbtp}{cmp}[chapter] % programmed figures
\floatname{Mycomp}{}
\makeatletter\let\ftype@Mycomp\ftype@figure % figure and compound are
\setlength{\unitlength}{0.1mm}
%taken from chemist.sty from the XyMTex package
\@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}}}

\DeclareRobustCommand{\mevalonate}{%
%
\begin{Mycomp}[H]
\fbox{
\parbox[c]{450\unitlength}{%
\centering

\includegraphics[width=400\unitlength]{example-image-a}
}%
}
\end{Mycomp}
}
\DeclareRobustCommand{\mevalonatePP}{%
%
\fbox{
\parbox[c]{450\unitlength}{%
\centering

\includegraphics[width=400\unitlength]{example-image-b}
}%
}
}
\begin{document}

\mevalonate     \mevalonatePP

In the text you will refer to the structures by \cref{mevalonatePP} and \cref{mevalonate}.

\end{document}

• If you change the \compdlabel to mevalonate and mevalonatePP than it works. Thank you Clemens – Bernhard Kleine Dec 30 '15 at 21:40