1

My apologies if this has been discussed elsewhere, but if it was I couldn't find it.

I am the author of a template for academic thesis for my university, but I'm definitely not a TeX expert. In this template I make extensive use of configuration file(s) that use an ad-hoc (self) defined array map. E.g.:

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

Commas in keys are used for visual effect and considered as a normal character, i.e., in “\margin{cover,bottom}={2cm}” the key is “cover,bottom”.

I can later access the values as in:

\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].''

will produce

The cover file is “phd_cover_file.pdf” and the margins for the cover are “3cm, 3cm, 2cm, and 2cm.”

Is there any other (solid) package implementing this functionality? If not, is there some solid way to implement it (maybe based in one of the KV packages)? Thanks.

  • I'd much prefer something like \margin{cover/left=5cm,cover/right=5cm,...} – egreg Mar 4 at 22:14
  • @egreg, I agree with you and I was precisely looking at pgfkeys. Any suggestion? – João Lourenço Mar 4 at 22:47
1

You can do it with 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}

enter image description here

  • I am going to nit-pick as it has Very Very frequently caused editorial problems and measurement errors when numbers are butted up hard agains units and whilst it may be common practice in many non American organisations the old rule was best USE SPACE FOR CLARITY see english.stackexchange.com/questions/2794/punctuation-with-units in dim light is that 4c m or 40 m – KJO Mar 5 at 0:36
  • @KJO Here the purpose is to show how to access the values, not to pretty print them. The OP wants to use \themargin{cover/top} for passing the value to geometry or for doing a direct assignment to a parameter. – egreg Mar 5 at 0:38
  • I am worried it is for a global "template" unless its target is Chicago style I suggest it could be made universally acceptable. – KJO Mar 5 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.