我有一个从默认加载的 Pandoc (v1.19.2.1) HTML5 模板 --data-dir
.在模板中,我需要加载外部资源,例如样式表和 JavaScript。我想相对于模板的路径加载这些资源,而不是工作目录或源文件。例如,在 macOS 上,在 ~/.pandoc/templates/hierarchical/hierarchical.html
:
…
<link rel="stylesheet" href="hierarchical.css">
…
哪里
hierarchical.css
位于 ~/.pandoc/templates/hierarchical/hierarchical.css
, 在与模板本身相同的目录中。然后从命令行调用:
pandoc \
--from=markdown_strict+header_attributes+yaml_metadata_block+pipe_tables\
--to=html5 \
--self-contained \
--template="hierarchical/template.html" \
--section-divs \
--output="$1.html" \
--toc \
--toc-depth=6 \
"$1.md"
我收到错误:
pandoc: Could not fetch hierarchical.css
hierarchical.css: openBinaryFile: does not exist (No such file or directory)
我已经尝试了各种其他的 CSS 文件相对路径。唯一有效的是绝对路径
/Users/jmakeig/.pandoc/templates/hierarchical/hierarchical.css
,当然,这只能在我的笔记本电脑上使用。有没有什么方法可以解决 Pandoc 模板中相对于模板本身的外部资源,以便模板是可移植的?我没有看到可以在模板或命令行选项中使用的明显外部变量。
最佳答案
我正在粘贴我为 created in github 提供的问题的解决方法不久以前。
在我创建这个问题两年多后回到这个话题,我发现了一个不错的解决方法。
显然, latex 使用环境变量 TEXINPUTS
作为资源的排序路径。因此,您只需在系统(linux、windows 等)中配置一次环境变量,然后引用与该路径相关的资源即可。
此链接提供了有关如何使用它的一些说明:
https://tex.stackexchange.com/questions/93712/definition-of-the-texinputs-variable
例如我有以下文件:
SOME_PATH_TO/templates/my_latex_template.tex
SOME_PATH_TO/templates/img/my_img.png
在我的系统中,我设置了环境变量(以 Windows 为例,虽然我实际上只是将它保存在系统配置下):
set TEXINPUTS=SOME_PATH_TO/templates/
在模板
my_latex_template.tex
我有类似的东西:%...
\includegraphics{img/my_img.png}
%...
我这样称呼模板:
pandoc file.txt -t pdf --template=SOME_PATH_TO/templates/my_latex_template.tex --output=output.pdf
关于pandoc - pandoc HTML 模板中的相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47271344/