由于其高级功能,我正在迁移到 chemnum 编号系统(谢谢!)。为了我的目的,我需要输入外部文件,其中的信息(针对每种化合物)存储为命令,然后将这些命令应用到模板中(以“填充”信息)。
您可以在下面看到“最小”代码(我没有裁剪序言中使用的包,以防出现我不知道的冲突或顺序问题)。基本上有三个命令用于存储化合物的信息,第四个命令用于插入新部分和 EPS 图(带有要替换的标签“TMP1”)。编译时,此标签在第二个事件中是可以的,但在第一个事件中则不行(!!!?)。
当替换发生时,我认为 psfrag 部分没有任何问题,但化合物本身的编号有问题。如果“renewcommand”方法不适合 chemnum,那么还有其他替代方法可以从不同的文件中引入信息并连续应用相同的模板吗?
多谢!
\documentclass[a4paper,12pt,oneside]{article}
\usepackage{environ,fixltx2e}
\usepackage{titletoc}
\usepackage[linktocpage=true,hidelinks,unicode]{hyperref}
\usepackage{fullpage}
\usepackage[detect-all]{siunitx}
\usepackage{graphicx}
\usepackage[runs=2,crop=off]{auto-pst-pdf}
\usepackage{chemnum}
\usepackage[journal=rsc]{chemstyle}
\usepackage[version=3]{mhchem}
\usepackage{bm}
\usepackage{multicol}
\usepackage{etoolbox}
\newcommand{\compoundtag}{}
\newcommand{\nameofthecompound}{}
\newcommand{\descriptiontext}{}
\newcommand{\compoundDATA}{
\section{\nameofthecompound{} - \cmpdplain{\compoundtag}}
\begin{scheme}[H]
\replacecmpd[tag=TMP1]{\compoundtag}
\includegraphics{a.eps}
\end{scheme}
\descriptiontext
}
\begin{document}
Main text mentioning \cmpd{A} and \cmpd{B}
%This data comes from a different file through an input event.
\renewcommand{\compoundtag}{A}
\renewcommand{\nameofthecompound}{Name of compound A}
\renewcommand{\descriptiontext}{Text of the compound A}
\compoundDATA
%This data comes from a different file through a second input event.
\renewcommand{\compoundtag}{B}
\renewcommand{\nameofthecompound}{Name of compound B}
\renewcommand{\descriptiontext}{Text of the compound B}
\compoundDATA
\end{document}
答案1
这是一个扩展问题,并不是 的chemnum
错。如果您添加\setchemnum{log=true}
或 ,您甚至会在日志文件中\setchemnum{log=verbose}
获得有关哪些复合标签由 定义的信息:chemnum
.................................................
. chemnum info: defined new compound `A' with output 1.
.................................................
.................................................
. chemnum info: defined new compound `B' with output 2.
.................................................
.................................................
. chemnum info: defined new compound `\compoundtag ' with output .
.................................................
这意味着在喂给朋友\compoundtag
之前应该先扩展一次。\cmpd
\expandafter\cmpdplain\expandafter{\compoundtag}
和
\expandafter\replacecmpd\expandafter{\compoundtag}
(tag=TMP1
是多余的 – 这是默认的)
使用选项\replacecmpd
需要多花点功夫。可能是这样的:
\begingroup
\edef\x{\endgroup
\replacecmpd[tag=TMP1]{\expandonce\compoundtag}%
}\x
\expandonce
etoolbox
由您已在加载的内容提供。
答案2
这里有一个解决方案,只需要定义一个稍微不同的命令版本(我删除了不必要的包,选项demo
只是graphicx
为了示例,不要自己添加)。
\documentclass[a4paper,12pt,oneside]{article}
\usepackage[demo]{graphicx}
\usepackage{chemnum}
\usepackage[journal=rsc]{chemstyle}
\usepackage[version=3]{mhchem}
\newcommand{\compoundtag}{}
\newcommand{\nameofthecompound}{}
\newcommand{\descriptiontext}{}
\setchemnum{log=true}
\ExplSyntaxOn
\NewDocumentCommand \xreplacecmpd { t+ o m }
{ \chemnum_cmpd_replace:nno { #1 } { #2 } { #3 } }
\cs_generate_variant:Nn \chemnum_cmpd_replace:nnn { nno }
\ExplSyntaxOff
\newcommand{\compoundDATA}{
\section{\nameofthecompound{} - \cmpdplain{\compoundtag}}
\begin{scheme}[H]
\xreplacecmpd[tag=TMP1]{\compoundtag}
\includegraphics{a.eps}
\end{scheme}
\descriptiontext
}
\begin{document}
Main text mentioning \cmpd{A} and \cmpd{B}
%This data comes from a different file through an input event.
\renewcommand{\compoundtag}{A}
\renewcommand{\nameofthecompound}{Name of compound A}
\renewcommand{\descriptiontext}{Text of the compound A}
\compoundDATA
%This data comes from a different file through a second input event.
\renewcommand{\compoundtag}{B}
\renewcommand{\nameofthecompound}{Name of compound B}
\renewcommand{\descriptiontext}{Text of the compound B}
\compoundDATA
\end{document}
注意,\xreplacecmd
而不是\replacecmpd
。
以下是该选项生成的日志的相关部分log=true
:
.................................................
. chemnum info: defined new compound `A' with output 1.
.................................................
.................................................
. chemnum info: defined new compound `B' with output 2.
.................................................