PyX — Example: text/

0.4 KB
34.8 KB
25.2 KB
13.5 KB
24.5 KB

Using the same color in PyX and in LaTeX

from pyx import *
unit.set(uscale=2, xscale=2)

col = color.cmyk.PineGreen

text.preamble(r"\definecolor{COL}{cmyk}{%g,%g,%g,%g}" % (col.c, col.m, col.y, col.k))

c = canvas.canvas()
c.text(0, 0, r"\textcolor{COL}{Text} and outline have the same color")
c.stroke(path.rect(-0.2, -0.2, 6.2, 0.6), [col])


This example shows three different methods how to use a color defined in PyX also in LaTeX. In the example code, we first define a cmyk color col, which is then used to define a color COL in LaTeX. The latter is then used in a LaTeX expression.

The same behavior can be achieved by two different methods in c.text,

r"\textcolor[named]{PineGreen}{Text} and outline ..."
r"\textcolor[pyx]{color.cmyk.PineGreen}{Text} and outline ..."

They are not as elegant as the above shown, since we need to insert the color definition PineGreen explicitly. The first alternative makes use of the named color model of color.sty. All colors of this model are predefined also in PyX. The other alternative allows to use PyX colors directly.

Note that no graphics driver has been used for the color.sty LaTeX package. PyX performs a hack to enforce the use of its own LaTeX driver file pyx.def. In case that you have installed the three files pyx.def, color.cfg, and graphics.cfg from the PyX distribution somewhere in the LaTeX search path, it is possible to use

text.set(mode="latex", pyxgraphics=0)

which is the more aesthetic variant.