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