============= TeX and LaTeX ============= General aspects =============== .. _what_is_tex: What is TeX/LaTeX? ------------------ TeX is a high quality typesetting system developed by Donald E. Knuth which is available for a wide variety of operating systems. LaTeX is a macro package originally developed by Leslie Lamport which makes life with TeX easier, in particular for complex typesetting tasks. The current version of LaTeX is referred to as LaTeX2e and offers e.g. improved font selection as compared to the long outdated LaTeX 2.09 which should no longer be used. Do I need to use TeX/LaTeX? --------------------------- Traditionally, typesetting in PyX is done with TeX or LaTeX. With PyX 0.15, the Unicode engine was introduced. This engine can be useful if one does not need the elaborate typesetting capabilities of TeX and LaTeX and wants to avoid installing the corresponding packages. A TeX installation may nevertheless be useful if one wants to make use of fonts distributed with it. For further information see :ref:`text_without_tex`. .. _intro_tex_latex: I don't know anything about TeX and LaTeX. Where can I read something about it? -------------------------------------------------------------------------------- Take a look at CTAN (cf. :ref:`ctan`) where in `CTAN:info `_ you may be able to find some useful information. There exists for example “A Gentle Introduction to TeX” by M. Doob (`CTAN:gentle/gentle.pdf `_) and “The Not So Short Introduction to LaTeX2e” (`CTAN:info/lshort/english/lshort.pdf `_) by T. Oetiker et al. The latter has been translated into a variety of languages among them korean (which you will not be able to read unless you have appropriate fonts installed) and mongolian. Of course, it is likely that these documents will go way beyond what you will need for generating graphics with PyX so you don't have to read all of it (unless you want to use TeX or LaTeX for typesetting which can be highly recommended). There exists also a number of FAQs on TeX at `CTAN:help `_. .. _ctan: What is CTAN? ------------- CTAN is the *Comprehensive TeX Archive Network* where you will find almost everything related to TeX and friends. The main CTAN server is `www.ctan.org `_ but there exists a large number of mirrors around the world. You can help to reduce the load on the main server by using `mirror.ctan.org `_ which will redirect you to a mirror nearby. A list of known mirrors is available at `http://mirror.ctan.org/README.mirrors `_. In this FAQ, ``CTAN:`` refers to the root of the CTAN tree, e.g. `http://www.ctan.org/tex-archive/ `_. The links to CTAN in this document point to the main server but you might consider using a server closer to you in order to reduce traffic load. Is there support for ConTeXt? ----------------------------- No, and as far as I know there no plans to provide it in the near future. Given the close ties between ConTeXt and MetaPost, ConTeXt users probably prefer to stick with the latter anyway. TeX and LaTeX commands useful for PyX ===================================== How do I get a specific symbol with TeX or LaTeX? ------------------------------------------------- A list of mathematical symbols together with the appropriate command name can be found at `CTAN:info/symbols/math/symbols.pdf `_. A comprehensive list containing almost 6000 symbols for use with LaTeX can be obtained from `CTAN:info/symbols/comprehensive/symbols-a4.pdf `_. In some cases it might be necessary to install fonts or packages available from CTAN (cf. :ref:`ctan`). TeX and LaTeX errors ==================== .. _undefined_usepackage: Undefined control sequence ``\usepackage`` ------------------------------------------ The command ``\usepackage`` is specific to LaTeX. Since by default PyX uses TeX, you have to specify the correct typesetting engine:: text.set(text.LatexEngine) Undefined control sequence ``\frac`` ------------------------------------ The command ``\frac`` is only available in LaTeX. The equivalent to ``\frac{a}{b}`` in TeX is ``{a \over b}``. As an alternative you may ask for the LaTeX engine as explained in :ref:`undefined_usepackage`. Missing ``$`` inserted ---------------------- You have specified TeX- or LaTeX-code which is only valid in math mode. Typical examples are greek symbols, sub- and superscripts or fractions. On the PyX level, you can specify math mode for the whole string by using ``text.mathmode`` as in :: c.text(0, 0, r"{\alpha}", text.mathmode) Keep also in mind that the standard Python interpretation of the backslash as introducing escape sequences needs to be prevented. On the TeX/LaTeX level you should enclose the commands requiring math mode in ``$``'s. As an example, ``$\alpha_i^j$`` will produce a greek letter alpha with a subscript i and a superscript j. The dollar sign thus allows you to specify math mode also for substrings. There exist other ways to specify math mode in TeX and LaTeX which are particularly useful for more complex typesetting tasks. To learn more about it, you should consult the documentation :ref:`intro_tex_latex`. Why do environments like ``itemize`` or ``eqnarray`` seem not to work? ---------------------------------------------------------------------- An itemize environment might result in a LaTeX error complaining about a ``missing \item`` or an eqnarray might lead to a LaTeX message ``missing \endgroup inserted`` even though the syntax appears to be correct. The TeXnical reason is that in PyX text is typeset in left-right mode (LR mode) which does not allow linebreaks to occur. There are two ways out. If the text material should go in a box of given width, a parbox can be used like in the following example:: text.set(text.LatexEngine) c = canvas.canvas() w = 2 c.text(0, 0, r"\begin{itemize}\item a\item b\end{itemize}", [text.parbox(w)]) Occasionally, one would like to have the box in which the text appears to be as small as possible. Then the ``fancybox`` package developed by Timothy Van Zandt is useful which provides several environments like ``Bitemize`` and ``Beqnarray`` which can be processed in LR mode. The relevant part of the code could look like:: text.set(text.LatexEngine) text.preamble(r"\usepackage{fancybox}") c = canvas.canvas() c.text(0, 0, r"\begin{Bitemize}\item a\item b\end{Bitemize}") Other environments provided by the ``fancybox`` package include ``Bcenter``, ``Bflushleft``, ``Bflushright``, ``Benumerate``, and ``Bdescription``. For more details, the documentation of the package should be consulted. .. _fontshape_undefined: Font shape ``OT1/xyz/m/n`` undefined ------------------------------------ You have asked to use font ``xyz`` which is not available. Make sure that you have this font available in Type1 format, i.e. there should be a file ``xyz.pfb`` somewhere. If your TeX system is TDS compliant (TDS=TeX directory structure, cf. `CTAN:tds/draft-standard/tds/tds.pdf `_) you should take a look at the subdirectories of ``$TEXMF/fonts/type1``. File ``…`` is not available or not readable ------------------------------------------- Such an error message might already occur when running the example file ``hello.py`` included in the PyX distribution. Usually, the error occurs due to an overly restrictive umask setting applied when unpacking the ``tar.gz`` sources. This may render the file mentioned in the error message unreadable because the python distutil installation package doesn't change the file permissions back to readable for everyone. If the file exists, the problem can be solved by changing the permissions to allow read access. No information for font ``cmr10`` found in font mapping file ------------------------------------------------------------ Such an error message can already be encountered by simply running the example file ``hello.py`` included in the PyX distribution. The likely reason is that the TeX system does not find the cmr fonts in Type1 format. PyX depends on these fonts as it does not work with the traditional pk fonts which are stored as bitmaps. Therefore, the first thing to make sure is that the cmr Type1 fonts are installed. In some TeX installations, the command ``kpsewhich cmr10.pfb`` will return the appropriate path if the cmr fonts exist in the binary Type1 format (extension ``pfb``) required by PyX. If the command does not work but the TeX system is TDS compliant (:ref:`fontshape_undefined`), a look should be taken at ``$TEXMF/fonts/type1/bluesky/cm`` where ``$TEXMF`` is the root of the ``texmf`` tree. If the Type1 fonts do not exist on the system, they may be obtained from the CTAN (cf. :ref:`ctan`) at `CTAN:fonts/cm/ps-type1/bluesky `_). See the ``README`` for information about who produced these fonts and why they are freely available. If the Type1 fonts exist, the next step is to take a look at ``psfonts.map``. There may be several files with this name on the system, so it is important to find out which one TeX is actually using. ``kpsewhich psfonts.map`` might give this information. The most likely problem is that this file does not contain a line telling TeX what to do if it encounters a request for font ``cmr10``, i.e. the following line may be missing :: cmr10 CMR10 `_ and its subdirectories as well as at the web page `http://home.vr-web.de/was/fonts.html `_ of Walter Schmidt. It is not unlikely that somebody has already done most of the work for you and created the files needed for the font to work properly with LaTeX. But remember: we are talking about commercial fonts here, so do not expect to find the fonts themselves for free. If none of these cases applies, you should spend some time reading manuals about font installation, e.g. `CTAN:macros/latex/doc/fntguide.pdf `_ (of course, I do not expect font wizards to read the last few lines). Can I use a TrueType font with PyX? ----------------------------------- Not directly as PyX only knows how to handle Type1 fonts (although it is possible to get LaTeX to work with TrueType fonts). However, you may use ``ttf2pt1`` (from `ttf2pt1.sourceforge.net `_) to convert a TrueType font into a Type1 font which you then install in your TeX system (cf. :ref:`other_font`). You will loose hinting information in the conversion process but this should not really matter on output devices with not too low resolution.