PyX — Examples: Creating text
One of the major features of PyX is to use the TeX typesetting engine to create text. PyX will start a single TeX or LaTeX instance as soon as text needs to be typeset. It passes the texts to this instance and directly reads the typeset information (dvi file) as created by the TeX interpreter. By this seamless and as far as we know unique integration, all advanced features of the TeX typesetting system like its high quality paragraph builder or the highly advanced math mode become available to PyX users.
Example overview for this section
The example shows the result of the different text attributes for horizontal alignment. We first need to emphasize, that PyX distinguishes between the alignment of the text box and the alignment of the material within the text box. The first line in the output shows the effect of the box alignment created by
boxright leading to left, center, and right alignment of the text box with respect to the dotted lines.
The example demonstrates the effect of several text attributes for vertical alignment.
In the first line of the output, the extent of the whole text box is taken into account by various versions of valign. While in this case, the valign attributes are combined with a parbox each, the valign technique also perfectly works for single line text. more ...
In LaTeX, there are nice packages allowing to switch fonts. Hence, for a simple example we change the mode of the default texrunner instance to LaTeX and use the
preamble method to load the
The example shows how to obtain specific coordinates in a (La)TeX text. This allows to mark specific portions of text, setting arrows, braces and many more. A marker can be set with the command
Using the same color in PyX and in LaTeX
This example shows three different methods how to use a color defined in PyX also in LaTeX more ...
Running and controlling TeX
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
Enlarge the surrounding of a textbox
This example introduces the concept of the
textbox, which is a canvas-like structure containing the text and its surrounding path and reference point. We demonstrate how to enlarge the surrounding box a little and use it as a decoration of the path.
Text along path
In order to set text along a given path, you can use the
curvedtext() decorator. The example shows a few useful parameter settings for this decorator.
To output just the curved text, but not the path, you can use the draw method of the canvas instead of the stroke method. By that the path is omitted in the output completely. In contrast, if you set the linewidth to zero instead, the path will still be visible, as those lines will be rendered as the thinnest available linewidth on the output device according to the PostScript and PDF specification.