{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n*********************************\nTypesetting With XeLaTeX/LuaLaTeX\n*********************************\n\nHow to typeset text with the ``pgf`` backend in Matplotlib.\n\nUsing the ``pgf`` backend, matplotlib can export figures as pgf drawing commands\nthat can be processed with pdflatex, xelatex or lualatex. XeLaTeX and LuaLaTeX\nhave full unicode support and can use any font that is installed in the operating\nsystem, making use of advanced typographic features of OpenType, AAT and\nGraphite. Pgf pictures created by ``plt.savefig('figure.pgf')`` can be\nembedded as raw commands in LaTeX documents. Figures can also be directly\ncompiled and saved to PDF with ``plt.savefig('figure.pdf')`` by either\nswitching to the backend\n\n.. code-block:: python\n\n matplotlib.use('pgf')\n\nor registering it for handling pdf output\n\n.. code-block:: python\n\n from matplotlib.backends.backend_pgf import FigureCanvasPgf\n matplotlib.backend_bases.register_backend('pdf', FigureCanvasPgf)\n\nThe second method allows you to keep using regular interactive backends and to\nsave xelatex, lualatex or pdflatex compiled PDF files from the graphical user interface.\n\nMatplotlib's pgf support requires a recent LaTeX_ installation that includes\nthe TikZ/PGF packages (such as TeXLive_), preferably with XeLaTeX or LuaLaTeX\ninstalled. If either pdftocairo or ghostscript is present on your system,\nfigures can optionally be saved to PNG images as well. The executables\nfor all applications must be located on your :envvar:`PATH`.\n\nRc parameters that control the behavior of the pgf backend:\n\n ================= =====================================================\n Parameter Documentation\n ================= =====================================================\n pgf.preamble Lines to be included in the LaTeX preamble\n pgf.rcfonts Setup fonts from rc params using the fontspec package\n pgf.texsystem Either \"xelatex\" (default), \"lualatex\" or \"pdflatex\"\n ================= =====================================================\n\n
TeX defines a set of special characters, such as::\n\n # $ % & ~ _ ^ \\ { }\n\n Generally, these characters must be escaped correctly. For convenience,\n some characters (_,^,%) are automatically escaped outside of math\n environments.