【问题标题】:Relative paths in pandoc HTML templatespandoc HTML 模板中的相对路径
【发布时间】:2017-11-13 18:41:23
【问题描述】:

我有一个从默认 --data-dir 加载的 Pandoc (v1.19.2.1) HTML5 模板。在模板中,我需要加载外部资源,例如样式表和 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 模板中相对于模板本身的外部资源,从而使模板具有可移植性?我没有看到可以在模板或命令行选项中使用的明显外部变量。

【问题讨论】:

标签: pandoc


【解决方案1】:

我正在粘贴我在不久前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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-24
    • 2017-08-01
    • 1970-01-01
    • 2013-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多