Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

Not able to use titlesec with markdown and pandoc?

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 tl@extractparagraph

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...