ヘルプ: 一般的な(そしてエレガントな)配列(変数)マップ構文を探しています。

ヘルプ: 一般的な(そしてエレガントな)配列(変数)マップ構文を探しています。

もしこれが他の場所で議論されていたら申し訳ありませんが、もしそうであったとしても、私はそれを見つけることができませんでした。

私は大学の学術論文のテンプレートの著者ですが、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 つに基づく)? ありがとうございます。

答え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}

ここに画像の説明を入力してください

関連情報