0

I've been typesetting a competition paper using the exam class, which has options for nice headers and cover pages.

Now, this competition has two different age categories, 'Junior' and 'Senior', and three different rounds: 'MCQ', 'Team', and 'Observation'. I'd like the title page and the headers to all reflect any one of the six resulting combinations by specifying options to a command, in the manner of key-value pairs. For instance, \setcatround[category=jnr, round=mcq] should set these variables appropriately, and these should be reflected in both the header and the title/cover page of the exam.

I have selected pgfkeys as my key-value package of choice. I passed over keyval, xkeyval, and kvoptions, because I find their syntax to be particularly esoteric compared to the relative straightforwardness of pgfkeys. Furthermore, Mr Wright (of siunitx fame) recommends pgfkeys or l3keys versus the others, here.

An M(N)WE [minimum (not) working example]:

\documentclass{exam}
\usepackage{pgfkeys} 

\pgfkeys{
    /ac/.is family, /ac,
    category/.estore in = \category,
    round/.estore in = \round
}

\newcommand*{\setcatround}[1]{\pgfqkeys{/ac}{#1}}

\setcatround{category=senior, round=mcq}

\header{My Exam}{}{\category{} \round{} Round}

\title{Competition}

\begin{document}
\maketitle
\centering
\LARGE{\category{} \round{} Round}
\thispagestyle{headandfoot}
\end{document}

Now, this MWE works okay, but my idea was to:

  1. Print the competition Category And Round In Title Case, like so: Junior MCQ Round, or Senior Team Round;

  2. Print the category and round together using only one command; for instance, \catround{} should yield Junior MCQ Round when the appropriate options are set with \setcatround{...};

  3. Allow users to specify either of jnr/junior, or snr/senior and output the appropriate results.

How might I go about specifying these, and possibly make it easily extensible for any future additions?

1 Answer 1

1

With the help of .is choice key handler, which is documented in PGF Manual, sec. 88.4.5:

\documentclass{exam}
\usepackage{pgfkeys} 

\pgfkeys{
  /ac/.cd,
  category/.is choice,
  category/jun/.code={\edef\category{Junior}},
  category/snr/.code={\edef\category{Senior}},
  % you can define similar choice-keys for "round"
  round/.estore in = \round
}

\newcommand*{\setcatround}[1]{\pgfqkeys{/ac}{#1}}

\setcatround{category=snr, round=mcq}

\header{My Exam}{}{\category{} \round{} Round}

\title{Competition}

\begin{document}
\maketitle
\centering
\LARGE{\category{} \round{} Round}
\thispagestyle{headandfoot}
\end{document}

enter image description here

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.