在pandoc中使用YAML标题选项可以控制什么?

在pandoc中使用YAML标题选项可以控制什么?,yaml,pandoc,Yaml,Pandoc,我只是碰巧看到了一个示例文档,它在Pandoc要处理的标记文件中的YAML标题选项中使用了toc:true行。并且没有提到使用YAML标题控制目录的这个选项。此外,我在同一个Pandoc自述网站的示例文档中看到了一些任意的行 主要问题: 使用YAML标题可以使用哪些Pandoc选项 元问题: 是什么决定了可使用YAML标题设置的可用Pandoc选项 注意:我的工作流程是使用标记文件(.md)并通过Pandoc处理它们以获取PDF文件。它用数学分层组织手稿写作。例如: pandoc --s

我只是碰巧看到了一个示例文档,它在Pandoc要处理的标记文件中的YAML标题选项中使用了
toc:true
行。并且没有提到使用YAML标题控制目录的这个选项。此外,我在同一个Pandoc自述网站的示例文档中看到了一些任意的行

主要问题:

  • 使用YAML标题可以使用哪些Pandoc选项
元问题:

  • 是什么决定了可使用YAML标题设置的可用Pandoc选项
注意:我的工作流程是使用标记文件(
.md
)并通过Pandoc处理它们以获取PDF文件。它用数学分层组织手稿写作。例如:

pandoc --standalone --smart \
    --from=markdown+yaml_metadata_block \
    --filter pandoc-citeproc \
    my_markdown_file.md \
    -o my_pdf_file.pdf

YAML元数据中设置的几乎所有内容都只有在使用中才会产生效果

Pandoc模板可能包含变量。例如,在HTML模板中,您可以编写:

<title>$title$</title>
见此:

回答您的问题:模板确定YAML元数据块中的哪些字段具有影响。例如,要查看默认latex模板,请使用:

$ pandoc -D latex

要查看由pandoc自动设置的某些变量,请执行以下操作:。最后,pandoc的其他行为(如降价扩展等)只能设置为命令行选项(使用时除外)。

您可以查看pandoc的文档以获取线索:

但要知道它将在何处使用,您可以查找pandoc的模板源:

例如,对于html5输出,文件为:

以下是代码的一部分:

<title>$if(title-prefix)$$title-prefix$ - $endif$$pagetitle$</title>
$if(标题前缀)$$title prefix$-$endif$$pagetitle$
如您所见,它有
标题前缀
页面标题


您可以查看文档,但最好的解决方案是查找您正在使用的版本的源代码。

这是一个相当长的列表,您可以通过在命令行中运行
man pandoc
并导航到“TEMPLATES”下的“Variables set by pandoc”部分来浏览

列表顶部包括许多其他选项:

Variables set by pandoc
   Some variables are set automatically by pandoc.  These vary somewhat depending  on  the
   output format, but include metadata fields as well as the following:

   title, author, date
          allow identification of basic aspects of the document.  Included in PDF metadata
          through LaTeX and ConTeXt.  These can be set through a pandoc title block, which
          allows for multiple authors, or through a YAML metadata block:

                 ---
                 author:
                 - Aristotle
                 - Peter Abelard
                 ...

   subtitle
          document subtitle; also used as subject in PDF metadata

   abstract
          document summary, included in LaTeX, ConTeXt, AsciiDoc, and Word docx

   keywords
          list  of  keywords  to  be  included in HTML, PDF, and AsciiDoc metadata; may be
          repeated as for author, above

   header-includes
          contents specified by -H/--include-in-header (may have multiple values)

   toc    non-null value if --toc/--table-of-contents was specified

   toc-title
          title of table of contents (works only with EPUB and docx)

   include-before
          contents specified by -B/--include-before-body (may have multiple values)

   include-after
          contents specified by -A/--include-after-body (may have multiple values)

   body   body of document

```

如果你能阅读哈斯克尔的文章,那么答案可以在@xmojmr上找到,我也许能学会。但我希望有一个自然语言的解释或概述。例如,对架构或其他东西的描述。谢谢,不过,我会看看的!我自己无法阅读Haskell(也不想学习它),除了源代码之外,我不知道pandoc内部行为的可信描述,所以我不知道答案是什么,只是在pandoc的作者()出现之前尽力提供帮助。它是否在任何地方明确说明,所有变量都支持其值来自YAML元数据块吗?此外,我想提到的是,将元数据块放入模板中只是在某些情况下,对于某些变量是一个好主意。文档特定变量(如标题)应始终在相应的文档中定义,以便模板可以用于其他未更改的文档(因为它是一个模板,而模板就是用于此目的的)。我不明白这个问题的答案是什么。在我看来,缺少的信息是:Pandoc的哪些选项可以设置为“变量”?都是吗?(您说变量可以在Yaml头中设置。)Yaml头可以只设置变量吗?或者有没有不是变量的选项?Yaml标题可以设置这些吗?(例如,是否可以在Yaml头中启用扩展?@Lii答案解释了可以在Yaml块的帮助下为变量赋值。是否在生成的输出中使用这些变量取决于所使用的模板(通过指定输出格式)。HTML和latex的内置默认模板都使用
toc
变量来控制目录的显示。您可以发明自己的变量并相应地扩展模板。这主要是因为一些变量也可以通过命令行开关进行设置。这间接表明YAML块只是一个选项。
<title>$if(title-prefix)$$title-prefix$ - $endif$$pagetitle$</title>
Variables set by pandoc
   Some variables are set automatically by pandoc.  These vary somewhat depending  on  the
   output format, but include metadata fields as well as the following:

   title, author, date
          allow identification of basic aspects of the document.  Included in PDF metadata
          through LaTeX and ConTeXt.  These can be set through a pandoc title block, which
          allows for multiple authors, or through a YAML metadata block:

                 ---
                 author:
                 - Aristotle
                 - Peter Abelard
                 ...

   subtitle
          document subtitle; also used as subject in PDF metadata

   abstract
          document summary, included in LaTeX, ConTeXt, AsciiDoc, and Word docx

   keywords
          list  of  keywords  to  be  included in HTML, PDF, and AsciiDoc metadata; may be
          repeated as for author, above

   header-includes
          contents specified by -H/--include-in-header (may have multiple values)

   toc    non-null value if --toc/--table-of-contents was specified

   toc-title
          title of table of contents (works only with EPUB and docx)

   include-before
          contents specified by -B/--include-before-body (may have multiple values)

   include-after
          contents specified by -A/--include-after-body (may have multiple values)

   body   body of document