Open MrJohz opened 4 years ago
which means that the person generating these documents needs to have the entire assets directory in every folder that they want to run pandoc in - this is obviously a bit ridiculous.
A good use case for symbolic links!
I suppose the most straightforward way to implement this would be to modify Text.Pandoc.App.OutputSettings, so that if getTemplate succeeds we add variables template-path
and template-dir
to writerVariables
. I fear that __file__
and __dir__
will be construed as referring to the file path rather than the template path, but maybe not.
I also want this feature very much.
I developed a collection of company-branded Pandoc/LaTeX templates for my colleagues to use, so I have the same problem. At the moment, I'm using an ugly hack for this.
In the directory where Pandoc is invoked, the user must create a file called config.yaml
which sets the value of template-dir
to the location of the directory where they installed my custom templates.
For each template, I have a YAML file that includes the line metadata-file: config.yaml
, allowing it access to the $template-dir$
variable.
All of my templates then specify the path of the resources they need relative to $template-dir$
.
The users invoke pandoc with a command like this:
pandoc myfile.md -o myfile.pdf --data-dir=/path/to/the/templates --defaults=mycustomtemplate
But now I want to create a Nix / NixOS package for my templates, and this hack becomes very impractical.
I'm trying to write a set of templates that can be shared between my team members, so that we can generate reports that have a consistent style. These templates include assets such as images and fonts that can't easily be included via the existing template partials mechanism. What I would like is a way to reference these assets in as cross-platform a way as possible.
Problem
For example, I have a template folder structure like this:
... and a LaTeX template that looks something like this:
If I use this template directly, this line will be executed in the context of the working directory of the user running
pandoc
, which means that the person generating these documents needs to have the entire assets directory in every folder that they want to run pandoc in - this is obviously a bit ridiculous.Alternatively, I could hard-code the path to the location that I want to install these templates. For example, on my Linux system, I might do something like:
Then as part of the install step, I can just run:
This works, but it's very fragile:
Suggested Solution
I suggest adding template variables like
$__file__$
and$__dir__$
that will always refer to the location of the file being templated, as it's being templated. So:$__file__$
would point toC:\Users\Me\AppData\Roaming\pandoc/templates/template.latex
and$__dir__$
would point toC:\Users\Me\AppData\Roaming\pandoc/templates/
.$__file__$
would point to/home/me/.my-pandoc-data/templates/template.latex
and$__dir__$
would point to/home/me/.my-pandoc-data/templates
.$__file__$
would point to/home/me/projects/my-templates/template.latex
, and$__dir__$
would point to/home/me/projects/my-templates/
.This way, I can write my template to look something like this:
Now, as long as I install my template to a location together with the assets directory, I don't need to know where that location is.