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.

Overview for this section


Horizontal alignment

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 boxleft, boxcenter and boxright leading to left, center, and right alignment of the text box with respect to the dotted lines. more ...


Vertical alignment

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 ...


Customize fonts

In LaTeX, there are nice packages allowing to switch fonts. Hence, for a simple example we change the mode of the default textengine instance to LaTeX and use the preamble method to load the times package. more ...


Typesetting non-ASCII characters with TeX

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.


Using markers

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 \PyXMarker more ...


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 textengine instance which controls a single running TeX or LaTeX instance at a time or uses direct Unicode text typesetting. To make life easy to our users more ...


Unicode engine

PyX supports basic text output without using TeX/LaTeX by text.UnicodeEngine instances more ...


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. more ...


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.