inserted doku on pyx.def
[PyX/mjg.git] / manual / text.tex
blob033436ba2191ca95c14658757f4e0b02311acd6c
1 \chapter{Module text: \TeX/\LaTeX{} interface}
2 \label{module:text}
4 \section{Basic functionality}
6 The \verb|text| module seamlessly integrates the famous typesetting
7 technique of \TeX/\LaTeX{} into \PyX. The basic procedure is:
8 \begin{itemize}
9 \item start \TeX/\LaTeX{} as soon as text creation is requested
10 \item create boxes containing the requested text on the fly
11 \item immediately analyse the \TeX/\LaTeX{} output for errors etc.
12 \item boxes are written into the dvi output
13 \item box extents are immediately available (they are contained in the
14 \TeX/\LaTeX{} output)
15 \item as soon as PostScript needs to be written, stop \TeX/\LaTeX{},
16 analyse the dvi output and generate the requested PostScript
17 \item use Type1 fonts for the PostScript generation
18 \end{itemize}
20 \section{The texrunner}
21 Instances of the class \verb|texrunner| represent a \TeX/\LaTeX{}
22 instance. The keyword arguments of the constructor are listed in the
23 following table:
25 \medskip
26 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
27 keyword&description\\
28 \hline
29 \texttt{mode}&\texttt{"tex"} (default) or \texttt{"latex"}\\
30 \texttt{lfs}&Specifies a latex font size file to be used with \TeX. Those files (with the suffix \texttt{.lfs}) can be created by \texttt{createlfs.tex}. Possible values are listed when a requested name could not be found.\\
31 \texttt{docclass}&\LaTeX{} document class; default is \texttt{"article"}\\
32 \texttt{docopt}&specifies options for the document class; default is \texttt{None}\\
33 \texttt{usefiles}$^1$&filenames to be as jobname files for \TeX/\LaTeX{}; default: \texttt{None}; example: \texttt{("spam.aux", "eggs.log")}\\
34 \texttt{waitfortex}&wait this number of seconds for a \TeX/\LaTeX{} response; default \texttt{5}\\
35 \texttt{texdebug}&\TeX/\LaTeX{} debug messages (boolean); default \texttt{0}\\
36 \texttt{dvidebug}&dvi debug messages like \texttt{dvitype} (boolean); default \texttt{0}\\
37 \texttt{texmessagestart}$^{1,2}$&parsers for the \TeX/\LaTeX{} start message; default: \texttt{texmessage.start}\\
38 \texttt{texmessagedocclass}$^{1,2}$&parsers for \LaTeX{}s \texttt{\textbackslash{}documentclass} statement; default: \texttt{texmessage.load}\\
39 \texttt{texmessagebegindoc}$^{1,2}$&parsers for \LaTeX{}s \texttt{\textbackslash{}begin\{document\}} statement; default: \texttt{(texmessage.load, texmessage.noaux)}\\
40 \texttt{texmessageend}$^{1,2}$&parsers for \TeX{}s \texttt{\textbackslash{}end}/ \LaTeX{}s \texttt{\textbackslash{}end\{document\}} statement; default: \texttt{texmessage.texend}\\
41 \texttt{texmessagedefaultpreamble}$^{1,2}$&default parsers for preamble statements; default: \texttt{texmessage.load}\\
42 \texttt{texmessagedefaultrun}$^{1,2}$&default parsers for text statements; default: \texttt{None}\\
43 \end{tabularx}
44 \medskip
46 $^1$
47 The parameter might contain None, a single entry or a sequence of entries.
49 $^2$
50 \TeX/\LaTeX{} message parsers are described in more detail below.
52 \medskip
53 The \verb|texrunner| instance provides three methods to be called by
54 the user. The first method is called \verb|set|. It takes the same
55 kewword arguments as the constructor and its purpose is to provide an
56 access to the \verb|texrunner|s settings for a given instance. This is
57 important for the \verb|defaulttextunner|. The \verb|set| method
58 fails, when a modification can't be applied anymore (e.g.
59 \TeX/\LaTeX{} was already started).
61 Secondly there is a \verb|preamble| method, which can be called before
62 the \verb|text| method only (see below). It takes a \TeX/\LaTeX{}
63 expression and optionally one or several \TeX/\LaTeX{} message
64 parsers. The preamble expressions should be used to perform global
65 settings, but should not create any \TeX/\LaTeX{} dvi output. In
66 \LaTeX, the preamble expressions are inserted before the
67 \verb|\begin{document}| statement.
69 Last, but first, there is a \verb|text| method. The first two
70 parameters are the x, y position of the output to be generated. The
71 third parameter is a \TeX/\LaTeX{} expression and further parameters
72 are attributes for this command. Those attributes might be
73 \TeX/\LaTeX{} settings as described below, \TeX/\LaTeX{} message
74 parsers as described below as well, \PyX{} transformations, and \PyX{}
75 fill styles (like colors). The \verb|text| method returns a box (see
76 chapter~\ref{module:box}), which can be inserted into a canvas
77 instance by its \verb|insert| method to get the text.
79 \section{\TeX/\LaTeX{} settings}
81 \begin{description}
82 \raggedright
83 \item[Horizontal alignment:] \verb|halign.left| (default),
84 \verb|halign.center|, \verb|halign.right|, \verb|halign(x)| (\verb|x|
85 is a value between \verb|0| and \verb|1| standing for left and right,
86 respectively)
87 \item[Vertical box:] Usually, \TeX/\LaTeX{} expressions are handled in
88 horizontal mode (so-called LR-mode in \TeX/\LaTeX; everything goes
89 into a single line). You may use \verb|parbox(x)|, where \verb|x| is the
90 width of the text, to switch to a multiline mode (so-called vertical
91 mode in \TeX/\LaTeX).
92 \begin{figure}
93 \centerline{\includegraphics{textvalign}}
94 \caption{valign example}
95 \label{fig:textvalign}
96 \end{figure}
97 \item[Vertical alignment:] \verb|valign.top|, \verb|valign.middle|,
98 \verb|valign.bottom|; when no \verb|parbox| is defined, additionally
99 \verb|valign.baseline| (default); when \verb|parbox| is defined,
100 additionally \verb|valign.topbaseline| (default),
101 \verb|valign.middlebaseline|, and \verb|valign.bottombaseline|; see
102 figure~\ref{fig:textvalign} for an example
103 \item[Vertical shift:] \verb|vshift.char(lowerratio, heightstr="0")|
104 (lowers the output by \verb|lowerratio| of the height of
105 \verb|heightstr|), \verb|vshift.bottomzero=vshift.char(0)| (doesn't
106 have an effect), \verb|vshift.middlezero=vshift.char(0.5)| (shifts
107 down by half of the height of a \verb|0|),
108 \verb|vshift.topzero=vshift.char(1)| (shifts down by the height of the a
109 \verb|0|), \verb|vshift.mathaxis| (shifts down by the height of the
110 mathematical axis)
111 \item[Mathmode:] \verb|mathmode| switches the mathmode of \TeX/\LaTeX
112 \item[Font size:] \verb|size.tiny|, \verb|size.scriptsize|,
113 \verb|size.footnotesize|, \verb|size.small|, \verb|size.normalsize|
114 (default), \verb|size.large|, \verb|size.Large|, \verb|size.LARGE|,
115 \verb|size.huge|, \verb|size.Huge|
116 \end{description}
118 \section{Using the graphics-bundle with \LaTeX}
120 The packages in \LaTeX-graphics bundle (color.sty, graphics.sty,
121 graphicx.sty, \ldots) make extensive use of \verb|\special| commands here
122 are some notes on this topic. Please install the appropriate driver file
123 \verb|pyx.def|, which defines all the specials, in your \LaTeX-tree and add
124 the content of both files \verb|color.cfg| and \verb|graphics.cfg| to your
125 personal configuration files.\footnote{If you do not know what I am talking about
126 right now -- just ignore this paragraph, but make sure not to set the
127 \texttt{pyxgraphics} keyword to 0.} After you have installed the \verb|.cfg|
128 files please use the \verb|text| module always with the \verb|pyxgraphics|
129 keyword set to 0, this switches off a hack that might be convenient for less
130 experienced \LaTeX-users.\medskip
132 You can then import the packages of the graphics-bundle and related packages
133 (e.g.~rotating, \ldots) with the option~\verb|pyx|, e.g.{}\\
134 \rule{0.1\linewidth}{0sp}\verb|\usepackage[pyx]{color,graphicx}|\\
135 Please note that the option~\verb|pyx| is only available with
136 \verb|pyxgraphics=0| and a properly installed driver file. Otherwise do not
137 use this option, omit it completely or say~\verb|[dvips]|.\medskip
139 When defining colours in \LaTeX as one of \{\verb|gray|, \verb|cmyk|,
140 \verb|rgb|, \verb|RGB|, \verb|hsb|\} then pyx will use the corresponding
141 values (one to four reals) for output. When you use one of the \verb|named|
142 colors in \LaTeX then pyx will use the corresponding predefined colour (see
143 module \verb|color| and the colour table at the end of the manual).
145 When importing eps-graphics in \LaTeX then pyx will rotate, scale and clip
146 your file like you expect it. Note that pyx cannot import other than eps-files
147 at the moment.\medskip
149 In total, the following specials can be handled by the \verb|text| module at
150 the moment:\medskip
152 \begingroup
153 \leftskip3em
154 \parindent-3em
155 \parskip0.5ex
156 \texttt{PyX:color\_begin (model) (spec)}\\
157 starts a colour. (model)~is one of
158 \{\verb|gray|, \verb|cmyk|, \verb|rgb|, \verb|hsb|, \verb|texnamed|\}.
159 (spec)~depends on the model: a name or some numbers.\par
160 \texttt{PyX:color\_end} ends a colour.\par
161 \texttt{PyX:epsinclude file= llx= lly= urx= ury= width= height= clip=0/1}\\
162 includes an eps-file. The values of llx to ury are in the files' coordinate
163 system and specify the part of the graphics that should become the specified
164 width and height in the outcome. The graphics may be clipped. The last three
165 parameters are optional.\par
166 \texttt{PyX:scale\_begin (x) (y)}\\
167 begins scaling from the current point.\par
168 \texttt{PyX:scale\_end} ends scaling.\par
169 \texttt{PyX:rotate\_begin (angle)} begins rotation around the current
170 point.\par
171 \texttt{PyX:rotate\_end} ends rotation.\par
172 \endgroup
175 \section{\TeX/\LaTeX{} message parsers}
177 Message parsers are used to scan the output of \TeX/\LaTeX. The output
178 is analysed by a sequence of message parsers. Each of them analyses
179 the output and remove those parts of the output, it feels responsible
180 for. If there is nothing left in the end, the message got validated,
181 otherwise an exception is raised reporting the problem.
183 \medskip
184 \begin{tabular}{ll}
185 parser name&purpose\\
186 \hline
187 \texttt{texmessage.load}&loading of files (accept \texttt{(file ...)})\\
188 \texttt{texmessage.graphicsload}&loading of graphic files (accept \texttt{<file ...>})\\
189 \texttt{texmessage.ignore}&accept everything as a valid output\\
190 \end{tabular}
191 \medskip
193 More specialised message parsers should become available as required.
194 Please feal free to contribute (e.g. with ideas/problems; code is
195 desired as well, of course). There are further message parsers for
196 \PyX{}s internal use, but we skip them here as they are not
197 interesting from the users point of view.
199 \section{The defaulttexrunner instance}
200 The \verb|defaulttexrunner| is an instance of the class
201 \verb|texrunner|, which is automatically created by the \verb|text|
202 module. Additionally, the methods \verb|text|, \verb|preamble|, and
203 \verb|set| are available as module functions accessing the
204 \verb|defaulttexrunner|. This single \verb|texrunner| instance is
205 sufficient in most cases.