Hi,

When creating figures to be included in Latex documents I encountered a few
problems. In the end the text rendering just doesn't blend in well, one way
or another. I found that the problems can be fixed by using Xelatex, which
provides full unicode support and is able to use the installed fonts of your
operating system.

I wrote a new backend that uses the "pgf" latex package for drawing
matplotlib figures. It is compatible with pdflatex, xelatex and lualatex.
The pgf pictures can be included in latex documents or can be directly
compiled to PDF by the backend, utilizing the benefits of Xelatex.

The code for the backend and a script creating a test figure is on github:
https://github.com/pwuertz/matplotlib-backend-pgf/

A document that demonstrates the benefits of using pgf/xelatex is also
there:
https://github.com/pwuertz/matplotlib-backend-pgf/raw/master/demo/demo.pdf

Although I think the pgf backend is very useful already and produces figures
in publication quality (an overused expression ;) ), there are still some
loose ends. Basically, everything I need works but I don't have the time
anymore to figure out all the rest. Maybe someone is interested in improving
this backend, possibly making it a real option for the masses? I wrote down
all open questions I had in TODO comments within the code. To summarize
them:

* The default font for the backend is the unicode variant of Computer Modern
(CMU Serif), which might not be present on most users' systems. If you don't
want to install/use it, you can just specify another (see test script). I
could as well check for the fonts specified in the rc parameters but these
just do fit in Latex documents.

* When printing pgf commands, the actual font depends on the latex
environment you are embedding the figure in. Matplotlib only needs a font
for calculating the text positions and for direct PDF output.

* I'm not sure how certain draw methods of the renderer should behave due to
lack of documentation.

* Some text properties like switching font families or making the text
italic/bold are ignored since I did not need them.

* Backends like svg or pdf are able to display the document upon show(). I
don't know how this is achieved without creating a graphical user interface
myself. The other backends don't implement it.

* The method of obtaining the metrics of text elements is pretty cool I
think (XelatexManager), but it breaks easily since there is no way of
defining a timeout for reading the output of a subprocesses that keeps
running during the figure creation process. Right now, if Latex doesn't
understand a text-element the process stalls. An alternative is to run a new
latex process for every single text element or start using threads.

-- 
View this message in context: 
http://old.nabble.com/Pgf-Backend-with-Xelatex-support-tp34072290p34072290.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to