PyX — Example: text/encoding.py

0.2 KB
15.4 KB
22.0 KB
12.2 KB
9.6 KB

Typesetting non-ASCII characters with TeX

encoding.png
from pyx import *

text.set(text.LatexEngine, texenc='utf-8')
text.preamble(r'\usepackage[utf8]{inputenc}')

c = canvas.canvas()
c.text(0, 0, r'Héllò, wørłd!')
c.writeEPSfile()
c.writePDFfile()
c.writeSVGfile()

Description

TeX can typeset an enormous amount of characters. Historically it uses special TeX commands for individual characters. To directly use Unicode characters instead, the input encoding package of LaTeX can be used. To tell PyX to communicate with LaTeX in a certain character encoding differently from the default ASCII encoding, a texenc argument has to be passed to the text.set method as shown in the example for the UTF-8 encoding.