【问题标题】:Pandoc and listings in YAML header?Pandoc 和 YAML 标头中的列表?
【发布时间】:2021-04-15 10:21:18
【问题描述】:

我有以下test.md

---
listings: true # here it just seems to include usepackage, but still keeps code blocks in {verbatim}; only --listings on command line starts wrapping code block in lstlisting ?
title: "Some title here"
author: John Doe
date: \today
---

# Introduction

Here is some code output, obtained with the `devcon.exe` command line tool:

```
PCI\VEN_8086&DEV_A295&SUBSYS_36E217AA&REV_F0\3&11583659&0&E0
    Name: Intel(R) 200 Series Chipset Family PCI Express Root Port #6 - A295
    Driver is running.
PCI\VEN_8086&DEV_5912&SUBSYS_36E217AA&REV_04\3&11583659&0&10
    Name: Intel(R) HD Graphics 630
    Driver is running.
ACPI\ACPI000C\2&DABA3FF&1
    Name: ACPI Processor Aggregator
    Driver is running.
```

So ...

所以,如果我按原样使用 pandoc 构建这个,代码块 仍然 包裹在 {verbatim} 环境中,即使包含 \usepackage{listings},因为存在 listings: true在 YAML 标头中:

$ pandoc test.md -s -o test.tex && grep '\\begin\|list' test.tex
\usepackage{listings}
\providecommand{\tightlist}{%
\begin{document}
\begin{verbatim}

仅当我将--listings 开关添加到命令行时,我才会将代码块包装在{lstlistings} 环境中:

$ pandoc test.md --listings -s -o test.tex && grep '\\begin\|list' test.tex
\usepackage{listings}
\providecommand{\tightlist}{%
\begin{document}
\begin{lstlisting}
\end{lstlisting}

我的问题是:有什么方法可以在 YAML 标头中指定使用 listingsonly -- 无需 必须使用 --listings在命令行中切换pandoc调用?

编辑:这是在 pandoc 2.11.4

【问题讨论】:

    标签: markdown pandoc pdflatex


    【解决方案1】:

    有一个 open pandoc issue 关于这个。

    您可以使用包装脚本,或者使用 pandoc 的--defaults option,可以如下使用它来指定文件中的命令行选项。如果例如input.md 包含:

    ---
    listings: true
    ...
    
    # my title
    
    rest of my document
    

    你可以这样调用pandoc:

    pandoc --defaults input.md input.md
    

    是的,目前您必须指定两次文件:一次用于--defaults 选项以读取 YAML,一次作为 Markdown 输入文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-31
      • 1970-01-01
      • 2014-03-25
      • 2015-10-28
      • 2015-11-14
      • 1970-01-01
      • 2019-12-03
      相关资源
      最近更新 更多