Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandoc generation of pdf from markdown 4th header is rendered differently

Tags:

I am using pandoc to generate a pdf from some markdown. I am using h1 through h4 via hash symbols. Example h1=#, h4=####. When I generate my document like this:

pandoc input.md -o output.pdf

I get a document where h1, h2 and h3 have a newline after them but h4 does not have a new line. The text starts on the same line as the header (it isn't formatted the same way, but there isn't a newline character between).

I've tried adding spaces after the #### and adding manual line returns using my editor but nothing seems to work.

Any ideas?

like image 910
storrgie Avatar asked Jan 17 '14 23:01

storrgie


People also ask

How do I convert Markdown to PDF with pandoc?

There are actually two steps involved in converting a Markdown file to a PDF file: The Markdown source file is converted to a LaTeX source file. Pandoc invokes the pdflatex or xelatex or other TeX command and converts the . tex source file to a PDF file.

Can pandoc convert from PDF?

You can use the program pandoc on the SCF Linux and Mac machines (via the terminal window) to convert from formats such as HTML, LaTeX and Markdown to formats such as HTML, LaTeX, Word, OpenOffice, and PDF, among others.

What is a pandoc template?

Pandoc is a command line tool that you can use to automatically convert files from markup format to another. With Pandoc, you can write in something easy like Markdown, Microsoft Word, or LibreOffice, and convert it something hard like: HTML. Ebook formats.

Can pandoc convert HTML to Markdown?

Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.


2 Answers

pandoc generates PDFs via LaTeX. In LaTeX, "headers" are generated using the following commands:

  1. \section
  2. \subsection
  3. \subsubsection
  4. \paragraph
  5. \subparagraph

As you can see, a "level four heading" corresponds to the \paragraph command, which is rendered as you describe. There simply isn't a \subsubsubsection command to use.

The only way to get what you want is to redefine the \paragraph command, which is quite tricky. I haven't been able to make it work with Pandoc.

like image 164
Chris Avatar answered Sep 16 '22 19:09

Chris


While the mentioned solutions work fine, pandoc offers a build-in variable to enable block-headings for \paragraph.

pandoc -s -o out.pdf some.md -V block-headings

Pandoc Manual

like image 20
Nikla Avatar answered Sep 20 '22 19:09

Nikla