我可以使用 YAML 元数据设置命令行参数吗 [英] Can I set command line arguments using the YAML metadata
问题描述
Pandoc 支持 Markdown 文档中的 YAML 元数据块.这可以设置标题和作者等.它还可以通过更改字体大小、边距宽度和赋予包含的图形的框架大小来操纵 PDF 输出的外观.这里给出了很多细节.
Pandoc supports a YAML metadata block in markdown documents. This can set the title and author, etc. It can also manipulate the appearance of the PDF output by changing the font size, margin width and the frame sizes given to figures that are included. Lots of details are given here.
我想使用元数据块来记住我应该使用的命令行参数,例如 --toc
和 --number-sections代码>.我试过了,将以下内容添加到我的降价顶部:
I'd like to use the metadata block to remember the command line arguments that I'm supposed to be using, such as --toc
and --number-sections
. I tried this, adding the following to the top of my markdown:
---
title: My Title
toc: yes
number-sections: yes
---
然后我用命令行:
pandoc -o guide.pdf articheck_guide.md
这确实生成了一个目录,但没有给章节编号.我想知道为什么会这样,如果有办法我可以从文档中指定这种东西,这样我就不需要在命令行中添加它了.
This did produce a table of contents, but didn't number the sections. I wondered why this was, and if there is a way I can specify this kind of thing from the document so that I don't need to add it on the command line.
推荐答案
YAML 元数据不是作为参数传递给 pandoc
,而是作为变量.当您在 MWE 上调用 pandoc
时,它不会产生这个:
YAML metadata are not passed to pandoc
as arguments, but as variables. When you call pandoc
on your MWE, it does not produce this :
pandoc -o guide.pdf articheck_guide.md --toc --number-sections
正如我们所想.相反,它调用:
as we think it would. rather, it calls :
pandoc -o guide.pdf articheck_guide.md -V toc:yes -V number-sections:yes
那么,为什么你们 MWE 会生成目录?因为默认的乳胶模板使用 toc
变量:
Why, then, does you MWE produces a toc? Because the default latex template makes use of a toc
variable :
~$ pandoc -D latex | grep toc
$if(toc)$
setcounter{tocdepth}{$toc-depth$}
因此,将 toc
设置为任何值都应该产生一个目录,至少在乳胶输出中是这样.在这个模板中,没有 number-sections
变量,所以这个不起作用.但是,有一个 numbersections
变量:
So setting toc
to any value should produce a table of contents, at least in latex output. In this template, there is no number-sections
variables, so this one doesn't work. However, there is a numbersections
variable :
~$ pandoc -D latex | grep number
$if(numbersections)$
将 numbersections
设置为任何值都会在 Latex 输出中使用默认模板生成编号
Setting numbersections
to any value will produce numbering in a latex output with the default template
---
title: My Title
toc: yes
numbersections: yes
---
此解决方案的问题在于它仅适用于某些输出格式.我以为我在 pandoc 邮件列表的某个地方读到过,我们很快就能按预期在 YAML 块中使用元数据(即作为参数而不是变量),但我再也找不到它了,所以也许它不会不会很快发生.
The trouble with this solution is that it only works with some output format. I thought I had read somewhere on the pandoc mailing-list that we soon would be able to use metadata in YAML blocks as intended (ie. as arguments rather than variables), but I can't find it anymore, so maybe it won't happen very soon.
这篇关于我可以使用 YAML 元数据设置命令行参数吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!