I want to define a new environment whose contents can be typeset using a specific font family and size optionally specified as key-value pairs. For handling the key-value pairs I am using pgfkeys. Why is LaTeX not accepting passing the font size as a key-value pair like fontsize=\large, though it has no problem with fontfamily=\sffamily? How to fix this?

Here is a minimal example:


  fontfamily/.store in = \myenvfontfamily,
  fontsize/.store in = \myenvfontsize,



pdflatex fails with the message:

! Undefined control sequence.
\myenvfontsize ->\large 

l.24 ...env}[fontfamily=\sffamily,fontsize=\large]

I want to define an environment where the user should be able to set the font using key-value pairs, much like the Verbatim environment from the fancyvrb package (although font setting is not the primary goal of the environment).

  • My first guess is maybe it's being expanded when it shouldn't be?
    – Seamus
    Dec 21, 2011 at 15:03

1 Answer 1


You code compiles (and seems to work) if you use \documentclass{article}: The minimal class has no \large.

Note that you could improve your code by means of

  fontfamily/.store in = \myenvfontfamily,
  fontsize/.store in = \myenvfontsize,

in which case you could omit the \ifdefined -- simply write \myenvfontfamily. In the default case it would expand to the empty string which has no effect. This would allow your users to reset the style effectively.

Note furthermore, that you could benefit from pgfkeys' builtin variables, i.e. by means of


combined with .... \pgfkeysgetvalue{/myenv/fontfamily}\temp ... \temp: this would allow you to write


the /.add={prefix}{suffix} allows to modify an existing variable rather than replacing it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .