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

Didier Rémy

Version 1.00,

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.00.tgz from the distribution, uncompress and untar it in some working directory, as follows:
gunzip whizzytex-1.00.tgz
tar -xvf whizztex-1.00.tar
cd whizzytex-1.00
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) and then process configured version of the files.

To customize the installation, you either edit and modify Makefile.config, manually; you can also run
make config
which will prompt for choices and override the default Makefile.config (which you can again edit to adjust choices). Check the output Makefile.config and edit manually if necessary. At the end of customization, run make all again.

Finally, to install files to their destination, type:
make install

1.2  Manual installation

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

1.3  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.00whizzytex
(which will be maintained as a link the current version by the manager). Alternatively, you can use whizzytex-1.00 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
(all emacs-commands of the manual should followed by the Return key). 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/bin/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 a LATEX Emacs buffer. To start it, 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 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 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 '&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).

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
(In XEmacs, you may need to use
ESC x hyper-describe-function RET whizzytex-mode
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.

See help for whizzytex-mode a list of user-configurable variables, to which you may give default values in your Emacs startup file that will 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ñ ] [ -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 basename.new and should produce basename.tex. 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.

-fmt FORMAT


By default WhizzyTeX build a specialized format of the latex document format by loading macros of your document. The above option will use FORMAT instead of latex as the initial format. 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 -dvi xdvi
tells whizzytex not to take the whole document as a slice use a dvi previewer called with the command xdvi

More evolved configuration lines are:
   %; whizzy section -advi dview -whizzy -pre make -duplex
   %; whizzy section -advi "dview -whizzy" -pre make -duplex
These two lines are equivalent, since Emacs will remove outer quotes in option arguments. They both tell whizzytex to be be launch in section mode and use a dvi previewer called with the command dview -whizzy (a shell-script to be defined), use make to preprocess files and provide duplex views.

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.

By default, WhizzyTeX send itself a kill -STOP signal when it finds nothing in the pool (this allows you to let WhizzyTeX inactive for hours without consuming any CPU. Correspondingly, when Emacs drops a new file in the pool, it sends a kill -CONT signal. If you want to watch other files and not have to deal with waking up WhizzyTeX you can pass the extra option -nonstop to the whizzytex command-line; then it will sleep instead of stopping itself, and will periodically watch for news files in the pool without you need to signal it to continue. In case you want to keep with the stop-mode and wake it up explicitly, the process number is stored in the file ._whizzy_$BASICNAME.tex.

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: For instance, your could then set Hence, my Emacs setup executes
(set-default 'whizzy-viewers
  (("-advi" "advi -html Start-Document") 
   ("-dvi" "xdvi") ("-ps" "gv")))))

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.