octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TeX interpreter and rendering in OpenGL based backends


From: Ole Jacob Hagen
Subject: Re: TeX interpreter and rendering in OpenGL based backends
Date: Fri, 26 Aug 2011 20:15:03 +0200

I've asked that matplotlib developers on the design and work flow in their TeX interpreter.
Their replies are added in the bottom of this message.

It this the way to do it?

Ole



The first one is reply from Michael Droettboom at matplotlib:


Hi,

I'm about to implement a TeX interpreter for the graphical backend to GNU Octave (http://www.octave.org). The rendering is in OpenGL context.
As I understand it, matplotlib doesn't use OpenGL at all?
Mike: Not at present -- though various people are working on it.


Could you tell me about the design and work flow for the Tex/Latex interpreter and rendering system for TeX/Latex fonts?

Mike:

There are two.  One is a Python reimplementation of part of the TeX math algorithms called "mathtext" (I am the original author).  It uses Truetype versions of either the Computer Modern fonts or the STIX fonts.  It is able to produce either raster images or data that is then used by the matplotlib backends to generate PS, PDF, SVG etc.

The other approach is used when "text.usetex" is True.  It calls out to a real "tex" interpreter and then interprets the DVI it produces to convert it into a form the matplotlib backends can use.  Since I didn't write this code, I'm not as familiar with the details.

In the case of OpenGL, since you only want images anyway, you may be best off using a tool like dvipng along with the preview LaTeX package, if having "real" LaTeX as a dependency is acceptable.

------------------------------------------------------------------------------------------
Jouni K. Seppänen gave a comment on Mike's reply:

The other approach is used when "text.usetex" is True.  It calls out
> to a real "tex" interpreter and then interprets the DVI it produces to
> convert it into a form the matplotlib backends can use.  Since I
> didn't write this code, I'm not as familiar with the details.

Jouni's comments:

There are actually at least three mechanisms used by text.usetex:

(1) The Postscript backend uses psfrag. The Postscript file has
placeholders for LaTeX text, and the file is processed with LaTeX and
dvips to replace these placeholders with typeset text.

(2) The Agg backend puts each piece of TeX text into a separate file
(which you can find in ~/.matplotlib/tex.cache), processes it with LaTeX
into dvi and with dvipng into png, reads in the png files and overlays
them onto the image. (That's at least what I imagine it does; I have not
looked at the code.)

(3) The pdf backend uses the dviread module (written originally by me).
The various pieces of text are written into different tex files, just as
with the Agg backend, then processed with LaTeX into dvi files, which in
turn are translated by dviread into sequences of (x, y, font, character)
tuples. The dviread module reads the pdftex.map configuration file,
which maps the TeX font names into Postscript fonts, which are embedded
in the output PDF file, and the characters are placed at the coordinates
specified in the dvi file.

The dvipng approach avoids dealing with fonts, but the output is a
bitmap. With psfrag you can only get Postscript output (which is
nontrivial to parse), but it includes scalable fonts. The dviread
approach gets you both scalable fonts and the information of where each
character is, but you will have to deal with the fonts yourself. In PDF
output this is relatively easy, since we can piggyback on the pdftex.map
configuration file, which conveniently points to font files that can be
embedded in PDF.


End of Jouni comments


reply via email to

[Prev in Thread] Current Thread [Next in Thread]