我可以使用YAML元数据设置命令行参数吗 [英] Can I set command line arguments using the YAML metadata

查看:320
本文介绍了我可以使用YAML元数据设置命令行参数吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Pandoc在降价文档中支持 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

did 会生成一个目录,但未对这些部分进行编号.我想知道为什么会这样,是否有办法从文档中指定此类内容,而无需在命令行中添加它.

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?因为默认的乳胶模板使用了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设置为任何值都会在带有默认模板的乳胶输出中产生编号

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆