.. title: LaTeX vs. Unicode
.. slug: latex-vs-unicode
.. date: 2016-11-13 10:03:52 UTC
.. tags: latex, presentations
.. category: 
.. link: 
.. description: 
.. type: text

I'm using `matplotlib to create figures for my publications <http://pdes-net.org/cobra/posts/toolchain.html>`_. For axes labels, legends, and everything else requiring text and symbols in a figure, I've so far used the excellent LaTeX support of matplotlib, and the results are (obviously) highly satisfactory:

|

.. image:: ../images/plot_tex.svg 
   :width: 600

|

There's a disadvantage, though: there are not too many fonts to chose from. Naively, I thought that this limitation would be lifted if I wouldn't use LaTeX, but Unicode instead:

|

.. image:: ../images/plot_uc.svg 
   :width: 600

|

And wouldn't XeLaTeX even combine the advantages of both?

|

.. image:: ../images/plot_xetex.svg 
   :width: 600

|

As you can see, matplotlib allows you to use any of these options, but what you don't see is that the desired results can be achieved only with a very limited set of fonts. For example, there are only a few fonts that include the unicode character for a 'superscript minus' (for an overview, see `here <http://www.fileformat.info/info/unicode/char/207b/fontsupport.htm>`_). Sadly, most of these are part of the `ClearType Font Collection, <https://www.microsoft.com/typography/ClearTypeFonts.mspx>`_ which was introduced by Microsoft with Windows Vista. Free fonts with a 'superscript minus' include Dejavu Sans, Free Sans, and Free Serif. If the 'superscript minus' is included instead as a command by employing the internal LaTeX support of matplotlib, many more fonts become accessible. Examples are shown in the table below. But even then one can't make any assumptions: while Source Sans Pro works fine, Source Serif Pro doesn't. I have no idea why.

You see from my last statement that this post in not in the least authoritative. I'm just toddling around, and if you find a better way, I'd appreciate corrections and additions. That's particularly true for the case of XeLaTeX, the use of which seems to require OTF-only fonts with math table support. I wasn't even able to find a single Sans Serif font with this profile 😞 . Others have `similar <http://tex.stackexchange.com/questions/96024/how-to-use-system-font-for-equation-in-xelatex>`_ `problems <http://tex.stackexchange.com/questions/118244/what-is-the-difference-between-unicode-math-and-mathspec>`_. 
  
+-----------+--------------------+----------------------------+
| Renderer  | Serif              | Sans Serif                 |
+===========+====================+============================+
| LaTeX     | Palatino, Fourier  | Kurier, CM Bright          |
+-----------+--------------------+----------------------------+
| Unicode   | Noto, Gentium Plus | Open Sans, Source Sans Pro |
+-----------+--------------------+----------------------------+
| XeLaTeX   | Libertinus, XITS   | ?                          |
+-----------+--------------------+----------------------------+

Finally, `here's an archive <http://pdes-net.org/scripts/plot.tar.xz>`_ containing the three scripts I've used to create the figures above. In each case, I let matplotlib render a pdf, convert that into an svg by pdftocairo, and compress this svg files by gzip:

::

    ./plot_uc.py
    pdftocairo -svg plot_uc.pdf plot_uc.svg
    gzip -S z plot_uc.svg

The results are compressed scalable vector graphics that are fully compatible with inkscape if a post-processing should be necessary. That's how I got the `unicode logo <https://en.wikipedia.org/wiki/File:Unicode_logo.svg>`_ in, by the way. 😉
