
如果其他地方已經討論過這個問題,我很抱歉,但如果是的話,我找不到它。
我是我大學學術論文範本的作者,但我絕對不是 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}