# Getting Hebrew Support Working with Pandoc

Does anyone know why pandoc, with the xelatex engine might not generate hebrew characters while directly calling xelatex does?

That is, I have a simple .tex file with some hebrew in it.

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\setmainfont{Times New Roman}
\newfontfamily{\hebrewfont}{New Peninim MT}
\begin{document}
\title{שלום עולם}
\author{שלום עולם}
\maketitle

שלום עולם

\end{document}


If I feed this to xelatex

$xelatex simple.tex  I get a PDF file will hebrew characters. Yay! However, if I feed the same document to pandoc, specifying the --latex-engine=xelatex engine. $ pandoc --latex-engine=xelatex simple.tex -o test.pdf


I get a PDF with no rendered hebrew characters. Does anyone know why this happens, and how I might fix it? I assume pandoc is calling xelatex in the background -- is there a way to view which options/arguments/flags its invoking it with, or to clearout those options?

Also -- My ultimate goal is to convert an HTML document with some hebrew characters into a PDF file with pandoc and I run into similar problems when I have a file (simple.html) like

<h1>שלום עולם</h1>


and then attempt to convert it

pandoc --latex-engine=xelatex simple.html -o test.pdf


The above also produces a hebrew-less file.

So, I'm using pandoc to convert to the simple.tex file as a debugging technique, not because I'm actually moving from tex to PDF. I know I can invoke xelatex directly and get this to work, but for complicated reasons I'd like this working with pandoc. I'd also like to understand how pandoc is actually interacting with LaTeX. So bonus points for those sorts of answers :)

Pandoc can work with unicode hebrew text, if the font configuration is right (the readers are omitting font info since they are not represented in pandoc's AST).

1. Configure fonts in pandoc explicitly

So you have to tell pandoc explicitly, which font to use: -V mainfont:"Times New Roman" And if you want to set the text direction to right-to-left you can use: -V dir:rtl

Which yields:

pandoc --latex-engine=xelatex \
-V mainfont:"Times New Roman" \
-V dir:rtl \
simple.tex -o test.pdf


pandoc --latex-engine=xelatex \
-V mainfont:"Times New Roman" \
-V dir:rtl \
simple.html -o test.pdf


2. Add the font configuration to the template:

You need a new file include.tex:

% include.tex
\setmainfont{Times New Roman}
\newfontfamily{\hebrewfont}{New Peninim MT}


also tell pandoc to use hebrew as main language: -V lang:he

Which yields:

pandoc --latex-engine=xelatex \
-V lang:he \
-H include.tex \
simple.tex -o test.pdf


pandoc --latex-engine=xelatex
-V lang:he \
-H include.tex \
simple.html -o test.pdf


Your pandoc command expects a .html file as input*. It is thus normal that is does not work when you use a .tex file as input.

Indeed pandoc principle is the following:

.html-file -->[html-to-latex]--> .tex-file -->[(xe)latex compiling]--> .pdf-file
|___________________________________________________|
pandoc, as a black-box


For example the following html document:

<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<title>My title</title>
<body>
<h1>Lorem</h1>
Ipsum dolor sit amet
</body>
</html>


would be converted into such a tex document (this is a dummy example, just to explain the principle. I'm not sure the -->[html-to-latex]--> would give exactly the same output):

\documentclass{article}
\title{My title}
\begin{document}
\section{Lorem}
Ipsum dolor sit amet
\end{document}


Pandoc might include some packages in the preable (e.g. inputenc, etc.) but it is not smart enough to know that you want some specific package or settings (in your case \setmainlanguage{hebrew}, \setmainfont{Times New Roman}, and \newfontfamily{\hebrewfont}{New Peninim MT}). You should thus check pandoc's documentation to know how to include these settings in the preamble of your document.

* Well, it's a bit over-simplified, as pandoc as a much broader range of application. This simplification is for explanation purpose only.

• Thank you for your attention. However -- Your pandoc command expects a .html file as input -- I'm not sure this is 100% correct. If you look at the pandoc demo page (pandoc.org/demos.html) it seems like pandoc's a program for converting between various text formats. HTML to [Something Else] might be the most common case, but [tex] to [pdf] seems equally valid. Also, at the heart of my questions is how is pandoc and xelatex interact. I get the basic pipeline -- what I'm after is how pandoc is using xelatex, and how customizable it is. – Alan Storm Jun 17 '17 at 16:18
• @AlanStorm You're right: pandoc is basically used to convert a x-file into a y-file (e.g. I use it to transform a .tex file into a .doc one). Your question thus focus on "how to customize the html-to-latex function in pandoc". You can have a look at the documentation (§ Variables for LaTeX) but I'm not sure it's enough to solve your question. It might become a bit out-of-scope for this site, though. – ebosi Jun 17 '17 at 16:25
• @AlanStorm (In my case, I defined a .doc template that is given as parameter when running pandoc. Something similar might be possible with .tex boilerplates, but I don't know how to do it.) – ebosi Jun 17 '17 at 16:26
• Thanks @ebo -- i get that its on the fringes of scope for this site, but as it does involved xelatex I'm hoping it falls inside the ring of acceptable question. Not your job to go above and beyond though, and thank you for your help both today and last night! – Alan Storm Jun 17 '17 at 16:27