化学编号

化学编号

包定义了导致计数器指向复合“名称”的XyMTeX环境。我想知道这个宏的基本步骤是什么,以及在没有包的情况下重建它会有多复杂。XyMcompd{name}\cref{name}\crefXyMTeX

感谢您的帮助

伯恩哈德

答案1

您可以在文件中找到 XyMTeX 的完整化合物标记机制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}}}

让我们来看看:

\@ifundefined{chapter}{\newcounter{compd}}{\newcounter{compd}[chapter]}

这定义了一个计数器compd,如果存在宏,\chapter则将其添加到计数器chapter的重置列表中。

\def\thecompd{\arabic{compd}}

这重新定义了\thecompd\@arabic \c@compd\arabic{compd}基本上是多余的。

\def\compd{\leavevmode\refstepcounter{compd}{\large\bf \thecompd}}

这定义了一个宏\compd,该宏会步进所述计数器并以粗体大号打印数字。XyMcompd如果相应的参数不为空,您在问题中提到的环境将使用此宏。

\def\nocompd{\refstepcounter{compd}}

这定义了一个宏\nocompd,它步进计数器但不打印数字。

\def\compdlabel#1{\compd \label{#1}}

这定义了一个\compdlabel带有强制参数的宏,该宏使用该参数步进计数器、打印数字并添加标签。

\def\nocompdlabel#1{\nocompd \label{#1}}

相同,但不打印数字。

\@ifundefined{bf}{\def\bf{\normalfont\bfseries}}{}

这将检查是否\bf未定义,如果是,则将其定义为\normalfont\bfseries

\def\cref#1{{\bf \ref{#1}}}

这定义\cref为采用一个参数来引用一个标签并以粗体打印它。


以下是一些稍微修改过的代码,复制如下:

\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}

在此处输入图片描述

与XyMTeX对应的代码如下:

\documentclass{article}
\usepackage{xymtex}

\begin{document}

foo \compd\ bar and \compdlabel{ethanol} and later \cref{ethanol}.

\end{document}

在此处输入图片描述

答案2

我使用了 XyMTeX 的代码,并且结构已标记,但仍然缺少引用,我不明白,因为它们位于浮点数内,至少应该为宏提供正确的引用\mevalonate

@Clemens BTW 使用您的代码和 \compoundlabel 和 \compoundref 对导致相同的警告: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  
    {\large\bfseries Mevalonate}\quad\compdlabel{Mevalonat}\\\vspace*{.5em}

    \includegraphics[width=400\unitlength]{example-image-a}
    }%
}
\end{Mycomp}
}
\DeclareRobustCommand{\mevalonatePP}{%
%
\fbox{
    \parbox[c]{450\unitlength}{%
    \centering  
    {\large\bfseries Mevalonate pyrophosphate}\quad\compdlabel{MevalonatPP}\\\vspace*{.5em}

    \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}

相关内容