Installing preview-latex
************************

Installing preview-latex should be simple: merely `./configure',
`make', and `make install'.  This does not yet activate the package,
but merely makes it available.  See *Note Loading the package:: for the
activation.  Note that unlike most emacs add-ins, preview-latex
consists of a TeX part and an Emacs part (that uses AUCTeX).  This
makes configuration a bit trickier than normal.  Please read through
this document fully before installing anything.

Prerequisites
=============

   * A recent version of Emacs 21, alternatively XEmacs

     The first version known to work with preview-latex is Emacs-21.1.
     Since preview-latex heavily exercises new features of Emacs 21,
     getting the newest release is a good idea.

     While image support for Emacs under Microsoft Windows has not been
     implemented as of version 21.3, it is under development and can be
     accessed by anonymous CVS at
     `http://savannah.gnu.org/projects/emacs'; please help in testing it
     before Emacs 21.4 gets released.

     There is additional information for Windows installations in the
     file `INSTALL.windows'.

     For XEmacs, at least version 21.4.9 is recommended.  Earlier
     versions might be made to work with less than optimal results.

   * A working AUCTeX installation

     AUCTeX can be found at `http://www.gnu.org/software/auctex'.  This
     site now provides up-to-date beta and stable versions as well as
     RPMs.  At the time of this writing, the latest version is 11.14
     which is necessary for multi-directory documents.  Apply the patch
     in `patches/auctex-11.13.patch' for 11.13 or earlier in case you
     are hit by this bug.  Apply the patch in `patches/auctex-10.patch'
     for versions before 11.0 if you really must, but complain to
     whoever stuck you with them.

   * A working LaTeX installation

     Preview should work with nearly any LaTeX installation which
     contains dvips, though most testing has taken place using
     teTeX-based distributions.

   * A recent GhostScript

     This is not really needed to _install_ the package, but will be
     required for stable operation of it.  Most problems we have
     encountered come from interaction with not so recent versions of
     GhostScript, so it is a good idea to have, say GhostScript 6.51 or
     later installed.  preview-latex should in its current version work
     with most versions after that.  If you encounter problems, check
     the `PROBLEMS' file.

   * The `texinfo' package

     This is needed for building the documentation.  At least
     version 4.0 is required.  If you don't have this, you may download
     a separate tar file with the prebuilt documentation from
     Sourceforge and install it over the main unpacked tar archive.

   For some known issues with various software, see the `PROBLEMS' file.

Configure
=========

   The first step is to configure the source code, telling it where
various files will be.  To do so, run

     ./configure OPTIONS

   (Note: if you have fetched preview-latex from CVS rather than a
regular release, you will have to first generate `./configure' by
running `autogen.sh' in the `preview' directory.)

   On many machines, you will not need to specify any options, but if
`configure' cannot determine something on its own, you'll need to help
it out with one of these options:

`--with-emacs[=/PATH/TO/EMACS]'
     If you are using a pretest which isn't in your `$PATH', or
     `configure' is not finding the right Emacs executable, you can
     specify it with this option.

`--with-xemacs[=/PATH/TO/XEMACS]'
     Configure for generation under XEmacs (Emacs is the default).
     Again, the name of the right XEmacs executable can be specified,
     complete with path if necessary.

`--with-lispdir=/DIR'
     This tells where to install Emacs Lisp files.  Normally, this
     option is unnecessary, but may be used if you don't like the
     directory that configure is suggesting.

`--with-packagedir=/DIR'
     This tells where to install the XEmacs Package.  Again, this
     option is normally unnecessary, but may be used if you don't like
     the directory that configure is suggesting, and you know that
     XEmacs regards the directory you specify as a package directory.

     If you are installing preview-latex for a single user, and you have
     installed no XEmacs packages as that user before, then `configure'
     may try to install preview-latex in the systemwide package
     directory (that it cannot write to), causing installation to fail.
     In that case, a good value for this option is
     `~/.xemacs/xemacs-packages', as XEmacs looks there for per-user
     packages by default.

`--with-tex-site=/DIR'
     If AUCTeX is installed in a non-standard location, use this option
     to specify the location of its `tex-site.el' file.

`--with-texmf-dir=/DIR
     --with-tex-dir=/DIR'
     Both of these options can be used to specify the location to
     install the preview TeX files.  They are not necessary for most
     TeX installs, but may be used if you don't like the directory that
     configure is suggesting.  Using `--with-texmf-dir=/DIR' you can
     specify where the TeX TDS directory hierarchy resides, and the TeX
     files will be installed in `/DIR/tex/latex/preview'.  If you want
     to specify an exact directory for the preview TeX files, use
     `--with-tex-dir=/DIR'. In this case, the files will be placed in
     `/DIR'.

`--with-doc-dir=/DIR'
     This option may be used to specify where the TeX documentation
     goes.  It is to be used when you are using `--with-tex-dir=/DIR',
     but is normally not necessary otherwise.

`--disable-8bit-test'
     There can be problems if your LaTeX implementation is not 8-bit
     clean.  This switch disables the 8-bit test, in case you know that
     your installation is clean and the test is simply failing.  By
     specifying this switch, you signal your acceptance of having
     preview-latex fail on LaTeX files containing 8-bit characters.
     Check the `LaTeX international characters' section in the
     `PROBLEMS' file for more details.

`--help'
     This is not an option specific to preview-latex. A number of
     standard options to `configure' exist, and we do not have the room
     to describe them here; a short description of each is available,
     using `--help'.

Build/install
=============

   Once `configure' has been run, simply enter

     make

at the prompt to byte-compile the lisp files, extract the TeX files and
build the documentation files.  To install the files into the locations
chosen earlier, type

     make install

You may need special privileges to install, e.g., if you are installing
into system directories.

Loading the package
===================

   First you should make sure that AUCTeX gets loaded.  You then need to
place a few lines in your personal `.emacs' file (or a site-wide
configuration file).

   For XEmacs, if you specified a valid package directory during
installation, or none at all, then XEmacs installation should do
everything necessary in order to install preview-latex as a package and
activate it.  Restarting XEmacs should then make the package visible,
and `C-c C-p C-d' should produce previews.

   If you used `--with-packagedir', you have to make sure that the
directory `lisp/preview' under the directory you specified is in
XEmacs' `load-path' variable.

   For GNU Emacs, the recommended way to activate preview-latex is to
copy the file `preview-latex.el' (which is generated during the
installation) to a place where your installation keeps automatically
loaded startup files.  Alternatively, you can copy it to some place on
your `load-path' and load it with

     (load "preview-latex.el" nil t t)

   That is all.  There are other ways of achieving the equivalent thing,
but we don't mention them here any more since they are not better, and
people got confused into trying everything at once.

   `preview-latex.el' itself is rather short, and loaded quite fast.
When you first load a LaTeX file, `preview.el' itself gets loaded (if
you have AUCTeX up and working).  `C-c C-p C-d' should then give you a
graphics preview.  You can customize the default option set and other
settings of the Emacs package by entering `M-x customize-group <RET>
preview <RET>'.

   There is a sample file `circ.tex' which you can use for testing
around a bit, and which serves as sort of a reference for initial bug
reports.  See the `PROBLEMS' file for a list of known problems.

Providing preview-latex as a package
====================================

   As a package provider, you should make sure that your users will be
served best according to their intentions, and keep in mind that a
system might be used by more than one user, with different preferences.
The use of packages should in general not impact performance negatively
if a user chooses not to employ it, but should be as convenient as
possible. For example, the policy with regard to AUCTeX typically has
been to _refrain_ from activating it automatically when it is installed
as a package.  This is reasonable because

   * Emacs comes with a simpler default TeX mode with different
     keybindings.  Some users might prefer that.

   * AUCTeX is activated via `(require 'tex-site)'.  Once this has
     happened, it is not possible to get back the original TeX mode.  A
     site-wide default would for this reason be hard to override.

   In contrast, preview-latex does not affect operation of AUCTeX
unless you exercise its features.  The recommended invocation (see
above), also provided in the autogenerated file `preview-latex.el',
will delay loading and activating preview-latex until the first LaTeX
file gets loaded.  For this reason, should a user decide that he does
not want to get preview-latex loaded and activated, placing the line

     (remove-hook 'LaTeX-mode-hook 'LaTeX-preview-setup)

in his personal configuration file will be completely sufficient to keep
his personal setup free from any impact of preview-latex's presence.

   For this reason we recommend installing the invocation provided in
the file `preview-latex.el' at a place where it gets executed during
the site startup phase of Emacs.  This will result in a default behavior
of loading preview-latex whenever AUCTeX gets loaded.

   XEmacs uses a package system.  The default preview-latex installation
should cater for everything necessary in that case.

   For RPM files we include a `preview-latex.spec' file in the tarball
distribution, suitable for recent RedHat systems, that should do just
that.

Installation for non-privileged users
=====================================

   Often people without system administration privileges want to install
software for their private use.  In that case you need to specify more
options top the `configure' script.  For XEmacs users, this is fairly
easy, because the XEmacs package system has been designed to make this
sort of thing practical: but GNU Emacs users (and XEmacs users for whom
the package system is for some reason misbehaving) may need to do a
little more work.

   GNU Emacs users can solve this problem by using the `--prefix'
option to the `configure' script, and let it point to the personal home
directory.  In that way, resulting binaries will be installed under the
`bin' subdirectory of your home directory, manual pages under `man' and
so on.  That way, it is reasonably easy to maintain a bunch of
additional packages, since the prefix argument is supported by most
`configure' scripts.

   You'll have to add something like
`/home/myself/share/emacs/site-lisp' to your `load-path' variable, if
it isn't there already.

   XEmacs users can achieve the same end by pointing `configure' at an
appropriate package directory (normally
`--with-packagedir=~/.xemacs/xemacs-packages' will serve).  This should
only need to be done once, and should be needed fairly rarely; if you
have installed any personal XEmacs packages before, `configure' should
detect that, and automatically install preview-latex there too;
equally, if you have installed preview-latex somewhere searched by
XEmacs, preview-latex should be automatically reinstalled over that
copy.

   (`configure' may guess wrong if the site administrator has installed
preview-latex somewhere else: if so, just use the `--with-packagedir'
option to override `configure''s choice.)

   But there is another problem: perhaps you want to make it easy for
other users to share parts of your personal Emacs configuration.  In
general, you can do this by writing `~myself/' anywhere where you
specify paths to something installed in your personal subdirectories,
not merely `~/', since the latter, when used by other users, will point
to non-existent files.

   For yourself, it will do to manipulate environment variables in your
`.profile' resp. `.login' files.  But if people will be copying just
Elisp files, their copies will not work.  While it would in general be
preferable if the added components where available from a shell level,
too (like when you call the standalone info reader, or try using
`preview.sty' for functionality besides of Emacs previews), it will be
a big help already if things work from inside of Emacs.

   Here is how to do the various parts:

Making the Elisp available
--------------------------

   In XEmacs, you should ask the other users to add symbolic links in
their `~/.xemacs/xemacs-packages/lisp',
`~/.xemacs/xemacs-packages/info' and `~/.xemacs/xemacs-packages/etc'
directories. (Alas, there is presently no easy programmatic way to do
this, except to have a script do the symlinking for them.)

   In GNU Emacs, you'll want the invocation lines from the autogenerated
file `preview-latex.el'.  In addition, you'll want a line such as

     (add-to-list 'load-path "~myself/share/emacs/site-lisp/preview")

Making the Info files available
-------------------------------

   While for yourself, you'll probably want to manipulate the
`INFOPATH' variable; for access inside of Elisp something like the
following might be convenient:

     (eval-after-load 'info
        '(add-to-list 'Info-directory-list "~myself/info"))

   In XEmacs, as long as XEmacs can see the package, there should be no
need to do anything at all; the info files should be immediately
visible.  However, you might want to set `INFOPATH' anyway, for the
sake of standalone readers outside of XEmacs. (The info files in XEmacs
are normally in `~/.xemacs/xemacs-packages/info'.)

Making the LaTeX style available
--------------------------------

   Again, for yourself you want to manipulate the `TEXINPUTS'
environment variable or an appropriate setting of a personal
`texmf.cnf' file.  It may well be that your site configuration already
installs access to a personal user's `texmf' tree, in which case having
specified the appropriate tree to `./configure' will have set up
everything for yourself.  If that personal tree is not located at the
equivalent of `~myself/share/texmf', it is a good idea to make this so
with the help of a symbolic link, so that the usual `--prefix'
invocation to `./configure' is everything that is needed.

   For others, you want to add something like

     (setenv "TEXINPUTS"
             (concat "~myself/share/texmf/tex/latex/preview:"
                     (getenv "TEXINPUTS")))
     
     (setenv "TEXDOCS"
             (concat "~myself/share/texmf/doc/latex/styles:"
                     (getenv "TEXDOCS")))

   This just exports the relevant directories for preview-latex; you
might have more to share.  Also, the `TEXDOCS' change is hardly likely
to be effective: most people call `texdoc' from a shell window rather
than from inside of Emacs, and those that are interested in the style
documentation will usually want to have the style itself available
anyhow without having to call LaTeX from within Emacs.

   But at least for people just interested in preview-latex from inside
of Emacs, the augmentation of `TEXINPUTS' will be helpful.  Although it
does not appear like it, under `web2c'-based systems like teTeX, this
invocation will also do the right thing in case `TEXINPUTS' has no
previous value.

