Not able to use titlesec with markdown and pandoc?

白昼怎懂夜的黑 提交于 2019-11-26 17:00:13

问题


When I used titlesec in my markdown document as below:

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

when processing it by pandoc, I got the following error:

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

pandoc: Error producing PDF

by searching, I found the following work-around for R-markdown: Can't knit to pdf with custom styles

I wonder how can I implement a similar work-around with markdown and YAML headers?

I also found and verified the following approach would work:

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

But it's harder for the user, as one might forget the work-around.

There are some discussion of the work-around https://www.bountysource.com/issues/40574981-latex-template-incompatible-with-titlesec, but it's beyond my knowledge

Thanks for your help


回答1:


This is because the default LaTeX template redefines \paragraph. To disable this behaviour, you can use the subparagraph variable in pandoc. You could supply this at the command-line:

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

Or you could embed it in the document's YAML metadata, with any non-null value:

---
subparagraph: yes
---

From man pandoc (and the 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

After this, titlesec.sty should work.



来源:https://stackoverflow.com/questions/42916124/not-able-to-use-titlesec-with-markdown-and-pandoc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!