add release date
[PyX.git] / faq / pyxfaq.tex
blob63cf24d25a3d9237db74ecd34ff87dc504d5da14
1 % $Id$
2 \documentclass[11pt,DIV14]{scrartcl}
3 \usepackage[latin1]{inputenc}
4 \usepackage{url}
5 \usepackage{mathptmx}
6 \usepackage{tipa}
7 %\usepackage[all,comments]{glifaq}
8 \usepackage[answered]{glifaq}
9 \usepackage[pdftex]{hyperref}
10 \hypersetup{pdftitle={PyX FAQ}%
11 ,pdfauthor={\textcopyright\ Gert-Ludwig Ingold
12 <gert.ingold@physik.uni-augsburg.de>}%
13 ,colorlinks=true%
14 ,linkcolor=blue}
15 \def\pyxversion{\input{pyxversion}}
16 \begin{document}
18 \begin{center}
19 \LARGE\sffamily Some frequently and\\
20 not so frequently asked questions\\
21 about \PyX
22 \par
23 {\small\sffamily (version \pyxversion)}\\[1truecm]
24 \large
25 Gert-Ludwig Ingold \par
26 \href{mailto:gert.ingold@physik.uni-augsburg.de}{\url{<gert.ingold@physik.uni-augsburg.de>}}
27 \end{center}
28 \toc
30 \vspace{2truecm}
31 \section*{Acknowledgements}
32 The following persons have in one way or the other, e.g. by asking good
33 questions or providing answers, contributed to this FAQ:\\
34 Walter Brisken, Jörg Lehmann, Michael Schindler, Andr{\'e} Wobst.
35 \newpage
37 \section{General aspects of \PyX}
38 \question{a}{The name of the game \new}
40 {Originally, the name \PyX{} was constructed as a combination of
41 \textbf{P}ostscript, i.e.\ the first output format supported by \PyX{},
42 P\textbf{y}thon, i.e.\ the language in which \PyX{} is written, and
43 Te\textbf{X}, i.e.\ the program which \PyX{} uses for typesetting purposes.
44 Actually, the title of this question is a tribute to \TeX{} because it is
45 taken from the first chapter of the \TeX{}book\footnote{D.~Knuth, \textit{The
46 \TeX{}book} (Addison-Wesley, 1984)} where the origin of the name \TeX{} and its
47 pronunciation are explained.
49 Despite the ties between \TeX{} and \PyX{}, their pronunciation is quite
50 different. According to the developers of \PyX{}, it should be pronounced as
51 \textipa{[pYks]}. Please do not pronounce it as \textipa{[pYx]} or
52 \textipa{[pY\c c]}.
55 \question{a}{Where do I get the latest version of \PyX?}
57 {The current release of \PyX{} (as well as older ones) is freely available
58 from \url{http://pyx.sourceforge.net} where also a CVS repository with the
59 latest patches can be found. Possibly older versions of \PyX{} are
60 also available as package for
61 various Linux distributions: see, for instance,
62 \url{http://packages.debian.org/testing/python/python-pyx.html} for
63 information on the \PyX{} package in Debian GNU/Linux,
64 \url{http://packages.gentoo.org/ebuilds/?pyx-0.3.1} for a Gentoo Linux
65 ebuild, and
66 \url{http://www.suse.de/en/private/products/suse_linux/i386/packages_professional/python-pyx.html}
67 for the \PyX{} package in the SUSE LINUX professional distribution.
70 \question{c}{How can I determine the version of \PyX{} running on my
71 machine?}
73 {Start a python session (usually by typing \texttt{python} at the system
74 prompt) and then type the following two commands (\texttt{>>>} is the python
75 prompt)
76 \begin{progcode}
77 >>> import pyx\\
78 >>> pyx.\us\us{}version\us\us
79 \end{progcode}
82 \question{c}{Does \PyX{} run under my favorite operating system?}
84 {Yes, if you have installed Python (\uaref{q:what_is_python})
85 and \TeX{} (\uaref{q:what_is_tex}). Both are available for
86 a large variety of operating systems so chances are pretty good that you will
87 get \PyX{} to work on your system.
90 \question{c}{Under which versions of Python will \PyX{} run?}
92 {\PyX{} is supposed to work with Python 2.0 and above. However, most of the
93 development takes place under the current production version of Python (2.3.3
94 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
95 versions 2.x. \PyX{} will not work with Python 1.x due to missing language
96 features.
98 The version of your Python interpreter can be determined by calling
99 it with the option \texttt{-V}. Alternatively, you can simply start the
100 interpreter and take a look at the startup message. Note that there may be
101 different versions of Python installed on your system at the same time. The
102 default Python version need not be the same for all users.
105 \question{a}{Does \PyX{} provide a GUI to view the produced image?}
107 {No, \PyX{} itself does not provide a means to view the produced image. The
108 result of a \PyX{} run is an EPS (= Encapsulated PostScript) file which can
109 be viewed, printed or imported into other applications. There are several
110 means of viewing EPS files. A common way would be to use \texttt{ghostview}
111 which provides a user interface to the PostScript interpreter
112 \texttt{ghostscript}. More information about this software, which is
113 available for a variety of platforms, can be found at
114 \url{http://www.cs.wisc.edu/~ghost/}. If you do not own a printer which is
115 capable of printing PostScript files directly, \texttt{ghostscript} may
116 also be useful to translate the EPS file produced by \PyX{} into something
117 your printer will understand.}
119 \question{a}{Where can I get help if my question is not answered in this
120 FAQ?}
122 {The \PyX{} sources contain a reference manual which is also available
123 online at \url{http://pyx.sourceforge.net/manual/}. Furthermore, there
124 exists a set of examples demonstrating various features of \PyX, which is
125 available in the sources or can be browsed at \url{http://pyx.sourceforge.net/examples.html}.
126 If the feature you are looking for is among them, using the appropriate part
127 of the example code or adapting it for your purposes may help.
129 There is also a user discussion list about \PyX{} which you can subscribe to
130 at \url{http://lists.sourceforge.net/lists/listinfo/pyx-user}. The archive of
131 the discussion list is available at \url{http://sourceforge.net/mailarchive/forum.php?forum_id=23700}.
133 Finally, it might be worth checking \url{http://pyx.sourceforge.net/pyxfaq.pdf}
134 for an updated version of this FAQ.
137 \section{Python}
139 \question{c}{What is Python?}
141 {\label{q:what_is_python}
142 From \url{www.python.org}:
143 \begin{quote}
144 Python is an \textit{interpreted, interactive, object-oriented} programming
145 language. It is often compared to Tcl, Perl, Scheme or Java.
147 Python combines remarkable power with very clear syntax. It has modules,
148 classes, exceptions, very high level dynamic data types, and dynamic typing.
149 There are interfaces to many system calls and libraries, as well as to various
150 windowing systems (X11, Motif, Tk, Mac, MFC). New built-in modules are easily
151 written in C or C++. Python is also usable as an extension language for
152 applications that need a programmable interface.
154 The Python implementation is portable: it runs on many brands of UNIX, on
155 Windows, OS/2, Mac, Amiga, and many other platforms. If your favorite system
156 isn't listed here, it may still be supported, if there's a C compiler for it.
157 Ask around on \href{news:comp.lang.python}{news:comp.lang.python} --- or just
158 try compiling Python yourself.
160 The Python implementation is
161 \href{http://www.python.org/doc/Copyright.html}{copyrighted}
162 but \textbf{freely usable and distributable, even for commercial use}.
163 \end{quote}
166 \question{a}{Where can I learn more about Python?}
168 {The place to start is \url{www.python.org} where you will find plenty of
169 information on Python including tutorials.
172 \question{c}{What do I need to import in order to use \PyX?}
174 {It is recommended to begin your Python code with
175 \begin{progcode}
176 from pyx import *
177 \end{progcode}
178 when using \PyX. This allows you for example to write simply
179 \texttt{graph.graphxy}
180 instead of \texttt{pyx.graph.graphxy}. The following modules will be loaded:
181 \texttt{attr}, \texttt{box}, \texttt{canvas}, \texttt{color}, \texttt{connector}, \texttt{data},
182 \texttt{deco}, \texttt{epsfile}, \texttt{graph}, \texttt{path},
183 \texttt{style}, \texttt{trafo}, \texttt{text}, and \texttt{unit}.
185 For convenience, you might import specific objects of a module like in
186 \begin{progcode}
187 from graph import graphxy
188 \end{progcode}
189 which allows you to write \texttt{graphxy()} instead of \texttt{graph.graphxy()}.
191 All code segments in this document assume that the import line mentioned in
192 the first code snippet is present.
195 \question{a}{What is a raw string and why should I know about it when
196 using \PyX?}
198 {\label{q:raw_string}
199 The backslash serves in standard Python strings to start an escape sequence.
200 For example {\cs n} corresponds to a newline character. On the other hand,
201 \TeX{} and \LaTeX{}, which do the typesetting in \PyX, use the backslash to
202 indicate the start of a command. In order to avoid the standard interpretation,
203 the string should be marked as a raw string by prepending it by an \texttt{r}
204 like in
205 \begin{progcode}
206 c.text(0, 0, r"\${\cs alpha}{\cs beta}{\cs gamma}\$")
207 \end{progcode}
210 \section{Plotting of graphs}
212 \subsection{General aspects}
214 \question{c}{How do I generate a graph from data as simply as possible?}
216 {\label{q:mingraphdata}
217 Suppose that you have a data file \texttt{x.dat} containing values for
218 $x$ and $y$ in two columns. Then the following code will do the job
219 \begin{progcode}
220 from pyx import *\\
222 g = graph.graphxy(width=10)\\
223 g.plot(graph.data.file("x.dat", x=1, y=2))\\
224 g.writeEPSfile("x")
225 \end{progcode}
226 \texttt{graphxy} creates a canvas (called \texttt{g} in this example) onto
227 which the graph will be drawn and it sets the default behavior including the
228 axis. There is, however, no default value for the width of the graph. In
229 \texttt{plot} you have to specify the name of the data file and the columns
230 from which the data should be taken. Finally, \texttt{writeEPSfile} will
231 generate the postscript file \texttt{x.eps} which you can view or print.
233 A minimal example is also provided in the \PyX{} distribution as
234 \path{examples/graphs/minimal.py}.
237 \question{a}{How do I generate a graph of a function as simply as possible?}
239 {\label{q:mingraphfunc}
240 The following example will draw a parabola:
241 \begin{progcode}
242 from pyx import *\\
244 g = graph.graphxy(width=10,\\
245 ~~~~~~~~~~~~~~~~~~x=graph.axis.linear(min=-2, max=2)\\
246 ~~~~~~~~~~~~~~~~~~)\\
248 g.plot(graph.data.function("y=x**2"))\\
250 g.writeEPSfile("x")
251 \end{progcode}
252 Most of the code has been explained in \uaref{q:mingraphdata}. The main
253 difference is that here you need to specify minimum and maximum for the
254 $x$-axis so that \PyX{} knows in which range to evaluate the function.
256 Another, slightly more complex, example is also provided in the \PyX{}
257 distribution as \path{examples/graphs/piaxis.py}.
260 \question{a}{How can I stack graphs?}
262 {\PyX{} always needs a canvas to draw on. One possibility therefore consists
263 in creating a new canvas with
264 \begin{progcode}
265 c = canvas.canvas()
266 \end{progcode}
267 and inserting the graphs into this canvas with \texttt{c.insert(...)}. Here,
268 \texttt{...} has to be replaced by the name of the graph. Alternatively, the
269 canvas created with \texttt{graph.graphxy} for one of the graphs can be used
270 to insert the other graphs even if they will be positioned outside the
271 first graph.
273 The second issue to address is positioning of the graphs. By specifying
274 \texttt{xpos} and \texttt{ypos} when calling \texttt{graphxy}, you can
275 define the position of a graph. Later on, the position and size of a
276 graph \texttt{g} can be referred to as \texttt{g.xpos}, \texttt{g.ypos},
277 \texttt{g.width}, and \texttt{g.height} even if for example the height has
278 never been specified explicitly but is only defined by a \PyX{} default.
280 The following example shows how to put graph \texttt{gupper} above graph
281 \texttt{glower} on a canvas \texttt{c}:
282 \begin{progcode}
283 from pyx import *\\
284 from graph import graphxy\\
286 c = canvas.canvas()\\
288 glower = graphxy(width=10)\\
289 glower.plot(...)\\
290 c.insert(glower)\\
292 gupper = graphxy(width=10, ypos=glower.ypos+glower.height+2)\\
293 gupper.plot(...)\\
295 c.insert(gupper)\\
296 c.writeEPSfile(...)
297 \end{progcode}
298 where \texttt{...} has to be replaced by the appropriate information like
299 data and symbol specifications and the name of the output file. Here,
300 \texttt{c.insert} is used to actually insert the subcanvasses
301 for the graphs into the main canvas \texttt{c} and \texttt{c.writeEPSfile}
302 in the last line requests to write the contents of this canvas to a file.
304 %In order to suppress the labels of the $x$-axis of the upper graph, use
305 %\begin{progcode}
306 %myaxispainter = graph.axispainter(labelattrs=None)
308 %gupper = graph.graphxy(...,
309 % x=graph.axis.linear(...,
310 % part=graph.linpart(),
311 % painter=myaxispainter)
313 %\end{progcode}
316 \question{a}{How can I plot grid data? \changed}
318 {\PyX{} offers support for plotting three-dimensional data as two-dimensional
319 color plots or grey-scale plots and of vector fields by providing ways to
320 plot rectangles and arrows in graphs.
322 We start by considering the task of creating a two-dimensional color plot by
323 plotting a number of filled rectangles. One first needs to create a data set
324 which consists of five entries per data point. These are the lower left corner
325 $(x_\mathrm{min},y_\mathrm{min})$ and the upper right corner
326 $(x_\mathrm{max},y_\mathrm{max})$ of the triangle and a value between 0 and 1
327 determining the color via a \PyX{} color palette. The following code gives an
328 idea of how to proceed:
329 \begin{progcode}
330 g.plot(graph.data.file("datafile.dat"), xmin=1, xmax=2, ymin=3, ymax=4, color=5),\\
331 ~~~~~~~[graph.style.rect(color.palette.ReverseRainbow)]\\
332 ~~~~~~)\\
333 g.dodata()
334 \end{progcode}
335 Here, we assume that the data are stored in \texttt{datafile.dat} and the
336 columns contain $x_\mathrm{min}$, $x_\mathrm{max}$, $y_\mathrm{min}$,
337 $y_\mathrm{max}$, and the color value in this order. The columns are
338 numbered from 1, since the 0th column contains the line number. To
339 determine the color, we use the \texttt{ReverseRainbow} palette. The
340 last line instructs \PyX{} to plot the rectangles before plotting the
341 axes. Otherwise, the axes might be covered partially by the rectangles
342 and, in particular, the ticks might not be visible. Gray-scale plots
343 can easily be generated by specifying the palette \texttt{Gray} or
344 \texttt{ReverseGray} (cf.\ appendix C of the manual for a list of
345 predefined palettes).
347 At first sight, it seems surprising that plotting of grid data requires
348 the specification of four coordinates for the rectangle. The reason is that
349 this allows to draw rectangles of varying sizes which may help to reduce the
350 size of the postscript file by combining rectangles of the same color in
351 horizontal or vertical direction. For example, it may be sufficient to plot
352 a grey-scale image in a small number of grey shades and then combining
353 rectangles may be appropriate. Note, though, that this step is part of the
354 data creation and not preformed by \PyX{}. Another advantage of fully
355 specifying each rectangle is that it is straightforward to leave parts of the
356 graph blank.
358 The same ideas as for the color plot can be applied to plot vector fields where
359 each data point is represented by an arrow. In this case a data point is
360 specified by the position of the arrow, its size and its direction as indicated
361 in the following code snippet:
362 \begin{progcode}
363 g.plot(graph.data.file("datafile.dat"), x=1, y=2, size=3, angle=4),\\
364 ~~~~~~~[graph.style.arrow()]\\
365 ~~~~~~)
366 \end{progcode}
368 Complete code examples can be found in \path{examples/graphs/mandel.py} and
369 \path{examples/graphs/arrows.py}\,.
372 \question{a}{How can I access points in problem coordinates of a graph? \new}
374 {\label{q:problemcoord}
375 Sometimes it may be necessary to add graphical elements to a graph in addition
376 to the data or function(s) which have been plotted as described in
377 \uaref{q:mingraphdata} and \uaref{q:mingraphfunc}. For a graph instance
378 \texttt{g} the positioning can easily be done in canvas coordinates by making
379 use of the origin (\texttt{g.xpos}, \texttt{g.ypos}) and the width
380 (\texttt{g.width}) and height (\texttt{g.height}) of the graph.
382 Occasionally, it may be more convenient to specify the position of the
383 additional material in terms of problem coordinates. However, this requires
384 that the mapping from problem coordinates to canvas coordinates is known.
385 By default this is not the case before the content of the canvas is written
386 to the output which is too late for our purpose. One therefore needs to
387 explicitly instruct \PyX{} to determine this mapping. One possibility is to
388 ask \PyX{} to finish the graph by means of \texttt{g.finish()}. Now, problem
389 coordinates can be used to insert additional material which will end up in
390 front of the graph. If this is not desired, one should only fix the layout
391 of the graph by means of \texttt{g.dolayout()}. Then, the additional material
392 can be put onto the canvas before the graph is drawn and it will therefore
393 appear behind the graph.
395 The conversion of problem coordinates (\texttt{px}, \texttt{py}) to canvas
396 coordinates (\texttt{x}, \texttt{y}) is performed as follows:
397 \begin{progcode}
398 x, y = g.pos(px, py)
399 \end{progcode}
400 By default, the problem coordinates will refer to the ranges of the $x$ and $y$
401 axes. If several axes with different ranges exist, the
402 instances of the desired axes should be passed to the \texttt{pos} method by
403 means of the keyword arguments \texttt{xaxis} and \texttt{yaxis}.
405 We remark that the drawing of lines parallel to one of the axes at specific
406 problem coordinates can also be done by adapting the method described in
407 \uaref{q:zeroline}.
410 \question{t}{I would like a key for only some of my data sets. How do I do
411 that?}
416 \subsection{Axis properties}
418 \question{a}{How do I specify the tick increment?}
420 {In the partition of a linear axis, the increments associated with ticks,
421 subticks etc.\ can be specified as argument of \texttt{parter.linear}. In the
422 following example, ticks will be drawn at even values while subticks will
423 be drawn at all integers:
424 \begin{progcode}
425 from pyx.graph import axis\\
426 tg = graph.graphxy(width=10,\\
427 ~~~~~~~~~~~~~~~~~~~x=axis.linear(min=1, max=10,\\
428 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~parter=axis.parter.linear(tickdist=[2,1]))\\
429 ~~~~~~~~~~~~~~~~~~~)
430 \end{progcode}
433 \question{a}{How do I plot the zero line?}
436 \label{q:zeroline}
437 \PyX{} releases before 0.6 offered the possibility to stroke a zero line by
438 specifying \texttt{zeropathattrs} in the painter constructor. In more recent
439 releases, one proceeds as follows. First one has to fix the layout information
440 of the graph by means of the \texttt{finish} or \texttt{dolayout} method (see
441 \ref{q:problemcoord} for a more detailed explanation). Then, the
442 \texttt{xgridpath} or \texttt{ygridpath} method of a graph will return a grid
443 path parallel to the $y$ or $x$ axis, respectively, at the specified $y$ value.
444 As an example, a zero line in $x$ direction can be drawn as follows:
445 \begin{progcode}
446 g.finish()\\
447 g.stroke(g.ygridpath(0))
448 \end{progcode}
451 \subsection{Data properties}
453 \question{a}{How do I choose the symbol? \changed}
455 {\label{q:choose_symbol}
456 Suppose a graph called \texttt{g} has been initialized, e.g. by using
457 \texttt{graph.graphxy}. Then, data and the style of their representation
458 in the graph are defined by calling \texttt{g.plot} like in the following
459 example in which filled circles are requested:
460 \begin{progcode}
461 g.plot(graph.data.file("test.dat"),\\
462 ~~~~~~~[graph.style.symbol(graph.style.symbol.circle, symbolattrs=[deco.filled])]\\
463 ~~~~~~~)
464 \end{progcode}
467 \question{a}{How do I choose the color of the symbols? \changed}
469 {Colors are not properties of the symbol as such and can therefore not
470 be specified in \texttt{symbolattrs} directly. The color is rather related
471 to the plotting of the symbol as defined by \texttt{deco.stroked} or
472 \texttt{deco.filled}. With
473 \begin{progcode}
474 graph.style.symbol(graph.style.symbol.circle,\\
475 ~~~~~~~~~~~~~~~~~~~symbolattrs=[deco.stroked([color.rgb.red]),\\
476 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~deco.filled([color.rgb.green])]\\
477 ~~~~~~~~~~~~~~~~~~~)
478 \end{progcode}
479 you will obtain a circle filled in green with a red borderline.
482 \question{a}{How do I choose the line style? \changed}
484 {If you do not want to use symbols, you can set the line style as in this
485 example
486 \begin{progcode}
487 g.plot(graph.data.file("test.dat"),\\
488 ~~~~~~~[graph.style.line([style.linewidth.Thin])]\\
489 ~~~~~~~)
490 \end{progcode}
491 where the linewidth is set.
493 If you also want to use symbols, you can combine the symbol and the
494 line style as in
495 \begin{progcode}
496 g.plot(graph.data.file("test.dat"),\\
497 ~~~~~~~[graph.style.line(lineattrs=[style.linewidth.Thin,\\
498 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~style.linestyle.dashed]),\\
499 ~~~~~~~~graph.style.symbol(graph.style.symbolline.circle,\\
500 ~~~~~~~~~~~~~~~~~~~~~~~~~~~symbolattrs=[deco.filled])
501 ~~~~~~~]
502 ~~~~~~)
503 \end{progcode}
504 to plot the symbols on top of a thin, dashed line. You may alter the
505 order of the styles to plot the line on top of the symbols.
508 \section{\TeX{} and \LaTeX{}}
510 \subsection{General aspects}
512 \question{a}{What is \TeX/\LaTeX{} and why do I need it?}
514 {\label{q:what_is_tex}
515 \TeX{} is a high quality typesetting system developed by Donald E. Knuth
516 which is available for a wide variety of operating systems. \LaTeX{} is a
517 macro package originally developed by Leslie Lamport which makes life with
518 \TeX{} easier, in particular for complex typesetting tasks. The current
519 version of \LaTeX{} is referred to as \LaTeXe{} and offers e.g.\ improved
520 font selection as compared to the older \LaTeX{} 2.09 which should no longer
521 be used.
523 All typesetting tasks in \PyX{} are finally handed over to \TeX{} (which is the
524 default) or \LaTeX{}, so that \PyX{} cannot do without it. On the other hand,
525 the capabilities of \TeX{} and \LaTeX{} can be used for complex tasks where
526 both graphics and typesetting are needed.
529 \question{a}{I don't know anything about \TeX{} and \LaTeX{}. Where can I read
530 something about it?}
532 {\label{q:intro_tex_latex}
533 Take a look at CTAN (\uaref{q:ctan}) where in \ctan{info}
534 you may be able to find some useful information. There exists for example
535 ``A Gentle Introduction to \TeX'' by M.~Doob (\ctan{gentle/gentle.pdf}) and
536 ``The Not So Short Introduction to \LaTeXe''
537 (\ctan{info/lshort/english/lshort.pdf}) by T.~Oetiker et al. The latter has
538 been translated into a variety of languages among them korean (which you will
539 not be able to read unless you have appropriate fonts installed) and mongolian.
541 Of course, it is likely that these documents will go way beyond what you
542 will need for generating graphics with \PyX{} so you don't have to read all
543 of it (unless you want to use \TeX{} or \LaTeX{} for typesetting which can be
544 highly recommended).
546 There exists also a number of FAQs on \TeX{} at \ctan{help}.
549 \question{a}{What is CTAN?}
551 {\label{q:ctan}
552 CTAN is the Comprehensive TeX Archive Network where you will find almost
553 everything related to \TeX{} and friends. The main CTAN servers are
554 \url{tug.ctan.org}, \url{dante.ctan.org}, and \url{cam.ctan.org}. A list of
555 FTP mirrors can be found at \ctan{CTAN.sites}.
557 In this FAQ, \texttt{CTAN:} refers to the root of an anonymous ftp CTAN tree,
558 e.g. \url{ftp://ctan.tug.org/tex-archive/},
559 \url{ftp://ftp.dante.de/tex-archive/},
560 and \url{ftp://ftp.tex.ac.uk/tex-archive/}. The links to CTAN in this document
561 point to one of these servers but you might consider using a FTP mirror closer
562 to you in order to reduce traffic load.
565 \question{a}{Is there support for Con\TeX{}t?}
567 {No, and as far as I know there no plans to provide it in the near future.
568 Given the close ties between Con\TeX{}t and Meta\-Post, Con\TeX{}t users
569 probably prefer to stick with the latter anyway.
572 \subsection{\TeX{} and \LaTeX{} commands useful for \PyX}
574 \question{a}{How do I get a specific symbol with \TeX{} or \LaTeX?}
576 {A list of mathematical symbols together with the appropriate command name
577 can be found at \ctan{info/symbols/math/symbols.ps}. A comprehensive list
578 containing more than 2500 symbols for use with \LaTeX{} can be obtained from
579 \ctan{info/symbols/comprehensive/symbols-a4.pdf}. In some cases it might be
580 necessary to install fonts or packages available from CTAN
581 (\uaref{q:ctan}).
584 \subsection{\TeX{} and \LaTeX{} errors}
586 \question{a}{Undefined control sequence \cs{usepackage}}
588 {\label{q:undefined_usepackage}
589 The command \cs usepackage is specific to \LaTeX{}. Since by default \PyX{}
590 uses \TeX{}, you have to specify the correct mode:
591 \begin{progcode}
592 text.set(mode="latex")
593 \end{progcode}
596 \question{a}{Undefined control sequence \cs{frac}}
598 {\label{q:undefined_frac}
599 The command \cs frac is only available in \LaTeX{}. In \TeX{} you should
600 use \texttt{\cb{a\cs over b}} in math mode to produce ${a\over b}$. As an
601 alternative you may ask for the \LaTeX{} mode as explained in
602 \ref{q:undefined_usepackage}.
605 \question{a}{Missing \$ inserted}
607 {You have specified \TeX- or \LaTeX-code which is only valid in math mode.
608 Typical examples are greek symbols, sub- and superscripts or fractions.
610 On the \PyX{} level, you can specify math mode for the whole string by using
611 \texttt{text.mathmode} as in
612 \begin{progcode}
613 c.text(0, 0, r"{\cs alpha}", text.mathmode)
614 \end{progcode}
615 Keep also in mind that the standard Python interpretation of the backslash as
616 introducing escape sequences needs to be prevented
617 \uaref{q:raw_string}.
619 On the \TeX/\LaTeX{} level you should enclose the commands requiring math
620 mode in \$'s. As an example, \texttt{\$\cs alpha\us i\hat j\$} will produce
621 $\alpha_i^j$. This allows you to specify math mode also for substrings. There
622 exist other ways to specify math mode in \TeX{} and \LaTeX{} which are
623 particularly useful for more complex typesetting tasks. To learn more about
624 it, you should consult the documentation
625 \uaref{q:intro_tex_latex}.
628 \question{a}{Why do environments like itemize or eqnarray seem not to work?
629 \new}
631 {An itemize environment might result in a \LaTeX{} error complaining about
632 a ``\texttt{missing \cs item}'' or an eqnarray might lead to a \LaTeX{} message
633 ``\texttt{missing \cs endgroup inserted}'' even though the syntax appears to be
634 correct. The \TeX{}nical reason is that in \PyX{} text is typeset in left-right
635 mode (LR mode) which does not allow linebreaks to occur. There are two ways out.
637 If the text material should go in a box of given width, a parbox can be used
638 like in the following example:
639 \begin{progcode}
640 text.set(mode="latex")\\
641 c = canvas.canvas()\\
642 w = 2\\
643 c.text(0, 0, r"\cs begin\cb{itemize}\cs item a\cs item b\cs end\cb{itemize}", [text.parbox(w)])
644 \end{progcode}
646 Occasionally, one would like to have the box in which the text appears to be as
647 small as possible. Then the \texttt{fancybox} package developed by Timothy Van
648 Zandt is useful which provides several environments like \texttt{Bitemize} and
649 \texttt{Beqnarray} which can be processed in LR mode. The relevant part of the
650 code could look like:
651 \begin{progcode}
652 text.set(mode="latex")\\
653 text.preamble(r"\cs usepackage\cb{fancybox}")\\
654 c = canvas.canvas()\\
655 c.text(0, 0, r"\cs begin\cb{Bitemize}\cs item a\cs item b\cs end\cb{Bitemize}")
656 \end{progcode}
657 Other environments provided by the \texttt{fancybox} package include
658 \texttt{Bcenter}, \texttt{Bflushleft}, \texttt{Bflushright},
659 \texttt{Benumerate}, and \texttt{Bdescription}. For more details, the
660 documentation of the package should be consulted.
663 \question{a}{Font shape `OT1/xyz/m/n' undefined}
665 {\label{q:fontshape_undefined}
666 You have asked to use font \texttt{xyz} which is not available. Make sure that
667 you have this font available in Type1 format, i.e.\ there should be a
668 file \texttt{xyz.pfb} somewhere. If your \TeX{} system is TDS compliant
669 (TDS=\TeX{} directory structure, cf.\ \ctan{tds/draft-standard/tds/tds.pdf})
670 you should take a look at the subdirectories of
671 \path{TEXMF/fonts/type1}.
674 \question{a}{File \dots\ is not available or not readable}
676 {\label{q:no_lfs}
677 Such an error message might already occur when running the example file
678 \texttt{hello.py} included in the \PyX{} distribution. Usually, the error
679 occurs due to an overly restrictive umask setting applied when unpacking the
680 \texttt{tar.gz} sources. This may render the file mentioned in the error
681 message unreadable because the python distutil installation package doesn't
682 change the file permissions back to readable for everyone.
684 If the file exists, the problem can be solved by changing the permissions to
685 allow read access.}
687 \question{a}{No information for font `cmr10' found in font mapping
688 file \changed}
690 {\label{q:no_cmr10}
691 Such an error message can already be encountered by simply running the example
692 file \texttt{hello.py} included in the \PyX{} distribution. The likely reason
693 is that the \TeX{} system does not find the cmr fonts in Type1 format.
694 \PyX{} depends on these fonts as it does not work with the traditional
695 pk fonts which are stored as bitmaps.
697 Therefore, the first thing to make sure is that the cmr Type1 fonts are
698 installed. In some \TeX{} installations, the command \texttt{kpsewhich
699 cmr10.pfb} will return the appropriate path if the cmr fonts exist in the
700 binary Type1 format (extension \texttt{pfb}) required by \PyX. If the command
701 does not work but the TeX{} system is TDS compliant
702 (\uaref{q:fontshape_undefined}), a look should be taken at
703 \path{TEXMF/fonts/type1/bluesky/cm} where \texttt{TEXMF} is the root of the
704 \texttt{texmf} tree.
706 If the Type1 fonts do not exist on the system, they may be obtained from
707 the CTAN \uaref{q:ctan} at \ctan{fonts/cm/ps-type1/bluesky}. See the
708 \texttt{README} for information about who produced these fonts and why they
709 are freely available.
711 If the Type1 fonts exist, the next step is to take a look at
712 \texttt{psfonts.map}. There may be several files with this name on the system,
713 so it is important to find out which one TeX is actually using.
714 \texttt{kpsewhich psfonts.map} might give this information.
716 The most likely problem is that this file does not contain a line telling TeX
717 what to do if it encounters a request for font \texttt{cmr10}, i.e. the
718 following line
719 may be missing
720 \begin{progcode}
721 ~~~cmr10~~~~~~~~~~~CMR10~~~~~~~~~~~<cmr10.pfb
722 \end{progcode}
723 It is probable that the required lines (in practice, you do not just need
724 \texttt{cmr10}) are found in a file named \texttt{psfonts.cmz} which resides in
725 \path{TEXMF/dvips/bluesky}.
727 One solution is to instruct \PyX{} to read additional map files like
728 \texttt{psfonts.cmz} or \texttt{psfonts.amz}. This can be achieved by modifying
729 the appropriate \texttt{pyxrc} file which is either the systemwide
730 \texttt{/etc/pyxrc} or \texttt{.pyxrc} in the user's home directory. Here, the
731 names of the map files to be read by \PyX{} should be appended separated by
732 whitespaces like in the following example:
733 \begin{progcode}
734 [text]\\
735 fontmaps = psfonts.map psfonts.cmz psfonts.amz
736 \end{progcode}
737 The same effect can be achieved by inserting the following line into the
738 \PyX{} code:
739 \begin{progcode}
740 text.set(fontmaps="psfonts.map psfonts.cmz psfonts.amz")
741 \end{progcode}
742 Note that the default map (psfonts.map) has to be specified explicitly.
744 An alternative approach consists in modifying the \TeX{} installation by
745 inserting the contents of the desired map files like \texttt{psfonts.cmz} into
746 \texttt{psfonts.map}. Probably, \texttt{psfonts.map} recommends not to do this
747 by hand. In this case the instructions given in the file should be followed.
748 Otherwise, \texttt{psfonts.cmz} should be copied into \texttt{psfonts.map} while
749 keeping a backup of the old \texttt{psfonts.map} just in case. After these
750 changes, \PyX{} most likely will be happy. When inserting \texttt{psfonts.cmz}
751 into \texttt{psfonts.map} it may be a good idea to include \texttt{psfonts.amz}
752 as well. \texttt{psfonts.amz} contains information about some more fonts which
753 might be needed at some point. Making these changes ot \texttt{psfonts.map}
754 will imply that the \TeX{} system will use the cmr fonts in Type1 format
755 instead of pk format which is actually not a bad thing, in particular if
756 \texttt{latex}~/ \texttt{dvips}~/ \texttt{ps2pdf} is used to generate PDF
757 output. With fonts in pk format this will look ugly and using Type1 fonts
758 solves this problem as well. When \texttt{pdflatex} is used to create PDF files,
759 Type1 fonts will be used anyway.
762 \subsection{Fonts}
764 \question{t}{I have Type1 fonts in \texttt{pfa} format. How do I obtain the
765 corresponding \texttt{pfb} files needed by \PyX?}
770 \question{a}{I want to use a font other than computer modern roman}
772 {\label{q:other_font}
773 As long as you have a font in Type1 format available, this should be no
774 problem (even though it may cost you some time to set up things properly).
776 In the simplest case, your \LaTeX{} system contains everything needed.
777 Including the following line into your code will probably work
778 \begin{progcode}
779 text.set(mode="latex")\\
780 text.preamble(r"\cs{usepackage}\cb{mathptmx}")
781 \end{progcode}
782 and give you Times as roman font.
784 If you own one of the more common commercial fonts, take a look at
785 \ctan{fonts} and its subdirectories as well as at the web page
786 \url{http://home.vr-web.de/was/fonts.html} of Walter Schmidt. It is not
787 unlikely that somebody has already done most of the work for you and created
788 the files needed for the font to work properly with \LaTeX. But remember:
789 we are talking about commercial fonts here, so do not expect to find the fonts
790 themselves for free.
792 If none of these cases applies, you should spend some time reading
793 manuals about font installation, e.g.\ \ctan{macros/latex/doc/fntguide.pdf}
794 (of course, I do not expect font wizards to read the last few lines).
797 \question{a}{Can I use a TrueType font with \PyX?}
799 {Not directly as \PyX{} only knows how to handle Type1 fonts (although it is
800 possible to get \LaTeX{} to work with TrueType fonts). However, you may use
801 \texttt{ttf2pt1} (from \url{http://ttf2pt1.sourceforge.net}) to convert a
802 TrueType font into a Type1 font which you then install in your \TeX{} system
803 \uaref{q:other_font}. You will loose hinting information
804 in the conversion process but this should not really matter on output devices
805 with not too low resolution.
808 \end{document}