将 yaml 元数据(标头包含)与 Pandoc 相结合

发布于 2025-01-15 23:48:28 字数 551 浏览 2 评论 0原文

如果我有这些文件:

text.md:

---
header-includes:
- \usepackage{pgf-pie}
---

\begin{tikzpicture}
\pie{50/, 50/}
\end{tikzpicture}

settings.yaml:

variables:
    header-includes:
    - \pagecolor{black}

并且我使用 pandoc 使用以下命令编译它们:

pandoc text.md -d settings -o text.pdf

...默认文件中的 header-includessettings.yaml< /code> 会覆盖 text.md 中的元数据块,从而导致编译失败。

有没有办法让 pandoc 组合两个 header-includes 列表?

If I have these files:

text.md:

---
header-includes:
- \usepackage{pgf-pie}
---

\begin{tikzpicture}
\pie{50/, 50/}
\end{tikzpicture}

settings.yaml:

variables:
    header-includes:
    - \pagecolor{black}

and I compile them with pandoc with the command:

pandoc text.md -d settings -o text.pdf

...the header-includes value in the defaults file settings.yaml will overwrite the metadata block in text.md, thus failing to compile.

Is there a way to get pandoc to combine the two header-includes lists instead?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的夜不怕黑 2025-01-22 23:48:28

组合这些 header-includes 列表是不可能的。

这样做有两个原因:第一,默认文件中的值始终优先。此外,如果名称既用作变量又在元数据中使用,则将使用该变量。

有关本主题的其他信息和讨论,请参阅这些 pandoc GitHub 问题:


可能的解决方法是使用“新样式”自定义 writer,因为它们提供对元数据和变量的写访问权限:

function Writer (doc, opts)
  local includes_tmpl = pandoc.template.compile('$header-includes

但是请注意,这当前需要开发版本,因此您' d 需要使用每晚构建。您还需要显式指定模板和 PDF 引擎,例如 --template=default.latex --pdf-engine=xelatex

) local vars = {['header-includes'] = opts.variables['header-includes'] or ''} -- Write header-includes, once with variables, once without (thus -- allowing metadata values to be used instead) opts.variables['header-includes'] = pandoc.write(doc, 'latex', {template=includes_tmpl, variables=vars}) .. '\n' .. pandoc.write(doc, 'latex', {template=includes_tmpl}) return pandoc.write(doc, 'latex', opts) end

但是请注意,这当前需要开发版本,因此您' d 需要使用每晚构建。您还需要显式指定模板和 PDF 引擎,例如 --template=default.latex --pdf-engine=xelatex

Combining these header-includes lists is not possible.

There are two reasons to this: One, the values from the defaults file always take precedence. In addition, if a name is used both as as a variable and in the metadata, then the variable will be used.

For additional info and discussions of this topic, see these pandoc GitHub issues:


A possible workaround would be to use a "new style" custom writer, as these provide write access to both metadata and variables:

function Writer (doc, opts)
  local includes_tmpl = pandoc.template.compile('$header-includes

Note, however, that this currently requires the development version, so you'd need to use a nightly build. You'll also need to explicitly specify the template and PDF engine, e.g., --template=default.latex --pdf-engine=xelatex.

) local vars = {['header-includes'] = opts.variables['header-includes'] or ''} -- Write header-includes, once with variables, once without (thus -- allowing metadata values to be used instead) opts.variables['header-includes'] = pandoc.write(doc, 'latex', {template=includes_tmpl, variables=vars}) .. '\n' .. pandoc.write(doc, 'latex', {template=includes_tmpl}) return pandoc.write(doc, 'latex', opts) end

Note, however, that this currently requires the development version, so you'd need to use a nightly build. You'll also need to explicitly specify the template and PDF engine, e.g., --template=default.latex --pdf-engine=xelatex.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文