PyX — Example: text/texrunner.py

0.5 KB
4.6 KB
36.7 KB
19.9 KB

Running and controlling TeX

texrunner.png
from pyx import *

# Set properties of the defaulttexrunner, e.g. switch to LaTeX.
text.set(text.LatexRunner)

c = canvas.canvas()
# The canvas, by default, uses the default_runner from the text module.
# This can be changed by the canvas method settexrunner.
c.text(0, 0, r"This is \LaTeX.")

# If you want to use another texrunner temporarily, you can just insert
# a text box manually
plaintex = text.TexRunner() # plain TeX runner
c.insert(plaintex.text(0, -1, r"This is plain \TeX."))

c.writeEPSfile("texrunner")
c.writePDFfile("texrunner")

Description

Usually, all you will ever need is a single texrunner instance which controls a single running TeX or LaTeX instance at a time. To make life easy to our users, such an instance is created automatically upon startup and its called the defaulttexrunner. Whenever you use the function shortcuts like text.text() and in particular text.set(), you are accessing this defaulttexrunner instance. Also, the shortcut method text of any canvas instance uses this defaulttexrunner by default.

However, it is possible to create several texrunner instances. In this example, we are using two of them. To make it a little more interesting, we instruct the defaulttexrunner to use LaTeX, while keeping TeX for the plaintexrunner instance. It is you turn to try expressions valid in TeX or LaTeX only at the different texrunner instances.

Note that you do not have to worry about mixing the results of different texrunners into a single output. Even the embedded fonts in the output are shared. You can, by the way, also restart a texrunner instance including the defaulttexrunner and change its configuration on that occasion.