我尝试在 YAML 标头中包含一个命名的部分(在变量
frontmatterFile
中),即部分调用中的变量:
代码是:
$if(frontmatterFile)$
${ ${frontmatterFile}.dtpl() }
$else$
${ frontmatter_short.dtpl() }
$endif$
Latex 仅生成
frontmatterFile
中的值,但不处理部分内容 - 在检查生成的 tex
文件中确认。
有没有办法将变量扩展到文件名,然后用作部分?
Pandoc 的模板引擎不支持此功能。但是,您可以编写一个自定义 Lua 编写器来替换模板中的该值。
Template = -- define template, or load from external file
function Writer (doc, opts)
-- get frontmatter file from metadata or variables
local frontmatter_file = pandoc.utils.stringify(doc.meta.frontmatter_file)
or opts.variables.frontmatter_file
opts.template = modify_template(opts.template, frontmatter_file)
return pandoc.write(doc, opts)
end