WhizzyTeX1
An Emacs minor-mode
for incremental viewing of
LATEX documents

Didier Rémy

Version 1.00ii,

Abstract: WhizzyTeX is an Emacs minor mode for incrementally viewing LATEX documents that you are editing. It works under Unix with gv and xdvi viewers, but the Active-DVI viewer will provide much better visual effects and offer more functionalities.

1  Installation

To use whizzytex, you need Emacs or XEmacs, latex2e, and bash installed, and at least one DVI or Postscript previewer, such as advi, xdvi, or dvips combined with gv.

WhizzyTeX has been developed under Linux Redhat 7.2 but has not been extensively tested on other platforms. While LATEX and Emacs are quite portable, you may run into compatibility problem with the bash shell-script.

Get the source whizzytex-1.00ii.tgz from the distribution, uncompress and untar it in some working directory, as follows:
gunzip whizzytex-1.00ii.tgz
tar -xvf whizztex-1.00ii.tar
cd whizzytex-1.00ii
Then, the installation can be automatic (default or customized), or manual.

1.1  Automatic installation

By default, all files will be installed in the directory /usr/local/lib/whizzytex/ and Emacs-lisp code will not be byte-compiled. Then, just type:
make all
This will create a Makefile.config file (only if nonexistent) by taking a copy of the template Makefile.config.in. This will also check that the Makefile.config (whether it is the default or a modified version) makes sense. If you wish to change the default configuration, or if your configuration is rejected, see ``Customizing the installation'' below. This will also prepared configured versions of the files for installation.

Finally, to install files to their final destination, type:
make install
See Using WhizzyTeX (Section 2) to test your installation.

1.2  Customizing the installation

To customize the installation, you can edit Makefile.config, manually. You may also use the command
make config
for semi-automatic editions. This will test your system configuration and choose default values accordingly and prompt for confirmation or when a decision need to be taken. Of course, you can combine both, doing manual corrections at the end.

The automatic configuration only check for the existence of commands, but will not test their interface. Moreover, manual configuration allows to choose commands that may not even exists.

Checking Makefile.config
A misconfiguration of your installation, or ---much more subttle--- a misconfiguration of other commands (many installation wrap scripts around standard commands that are sometimes incorrect and break their interface), may lead to systematic errors when launching WhizzyTeX. To prevent delaying such obvious errors, some sanity checks are done on the file Makefile.config before building other files. This includes checking for mandatory bindings and for the conformance of latex and viewers commands to their expected interface. The later is done by simulating the core of a small WhizzyTeX session: a small file is created, a specialed version of latex format is build for that file, and used to run LATEX on on the file; finally, all declared viewers are tested on the DVI output, which open windows, temporarily.

If the sanity check fails, at least part of your configuration is suspicious. If some windows remain opened, your confirguration is likely to be erronesous (and so, even if not detected by the script).

However, if you really know what you are doing, you may bypass the check by typing make config.force, which will stamp your Makefile.config as correct without checking it.

At the end of customization, proceed as described in ``Automatic installation'' (Section 1.1)

Customization guide
By default, WhizzyTeX assumes the standard convention that latex is the command name used to call LATEX, initex, the command name used to build a new format, and that the latex predefined format is latex.

These values may be changed if you have another implementation of LATEX uses other names. Then, just redefine the variables INITEX, LATEX, and LATEXFMT accordingly in the file Makefile.config. For instance, platex could be use the default configuration
INITEX = iniptex
LATEX = platex
LATEXFMT = platex
If you wish to run WhizzyTeX with several configuration, you must choose a default configuration, but you will be able to call WhizzyTeX with another configuration from emacs (see Section 3.1 below).

1.3  Manual installation

Since WhizzyTeX only need three files to run, installation can also be done manually:

1.4  Automatic upgrading

For convenience, the distribution also offers a facility to download and upgrade new versions of WhizzyTeX (this requires wget installed). If automatic upgrading does not work, just do it manually.

All operations should be performed in the WhizzyTeX top directory, i.e. where you untar whizzytex for the first time. We assume that have created a link:
ln -s whizzytex-1.00ii whizzytex
(which will be maintained as a link the current version by the manager). Alternatively, you can use whizzytex-1.00ii in place of whizzytex below. The main commands are:
make -f whizzytex/Manager upgrade
make -f whizzytex/Manager install
The command upgrade will successively download the newest version, unpack it, copy the configuration of the current version to the newest version, and bring the newest version up-to-date. The command install will install files of the newest version.

The following command will (re-)install and old version:
make VERSION=<version> download downgrade install

2  Using WhizzyTeX

2.1  Loading whizzytex.el

Maybe, whizzytex is already installed on your (X)Emacs system, by trying
ESC x whizzytex-mode RET
If this works, skip this section. Otherwise, you should first load the library whizzytex.el or, better, declare it autoload. To do this permanently, include the following declaration in your Emacs startup file (probably is ~/.emacs).
(autoload 'whizzytex-mode
"/usr/local/lib/whizzytex/lisp/whizzytex.el"
"WhizzyTeX, a minor-mode WYSIWIG environment for LaTeX" t)
(where /usr/local/bin/whizzytex/lisp/whizzytex.el is the exact location of whizzytex.el, which depends on your installation.) If whizzytex.el in your (X)Emacs load-path, or if you have adjusted this variable appropriately, you can simply write:
(autoload 'whizzytex-mode "whizzytex"
"WhizzyTeX, a minor-mode WYSIWIG environment for LaTeX" t)

2.2  Quick start

WhizzyTeX runs as a minor mode of Emacs to be launched on an LATEX Emacs buffer. The extension of the buffer should be .tex. WhizzyTeX also understands .ltx extensions, but gives priority to the former when it has to guess the extension. Other extensions are not possible.
The file attached to the buffer must exists and either be a well-formed LATEX source file, or be mastered, i.e. loaded by another LATEX source file. Thus, when the buffer is does not look well-formed (it does not contain a \begin{document} command), WhizzyTeX will search for its master file, asking the user if need be, so as to first launch itself on a buffer visiting the master file. In particular, an empty buffer will be considered as beeing mastered, which may not be what you intend.
To start WhizzyTeX on either kind of buffer, type:
ESC x whizzytex-mode RET
By default, this should add new bindings so that you can later turn mode on and off with key strokes C-c w. This will also add a new menu Whizzy in the menu bar call ``the'' menu below.

When whizzytex-mode is started for the first time on a new buffer, it attempts to configure buffer local variables automatically by examining the content of file, and using default values of global bindings.

You may customize default settings globally by running appropriate hooks or locally by inserting appropriate comments in the source file ---see the manual below.

You may also change the settings interactively using the menu, or tell whizzytex-mode to prompt the user for local customization by passing prefix argument 4 (using, for instance, key sequence C-u C-c w).

2.3  Editing

Once whizzytex-mode is on, just type in as usual. WhizzyTeX should work transparently, refreshing the presentation as you type or move into your LATEX buffer.

Additionally, a gray overlay is put outside of the current slice (the slice is the region of your buffer under focus, which is automatically determined by WhizzyTeX). When a LATEX error occurs and it can be localized in the source buffer, a yellow overlay also is put on the region around the error, and removed when the error is fixed.

Furthermore, when an error is persistent for several slices or some amount of time, the interaction-buffer will pop up with the error log (this option can be toggled on and off with the Auto interaction menu entry).

2.4  Recovering from errors

WhizzyTeX makes a good attempt at doing everything automatically. However, there remains situations where the user need to understand WhizzyTeX ---when WhizzyTeX does not seem to understand the user anymore.

For that purpose, WhizzyTeX report processing and error messages in its interaction window. Thus the first help for debugging is always to look at interaction window (buffer *filename.tex* (where filename stands for the name of the file associated with the main buffer in case several files are composing your document).

This window will pop up and down automatically when an error persists or disappear. For debugging, you may switch this Auto interaction mode off so as to see the buffer permanently. You may also set the mark to prevent the region between (point-min) and (mark) to be erased automatically (as long as the buffer is visible).

The Log... menu entry can be used to view log files of last actions performed by whizzytex.

2.5  Error during initialization

The most delicate part of WhizzyTeX is when starting whizzytex-mode, and usually for the first time in a new buffer, since at that time all kinds of initialization errors may occur (in addition to LATEX errors.

WhizzyTeX will attempt to identify the error and report appropriate messages in the interaction buffer. (In case an error occurs ---or nothing happens--- always have a look at the interaction buffer, even if it did not prompted automatically.)

Here are a description of errors during initialization mostly in chronological order.

Emacs fails during setup
This is all under Emacs, so easily under control. Normally, Emacs should report error messages. See the documentation for explanations.

In case, of uncaught fatal errors, you may ESC X toggle-debug-on-error to get help from Emacs, and try to fix the problem.

Emacs cannot find whizzytex
This should typically be an installation problem, where the variable whizzytex-command-name is erroneous (maybe you need to give the full path). Try to evaluate (shell-command whizzytex-command-name) in the minibuffer, which of course should fail, but only after the command has been reached.

Whizzytex cannot build a format
Then WhizzyTeX will refuse to start. This is most probably an error in your macros. Try to compile LATEX your file. Also try to erase all auxiliary files, since if those are erroneous, they may disturb the creation of the format (which loads some of the auxiliary files).

There still could be some bad interaction between your macros and WhizzyTeX macros, but this is very rare.

Whizzytex cannot launch the previewer
Usually, this is because whizzytex received wrong previewer parameter. See the command echoed in the interaction buffer or try to evaluate (whizzy-get whizzytex-view-mode).

Other errors
There are two remaining problems that could happen at launch time, but that are not particular to launch time: WhizzyTeX could not recompiled the whole document or the current slice. However, these should not be fatal. In the former case, whizzytex will proceed, ignoring the whole document (or using the slice instead if you are in duplex mode). In the later case, whizzytex will replace the slice by an empty slice ---and print a welcoming document, as if you launch WhizzyTeX outside of any slice.

2.6  Errors during normal edition

After initialization time, WhizzyTeX will keep recompiles slices as you type or move, but also recompiles the format and the whole document when you save a file. Each of this step may failed, but this should not be fatal, and Emacs should report the error, possible pop up the interaction window, and continue.

Whizzytex fails on the current slice
This should not be considered as an error, it must happen during edition. In particular, WhizzyTeX is not much aware of LATEX and could very well slice in the middle of the typesetting of an environment or a macro command. This should not matter, since the erroneous slice will be ignore temporarily until the slice is correct again.

Whizzytex keeps failing on the current slice
The slice can also be erroneous because the Emacs did not correctly inferred where to insert the cursor, which may slice erroneous, although what you typed is correct. Hopefully, this will not occur too often, and disappear as you move the point. It should also disappear if you switch off both Point visible and Page to Point options, which is actually a good thing to do when you suspect some misbehavior. This will make WhizzyTeX more robust, but less powerful and more boring.

Whizzytex does not seem to slice at all
The interaction window does not produce any output. Try to move in the slice, or to another slice.

If nothing happens, check the interaction window, to see if it did attempt to recompile the slice. If nothing happens in the interaction window, check for Emacs messages (in the *Messages* buffer). You may also check for the presence (and content) of the slice by visiting _whizzy_filename.tex or
_whizzy_filename/input/_whizzy_name.new
If neither file exists, it means that Emacs did not succeed to slice, which you may force by evaluating (whizzy-observe-changes t). This can be run in even if whizzytex-mode is suspended, which may avoid automatic processing of slices, and their erasure.

If the slice is present, you may try to compile it by hand (outside of Emacs) with
latex '&_whizzy_filename' _whizzy_filename.tex
and see if it succeeds.

Reformatting failed
Formatting errors are fatal during initialization, but accepted once initialized. In case of an error during reformatting, WhizzyTeX will ignore the error and continue with the old format. This means that new macros may be ignored leading to further slicing errors. When rebuilding the format failed, the mode-line string will display the suffix FMT until the error is fixed. See the interaction buffer or select format from the log... menu entry).

You may also force reformatting by typing the reformat command in the interaction buffer.

Whizzytex cannot process the whole document
This is very likely a problem with you document, so try to LATEX it first. There is a small possibility of strange interaction between your macros and WhizzyTeX package. Try to turn options Page to Point and Point visible off and retry. This will make WhizzyTeX more robust (but also less powerful and more boring).

2.7  Debugging

If you are completely lost, and none of the above helped, you may need some debugging. If this is your first attempt at WhizzyTeX, you should suspect your configuration. You should them try with the examples of the distribution. Otherwise, you may rollback to a file and configuration that used to work, and make incremantal changes.

You can turn emacs debug mode on and off with
ESC x toggle-debug-on-error RET
You can also turn whizzytex debug mode on and off by typing either line in the interaction window:
debug on
debug off

3  Manual

This section describes how to use and parameterize WhizzyTeX.

Since, most of the documentation is available online in Emacs from the Help entry of the menu by following hyperlinks, we keep this section to a minimal, so as to avoid redundancy.

Alternatively, you can type
ESC x describe-function RET whizzytex-mode RET
(In XEmacs, you may need to use
ESC x hyper-describe-function RET whizzytex-mode RET
instead of describe-function to see hyper-links.)

Section 3.1, 3.2 and 3.3 are also available as online help.

3.1  Configuration

3.1.1  Emacs global configuration

See Emacs help for whizzy-default-bindings and whizzytex-mode-hook for list of bindings.

The Emacs on-line help for whizzytex-mode lists all user-configurable variables, which may be given default values in your Emacs startup file to be used instead of WhizzyTeX own default values.

3.1.2  File-based configuration

A configuration line is one that starts with regexp prefix ``^%; +'' followed by a configuration keyword. If two configuration lines have the same keyword, only the first one is considered. The argument of a configuration line is the rest of the line stripped of its white space.

The keywords are:
whizzy-master
ámasterñ
This only makes sense for a file loaded by a master file. ámasterñ is the relative or full name of the master file. Optional surrounding quotes (character ") are stripped off, so that "foo.tex" and foo.tex are equivalent.

whizzy
[ áslicingñ ] [ áviewerñ [ ácommandñ ] ] [ -pre ámakeñ ] [ -tex ásuffixñ ]
[ -initex áinitexñ ] [ -latex álatexñ ] [ -fmt áformatñ ] [ -duplex ]
All arguments are optional, but if present they must appear in order:
áslicingñ

is determines the way the document is sliced (see section 3.2).

áviewerñ

is the type of viewer and can only be one of -advi, -xdvi, or -ps (see section 3.3)

ácommandñ

is optional and is the command used to call the viewer (of course, it should agree with áviewerñ).

-pre ámakeñ

tells WhizzyTeX to use the command ámakeñ to preprocess the slice. The command ámakeñ will receive one argument _whizzy_basename.new and should produce _whizzy_basename.tex (or _whizzy_basename.ltx if the extension of the master file is .ltx). By default, mv is simply used.

The Unix make can itself be used as a preprocessor (with an appropriate Makefile). However, one may have to work around make's notion of time (using FORCE), which is usually too rough. This is safe, since WhizzyTeX tests itself for needed recompilations.

-initex áinitexñ


uses áinitexñ for the initex command instead of the value assign to INITEX in Makefile.config (or whizzytex)

-latex álatexñ


uses álatexñ for the latex command instead of the value assign to LATEX in Makefile.config (or whizzytex)

-fmt áformatñ


uses áformatñ for the latex format instead of the value set to LATEXFMT in Makefile.config (or whizzytex). This can either be used in combination with -latex and -initex, or alone. For instance, hugelatex could be used (depending on your LATEX configuration) to build a larger format to process huge files.

-duplex

tells WhizzyTeX to launch another window with the whole document (which is recompiled every time the source buffer is saved).

With -advi previewers, both views communicate with Emacs and can be used to navigate through source buffers and positions.

For instance, a typical configuration line will be:
   %; whizzy subsection -dvi "xdvi -s 3"
It tells whizzytex to run in subsection slicing mode and use a dvi style viewer called with the command xdvi -s 3. This is also equivalent to
   %; whizzy subsection -dvi xdvi -s 3
since Emacs removes outer double-quotes in option arguments.

A more evolved configuration line is:
   %; whizzy -pre make -initex iniptex -latex platex -fmt platex
It tells WhizzyTeX to use iniptex and platex comands instead of initex and latex and to use the format file platex.fmt instead of latex.fmt. Moreover, it should use make to preprocess files.

whizzy-paragraph
regexp
This sets the Emacs variable whizzy-paragraph to regexp.

3.2  Modes

WhizzyTeX recognizes three modes slide, section, and document. The mode determines the slice of the document being displayed and how frequently updates occurs.
slide


The mode slide is mainly used for documents of the class seminar. In slide mode, the slide is the text between two \begin {slide} comments (thus, the text between two slides is displayed after the preceding slide).

In slice modes, overlays are ignored i.e. all overlays all displayed in the same slide, unless a command \overlay {n} occurs on the left of the point, on the same line (if several commands are on the same line, the right-most one is taken), in which case only layers p £ n are displayed.

section
In section mode, the slice of text is the current chapter, section.

subsection
As section but also slice at subsections.

paragraph
The paragraph mode is a variation on section mode where, the separator whizzy-paragraph is defined by the user (set to two empty lines by default) instead of using \section and \subsection commands. subsection.

document
The document take the region between \begin{document} and \end{document} as the slice.

none
In none slicing mode, there is no sectioning unit at all and the whole document is recompiled altogether. Currently, pages are not turned to point and the cursor is not shown in document mode, because full documents are not sliced. (A slicing document mode could be obtained by working in paragraph mode, with an appropriate regexp.)

3.3  Viewer types

See help for whizzy-viewers.

The previewer types can have three possible values: -ps, -dvi, or -advi.

The previewer type should agree with the previewer command in several ways: Then, the previewer command is the command to call the previewer. This string will be passed as such to the WhizzyTeX shell-script. Note that the name of the dvi or postscript file will be appended to the previewer command.

3.4  Watching other files

WhizzyTeX is designed to watch other files and not just the slice saved by Emacs. In fact, it watches any file dropped in the pool directory. For instance, if your source file uses images, you can just change the image and drop the new version in the pool. Then WhizzyTeX will pick the new version, move it to the working directory and recompile a new slice. Be aware of name clashes: if you drop a file in the pool, it will automatically be move to the working directory with the same name, overriding any file of the same name sitting there.

However, activity is entirely controlled by Emacs, since after every iteration WhizzyTeX waits for Emacs to send a new command (usually the empty command that means iterate again). Hence, other files will only be taken into account at the next iteration. If you really wish these files to be watched you need to instrument emacs to send and empty line input to the interaction buffer regularly, even when idle.

3.5  Frequency of recompilation

To obtain maximum WhizzyTeX effect, a new slice should be save after any edition changed or any displacement that outside of the current slice. However, to avoid overloading the machine with useless and annoying refreshments, some compromise is made, depending on Emacs several parameters: edition v.s. move Emacs last commands, successful v.s. erroneous last slice, and the duration of last slice recompilation. This usually works well. However, different behavior may wish to be obtained in different situations. For instance, when editing on a lab-top, one may wish to save batteries by keeping the load rather low, hence not using the full power of the processor. Conversely, one may wish WhizzyTeX to be as responsive as possible. There is an function whizzy-load-factor that control a variable of the same name, which can be used to adjust the responsiveness (by increasing or decreasing the load-factor). This simply adds extra delays between slicing.

The format is automatically recompiled at the beginning of each session, and whenever the buffer containing the file is saved. That is, to load new packages or define new global macros (before the \begin{document}), it suffices to save the current file.

3.6  Cross-references, page and section numbers

The slice is always recompiled with the .aux file of the whole document. In paragraph mode, cross references and section numbers are recompiled whenever the buffer itself is saved (manually). This recompilation operates in batch and concurrently with the recompilation of slices, so it may take several slices before the new counters or references are adjusted.

(The recompilation of the whole document is off in slide mode.)

4  Viewers

4.1  Viewing with Active-Dvi

Active-DVI is a DVI previewer with several additional features. In particular, it recognizes extra specials, some of which are particular useful for whizzytex that allows a two way communication between the source Emacs buffer and the previewer:

4.2  Defining your own previewer

To use your own command as a previewer, you must choose either type -dvi or -ps . In particular, your previewer should accept SIGUSR1 (for -dvi) signal or SIGHUP (for -ps) signal and respond by reloading the file.

4.3  Viewing with acroread

This does not work because they is no simple way to tell acroread to reload its file in batch.

5  Implementation

In short, WhizzyTeX is selecting a small slice of the document that you are editing around the cursor (according to the selected mode) and redisplay the slice incrementally as it changes through edition. The rest of this section briefly describe these three parts2, and their interactions.

5.1  Emacs code

The main trick is to use post-command-hook to make Emacs watch changes. It uses buffer-modified-tick to tell if any editing has actually occurred, and compare the point position with the (remembered) position of the region being displayed to see if saving should occur. It uses sit-for to delay slicing until at least the time of slice computation has ellapsed since last saving, a significant number of editing changes has occurred, or iddleness.

WhizzyTeX can also display the cursor position, in which case slices are also recomputed when the cursor moves, but with lower priority.

5.2  LATEX code

The main TeX trick is to build a format specialized to the current document so as to avoid reloading the whole macros at each compilation. This is (almost3) entirely transparent, that is, the source file does not have to understand this trick.

This is implemented by redefining \documentclass which in turn redefines \document to execute \dump (after redefining \document to its old value and \documentclass so that it skips everything till \document). This is robust ---and seems to work with rather complex macros.

The specialized format can be used in two modes: by default it expects a full document: it them dumps counters at sectioning commands (chapters, sections, and subsections). This is useful to correctly numberred sections and pages on slices.

There are also a a few other used to get more advanced behavior, especially to dump source line numbers and file names so that the previewer can transform clicks into source file positions.

When building the format, WhizzyTeX also look for a local file of name whizzy.sty, which if existing is loaded at the end of the macros. This may be used to add other macros in whizzy mode, e.g. some TeX environments may be redefined to changed they type setting, according to whether the current line is inside or outside the environment. (We have written such an extension for an exercise package that sends the answers at the end in an appendix, unless the cursor is inside the answer, in which case the answer is in-lined.)

5.3  Bash code

There is no real trick there. This is a shell-script watching the pool (a directory where slices and other new version of files must be dropped). It them recompiles a slice and wait for input (in stdin). It recognizes a few one-line commands as input reformat, dupplex, and by default just watch for the presence of a new slice. It recompiles the format file (and the page and section number, but in batch mode) whenever the source file (its Unix date) has changed and recompiles the slice whenever it is present (since WhizzyTeX renames ---hence removes--- the slice before processing it).

If the file has been recompiled successfully, it triggers the previewer (ghostscript or xdvi) so that it rereads the dvi or ps file. Otherwise, it processes the TeX log file and tries to locate the error. It then sends part of the log file with annotations to the *TeX-shell* buffer from which Emacs has been WhizzyTeX, so that Emacs can report the error.

5.4  Interaction between the components

The control is normally done by Emacs, which launches and kills the Unix daemon. Quitting the previewer should be noticed by the daemon, which tells Emacs to turn mode off before exiting.

Muliple WhizzyTeX running on the same file would certainly raise racing conditions between files and would not make sense. For that purpose, the daemon pid is saved in a file and WhizzyTeX will kill any old WhizzyTeX process on startup.

6  Whizzy dream

When used together with Active-DVI, WhizzyTeX could be made much mode powerful. In particular, it would be quite easy to to lift WhizzyTeX from an incremental viewer to an assistant editor.

Active-DVI could easily provide a notion of active boxes. These would be recognized by \special annotations preceeding boxes. Active boxes would be autoraise on focus and could be moved or resized with the mouse. Rather than displaying actions on screen, which would be unaware of TeX position stategies, actions should rather be reported in stdout, as is already done for positions.

Active-DVI actions could then easily be interepreted by WhizzyTeX by adjusting or inserting the correct vertical or horizontal dimension around active objects, and processed in the next slice. Thanks to the short incremental loop, this would (almost) appear as if actions where executed by Active-DVI.


1
Whizzytex is free software, Copyright ©2001, 2002 INRIA and distributed under the GNU General Public License (See the COPYING file enclosed with the distribution).
2
This section is not quite up-to-date, hence it puts emphasis on the original design, but several aspects have changed significantly since the first version. Implementation of more recent features is thus omitted.
3
\begin{document} should be typed as such without any white white space

This document was translated from LATEX by HEVEA.