TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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).

share|improve this question
My first guess is maybe it's being expanded when it shouldn't be? – Seamus Dec 21 '11 at 15:03
up vote 5 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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