How can I get localized quotation marks with pandoc?
Asked Answered
R

4

7

I would like to get quotation marks like these „...” but when I process my markdown text wih Pandoc, it gives me “...”. It probably boils down to the question how to make Pandoc use locale settings? Here is my command line:

pandoc -o out.pdf  -f markdown -t latex in.md
Resolutive answered 26/11, 2015 at 15:44 Comment(0)
P
4

You may want to specify the language for the whole document, so that it not only affects the quotes, but also ligatures, unbreakable spaces, and other locale specifics.

In order to do that, you may specify the lang option. From pandoc's manual:

lang: identifies the main language of the document, using a code according to BCP 47 (e.g. en or en-GB). For some output formats, pandoc will convert it to an appropriate format stored in the additional variables babel-lang, polyglossia-lang (LaTeX) and context-lang (ConTeXt).

Moreover, the same manual states that:

if your LaTeX template or any included header file call for the csquotes package, pandoc will detect this automatically and use \enquote{...} for quoted text.

In my opinion, the best way to ensure quotes localization is thus to add:

---
lang: fr-FR
header-includes:
- \usepackage{csquotes}
---

Or even better, to edit the pandoc default template

pandoc -D latex > ~/.pandoc/templates/default.latex

and permanently add \usepackage{csquotes} to it.

Piecework answered 28/3, 2017 at 17:30 Comment(3)
According to pandoc.org/MANUAL.html#creating-a-pdf, you need to add also csquotes: true to the frontmatter.Emilemile
@Emilemile you need the variable to be "set to a true value" which happens, iirc, as soon as the string "csquotes" appears in the latex templatePiecework
@Emilemile @Piecework Actually it's sufficient to only include csquotes: true in the yaml block, which saves you the somewhat ugly header-includes and is just nicer (and more descriptive) in general.Stoke
N
2

Pandoc currently (Nov. 2015) only generates English type quotes. But you have two options:

  1. You can use the --no-tex-ligatures option to turn off the --smart typography option which is turned on by default for LaTeX output. Then use the proper unicode characters (e.g. „...”) you desire and use a --latex-engine that supports unicode (lualatex or xelatex).

  2. You could use \usepackage[danish=quotes]{csquotes} or similar in your Pandoc LaTeX template. From the README:

    If the --smart option is specified, pandoc will produce typographically correct output, converting straight quotes to curly quotes, --- to em-dashes, -- to en-dashes, and ... to ellipses. Nonbreaking spaces are inserted after certain abbreviations, such as “Mr.”

    Note: if your LaTeX template calls for the csquotes package, pandoc will detect this automatically and use \enquote{...} for quoted text.

Nika answered 27/11, 2015 at 9:6 Comment(1)
To get this to work (turn off smart-mode), I had to use the following argument -f markdown-smart.Tableau
D
1

Even though @mb21 already provided an answer, I would like to add, that nowadays it's possible to simply include what you need in (for example) your yaml metadata block, so it is not necessary anymore to create your own template. Example:

---
title: foo
author: bar
# other stuff
header-includes:
    - \usepackage[german=quotes]{csquotes}
---

# contents
Demilune answered 28/3, 2017 at 16:33 Comment(0)
N
0

For my version of pandoc 3.1.3, the accepted answer does not work. The in my opinion nicer and simpler solution mentioned by @rriemann does work:

Use lang and csquotes: true yaml metadata fields

Example:

---
lang: fr-FR
csquotes: true
---
Natalyanataniel answered 3/6 at 16:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.