make all parts of the manual compile again; parts of the manual are still out of...
[PyX/mjg.git] / manual / text.tex
blob084bb2af4e838e294b51ea9a299d7d8f4926fde3
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 Note that in order that Type1 fonts can be used by \PyX, an
21 appropriate \verb|psfonts.map| containing entries for the used fonts
22 has to be present in your texmf tree.
24 \section{The texrunner}
25 Instances of the class \verb|texrunner| represent a \TeX/\LaTeX{}
26 instance. The keyword arguments of the constructor are listed in the
27 following table:
29 \medskip
30 \begin{tabularx}{\linewidth}{l>{\raggedright\arraybackslash}X}
31 keyword&description\\
32 \hline
33 \texttt{mode}&\texttt{"tex"} (default) or \texttt{"latex"}\\
34 \texttt{lfs}&Specifies a latex font size file to be used with \TeX{} (not in \LaTeX). 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.\\
35 \texttt{docclass}&\LaTeX{} document class; default is \texttt{"article"}\\
36 \texttt{docopt}&specifies options for the document class; default is \texttt{None}\\
37 \texttt{usefiles}$^1$&access to \TeX/\LaTeX{} jobname files; default: \texttt{None}; example: \texttt{("spam.aux", "eggs.log")}\\
38 \texttt{fontmaps}&whitespace separated names of font mapping files; default \texttt{"psfonts.map"}\\
39 \texttt{waitfortex}&wait this number of seconds for a \TeX/\LaTeX{} response; default \texttt{60}\\
40 \texttt{showwaitfortex}&show a message about waiting for \TeX/\LaTeX{} response on \texttt{strerr}; default \texttt{5}\\
41 \texttt{texipc}&use the \texttt{--ipc} option of \TeX/\LaTeX{} for immediate dvi-output access (boolean); check the output of \texttt{tex --help} if this option is available in your \TeX/\LaTeX{} installation; default \texttt{0}\\
42 \texttt{texdebug}&filename to store \TeX/\LaTeX{} commands; default \texttt{None}\\
43 \texttt{dvidebug}&dvi debug messages like \texttt{dvitype} (boolean); default \texttt{0}\\
44 \texttt{errordebug}&verbose level of \TeX/\LaTeX{} error messages; valid values are \texttt{0}, \texttt{1} (default), \texttt{2}\\
45 \texttt{pyxgraphics}&enables the usage of the graphics package without further configuration (boolean); default 1\\
46 \texttt{texmessagestart}$^{1,2}$&parsers for the \TeX/\LaTeX{} start message; default: \texttt{texmessage.start}\\
47 \texttt{texmessagedocclass}$^{1,2}$&parsers for \LaTeX{}s \texttt{\textbackslash{}documentclass} statement; default: \texttt{texmessage.load}\\
48 \texttt{texmessagebegindoc}$^{1,2}$&parsers for \LaTeX{}s \texttt{\textbackslash{}begin\{document\}} statement; default: \texttt{(texmessage.load, texmessage.noaux)}\\
49 \texttt{texmessageend}$^{1,2}$&parsers for \TeX{}s \texttt{\textbackslash{}end}/ \LaTeX{}s \texttt{\textbackslash{}end\{document\}} statement; default: \texttt{texmessage.texend}\\
50 \texttt{texmessagedefaultpreamble}$^{1,2}$&default parsers for preamble statements; default: \texttt{texmessage.load}\\
51 \texttt{texmessagedefaultrun}$^{1,2}$&default parsers for text statements; default: \texttt{(texmessage.loadfd, texmessage.graphicsload)}\\
52 \end{tabularx}
53 \medskip
55 $^1$
56 The parameter might contain None, a single entry or a sequence of entries.
58 $^2$
59 \TeX/\LaTeX{} message parsers are described in more detail below.
61 \medskip
62 The \verb|texrunner| instance provides several methods to be called by
63 the user. First there is a method called \verb|set|. It takes the same
64 kewword arguments as the constructor and its purpose is to provide an
65 access to the \verb|texrunner| settings for a given instance. This is
66 important for the \verb|defaulttextunner|. The \verb|set| method
67 fails, when a modification can't be applied anymore (e.g.
68 \TeX/\LaTeX{} was already started).
70 The \verb|preamble| method can be called before the \verb|text| method
71 only (see below). It takes a \TeX/\LaTeX{} expression and optionally
72 one or several \TeX/\LaTeX{} message parsers. The preamble expressions
73 should be used to perform global settings, but should not create any
74 \TeX/\LaTeX{} dvi output. In \LaTeX, the preamble expressions are
75 inserted before the \verb|\begin{document}| statement. Note, that you
76 can use \verb|\AtBeginDocument{...}| to postpone the direct
77 evaluation.
79 Finally there is a \verb|text| method. The first two parameters are
80 the \verb|x| and \verb|y| position of the output to be generated. The
81 third parameter is a \TeX/\LaTeX{} expression and further parameters
82 are attributes for this command. Those attributes might be
83 \TeX/\LaTeX{} settings as described below, \TeX/\LaTeX{} message
84 parsers as described below as well, \PyX{} transformations, and \PyX{}
85 fill styles (like colors). The \verb|text| method returns a box (see
86 chapter~\ref{module:box}), which can be inserted into a canvas
87 instance by its \verb|insert| method to get the text.
89 The box returned by the \verb|text| method has an additional method
90 \verb|marker|. You can place markers in the \TeX/\LaTeX{} expression
91 by the command \verb|\PyXMarker{<string>}|. When calling the
92 \verb|marker| method with the same \verb|<string>| you can get back the
93 position of the marker later on. Only digits, letters and the \verb|@|
94 symbol are allowed within the string. Strings containing the \verb|@|
95 symbol are not considered for end users like it is done for commands
96 including the \verb|@| symbol in \LaTeX{} as well.
98 Note that for the generation of the PostScript code the \TeX/\LaTeX{}
99 instance must be terminated except when \verb|texipc| is turned on.
100 However, a \TeX/\LaTeX{} instance is started again when the
101 \verb|text| method is called again. A call of the \verb|preamble|
102 method will still fail, but you can explicitly call the \verb|reset|
103 method to allow for new \verb|preamble| settings as well. The
104 \verb|reset| method takes a boolean parameter \verb|reinit| which can
105 be set to run the old preamble settings.
107 \section{\TeX/\LaTeX{} settings}
109 \begin{description}
110 \raggedright
111 \item[Horizontal alignment:] \verb|halign.left| (default),
112 \verb|halign.center|, \verb|halign.right|, \verb|halign(x)| (\verb|x|
113 is a value between \verb|0| and \verb|1| standing for left and right,
114 respectively)
115 \item[Vertical box:] Usually, \TeX/\LaTeX{} expressions are handled in
116 horizontal mode (so-called LR-mode in \TeX/\LaTeX; everything goes
117 into a single line). You may use \verb|parbox(x)|, where \verb|x| is the
118 width of the text, to switch to a multiline mode (so-called vertical
119 mode in \TeX/\LaTeX).
120 \begin{figure}
121 \centerline{\includegraphics{textvalign}}
122 \caption{valign example}
123 \label{fig:textvalign}
124 \end{figure}
125 \item[Vertical alignment:] \verb|valign.top|, \verb|valign.middle|,
126 \verb|valign.bottom|; when no \verb|parbox| is defined, additionally
127 \verb|valign.baseline| (default); when \verb|parbox| is defined,
128 additionally \verb|valign.topbaseline| (default),
129 \verb|valign.middlebaseline|, and \verb|valign.bottombaseline|; see
130 figure~\ref{fig:textvalign} for an example
131 \item[Vertical shift:] \verb|vshift.char(lowerratio, heightstr="0")|
132 (lowers the output by \verb|lowerratio| of the height of
133 \verb|heightstr|), \verb|vshift.bottomzero=vshift.char(0)| (doesn't
134 have an effect), \verb|vshift.middlezero=vshift.char(0.5)| (shifts
135 down by half of the height of a \verb|0|),
136 \verb|vshift.topzero=vshift.char(1)| (shifts down by the height of the a
137 \verb|0|), \verb|vshift.mathaxis| (shifts down by the height of the
138 mathematical axis)
139 \item[Mathmode:] \verb|mathmode| switches the mathmode of \TeX/\LaTeX
140 \item[Font size:] \verb|size.tiny|, \verb|size.scriptsize|,
141 \verb|size.footnotesize|, \verb|size.small|, \verb|size.normalsize|
142 (default), \verb|size.large|, \verb|size.Large|, \verb|size.LARGE|,
143 \verb|size.huge|, \verb|size.Huge|
144 \end{description}
146 \section{Using the graphics-bundle with \LaTeX}
148 The packages in \LaTeX-graphics bundle (color.sty, graphics.sty,
149 graphicx.sty, \ldots) make extensive use of \verb|\special| commands. Here
150 are some notes on this topic. Please install the appropriate driver file
151 \verb|pyx.def|, which defines all the specials, in your \LaTeX-tree and add
152 the content of both files \verb|color.cfg| and \verb|graphics.cfg| to your
153 personal configuration files.\footnote{If you do not know what I am talking about
154 right now -- just ignore this paragraph, but make sure not to set the
155 \texttt{pyxgraphics} keyword to 0.} After you have installed the \verb|.cfg|
156 files please use the \verb|text| module always with the \verb|pyxgraphics|
157 keyword set to 0, this switches off a hack that might be convenient for less
158 experienced \LaTeX-users.\medskip
160 You can then import the packages of the graphics-bundle and related packages
161 (e.g.~rotating, \ldots) with the option~\verb|pyx|, e.g.{}\\
162 \rule{0.1\linewidth}{0sp}\verb|\usepackage[pyx]{color,graphicx}|\\
163 Please note that the option~\verb|pyx| is only available with
164 \verb|pyxgraphics=0| and a properly installed driver file. Otherwise do not
165 use this option, omit it completely or say~\verb|[dvips]|.\medskip
167 When defining colours in \LaTeX\ as one of the colour models \{\verb|gray|,
168 \verb|cmyk|, \verb|rgb|, \verb|RGB|, \verb|hsb|\} then pyx will use the
169 corresponding values (one to four real numbers) for output. When you use one of the
170 \verb|named| colors in \LaTeX\ then pyx will use the corresponding predefined
171 colour (see module \verb|color| and the colour table at the end of the
172 manual).
174 When importing eps-graphics in \LaTeX\ then pyx will rotate, scale and clip
175 your file like you expect it. Note that pyx cannot import other graphics files
176 than eps at the moment.\medskip
178 For reference purpose, the following specials can be handled by the
179 \verb|text| module at the moment:\medskip
181 \begingroup
182 \leftskip3em
183 \parindent-3em
184 \parskip0.5ex
185 \texttt{PyX:color\_begin (model) (spec)}\\
186 starts a colour. (model)~is one of
187 \{\verb|gray|, \verb|cmyk|, \verb|rgb|, \verb|hsb|, \verb|texnamed|\}.
188 (spec)~depends on the model: a name or some numbers.\par
189 \texttt{PyX:color\_end} ends a colour.\par
190 \texttt{PyX:epsinclude file= llx= lly= urx= ury= width= height= clip=0/1}\\
191 includes an eps-file. The values of llx to ury are in the files' coordinate
192 system and specify the part of the graphics that should become the specified
193 width and height in the outcome. The graphics may be clipped. The last three
194 parameters are optional.\par
195 \texttt{PyX:scale\_begin (x) (y)}\\
196 begins scaling from the current point.\par
197 \texttt{PyX:scale\_end} ends scaling.\par
198 \texttt{PyX:rotate\_begin (angle)} begins rotation around the current
199 point.\par
200 \texttt{PyX:rotate\_end} ends rotation.\par
201 \endgroup
204 \section{\TeX/\LaTeX{} message parsers}
206 Message parsers are used to scan the output of \TeX/\LaTeX. The output
207 is analysed by a sequence of message parsers. Each of them analyses
208 the output and remove those parts of the output, it feels responsible
209 for. If there is nothing left in the end, the message got validated,
210 otherwise an exception is raised reporting the problem.
212 \medskip
213 \begin{tabular}{ll}
214 parser name&purpose\\
215 \hline
216 \texttt{texmessage.load}&loading of files (accept \texttt{(file ...)})\\
217 \texttt{texmessage.loadfd}&loading of files (accept \texttt{(file.fd)})\\
218 \texttt{texmessage.graphicsload}&loading of graphic files (accept \texttt{<file.eps>})\\
219 \texttt{texmessage.ignore}&accept everything as a valid output\\
220 \end{tabular}
221 \medskip
223 More specialised message parsers should become available as required.
224 Please feal free to contribute (e.g. with ideas/problems; code is
225 desired as well, of course). There are further message parsers for
226 \PyX{}s internal use, but we skip them here as they are not
227 interesting from the users point of view.
229 \section{The defaulttexrunner instance}
230 The \verb|defaulttexrunner| is an instance of the class
231 \verb|texrunner|, which is automatically created by the \verb|text|
232 module. Additionally, the methods \verb|text|, \verb|preamble|, and
233 \verb|set| are available as module functions accessing the
234 \verb|defaulttexrunner|. This single \verb|texrunner| instance is
235 sufficient in most cases.
237 %%% Local Variables:
238 %%% mode: latex
239 %%% TeX-master: "manual.tex"
240 %%% End: