3

I'm trying to get pandoc (which converts Markdown to PDF using LaTeX) to produce PDFs which respect French typesetting rules concerning non-breakable spaces.

The suggestions here do not seem to work, e.g. pandoc test.md -V lang:fr-FR -o test.pdf or pandoc test.md -M lang:fr-FR -o test.pdf.

What am I missing? I'm using pandoc 2.7.3 on Ubuntu 16.04. The goal is to start with a Markdown file text.md such as a;b and to obtain in output a PDF file showing a ;b where the space is non-breakable.

frougon
  • 24,283
  • 1
  • 32
  • 55
  • I really do thing that this question is off-topic and not connected to (La)TeX. On the other hand a\ b creates tilde during conversion to LaTeX or docx. – Wojtek Myszka Aug 21 '19 at 07:34

1 Answers1

6

The default pandoc template for LaTeX output appears to force shorthands=off in the babel options. Indeed, after running pandoc -D latex >default.latex, you should see:

\PassOptionsToPackage{unicode=true}{hyperref} % options for packages loaded elsewhere

(...)

$if(lang)$
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[shorthands=off,$for(babel-otherlangs)$$babel-otherlangs$,$endfor$main=$babel-lang$]{babel}
$if(babel-newcommands)$
  $babel-newcommands$
$endif$
\else

(...)

\end{document}

This shorthands=off option kills the feature you want. You can fix this the following way:

  1. Get the default LaTeX template in a file called mytemplate.latex:

    pandoc -D latex >mytemplate.latex
    
  2. In mytemplate.latex, use your favorite text editor to remove the shorthands=off option passed to babel.

  3. Compile with:

    pandoc -f markdown -t latex -M lang:fr-FR --template=mytemplate -o test.pdf test.md
    

This should work if mytemplate.latex is either in the current directory or in ~/.pandoc/templates.

frougon
  • 24,283
  • 1
  • 32
  • 55
  • Wonderful, thank you very much! – user3078439 Aug 21 '19 at 08:38
  • I ran into problems with --listings. I wanted to display inline \:Joueur`` which renders in PDF as Joueur: (not sure why, but the shortcuts are messing it up). I was able to work around this by turning it off around the inline listing by doing \shorthandoff{:}\:Joueur`\shorthandon{:}` inside the markdown. – Fuhrmanator Aug 05 '20 at 17:19