Quantcast
Channel: Loading pgfkeys key values from an external file without Expl3? - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 2

Loading pgfkeys key values from an external file without Expl3?

$
0
0

This is a followup of this question. Briefly, I want to load from an external file the argument to give to \pgfkeys, but this is not trivial.

Here is an example of what I tried to do, which however does not work due to lots of strange error messages:

\begin{filecontents}{keys.def}  key = {     Hellò  }\end{filecontents}\documentclass{article}\usepackage[utf8]{inputenc}\usepackage{pgfkeys}\pgfkeys{  /mykeys/key/.initial = {}}\pgfqkeys{/mykeys}{  \input{keys.def}}\begin{document}  Values: \pgfkeysvalueof{/mykeys/key}\end{document}

As you see I need to load the contents of a file as-is (hence the attempt of using \input) and feed it to the \pgfkeys command.

The use-case is the following: I want to make my class extensible, so I defined a discrete number of keys, and I want it to be configurable from an external file. This is not done in the context of typesetting a document, but inside a more involved system of which TeX-ing the file is only a stage, thus the file will be edited by third-party people and I need to hide the fact that this is TeX, so I cannot simply include the \pgfkeys call itself in the file. That said, I don't want to forbid to anybody who does know that this is TeX from doing anything fancy, so i don't want to simply parse a list of key-value pairs, instead parsing directly the argument to \pgfkeys, so advanced users can do whatever they want.

From what written above the requirements are the simple:

1) I need to read the whole contents of the file as-is, without any special format nor restrictions, and2) pass it to a \pgfkeys command as-if the above example that use \input had worked.3) In the MWE I've intentionally included inputenc and an UTF8 character in the example input, because the real input will contain localized text and I need for UTF8 to work.

The accepted answer of the linked question uses expl3, and it originally used also l3keys for key handling. I cannot use l3keys as I already set up everything using pgfkeys. Adapting that solution to pgfkeys results in the following:

\documentclass{article}\usepackage[utf8]{inputenc}\usepackage{expl3,pgfkeys}\begin{document}\pgfkeys{  gigabytes pgf/mykeys/.cd,  key/.initial={},}\ExplSyntaxOn\ior_new:N \l_gigabytes_stream\ior_open:Nn \l_gigabytes_stream { keys.def }\ior_map_inline:Nn \l_gigabytes_stream {  \pgfkeys { gigabytes~pgf / mykeys/.cd, #1}}\ior_close:N \l_gigabytes_stream\pgfkeysvalueof{gigabytes~pgf /mykeys / key}\ExplSyntaxOff\end{document}

However, the problem with this code is that the file is read with the cathode regime of expl3, thus all the spaces from the file are thrown away and this is not acceptable. Also, avoiding expl3 is better for me since I'm not used to it and all the rest of the system doesn't need it.

So how can I achieve my goal without using expl3?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images