I want to read xkeyval options from an external file, like:


I tried several combinations of \edef and \expandafter, but to no avail. Any ideas?

Best regards,


1 Answer 1


You can't \edef an \input because it isn't expandable. You have to first read the contents of the file to a temporary variable and then pass that to \setkeys.

Here's an expl3 implementation of \setkeysFile. It's the same as the standard \setkeys except that the second argument is a file that (should) contain a comma separated list of key-value pairs.

hello = world :D,
goodnews = everyone!,

\tl_new:N \l__nicolas_setkeys_tl
\NewDocumentCommand \setkeysFile { m m }
    \file_get:nnNTF {#2} {} \l__nicolas_setkeys_tl
      { \exp_args:NnV \setkeys {#1} \l__nicolas_setkeys_tl }
      { \__kernel_msg_error:nnn { kernel } { file-not-found } {#2} }



Hello \towhom

Good news \who


this prints:

enter image description here

  • 1
    \exp_args:NnV \setkeys{#1} \l__nicolas_setkeys_tl already supplies the braces and is more correct code anyhow. The \ior_open:Nn business is useless.
    – egreg
    Apr 22, 2019 at 17:32
  • Thanks :-) But why more correct? Oh, nevermind, it's because V gets the value of a register, and a register is an N type. Am I correct? Apr 22, 2019 at 17:35
  • 1
    @PhelypeOleinik Because a V-type argument must be a single token
    – Joseph Wright
    Apr 22, 2019 at 17:38
  • @JosephWright Thanks! Some day I'll learn how to use expl3 properly :) Apr 22, 2019 at 17:43
  • 1
    Thanks, that did the trick. My texlive distrib did not have \get_file used catchfile's CatchFileEdef instead.
    – NicolaF_
    Apr 23, 2019 at 4:40

You must log in to answer this question.

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