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