remove mathtree doc
[PyX/mjg.git] / examples / text / valign.py
blobe2dee0723d653ea50f37720a249b0f9c0e57b2e0
1 # You can vertically align the text using the box boundaries.
2 # But most of the time, you may want to use TeX's baseline for
3 # vertical alignment.
5 # Additionally, you have access to TeX's math axis. This is where
6 # TeX aligns mathematical symbols like plus, minus and equal signs.
7 # We're often use this axis to vertically align text, for example
8 # for labels at the axis ticks of vertical axes.
10 from pyx import *
12 c = canvas.canvas()
13 c.set([style.linestyle.dotted])
15 # apply global TeX setting
16 text.preamble(r"\parindent=0pt")
17 unit.set(xscale=1.5) # enlarge all text (we want to see the details)
18 w = 1.2 * unit.x_cm # an appropriate parbox width for spam & eggs
20 # vertical alignments by margins
21 c.stroke(path.line(0, 6, 12, 6), [style.linewidth.THin])
22 c.text(0, 6, r"spam \& eggs", [text.parbox(w), text.valign.top])
23 c.text(4, 6, r"spam \& eggs", [text.parbox(w), text.valign.middle])
24 c.text(8, 6, r"spam \& eggs", [text.parbox(w), text.valign.bottom])
26 # vertical alignments by baselines
27 c.stroke(path.line(0, 3, 12, 3), [style.linewidth.THin])
28 c.text(0, 3, r"spam \& eggs", [text.parbox(w, baseline=text.parbox.top)])
29 c.text(4, 3, r"spam \& eggs", [text.parbox(w, baseline=text.parbox.middle)])
30 c.text(8, 3, r"spam \& eggs", [text.parbox(w, baseline=text.parbox.bottom)])
32 # vertical shifts
33 c.stroke(path.line(0, 0, 12, 0), [style.linewidth.THin])
34 c.text(0, 0, r"x=0", [text.mathmode, text.vshift.topzero])
35 c.text(3, 0, r"x=0", [text.mathmode, text.vshift.middlezero])
36 c.text(6, 0, r"x=0", [text.mathmode, text.vshift.bottomzero])
37 c.text(9, 0, r"x=0", [text.mathmode, text.vshift.mathaxis])
39 c.writeEPSfile("valign")
40 c.writePDFfile("valign")