I have just managed to create my first command with pgfkeys. I defined a command \myset, whose purpose is to make (for example)


correspond to


Part of my goal was to do this in a way that would easily let me create variants later, using different delimiters; in particular, I didn't want my \pgfkeys code to refer to the \{ and \}.

Working from this TeX.SE thread and the relevant section of the PGF manual, here is what I came up with:

\pgfkeys{/delimitersizes/.is family, /delimitersizes,
 default/.style = {auto},
 auto/.style = {leftsize = auto, rightsize = auto},
 big/.style = {leftsize = big, rightsize = big},
 bigg/.style = {leftsize = bigg, rightsize = bigg},
 Big/.style = {leftsize = Big, rightsize = Big},
 Bigg/.style = {leftsize = Bigg, rightsize = Bigg},
 leftsize/.style = {leftdictionary/#1/.get = \leftdelimitersize},
 rightsize/.style = {rightdictionary/#1/.get = \rightdelimitersize},
  big/.initial = \bigl,
  bigg/.initial = \biggl,
  Big/.initial = \Bigl,
  Bigg/.initial = \Biggl,
  auto/.initial = \left, }
\pgfkeys{/delimitersizes, rightdictionary/.cd,
  big/.initial = \bigr,
  bigg/.initial = \biggr,
  Big/.initial = \Bigr,
  Bigg/.initial = \Biggr,
  auto/.initial = \right, }

\pgfkeys{delimitersizes, default, #1}
\leftdelimitersize\{#2\rightdelimitersize\} }


This functions as it is supposed to, but considering the finished product, it seems like there's a significant amount of "code duplication", and shuffling around of information before getting to use it. I realize this is a rather open-ended question, but can people suggest how to improve this code to make it more compact and streamlined?


This is more streamlined but I'm not sure if using pgf was a requirement in this case.




$\myset{abc}$  $\myset[Bigg]{xyz}$


enter image description here

| improve this answer | |

I think David has the right of it, but if you want to do something like this with pgfkeys, here is the style I like. This took me way too long to get right, though I think a year ago, before I got out of practice, it wouldn't have. This is also an argument against doing things this way for something so simple.


  util/create/.style = {
    util/name = #1,
    util/dict =
  util/name/.style = {
    #1/.style = {
      leftsize = #1,
      rightsize = #1
  util/dict/.style n args = {3}{
    leftdictionary/#1/.initial/.expand once = #2,
    rightdictionary/#1/.initial/.expand once = #3
  leftsize/.style = {
    leftdictionary/#1/.get =  \leftdelimitersize
  rightsize/.style = {
    rightdictionary/#1/.get = \rightdelimitersize
  default/.style = auto,
  util/create/.list = {big,bigg,Big,Bigg},
  % Treat auto specially
  util/name = auto,
  util/dict = {auto}{\noexpand\left}{\noexpand\right}




Basically, you create a bunch of utility keys that do the work of defining the keys you actually use, and then call the utility keys repeatedly. This is facilitated by the ever-useful .list handler, which I guess is the core of the code-repetition reduction strategy. Note that if you were going to call keys that made assignments via .loop, those assignments would have to be made globally or else (since \foreach is run in a group) they would be lost.

| improve this answer | |

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.