我有一个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模板中的外部资源,以便模板是可移植的?我看不到在模板或命令行选项中可以使用的明显的外部变量。
发布于 2019-10-26 20:55:00
我在粉饰我不久前为在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.pdfhttps://stackoverflow.com/questions/47271344
复制相似问题