I'm trying to make a class for a cv document. As part of that document, there will be a table that contains all the education information. What I'm trying to achieve is to have some sort of template that specifies what one of these blocks of information looks like, and then have a macro that instantiates one of those blocks with the relevant data. My current attempt is trying to use pgfkeys to handle passing the data into the macro. A stripped down version of the class looks like this:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{cv}
\LoadClass[10pt,a4paper]{article}
\RequirePackage{tabularx}
\RequirePackage{calc}
\RequirePackage{xparse}
\makeatletter
\protected\def\z#1{\pdfsavepos\write@auxout{\gdef\string\tpos#1{\the\pdflastxpos}}}%
\def\foo#1#2{\ifcsname tpos#1\endcsname\the\dimexpr\csname tpos#2\endcsname sp -\dimexpr\csname tpos#1\endcsname sp\relax\fi}
\makeatother
\RequirePackage{pgfkeys}
\pgfkeys{
/education/.is family, /education,
title/.estore in=\educationtitle,
programme/.estore in=\educationprogramme,
notes/.estore in=\educationnotes,
notes/.default={},
institute/.estore in=\educationinstitute,
thesisheader/.estore in=\educationthesisheader,
thesisheader/.default=Thesis:,
thesistitle/.estore in=\educationthesistitle,
selectedcourses/.estore in=\educationselectedcourses,
selectedcourses/.default={},
dates/.estore in=\educationdates,
}
\newenvironment{education}{
\setlength{\tabcolsep}{5pt}
\setlength{\extrarowheight}{0pt}
\begin{tabular}{!{\z{a}}r!{\z{b}}p{(\textwidth-\foo{a}{b})-\tabcolsep}}
}{
\end{tabular}
}
\NewDocumentCommand{\educationitem}{o}{
\pgfkeys{/education,notes,selectedcourses,thesisheader,#1}
\educationdates{} & \textbf{\educationtitle{}} \
& \educationprogramme{} \
& \educationnotes{} \
& \textit{\educationinstitute{}} \
\educationthesisheader{} & \educationthesistitle{} \
Selected courses: & \educationselectedcourses{} \
}
(There is some special stuff going on with the width of the columns, such that the second column fills out the remaining available width. I took this from some other answer here some time ago.)
I would ideally then use the class something like this:
\documentclass{cv}
\begin{document}
\begin{education}
\educationitem[
title={Master of Science},
programme={Some programme},
notes={Some notes about the degree},
institute={Some institute},
dates={2014--2017},
thesistitle={The title of the thesis},
selectedcourses={Some list of courses that might get pretty long, filling out the usable space of the row.},
]{}
\educationitem[
title={Bachelor of Science},
programme={Some other programme},
notes={Some more notes about the degree},
institute={Some other institute},
dates={2011--2014},
thesisheader={Honours thesis:},
thesistitle={The title of the thesis},
selectedcourses={Some list of courses that might get pretty long, filling out the usable space of the row.},
]{}
\end{education}
\end{document}
This should hopefully yield a table looking like this:
Unfortunately, instead I get an Undefined control sequence error on usage of the \educationitem macro. I just asked a question about this, but I simplified the situation a bit too much, leading to answers that don't work for my actual intent. (The XY-problem strikes again...)
So here's my real question: how can I construct a macro that can be used roughly as above to give the result I want? Solutions using pgfkeys are slightly preferred, but I'm not particularly attached to what I have so far. Hopefully I've supplied the correct amount of information this time!



pgfkeys. Thank you! – Jordi Vermeulen Aug 24 '22 at 14:15expkv-csdoes is thatexpkv-csonly needs to parse the key=value list once, what's being forwarded in the\ekvcHash-variant is a preparsed list in which access to a specific key's value is relatively fast. For comparison (using theeducationenvironment as defined in your answer): Your method A takes roughly 2.5 times as long as my\educationitem, and method B takes roughly 1.7 times as long; and using the faster yet harder to adapt\ekvcSplit-variant takes only ca. 0.7 times as long as the code from my answer. – Skillmon Aug 25 '22 at 07:48\NewDocumentCommandcall. That one should be\NewDocumentCommand{\educationitem}{O{}}(withoyou'll get an error frompgfkeysif no optional argument is used). – Skillmon Aug 25 '22 at 07:51\educationitemsthey all take roughly the same time to compile on my computer. – Qrrbrbirlbel Aug 26 '22 at 15:51l3benchmark, typesetting the wholetabularxin a vbox :) With a single usage the document structure and package load times dominate over the time needed for\educationitem. My numbers only compare the environment+\educationitemdirectly against each other. – Skillmon Aug 26 '22 at 18:17