如果这个问题已经在其他地方讨论过了,我深感抱歉,但如果有的话,我找不到它。
我是我所在大学学术论文模板的作者,但我绝对不是 TeX 专家。在这个模板中,我大量使用了使用临时(自)定义数组映射的配置文件。例如:
\arraymay{cover}
\cover{phd}={phd_cover_file.pdf}
\cover{msg}={msc_cover_file.pdf}
\arraymap{margin}
\margin{cover,left}={5cm}
\margin{cover,right}={5cm}
\margin{cover,top}={4cm}
\margin{cover,bottom}={4cm}
\margin{main,left}={3cm}
\margin{main,right}={3cm}
\margin{main,top}={2cm}
\margin{main,bottom}={2cm}
键中的逗号用于视觉效果,并被视为普通字符,即在“ \margin{cover,bottom}={2cm}
”中,键为“ cover,bottom
”。
稍后我可以按如下方式访问这些值:
\def\manuscripttype{phd}
The cover file is ``\thecover[\manuscripttype]'' and the margins for the cover are ``\themargin[cover,left], \themargin[cover,right], \themargin[cover,top], and \themargin[cover,bottom].''
将产生
The cover file is “phd_cover_file.pdf” and the margins for the cover are “3cm, 3cm, 2cm, and 2cm.”
有没有其他 (可靠的) 软件包可以实现此功能?如果没有,是否有可靠的方法来实现它(可能基于某个 KV 软件包)?谢谢。
答案1
你可以这样做pgfkeys
:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{pgfkeys}
\pgfkeys{
lourenco/.cd,
cover/phd/.initial={},
cover/msc/.initial={},
margin/cover/left/.initial=0pt,
margin/cover/right/.initial=0pt,
margin/cover/top/.initial=0pt,
margin/cover/bottom/.initial=0pt,
margin/main/left/.initial=0pt,
margin/main/right/.initial=0pt,
margin/main/top/.initial=0pt,
margin/main/bottom/.initial=0pt,
}
\newcommand{\setlourenco}[1]{\pgfkeys{lourenco/.cd,#1}}
\newcommand{\thecover}[1]{%
\pgfkeysvalueof{/lourenco/cover/#1}%
}
\newcommand{\themargin}[1]{%
\pgfkeysvalueof{/lourenco/margin/#1}%
}
%% settings
\setlourenco{
cover/phd=phd-cover-file.pdf,
cover/msc=msc-cover-file.pdf,
margin/cover/left=5cm,
margin/cover/right=5cm,
margin/cover/top=4cm,
margin/cover/bottom=4cm,
margin/main/left=3cm,
margin/main/right=3cm,
margin/main/top=2cm,
margin/main/bottom=2cm,
}
\def\manuscripttype{phd}
\begin{document}
The cover file is ``\thecover{\manuscripttype}'' and the margins
for the cover are ``\themargin{cover/left}, \themargin{cover/right},
\themargin{cover/top}, and \themargin{cover/bottom}.''
\end{document}