typo
[PyX/mjg.git] / manual / text.tex
blob7ad9d09df2fc14c79e21350b19d3e1b32f0f9af1
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{} attributes}
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 \begin{figure}
116 \centerline{\includegraphics{textvalign}}
117 \caption{valign example}
118 \label{fig:textvalign}
119 \end{figure}
120 \item[Vertical box:] Usually, \TeX/\LaTeX{} expressions are handled in
121 horizontal mode (so-called LR-mode in \TeX/\LaTeX; everything goes
122 into a single line). You may use \verb|parbox(x)|, where \verb|x| is the
123 width of the text, to switch to a multiline mode (so-called vertical
124 mode in \TeX/\LaTeX). The additional keyword parameter \verb|baseline|
125 can be set to \verb|parbox.top| (default), \verb|parbox.middle|,
126 \verb|parbox.bottom| to alter the position of the baseline; see
127 figure~\ref{fig:textvalign} for an example
128 \item[Vertical alignment:] \verb|valign.top|, \verb|valign.middle|,
129 \verb|valign.bottom|, \verb|valign.baseline| (default); 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 \verb|0|),
136 \verb|vshift.topzero=vshift.char(1)| (shifts down by the height of
137 \verb|0|), \verb|vshift.mathaxis| (shifts down by the height of the
138 mathematical axis)
139 \item[Mathmode:] \verb|mathmode| switches to mathmode of \TeX/\LaTeX
140 in displaystyle (\verb|nomathmode| removes this attribute)
141 \item[Font size:] \verb|size.tiny|, \verb|size.scriptsize|,
142 \verb|size.footnotesize|, \verb|size.small|, \verb|size.normalsize|
143 (default), \verb|size.large|, \verb|size.Large|, \verb|size.LARGE|,
144 \verb|size.huge|, \verb|size.Huge|
145 \end{description}
147 \section{Using the graphics-bundle with \LaTeX}
149 The packages in \LaTeX-graphics bundle (color.sty, graphics.sty,
150 graphicx.sty, \ldots) make extensive use of \verb|\special| commands. Here
151 are some notes on this topic. Please install the appropriate driver file
152 \verb|pyx.def|, which defines all the specials, in your \LaTeX-tree and add
153 the content of both files \verb|color.cfg| and \verb|graphics.cfg| to your
154 personal configuration files.\footnote{If you do not know what I am talking about
155 right now -- just ignore this paragraph, but make sure not to set the
156 \texttt{pyxgraphics} keyword to 0.} After you have installed the \verb|.cfg|
157 files please use the \verb|text| module always with the \verb|pyxgraphics|
158 keyword set to 0, this switches off a hack that might be convenient for less
159 experienced \LaTeX-users.\medskip
161 You can then import the packages of the graphics-bundle and related packages
162 (e.g.~rotating, \ldots) with the option~\verb|pyx|, e.g.{}\\
163 \rule{0.1\linewidth}{0sp}\verb|\usepackage[pyx]{color,graphicx}|\\
164 Please note that the option~\verb|pyx| is only available with
165 \verb|pyxgraphics=0| and a properly installed driver file. Otherwise do not
166 use this option, omit it completely or say~\verb|[dvips]|.\medskip
168 When defining colours in \LaTeX\ as one of the colour models \{\verb|gray|,
169 \verb|cmyk|, \verb|rgb|, \verb|RGB|, \verb|hsb|\} then pyx will use the
170 corresponding values (one to four real numbers) for output. When you use one of the
171 \verb|named| colors in \LaTeX\ then pyx will use the corresponding predefined
172 colour (see module \verb|color| and the colour table at the end of the
173 manual).
175 When importing eps-graphics in \LaTeX\ then pyx will rotate, scale and clip
176 your file like you expect it. Note that pyx cannot import other graphics files
177 than eps at the moment.\medskip
179 For reference purpose, the following specials can be handled by the
180 \verb|text| module at the moment:\medskip
182 \begingroup
183 \leftskip3em
184 \parindent-3em
185 \parskip0.5ex
186 \texttt{PyX:color\_begin (model) (spec)}\\
187 starts a colour. (model)~is one of
188 \{\verb|gray|, \verb|cmyk|, \verb|rgb|, \verb|hsb|, \verb|texnamed|\}.
189 (spec)~depends on the model: a name or some numbers.\par
190 \texttt{PyX:color\_end} ends a colour.\par
191 \texttt{PyX:epsinclude file= llx= lly= urx= ury= width= height= clip=0/1}\\
192 includes an eps-file. The values of llx to ury are in the files' coordinate
193 system and specify the part of the graphics that should become the specified
194 width and height in the outcome. The graphics may be clipped. The last three
195 parameters are optional.\par
196 \texttt{PyX:scale\_begin (x) (y)}\\
197 begins scaling from the current point.\par
198 \texttt{PyX:scale\_end} ends scaling.\par
199 \texttt{PyX:rotate\_begin (angle)} begins rotation around the current
200 point.\par
201 \texttt{PyX:rotate\_end} ends rotation.\par
202 \endgroup
205 \section{\TeX/\LaTeX{} message parsers}
207 Message parsers are used to scan the output of \TeX/\LaTeX. The output
208 is analysed by a sequence of message parsers. Each of them analyses
209 the output and remove those parts of the output, it feels responsible
210 for. If there is nothing left in the end, the message got validated,
211 otherwise an exception is raised reporting the problem.
213 \medskip
214 \begin{tabular}{ll}
215 parser name&purpose\\
216 \hline
217 \texttt{texmessage.load}&loading of files (accept \texttt{(file ...)})\\
218 \texttt{texmessage.loadfd}&loading of files (accept \texttt{(file.fd)})\\
219 \texttt{texmessage.graphicsload}&loading of graphic files (accept \texttt{<file.eps>})\\
220 \texttt{texmessage.ignore}&accept everything as a valid output\\
221 \end{tabular}
222 \medskip
224 More specialised message parsers should become available as required.
225 Please feal free to contribute (e.g. with ideas/problems; code is
226 desired as well, of course). There are further message parsers for
227 \PyX{}s internal use, but we skip them here as they are not
228 interesting from the users point of view.
230 \section{The defaulttexrunner instance}
231 The \verb|defaulttexrunner| is an instance of the class
232 \verb|texrunner|, which is automatically created by the \verb|text|
233 module. Additionally, the methods \verb|text|, \verb|preamble|, and
234 \verb|set| are available as module functions accessing the
235 \verb|defaulttexrunner|. This single \verb|texrunner| instance is
236 sufficient in most cases.
238 %%% Local Variables:
239 %%% mode: latex
240 %%% TeX-master: "manual.tex"
241 %%% End: