无法将 titlesec 与 markdown 和 pandoc 一起使用?

Not able to use titlesec with markdown and pandoc?

当我在 markdown 文档中使用 titlesec 时,如下所示:

---
header-includes:
    - \usepackage{titlesec}
---

用pandoc处理时,出现如下错误:

pandoc try.md -o try.pdf
! Argument of \paragraph has an extra }.
<inserted text> 
                \par 
l.1290 \ttl@extract\paragraph

pandoc: Error producing PDF

通过搜索,我为R-markdown找到了以下work-around: Can't knit to pdf with custom styles

我想知道如何使用 markdown 和 YAML headers 实现类似的 work-around?

我还发现并验证了以下方法是否有效:

pandoc --variable=subparagraph try.md -o try.pdf

但这对用户来说更难,因为人们可能会忘记 work-around。

有一些讨论work-around https://www.bountysource.com/issues/40574981-latex-template-incompatible-with-titlesec, 但这超出了我的知识范围

感谢您的帮助

这是因为默认的 LaTeX 模板重新定义了 \paragraph。要禁用此行为,您可以在 pandoc 中使用 subparagraph 变量。您可以在命令行中提供:

pandoc --variable subparagraph -o file.pdf file.md

或者您可以将它嵌入到文档的 YAML 元数据中,具有任何非空值:

---
subparagraph: yes
---

来自 man pandoc(和 user's guide):

subparagraph

disables default behavior of LaTeX template that redefines (sub)paragraphs as sections, changing the appearance of nested headings in some classes

在此之后,titlesec.sty 应该可以工作了。