Search code examples
fontslatexpandoccyrillic

Pandoc `lang` option makes font ugly


I am trying to learn pandoc. I used latex before because I always deal with formulas, code. Here is the simple document I compile to pdf:

---
title: Test
...

# Test!

This is a test of *pandoc*.

- list one
- list two
- $E=mc^2$
- На русском

Горит костер рябины красной.

$$
A = \int\limits_{-\infty}^{\infty} e^{-x^2}dx
$$

```python
class ClassName(object):
    """docstring for ClassName (Кириллица?)"""
    def __init__(self, arg):
        super(ClassName, self).__init__() # English comment
        self.arg = arg # Кириллический комментарий

```

I've tried two different commands to produce pdf:

  1. pandoc test1.md -o test1.pdf
  2. pandoc -V lang=ru-RU -o test1-2.pdf test1.md

The first command failed rendering for cyrillic symbols. Moreover, I always write non-English documents, so I need documents to be generated with captions written in russian. I used lang property to do it as pandoc documentation suggests. Now, cyrillic symbols render correct but if you look at the screenshot a couple of seconds you can see that font looks much uglier than before. Espesially code.

What is going on and how to fix it?

screenshot


Solution

  • I found it difficult to set-up fonts for Latin, Cyrillic, Math and code blocks in a consistent way with the interface offered by pandoc. The best compromise I found was:

    • Set lang equal to en and mark-up Russian parts explicitly.
    • Use XITS fonts for normal text and math
    • Use a fixed width font that covers Cyrillic, e.g. Liberation Mono
    • Process with XeLaTeX or LuaLaTeX

    All combined:

    ---
    title: Test
    mainfont: XITS
    monofont: Liberation Mono
    mathfont: XITS Math
    lang: en
    ---
    
    # Test!
    
    This is a test of *pandoc*.
    
    - list one
    - list two
    - $E=mc^2$
    - [На русском]{.class lang="ru-RU"}
    
    ::::: {.class lang="ru-RU"}
    
    Горит костер рябины красной.
    
    :::::
    
    
    $$
    A = \int\limits_{-\infty}^{\infty} e^{-x^2}dx
    $$
    
    
    ```python
    class ClassName(object):
        """docstring for ClassName (Кириллица?)"""
        def __init__(self, arg):
            super(ClassName, self).__init__() # English comment
            self.arg = arg # Кириллический комментарий
    
    ```
    

    Result of pandoc cyr.md --pdf-engine=lualatex -o cyr.pdf:

    enter image description here