I like to define commands to denote multi-parameter (mathematical) functions, e.g., \myf{x}{C} expands to f(x;C). During writing, however, it is sometimes hard to remember if I should use \myf{x}{C} or \myf{C}{x}, so I would like to use something like keyword arguments from Python. In my example, this means I would like to write \myf{set=C,at=x} or \myf{at=x,set=C} and get f(x;C) as the result for both commands. For that, I am using pgfkeys; see below.

I am running into an error when pdflatexing the code below:

  /myf/set/.estore in = \myfset,
  /myf/at/.estore in = \myfat,
  \pgfkeys{/myf/.cd, #1}

I get an error

<inserted text> 
l.16 \(\myf{set=\mathscr{C},at=a}

This error goes away if I replace \mathscr{C} with C or if I drop the package mathtools (which I need for other features).

Could anybody please help me fix this? Thanks!

  • 4
    Is there a reason you are using .estore in rather than just .sotre in? The former does expansion which may (and here does) go wrong with non-expandable input. – Joseph Wright Jan 20 '15 at 10:08
  • @JosephWright: the only reason is my ignorance. Thank you so much. This solved my problem. – mk1 Jan 20 '15 at 11:19

Just for fun a solution using l3keys. Here, the keys set defaults to \mathscr{A} and at to c, so you can use \myf{} with an empty argument.


\keys_define:nn { mk1 }
  set .tl_set:N  = \l_mk_set_tl   ,
  at  .tl_set:N  = \l_mk_at_tl    ,
  set .default:n = { \mathscr{A} },
  at  .default:n = { c }

\NewDocumentCommand { \myf } { m }
  \keys_set:nn { mk1 } { set,at,#1 }
  f( \tl_use:N \l_mk_at_tl ; \tl_use:N \l_mk_set_tl )

enter image description here

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