Consider the following title block in pandoc-flavored Markdown:
% Higgelty Pigglety Pop!
or
There Must Be More to Life
% Maurice Sendak
Here, line breaks are part of the title. It is possible to reformat the title in order to insert it into regular text flow, e.g. "Higgelty Pigglety Pop! Or, There Must Be More to Life", but when not talked about but used on the title page of a document, preserving the line breaks is crucial. Depending on the style, it might look like this:
Higgelty Pigglety Pop! or There Must Be More to Life Maurice Sendak
My question: How can I achieve a proper multi-line title display in the output of pandoc?
A portable version would be preferred, but I'd also be content with a LaTeX-only hack.
Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.
To break a line in R Markdown and have it appear in your output, use two trailing spaces and then hit return .
Commonly used markup languages include Markdown, ReStructuredText, HTML, LaTex, ePub, and Microsoft Word DOCX. In plain English, Pandoc allows you to convert a bunch of files from one markup language into another one. Typical examples include converting a Markdown file into a presentation, LaTeX, PDF, or even ePub.
% Higgelty Pigglety Pop! \
or \
There Must Be More to Life
% Maurice Sendak
Pandoc Markdown enables the escaped_line_breaks
extension by default:
A backslash followed by a newline is also a hard line break. Note: in multiline and grid table cells, this is the only way to create a hard line break, since trailing spaces in the cells are ignored.
When using YAML metadata blocks, the following works, too:
---
title: |
| First line
| Second line
---
Found the idea in this thread.
A very general, but less simple method is to use raw HTML to indicate line breaks, and to convert them into proper line breaks using a pandoc filter. Below is a Lua filter which translates any <br>
(or <br />
) in the source into a hard line break.
--- Transform a raw HTML element which contains only a `<br>`
-- into a format-indepentent line break.
function RawInline (el)
if el.format:match '^html' and el.text:match '%<br ?/?%>' then
return pandoc.LineBreak()
end
end
Save the file as linebreaks.lua
.
The title could then be written as
% Higgelty Pigglety Pop!<br>or<br>There Must Be More to Life
% Maurice Sendak
The above script must be passed to pandoc via the --lua-filter
option:
$ pandoc -o test.pdf --lua-filter ./linebreaks.lua test.md
The advantage of this method is that it is more universal and also works in other locations that one might want to add line breaks. E.g., a line break in a header can be added using the same syntax: # first line<br>second line
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With