some typos corrected
[PyX/mjg.git] / faq / pyxfaq.tex
blobf60ac6d937ac98e4cee2c3743b323ff989d59336
1 \documentclass[11pt,DIV14]{scrartcl}
2 \usepackage[latin1]{inputenc}
3 \usepackage{url}
4 \usepackage{rcs}
5 \usepackage{mathptmx}
6 %\usepackage[all,comments]{glifaq}
7 \usepackage[answered]{glifaq}
8 \usepackage[pdftex]{hyperref}
9 \hypersetup{pdftitle={PyX FAQ}%
10 ,pdfauthor={\textcopyright\ Gert-Ludwig Ingold
11 <gert.ingold@physik.uni-augsburg.de>}%
12 ,colorlinks=true%
13 ,linkcolor=blue}
14 \begin{document}
15 \RCS $Id$
16 \RCS $Revision$
17 \RCS $Date$
19 \begin{center}
20 \LARGE\sffamily Some frequently and\\
21 not so frequently asked questions\\
22 about \PyX\footnote{This version of the FAQ is intended for use with \PyX\
23 version 0.6.1.}\\
24 \par
25 {\small\sffamily (version \RCSRevision\ of \RCSDate)}\\[1truecm]
26 \large
27 Gert-Ludwig Ingold \par
28 \href{mailto:gert.ingold@physik.uni-augsburg.de}{\url{<gert.ingold@physik.uni-augsburg.de>}}
29 \end{center}
30 \toc
32 \vspace{2truecm}
33 \section*{Acknowledgements}
34 The following persons have in one way or the other contributed to the answers
35 given in this FAQ:\\
36 Jörg Lehmann, Michael Schindler, Andr{\'e} Wobst.
37 \newpage
39 \section{General aspects of \PyX}
40 \question{a}{Where do I get the latest version of \PyX?}
42 {The current release of \PyX{} (as well as older ones) is freely available
43 from \url{http://pyx.sourceforge.net} where also a CVS repository with the
44 latest patches can be found. Possibly older versions of \PyX{} are
45 also available as package for
46 various Linux distributions: see, for instance,
47 \url{http://packages.debian.org/testing/python/python-pyx.html} for
48 information on the \PyX{} package in Debian GNU/Linux,
49 \url{http://packages.gentoo.org/ebuilds/?pyx-0.3.1} for a Gentoo Linux
50 ebuild, and
51 \url{http://www.suse.de/en/private/products/suse_linux/i386/packages_professional/python-pyx.html}
52 for the \PyX{} package in the SUSE LINUX professional distribution.
55 \question{c}{How can I determine the version of \PyX{} running on my
56 machine?}
58 {Start a python session (usually by typing \texttt{python} at the system
59 prompt) and then type the following two commands (\texttt{>>>} is the python
60 prompt)
61 \begin{progcode}
62 >>> import pyx\\
63 >>> pyx.\us\us{}version\us\us
64 \end{progcode}
67 \question{c}{Does \PyX{} run under my favorite operating system?}
69 {Yes, if you have installed Python (\uaref{q:what_is_python})
70 and \TeX{} (\uaref{q:what_is_tex}). Both are available for
71 a large variety of operating systems so chances are pretty good that you will
72 get \PyX{} to work on your system.
75 \question{c}{Under which versions of Python will \PyX{} run?}
77 {\PyX{} is supposed to work with Python 2.0 and above. However, most of the
78 development takes place under the current production version of Python (2.3.3
79 by the time of this writing) and thus \PyX{} is better tested with this version. On the other hand, the examples and tests are verified to run with all Python
80 versions 2.x. \PyX{} will not work with Python 1.x due to missing language
81 features.
83 The version of your Python interpreter can be determined by calling
84 it with the option \texttt{-V}. Alternatively, you can simply start the
85 interpreter and take a look at the startup message. Note that there may be
86 different versions of Python installed on your system at the same time. The
87 default Python version need not be the same for all users.
90 \question{a}{Does \PyX{} provide a GUI to view the produced image? \new}
92 {No, \PyX{} itself does not provide a means to view the produced image. The
93 result of a \PyX{} run is an EPS (= Encapsulated PostScript) file which can
94 be viewed, printed or imported into other applications. There are several
95 means of viewing EPS files. A common way would be to use \texttt{ghostview}
96 which provides a user interface to the PostScript interpreter
97 \texttt{ghostscript}. More information about this software, which is
98 available for a variety of platforms, can be found at
99 \url{http://www.cs.wisc.edu/~ghost/}. If you do not own a printer which is
100 capable of printing PostScript files directly, \texttt{ghostscript} may
101 also be useful to translate the EPS file produced by \PyX{} into something
102 your printer will understand.}
104 \question{a}{Where can I get help if my question is not answered in this
105 FAQ? \changed}
107 {The \PyX{} sources contain a reference manual which is also available
108 online at \url{http://pyx.sourceforge.net/manual/}. Furthermore, there
109 exists a set of examples demonstrating various features of \PyX, which is
110 available in the sources or can be browsed at \url{http://pyx.sourceforge.net/examples.html}.
111 If the feature you are looking for is among them, using the appropriate part
112 of the example code or adapting it for your purposes may help.
114 There is also a user discussion list about \PyX{} which you can subscribe to
115 at \url{http://lists.sourceforge.net/lists/listinfo/pyx-user}. The archive of
116 the discussion list is available at \url{http://sourceforge.net/mailarchive/forum.php?forum_id=23700}.
118 Finally, it might be worth checking \url{http://pyx.sourceforge.net/pyxfaq.pdf}
119 for an updated version of this FAQ.
122 \section{Python}
124 \question{c}{What is Python?}
126 {\label{q:what_is_python}
127 From \url{www.python.org}:
128 \begin{quote}
129 Python is an \textit{interpreted, interactive, object-oriented} programming
130 language. It is often compared to Tcl, Perl, Scheme or Java.
132 Python combines remarkable power with very clear syntax. It has modules,
133 classes, exceptions, very high level dynamic data types, and dynamic typing.
134 There are interfaces to many system calls and libraries, as well as to various
135 windowing systems (X11, Motif, Tk, Mac, MFC). New built-in modules are easily
136 written in C or C++. Python is also usable as an extension language for
137 applications that need a programmable interface.
139 The Python implementation is portable: it runs on many brands of UNIX, on
140 Windows, OS/2, Mac, Amiga, and many other platforms. If your favorite system
141 isn't listed here, it may still be supported, if there's a C compiler for it.
142 Ask around on \href{news:comp.lang.python}{news:comp.lang.python} --- or just
143 try compiling Python yourself.
145 The Python implementation is
146 \href{http://www.python.org/doc/Copyright.html}{copyrighted}
147 but \textbf{freely usable and distributable, even for commercial use}.
148 \end{quote}
151 \question{a}{Where can I learn more about Python?}
153 {The place to start is \url{www.python.org} where you will find plenty of
154 information on Python including tutorials.
157 \question{c}{What do I need to import in order to use \PyX? \changed}
158 {checked for 0.6}
159 {It is recommended to begin your Python code with
160 \begin{progcode}
161 from pyx import *
162 \end{progcode}
163 when using \PyX. This allows you for example to write simply
164 \texttt{graph.graphxy}
165 instead of \texttt{pyx.graph.graphxy}. The following modules will be loaded:
166 \texttt{attr}, \texttt{box}, \texttt{canvas}, \texttt{color}, \texttt{connector}, \texttt{data},
167 \texttt{deco}, \texttt{epsfile}, \texttt{graph}, \texttt{path},
168 \texttt{style}, \texttt{trafo}, \texttt{text}, and \texttt{unit}.
170 For convenience, you might import specific objects of a module like in
171 \begin{progcode}
172 from graph import graphxy
173 \end{progcode}
174 which allows you to write \texttt{graphxy()} instead of \texttt{graph.graphxy()}.
176 All code segments in this document assume that the import line mentioned in
177 the first code snippet is present.
180 \question{a}{What is a raw string and why should I know about it when
181 using \PyX?}
182 {checked for 0.6}
183 {\label{q:raw_string}
184 The backslash serves in standard Python strings to start an escape sequence.
185 For example {\cs n} corresponds to a newline character. On the other hand,
186 \TeX{} and \LaTeX{}, which do the typesetting in \PyX, use the backslash to
187 indicate the start of a command. In order to avoid the standard interpretation,
188 the string should be marked as a raw string by prepending it by an \texttt{r}
189 like in
190 \begin{progcode}
191 c.text(0, 0, r"\${\cs alpha}{\cs beta}{\cs gamma}\$")
192 \end{progcode}
195 \section{Plotting of graphs}
197 \subsection{General aspects}
199 \question{c}{How do I generate a graph from data as simply as possible?
200 \changed}
201 {checked for 0.6}
202 {\label{q:mingraphdata}
203 Suppose that you have a data file \texttt{x.dat} containing values for
204 $x$ and $y$ in two columns. Then the following code will do the job
205 \begin{progcode}
206 from pyx import *\\
208 g = graph.graphxy(width=10)\\
209 g.plot(graph.data.file("x.dat", x=1, y=2))\\
210 g.writeEPSfile("x")
211 \end{progcode}
212 \texttt{graphxy} creates a canvas (called \texttt{g} in this example) onto
213 which the graph will be drawn and it sets the default behavior including the
214 axis. There is, however, no default value for the width of the graph. In
215 \texttt{plot} you have to specify the name of the data file and the columns
216 from which the data should be taken. Finally, \texttt{writeEPSfile} will
217 generate the postscript file \texttt{x.eps} which you can view or print.
219 A minimal example is also provided in the \PyX{} distribution as
220 \path{examples/graphs/minimal.py}.
223 \question{a}{How do I generate a graph of a function as simply as possible?
224 \changed}
225 {checked for 0.6}
226 {The following example will draw a parabola:
227 \begin{progcode}
228 from pyx import *\\
230 g = graph.graphxy(width=10,\\
231 ~~~~~~~~~~~~~~~~~~x=graph.axis.linear(min=-2, max=2)\\
232 ~~~~~~~~~~~~~~~~~~)\\
234 g.plot(graph.data.function("y=x**2"))\\
236 g.writeEPSfile("x")
237 \end{progcode}
238 Most of the code has been explained in \uaref{q:mingraphdata}. The main
239 difference is that here you need to specify minimum and maximum for the
240 $x$-axis so that \PyX{} knows in which range to evaluate the function.
242 Another, slightly more complex, example is also provided in the \PyX{}
243 distribution as \path{examples/graphs/piaxis.py}.
246 \question{a}{How can I stack graphs? \changed}
248 {\PyX{} always needs a canvas to draw on. One possibility therefore consists
249 in creating a new canvas with
250 \begin{progcode}
251 c = canvas.canvas()
252 \end{progcode}
253 and inserting the graphs into this canvas with \texttt{c.insert(...)}. Here,
254 \texttt{...} has to be replaced by the name of the graph. Alternatively, the
255 canvas created with \texttt{graph.graphxy} for one of the graphs can be used
256 to insert the other graphs even if they will be positioned outside the
257 first graph.
259 The second issue to address is positioning of the graphs. By specifying
260 \texttt{xpos} and \texttt{ypos} when calling \texttt{graphxy}, you can
261 define the position of a graph. Later on, the position and size of a
262 graph \texttt{g} can be referred to as \texttt{g.xpos}, \texttt{g.ypos},
263 \texttt{g.width}, and \texttt{g.height} even if for example the height has
264 never been specified explicitly but is only defined by a \PyX{} default.
266 The following example shows how to put graph \texttt{gupper} above graph
267 \texttt{glower} on a canvas \texttt{c}:
268 \begin{progcode}
269 from pyx import *\\
270 from graph import graphxy\\
272 c = canvas.canvas()\\
274 glower = graphxy(width=10)\\
275 glower.plot(...)\\
276 c.insert(glower)\\
278 gupper = graphxy(width=10, ypos=glower.ypos+glower.height+2)\\
279 gupper.plot(...)\\
281 c.insert(gupper)\\
282 c.writeEPSfile(...)
283 \end{progcode}
284 where \texttt{...} has to be replaced by the appropriate information like
285 data and symbol specifications and the name of the output file. Here,
286 \texttt{c.insert} is used to actually insert the subcanvasses
287 for the graphs into the main canvas \texttt{c} and \texttt{c.writeEPSfile}
288 in the last line requests to write the contents of this canvas to a file.
290 %In order to suppress the labels of the $x$-axis of the upper graph, use
291 %\begin{progcode}
292 %myaxispainter = graph.axispainter(labelattrs=None)
294 %gupper = graph.graphxy(...,
295 % x=graph.axis.linear(...,
296 % part=graph.linpart(),
297 % painter=myaxispainter)
299 %\end{progcode}
302 \question{a}{How can I plot grid data? \changed}
304 {\PyX{} offers support for plotting three-dimensional data as two-dimensional
305 color plots or grey-scale plots and of vector fields by providing ways to
306 plot rectangles and arrows in graphs.
308 We start by considering the task of creating a two-dimensional color plot by
309 plotting a number of filled rectangles. One first needs to create a data set
310 which consists of five entries per data point. These are the lower left corner
311 $(x_\mathrm{min},y_\mathrm{min})$ and the upper right corner
312 $(x_\mathrm{max},y_\mathrm{max})$ of the triangle and a value between 0 and 1
313 determining the color via a \PyX{} color palette. The following code gives an
314 idea of how to proceed:
315 \begin{progcode}
316 g.plot(graph.data.file("datafile.dat"), xmin=1, xmax=2, ymin=3, ymax=4, color=5),\\
317 ~~~~~~~graph.style.rect(color.palette.ReverseRainbow)\\
318 ~~~~~~)\\
319 g.dodata()
320 \end{progcode}
321 Here, we assume that the data are stored in \texttt{datafile.dat} and the
322 columns contain $x_\mathrm{min}$, $x_\mathrm{max}$, $y_\mathrm{min}$,
323 $y_\mathrm{max}$, and the color value in this order. The columns are
324 numbered from 1, since the 0th column contains the line number. To
325 determine the color, we use the \texttt{ReverseRainbow} palette. The
326 last line instructs \PyX{} to plot the rectangles before plotting the
327 axes. Otherwise, the axes might be covered partially by the rectangles
328 and, in particular, the ticks might not be visible. Gray-scale plots
329 can easily be generated by specifying the palette \texttt{Gray} or
330 \texttt{ReverseGray} (cf.\ appendix C of the manual for a list of
331 predefined palettes).
333 At first sight, it seems surprising that plotting of grid data requires
334 the specification of four coordinates for the rectangle. The reason is that
335 this allows to draw rectangles of varying sizes which may help to reduce the
336 size of the postscript file by combining rectangles of the same color in
337 horizontal or vertical direction. For example, it may be sufficient to plot
338 a grey-scale image in a small number of grey shades and then combining
339 rectangles may be appropriate. Note, though, that this step is part of the
340 data creation and not preformed by \PyX{}. Another advantage of fully
341 specifying each rectangle is that it is straightforward to leave parts of the
342 graph blank.
344 The same ideas as for the color plot can be applied to plot vector fields where
345 each data point is represented by an arrow. In this case a data point is
346 specified by the position of the arrow, its size and its direction as indicated
347 in the following code snippet:
348 \begin{progcode}
349 g.plot(graph.data.file("datafile.dat"), x=1, y=2, size=3, angle=4),\\
350 ~~~~~~~graph.style.arrow()\\
351 ~~~~~~)
352 \end{progcode}
354 Complete code examples can be found in \path{examples/graphs/mandel.py} and
355 \path{examples/graphs/arrows.py}\,.
358 \question{t}{I would like a key for only some of my data sets. How do I do
359 that?}
364 \subsection{Axis properties}
366 \question{a}{How do I specify the tick increment? \changed}
367 {checked for 0.6. Maybe we should add an from pyx.graph import axis}
368 {In the partition of a linear axis, the increments associated with ticks,
369 subticks etc.\ can be specified as argument of \texttt{linpart}. In the
370 following example, ticks will be drawn at even values while subticks will
371 be drawn at all integers:
372 \begin{progcode}
373 tg = graph.graphxy(width=10,\\
374 ~~~~~~~~~~~~~~~~~~~x=graph.axis.linear(min=1, max=10,\\
375 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~parter=graph.axis.parter.linear(tickdist=[2,1]))\\
376 ~~~~~~~~~~~~~~~~~~~)
377 \end{progcode}
381 \question{a}{How do I plot the zero line? \new}
382 {new for 0.6 since zeropathattrs was removed}
384 \tolerance=5000
385 Previous releases of \PyX{} offered the possibility to stroke a zero
386 line for a given axis by specifying \texttt{zeropathattrs} in the painter
387 constructor. This feature was removed in \PyX{} 0.6, but you can easily
388 draw a zero line by your own. In order to do so you first have to fix the
389 layout information of the graph (see first line of the code given below).
390 Then you can use, for instance, the \texttt{ygridpath} method of a graph
391 which returns a grid path at the given axis value. The so obtained path
392 can easily be stroked on the graph canvas:
393 \begin{progcode}
394 g.finish()\\
395 g.stroke(g.ygridpath(0))
396 \end{progcode}
400 \subsection{Data properties}
402 \question{a}{How do I choose the symbol? \changed}
403 {checked for 0.6}
404 {\label{q:choose_symbol}
405 Suppose a graph called \texttt{g} has been initialized, e.g. by using
406 \texttt{graph.graphxy}. Then, data and the style of their representation
407 in the graph are defined by calling \texttt{g.plot} like in the following
408 example in which filled circles are requested:
409 \begin{progcode}
410 g.plot(graph.data.file("test.dat"),\\
411 ~~~~~~~graph.style.symbol(graph.style.symbol.circle, symbolattrs=[deco.filled])\\
412 ~~~~~~~)
413 \end{progcode}
416 \question{a}{How do I choose the color of the symbols? \changed}
417 {checked for 0.6}
418 {Colors are not properties of the symbol as such and can therefore not
419 be specified in \texttt{symbolattrs} directly. The color is rather related
420 to the plotting of the symbol as defined by \texttt{deco.stroked} or
421 \texttt{deco.filled}. With
422 \begin{progcode}
423 graph.style.symbol(graph.style.symbol.circle,\\
424 ~~~~~~~~~~~~~~~~~~~symbolattrs=[deco.stroked([color.rgb.red]),\\
425 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~deco.filled([color.rgb.green])]\\
426 ~~~~~~~~~~~~~~~~~~~)
427 \end{progcode}
428 you will obtain a circle filled in green with a red borderline.
431 \question{a}{How do I choose the line style? \changed}
432 {checked for 0.6}
433 {If you do not want to use symbols, you can set the line style as in this
434 example
435 \begin{progcode}
436 g.plot(graph.data.file("test.dat"),\\
437 ~~~~~~~graph.style.line([style.linewidth.Thin])\\
438 ~~~~~~~)
439 \end{progcode}
440 where the linewidth is set.
442 If you also want to use symbols, you can set the line attributes together
443 with the symbols. Extending the example in \ref{q:choose_symbol},
444 you could use
445 \begin{progcode}
446 g.plot(graph.data.file("test.dat"),\\
447 ~~~~~~~graph.style.symbolline(graph.style.symbolline.circle,\\
448 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~symbolattrs=[deco.filled],\\
449 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~lineattrs=[style.linewidth.Thin, style.linestyle.dashed]\\
450 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~)\\
451 ~~~~~~~)
452 \end{progcode}
453 to set the linewidth and to choose dashed lines.
456 \section{\TeX{} and \LaTeX{}}
458 \subsection{General aspects}
460 \question{a}{What is \TeX/\LaTeX{} and why do I need it?}
462 {\label{q:what_is_tex}
463 \TeX{} is a high quality typesetting system developed by Donald E. Knuth
464 which is available for a wide variety of operating systems. \LaTeX{} is a
465 macro package originally developed by Leslie Lamport which makes life with
466 \TeX{} easier, in particular for complex typesetting tasks. The current
467 version of \LaTeX{} is referred to as \LaTeXe{} and offers e.g.\ improved
468 font selection as compared to the older \LaTeX{} 2.09 which should no longer
469 be used.
471 All typesetting tasks in \PyX{} are finally handed over to \TeX{} (which is the
472 default) or \LaTeX{}, so that \PyX{} cannot do without it. On the other hand,
473 the capabilities of \TeX{} and \LaTeX{} can be used for complex tasks where
474 both graphics and typesetting are needed.
477 \question{a}{I don't know anything about \TeX{} and \LaTeX{}. Where can I read
478 something about it?}
480 {\label{q:intro_tex_latex}
481 Take a look at CTAN (\uaref{q:ctan}) where in \ctan{info}
482 you may be able to find some useful information. There exists for example
483 ``A Gentle Introduction to \TeX'' by M.~Doob (\ctan{gentle/gentle.pdf}) and
484 ``The Not So Short Introduction to \LaTeXe''
485 (\ctan{info/lshort/english/lshort.pdf}) by T.~Oetiker et al. The latter has
486 been translated into a variety of languages among them korean (which you will
487 not be able to read unless you have appropriate fonts installed) and mongolian.
489 Of course, it is likely that these documents will go way beyond what you
490 will need for generating graphics with \PyX{} so you don't have to read all
491 of it (unless you want to use \TeX{} or \LaTeX{} for typesetting which can be
492 highly recommended).
494 There exists also a number of FAQs on \TeX{} at \ctan{help}.
497 \question{a}{What is CTAN?}
499 {\label{q:ctan}
500 CTAN is the Comprehensive TeX Archive Network where you will find almost
501 everything related to \TeX{} and friends. The main CTAN servers are
502 \url{tug.ctan.org}, \url{dante.ctan.org}, and \url{cam.ctan.org}. A list of
503 FTP mirrors can be found at \ctan{CTAN.sites}.
505 In this FAQ, \texttt{CTAN:} refers to the root of an anonymous ftp CTAN tree,
506 e.g. \url{ftp://ctan.tug.org/tex-archive/},
507 \url{ftp://ftp.dante.de/tex-archive/},
508 and \url{ftp://ftp.tex.ac.uk/tex-archive/}. The links to CTAN in this document
509 point to one of these servers but you might consider using a FTP mirror closer
510 to you in order to reduce traffic load.
513 \question{a}{Is there support for Con\TeX{}t?}
515 {No, and as far as I know there no plans to provide it in the near future.
516 Given the close ties between Con\TeX{}t and Meta\-Post, Con\TeX{}t users
517 probably prefer to stick with the latter anyway.
520 \subsection{\TeX{} and \LaTeX{} commands useful for \PyX}
522 \question{a}{How do I get a specific symbol with \TeX{} or \LaTeX?}
524 {A list of mathematical symbols together with the appropriate command name
525 can be found at \ctan{info/symbols/math/symbols.ps}. A comprehensive list
526 containing more than 2500 symbols for use with \LaTeX{} can be obtained from
527 \ctan{info/symbols/comprehensive/symbols-a4.pdf}. In some cases it might be
528 necessary to install fonts or packages available from CTAN
529 (\uaref{q:ctan}).
532 \subsection{\TeX{} and \LaTeX{} errors}
534 \question{a}{Undefined control sequence \cs{usepackage}}
536 {\label{q:undefined_usepackage}
537 The command \cs usepackage is specific to \LaTeX{}. Since by default \PyX{}
538 uses \TeX{}, you have to specify the correct mode:
539 \begin{progcode}
540 text.set(mode="latex")
541 \end{progcode}
544 \question{a}{Undefined control sequence \cs{frac}}
546 {\label{q:undefined_frac}
547 The command \cs frac is only available in \LaTeX{}. In \TeX{} you should
548 use \texttt{\cb{a\cs over b}} in math mode to produce ${a\over b}$. As an
549 alternative you may ask for the \LaTeX{} mode as explained in
550 \ref{q:undefined_usepackage}.
553 \question{a}{Missing \$ inserted}
555 {You have specified \TeX- or \LaTeX-code which is only valid in math mode.
556 Typical examples are greek symbols, sub- and superscripts or fractions.
558 On the \PyX{} level, you can specify math mode for the whole string by using
559 \texttt{text.mathmode} as in
560 \begin{progcode}
561 c.text(0, 0, r"{\cs alpha}", text.mathmode)
562 \end{progcode}
563 Keep also in mind that the standard Python interpretation of the backslash as
564 introducing escape sequences needs to be prevented
565 \uaref{q:raw_string}.
567 On the \TeX/\LaTeX{} level you should enclose the commands requiring math
568 mode in \$'s. As an example, \texttt{\$\cs alpha\us i\hat j\$} will produce
569 $\alpha_i^j$. This allows you to specify math mode also for substrings. There
570 exist other ways to specify math mode in \TeX{} and \LaTeX{} which are
571 particularly useful for more complex typesetting tasks. To learn more about
572 it, you should consult the documentation
573 \uaref{q:intro_tex_latex}.
576 \question{a}{Font shape `OT1/xyz/m/n' undefined}
578 {\label{q:fontshape_undefined}
579 You have asked to use font \texttt{xyz} which is not available. Make sure that
580 you have this font available in Type1 format, i.e.\ there should be a
581 file \texttt{xyz.pfb} somewhere. If your \TeX{} system is TDS compliant
582 (TDS=\TeX{} directory structure, cf.\ \ctan{tds/draft-standard/tds/tds.pdf})
583 you should take a look at the subdirectories of
584 \path{TEXMF/fonts/type1}.
587 \question{a}{File \dots\ is not available or not readable}
589 {\label{q:no_lfs}
590 Such an error message might already occur when running the example file
591 \texttt{hello.py} included in the \PyX{} distribution. Usually, the error
592 occurs due to an overly restrictive umask setting applied when unpacking the
593 \texttt{tar.gz} sources. This may render the file mentioned in the error
594 message unreadable because the python distutil installation package doesn't
595 change the file permissions back to readable for everyone.
597 If the file exists, the problem can be solved by changing the permissions to
598 allow read access.}
600 \question{a}{No information for font `cmr10' found in font mapping file}
602 {\label{q:no_cmr10}
603 Such an error message can already be encountered by simply running the example
604 file \texttt{hello.py} included in the \PyX{} distribution. The likely reason
605 is that the \TeX{} system does not find the cmr fonts in Type1 format.
606 \PyX{} depends on these fonts as it does not work with the traditional
607 pk fonts which are stored as bitmaps.
609 Therefore, the first thing to make sure is that the cmr Type1 fonts are
610 installed. In some \TeX{} installations, the command \texttt{kpsewhich
611 cmr10.pfb} will return the appropriate path if the cmr fonts exist in the
612 binary Type1 format (extension \texttt{pfb}) required by \PyX. If the command
613 does not work but the TeX{} system is TDS compliant
614 (\uaref{q:fontshape_undefined}), a look should be taken at
615 \path{TEXMF/fonts/type1/bluesky/cm} where \texttt{TEXMF} is the root of the
616 \texttt{texmf} tree.
618 If the Type1 fonts do not exist on the system, they may be obtained from
619 the CTAN \uaref{q:ctan} at \ctan{fonts/cm/ps-type1/bluesky}. See the
620 \texttt{README} for information about who produced these fonts and why they
621 are freely available.
623 If the Type1 fonts exist, the next step is to take a look at
624 \texttt{psfonts.map}. There may be several files with this name on the system,
625 so it is important to find out which one TeX is actually using.
626 \texttt{kpsewhich psfonts.map} might give this information.
628 The most likely problem is that this file does not contain a line telling TeX
629 what to do if it encounters a request for font \texttt{cmr10}, i.e. the
630 following line
631 may be missing
632 \begin{progcode}
633 ~~~cmr10~~~~~~~~~~~CMR10~~~~~~~~~~~<cmr10.pfb
634 \end{progcode}
635 It is probable that the required lines (in practice, you do not just need
636 \texttt{cmr10}) are found in a file named \texttt{psfonts.cmz} which resides in
637 \path{TEXMF/dvips/bluesky}.
639 One solution is to instruct \PyX{} to read additional map files like
640 \texttt{psfonts.cmz} or \texttt{psfonts.amz}. This can be achieved by modifying
641 the appropriate \texttt{pyxrc} file which is either the systemwide
642 \texttt{/etc/pyxrc} or \texttt{.pyxrc} in the user's home directory. Here, the
643 names of the map files to be read by \PyX{} should be appended separated by
644 whitespaces like in the following example:
645 \begin{progcode}
646 fontmaps = psfonts.map psfonts.cmz psfonts.amz
647 \end{progcode}
648 The same effect can be achieved by inserting the following line into the
649 \PyX{} code:
650 \begin{progcode}
651 text.set(fontmaps="psfonts.cmz psfonts.amz")
652 \end{progcode}
654 An alternative approach consists in modifying the \TeX{} installation by
655 inserting the contents of the desired map files like \texttt{psfonts.cmz} into
656 \texttt{psfonts.map}. Probably, \texttt{psfonts.map} recommends not to do this
657 by hand. In this case the instructions given in the file should be followed.
658 Otherwise, \texttt{psfonts.cmz} should be copied into \texttt{psfonts.map} while
659 keeping a backup of the old \texttt{psfonts.map} just in case. After these
660 changes, \PyX{} most likely will be happy. When inserting \texttt{psfonts.cmz}
661 into \texttt{psfonts.map} it may be a good idea to include \texttt{psfonts.amz}
662 as well. \texttt{psfonts.amz} contains information about some more fonts which
663 might be needed at some point. Making these changes ot \texttt{psfonts.map}
664 will imply that the \TeX{} system will use the cmr fonts in Type1 format
665 instead of pk format which is actually not a bad thing, in particular if
666 \texttt{latex}~/ \texttt{dvips}~/ \texttt{ps2pdf} is used to generate PDF
667 output. With fonts in pk format this will look ugly and using Type1 fonts
668 solves this problem as well. When \texttt{pdflatex} is used to create PDF files,
669 Type1 fonts will be used anyway.
672 \subsection{Fonts}
674 \question{t}{I have Type1 fonts in \texttt{pfa} format. How do I obtain the
675 corresponding \texttt{pfb} files needed by \PyX?}
680 \question{a}{I want to use a font other than computer modern roman}
682 {\label{q:other_font}
683 As long as you have a font in Type1 format available, this should be no
684 problem (even though it may cost you some time to set up things properly).
686 In the simplest case, your \LaTeX{} system contains everything needed.
687 Including the following line into your code will probably work
688 \begin{progcode}
689 text.set(mode="latex")\\
690 text.preamble(r"\cs{usepackage}\cb{mathptmx}")
691 \end{progcode}
692 and give you Times as roman font.
694 If you own one of the more common commercial fonts, take a look at
695 \ctan{fonts} and its subdirectories as well as at the web page
696 \url{http://home.vr-web.de/was/fonts.html} of Walter Schmidt. It is not
697 unlikely that somebody has already done most of the work for you and created
698 the files needed for the font to work properly with \LaTeX. But remember:
699 we are talking about commercial fonts here, so do not expect to find the fonts
700 themselves for free.
702 If none of these cases applies, you should spend some time reading
703 manuals about font installation, e.g.\ \ctan{macros/latex/doc/fntguide.pdf}
704 (of course, I do not expect font wizards to read the last few lines).
707 \question{a}{Can I use a TrueType font with \PyX?}
709 {Not directly as \PyX{} only knows how to handle Type1 fonts (although it is
710 possible to get \LaTeX{} to work with TrueType fonts). However, you may use
711 \texttt{ttf2pt1} (from \url{http://ttf2pt1.sourceforge.net}) to convert a
712 TrueType font into a Type1 font which you then install in your \TeX{} system
713 \uaref{q:other_font}. You will loose hinting information
714 in the conversion process but this should not really matter on output devices
715 with not too low resolution.
718 \end{document}