What I'd like to do is experiment with a TeX renderer, and write it in a good graphics library, which includes font support, so I ended up with Cairo.

Does it make sense to write a typesetting library/program on top of Cairo/Pango? Note I'm not interested in full-blown LaTeX compatibility, just basic math and text (yes, I know that won't cut it in the long run for beatiful documents...).

  • Newer version of XeTeX use Harfbuzz. Let's move this question to tex.se Mar 18, 2014 at 13:16
  • What are you trying to do what LaTeX, pstricks, tikz, metapost can't?
    – Keks Dose
    Mar 18, 2014 at 14:28
  • @keks move typesetting into a nice programming library that can be used in a variety of settings, without the hassle of compiling to e.g. a PNG and displaying that. I mean, really write to the drawing surface directly, and have access to the components that were typeset.
    – rubenvb
    Mar 18, 2014 at 15:43
  • 1
    @martin I'm not so sure this relates to using TeX as opposed to doing what TeX does, in a programming context. ALso, I doubt people here know what Cairo/Pango is.
    – rubenvb
    Mar 18, 2014 at 15:44

2 Answers 2


I wrote the project that cloutiy mentioned, but I am actually currently in the process of moving away from Pango/Cairo, so I thought it might be worth explaining why.

Pango and Cairo worked very well for basic typesetting use; I produced a couple of books using SILE and a Pango/Cairo backend, and they look good. However, there were a number of problems with them which made them unsuitable in the long run.

The most obvious is that Cairo's PDF surface is pretty basic. You can draw pictures and text on a page, which is most of what you need for typesetting, but people want the ability to add PDF outlines links, etc. which means that Cairo is not a general solution.

Another problem is with the shaper that Pango uses on Linux.

A fundamental part of TeX-like typesetting is putting text and glyphs onto boxes, measuring the boxes and calculating how many boxes fit nicely onto a line. Unfortunately, I can only make Pango's basic font shaping engine measure its boxes to the nearest point, which is not accurate enough; if you're laying out whole strings on text it works fine, because Pango/Cairo also handles the inter-glyph kerning, but if you want to put individual glyphs into boxes, then having the box size be inaccurate by about 12% leads to pretty horrible output. (The obvious solution is not to box up individual glyphs but to box up whole words; then the inaccuracy only affects the inter-word spacing. The problem with the obvious solution is that the TeX algorithm inserts discretionary nodes where words can be hyphenated. So you always end up with a few characters in each box, not a whole word.) The CoreText shaper on OS X works fine.

You can get a decent enough result with Pango/Cairo, and it will save a lot of work, but I think if you're aiming for something more general-purpose, it is worth putting in the work to talk to lower-level shaping libraries and PDF libraries.

If you haven't read it, State of Text Rendering is a good document which explains Cairo/Pango/Harfbuzz/etc. and how they all fit together.


Someone is working on implementing TeX formatting algorithm using Pango/Cairo here:

Pango-Cairo Typesetting

I kind of like where this project is headed - it could prove to be much more flexible in terms of what can be done and how easily it can be done by using newer technologies like Pango/Cairo for typesetting, but not building upon inherently limited older technology.

I love ConTeXt, but it also sits on top of TeX. SILE does not sit on top of TeX, but implements TeX's text typesetting algorithm.

  • As the original question is at the very edge of being connected to TeX at all, I doubt, that this answer is a answer to the question at all...
    – user31729
    Aug 3, 2014 at 20:31
  • 3
    @Christian: I asked this on Stackoverflow, it was migrated against my will, and I agree it has little to do with TeX... But this actually is the type of answer I'm looking for: can cairo/pango be used to typeset (a subset of) LaTeX.
    – rubenvb
    Aug 3, 2014 at 21:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .