Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support reference to environment variables within YAML defaults files #5977

Closed
allefeld opened this issue Dec 9, 2019 · 6 comments
Closed

Comments

@allefeld
Copy link
Contributor

allefeld commented Dec 9, 2019

Currently I'm using

variables:
  header-includes:
    - |
      \input{\string~/.pandoc/templates/definitions.tex}

in a YAML defaults file. Note that it includes \string~, which makes LaTeX expand ~ to the home directory. I use this to access a set of (personal) mathematical macros.

It would be nicer to simply write

include-in-header: ~/.pandoc/templates/definitions.tex

but that doesn't work because Pandoc does not expand the tilde.

As @jgm noticed in #5970, having Pandoc do so would be strange since this shortcut is a quirk of Unix-like operating systems, while Pandoc is cross-platform.

Instead I propose to support reference to environment variables within YAML defaults files, for example like this:

include-in-header: ${HOME}/.pandoc/templates/definitions.tex
@jgm
Copy link
Owner

jgm commented Dec 9, 2019

I don't think we can do this across the board, since for example one might want to include some verbatim code that uses ${HOME} in a variable. There ought to be some way to solve this problem, but it needs thought.

@allefeld
Copy link
Contributor Author

How about enabling it only for variables that contain paths?

@jgm
Copy link
Owner

jgm commented Dec 10, 2019

How about enabling it only for variables that contain paths?

And how would you identify these?
(Note that a variable that contains verbatim code, e.g. javascript, might contain a path with an environment variable, and you wouldn't want to mess with it in this context.)

@allefeld
Copy link
Contributor Author

allefeld commented Dec 10, 2019

I think "variables" is not the right term. What I mean is to enable it for those entries in a defaults file (not variables: or metadata:) which take a file or directory as an argument. Meaning those that correspond to these command line options:

$ pandoc --help | egrep "FILE|DIR"
pandoc [OPTIONS] [FILES]
  -o FILE               --output=FILE
                        --data-dir=DIRECTORY
                        --metadata-file=FILE
  -d FILE               --defaults=FILE
                        --template=FILE
  -H FILE               --include-in-header=FILE
  -B FILE               --include-before-body=FILE
  -A FILE               --include-after-body=FILE
                        --highlight-style=STYLE|FILE
                        --syntax-definition=FILE
                        --reference-doc=FILE
                        --abbreviations=FILE
                        --epub-subdirectory=DIRNAME
                        --epub-cover-image=FILE
                        --epub-metadata=FILE
                        --epub-embed-font=FILE
                        --bibliography=FILE
                        --csl=FILE
                        --citation-abbreviations=FILE
                        --log=FILE
                        --print-default-data-file=FILE
                        --print-highlight-style=STYLE|FILE

That would effectively simulate what the shell does on *nix systems, but for all platforms.

@jgm
Copy link
Owner

jgm commented Dec 10, 2019

Ah, right. This concerns certain entries in the defaults file, not variables.
Well, yes, it should be feasible to allow environment variables there.
We'd need to add a little parser for file paths that did the substitution.

@jgm
Copy link
Owner

jgm commented Jan 13, 2020

See discussion in #5982

@jgm jgm closed this as completed in 6dd7520 Mar 5, 2021
jgm added a commit that referenced this issue Mar 8, 2021
This allows the syntax `${HOME}` to be used, in fields that expect
file paths only.  Any environment variable may be interpolated
in this way. A warning will be raised for undefined variables.
The special variable `USERDATA` is automatically set to the
user data directory in force when the defaults file is parsed.
(Note: it may be different from the eventual user data directory,
if the defaults file or further command line options change that.)

Closes #5982.
Closes #5977.
Closes #6108 (path not taken).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants