# Difficulty getting pgfkeys to set my fontsizes as I want

I apologize that this isn't particularly short.

I'm going through old code and refactoring. In the process, I'm running into various bugs in how I've written things. In this particular example, the font sizes are not getting properly initialized and I can figure out why.

My issue here is that I can't seem to get the usefontsize/.initial to take effect unless I explicitly make a call to the fontsize key.

%-@-(1)-
\begin{filecontents}{samplecode}
% first line of material I don't want to see
\documentclass{article}
\begin{document}
document content here
\end{document}
\end{filecontents}
%-@-(2)-
\begin{filecontents}{ncode}
\makeatletter
\def\ae@box@fbox{}
\def\ae@mboxheight{}
\def\ae@value@is@none{}
\def\code@cat{%
\renewcommand{\FancyVerbFormatLine}[1]{##1}%
\ae@ncode@set{fontsize/relsize={-0.75},
examcodecolor,
input/method={\VerbatimInput
[gobble=\ae@ncode@get{gobble},
firstline=\ae@ncode@get{firstline},
lastline=\ae@ncode@get{lastline},
firstnumber=\ae@ncode@get{firstnumber},
numbers=\ae@ncode@get{numbers},
numbersep=\ae@ncode@get{numbersep},
fontfamily=courier,
fontsize=\relsize{-0.75},
]}}}
\pgfkeys
{%
/ae/ncode/.is family,
/ae/ncode,
%%:
input/method/.initial,
%%:
examcode/.code       = {\code@cat},
%%:
gobble/.initial        = 2,
width/.initial         = 3in,
firstline/.initial     = 1,
lastline/.initial      = 5000,
firstnumber/.initial   = 1,
rulecolor/.initial     = black,
fillcolor/.initial     = red!20,
numbers/.initial       = none,
numbersep/.initial     = 1em,
indent/.initial        = 0pt,
%%:
usefontsize/.initial     = \normalsize,
fontsize/.style          = { usefontsize=\csname #1\endcsname},
fontsize/relsize/.style  = { usefontsize=\relsize{#1}},
%%:
examcodecolor/.style   = { fillcolor=#1 },
examcodecolor/.default = red!30,
%%:
mboxheight/.initial = \ae@mboxheight,
height/.code = {\expandafter\ifx\csname ae@value@is@#1\endcsname\ae@value@is@none\else
\edef\ae@mboxheight{[#1]}\fi
},
%%:
/ae/ncode/.cd,
fbox/.style = { select/box/style/#1/.get = \ae@box@fbox, },
select/box/style/.cd,
none/.initial,
fbox/.initial      = \fbox,
fcolorbox/.initial = \fcolorbox{\ae@ncode@get{rulecolor}}{\ae@ncode@get{fillcolor}},
}
\def\ae@ncode@get#1{\pgfkeysvalueof{/ae/ncode/#1}}
\def\ae@ncode@set{\pgfqkeys{/ae/ncode}}
\newcommand{\nncode}[2][]{%
\pgfqkeys{/ae/ncode}{usefontsize,#1}% <--- doesn't seem to matter whether usefontsize is here or not
\edef\ae@begin@minipage{\noexpand\minipage[t]\ae@ncode@get{mboxheight}{\dimexpr\ae@ncode@get{width}-\ae@ncode@get{indent}}}%
\ae@box@fbox{%
\hspace*{\ae@ncode@get{indent}}%'
\ae@begin@minipage
\ae@ncode@get{usefontsize}% <--- doesn't seem to be taking effect in left version
\ae@ncode@get{input/method}{#2}%'
\endminipage}%'
}
\makeatother
\end{filecontents}
%-@-(3)-
\documentclass{article}
\usepackage{pgfkeys}
\usepackage{fancyvrb}
\usepackage{relsize}
\usepackage{xcolor}
\usepackage[margin=0.5in]{geometry}
\input{ncode}
\setlength{\parindent}{0pt}
\begin{document}

Shouldn't the left and the right boxes look identical?

{\nncode[examcode,
width={\dimexpr2.25in-2\fboxrule-2\fboxsep},
fbox=fcolorbox,
height=none,
firstline=6,
gobble=2,
indent=0.5em,
fontsize=normalsize,
]{samplecode}}%
%%'
{\nncode[examcode,
width={\dimexpr2.25in-2\fboxrule-2\fboxsep},
fbox=fcolorbox,
height=none,
firstline=6,
gobble=2,
indent=0.5em,
%        fontsize=normalsize,
]{samplecode}}%

\end{document}

I know there are parts of this code I could have written differently. For example, it looks like I could have just written one key word fontsize to accept, not a bare word, but the actual command name for the font. But keep in mind that I'm refactoring old code. My old version of this code, when I was just learning to use key-values, didn't allow me to pass command names. I now have hundreds of lines of code which now depend upon that old syntax. So, I need a solution that recognizes the need for the fontsize key word to accept a bare word (instead of macro name) for its value. Similarly with the wonky way I'm handling the keyword height since in my old code it's not always specified as a dimension.

EDIT

I should point out that there are other keys where I do similar finagling with other initialized keys. For example, examcodecolor resets the fillcolor, but seems to work fine whether or not examcodecolor was actually invoked. A bit more off the beaten path is height, but if you redefine \ae@mboxheight as say:

\def\ae@mboxheight{[2in]}

without having to invoke height at all the correct parameter value is used.

Is there something special about \normalsize that I'm not considering? Is it somehow being invoked at the time I'm defining usefontsize/.initial?

• @cgnieder That shouldn't be the case at all. usefontsize doesn't invoke the code involving \csname...\endcsname, and there's no where in my code where I write fontsize=\normalsize. – A.Ellett Jul 26 '13 at 17:57
• @cgnieder your suggestion should result in the string normalsize being printed in the final document. – A.Ellett Jul 26 '13 at 17:58
• Oh, you're right! I misread your code, sorry! Adding usefontsize/.code = #1 additional to usefontsize/.initial = normalsize seems to work. – clemens Jul 26 '13 at 18:03
• @cgnieder That works! But why??? In all the other initialized key values, I can access and use their initialized value through \ae@ncode@get. Why is that not the case with usefontsize and why then does writing usefontsize/.code = #1, produce the desired effect? – A.Ellett Jul 26 '13 at 18:06
• usefontsize is set to \relsize{-0.75} by \code@cat which you call implicitly by calling the examcode option. In the left example this is overwritten again, in the right it isn't. – clemens Jul 26 '13 at 18:28