home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-04 | 41.4 KB | 1,092 lines |
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 1 (of 2)."
- # Contents: MANIFEST README macro.pp tex-mode.el
- # Wrapped by allbery@uunet on Sun Mar 25 19:31:13 1990
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'MANIFEST' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'MANIFEST'\"
- else
- echo shar: Extracting \"'MANIFEST'\" \(269 characters\)
- sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
- X File Name Archive # Description
- X-----------------------------------------------------------
- X MANIFEST 1 This shipping list
- X README 1
- X macro.pp 1
- X tex-mode.el 1
- X texpp.c 2
- END_OF_FILE
- if test 269 -ne `wc -c <'MANIFEST'`; then
- echo shar: \"'MANIFEST'\" unpacked with wrong size!
- fi
- # end of 'MANIFEST'
- fi
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(14110 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- X ***************************************************************************
- X * *
- X * texpp TeX preprocessor, Version 1.2. *
- X * Laci Csirmaz, DIMACS - Rutgers *
- X * Feb. 25, 1990 *
- X * *
- X ***************************************************************************
- X * You are granted to use, modify, copy, redistribute this program any *
- X * way you want. However no warranties are made for this program or the *
- X * accopanying documentation. *
- X * *
- X * Please send your comments, suggestions, etc. to: *
- X * csirmaz@cs.rutgers.edu *
- X * *
- X ***************************************************************************
- X
- X
- X Tex Preprocessor M A N U A L
- X
- X 0. Introduction
- X
- X TeX, undoubtedly a very LOGICAL language, does not follow closely enough
- Xthe illogical nature of human beings. Using backslashes everywhere to signify
- Xa special treatment of a word is logical, but, of course, tedious and a bit
- Xboring. Whenever the word "alpha" appears in a text, with higher probability
- Xthan 0.9999 the author wishes the corresponding greek letter to appear, and
- Xnot this word. In the latter unlikely case, s/he is more willing to do some
- Xextra word to make the (now) exception the rule, and save a lot of work.
- X Another drawback is the (also very logical, but unnatural) handling of
- Xmacros. If an operator is applied to a word (or a single letter), TeX
- Xrequires the operator to precede its argument. While in some cases this
- Xis the natural approach, in some cases it is not. As in using a dot, tilde,
- Xor hat on a letter, the natural form is "x tilde", and not what is the
- Xobligatory form, "\tilde x".
- X TeX forbids almost all key combinations to use as macro names, only
- Xsequences of letters are allowed. Why cannot I write "|==" instead of
- X"\model", "/0" for "\empty", or, horribile dictu, "/\" instead of "\wedge"?
- XFormulas written in this way are more readable, and easier to type.
- X Finally, while TeX (and LaTeX) allows to redefine its macros, the user
- Xis usually not aware of its danger. Both plain TeX and LaTeX have a lot of
- Xbuilt-in macros which are absolutely necessary to run them. Redefining any
- Xof them the program simply goes crazy. And, in most of the cases, the user
- Xdoes not even know why the construct is wrong. What happens, for example,
- Xif "\and" is redefined in LaTeX so that it would produce the sign /\ -- a
- Xquite reasonable assumption. To avoid all the problems arising this way, TeX
- Xshould do these definitions locally, which it doesn't.
- X
- X All of the above problems lead to the development of the "texpp" TeX
- Xpreprocessor. Since TeX is quite ambivalent about handling the input layout
- X(often it says to be independent of whitespaces, but two consecutive newlines
- Xsignify a new paragraph, and comments are closed by newlines), I decided to
- Xuse layout a bit more significantly than TeX does. All macro definitions
- Xshould start at the first column. The preprocessor is not intended to be as
- Xgeneral as possible. It has a lot of wired in features (for example, the $
- Xand $$ to start and end math mode), but the C code is available, and (at
- Xleast I hope) can be modified easily. Also, the preprocessor is absolutely
- XNOT for TeX wizards. It can be fooled quite easily e.g. by redefining the
- Xescape character, but as far as it is used as a simple tool it works fine.
- X
- X
- X 1. Shipped files
- X
- X Besides the C source code of the program and this manual, you can find
- Xa sample macro file which show some extra features of texpp. Also I wrote
- Xa tex-mode.el (gnu)emacs template which embeds the 'texpp' preprocessor, and
- Xa dvi viewer.
- X The program was written for UNIX(TM) machines, but the code is highly
- Xportable (at least I hope so). Therefore it should be easy yo transport to
- Xother machines.
- X
- X
- X 2. Macro names
- X
- X Macro name can be any sequence of characters which does not contain
- Xbraces `{' and `}', dollar sign `$', percentage sign `%', and embedded
- Xwhitespaces. `Character' here means a character with ASCII code >=32 and
- X<= 126. Each line of the text is cut at braces and whitespaces, and what
- Xis left is compared against the list of macro names. If there is a hit, then
- Xthe closing braces or white spaces are erased, and the macro text is replaced.
- X
- X 3. Parameters
- X
- X A macro may have up to nine parameters, which can be either before or
- Xafter the macro name. Parameters are parsed starting from the macro name:
- Xeach parameter is either enclosed into braces, or contains no braces and is
- Xenclosed by whitespaces. A parameter must have balanced braces, if any.
- XIn braces, it may have embedded white spaces. Parameters may contain further
- Xmacro names, too, but parameter parsing is done BEFORE macro substitution.
- XTwo macros cannot share parameters. A parameter is always stripped off its
- Xenclosing characters, and then a macro substitution is executed on it. A
- Xparameter can be a macro name with further parameters (see the examples).
- XIf the macro name is enclosed into braces, all its parameters must also be
- Xinside.
- X
- X
- X 4. Macro definition
- X
- X Macros can be defined anywhere. A definition always starts at the first
- Xcharacter of the line, and signified by the key words `%define' or `%mdefine'.
- X(Starting with percentage sign, but NO BACKSLASH is here). The form of a
- Xdefinition is the following:
- X
- X %define <preceeding pars> name <follow up pars> %text% <any comment>
- X
- XLocal parameters are of the form #1, #2, ..., #9. No parameters are required,
- Xthey can appear in any order and in any place. The REPLACEMENT text is enclosed
- Xby `%' characters (thus it cannot contain `%', but of course it may contain
- Xthe `\%' pair!), and is used as it is, with the following exeptions:
- X
- X a) local parameters #1, ... #9 are replaced by the stripped and
- X expanded parameters of the invocation;
- X b) the pair ## is replaced by a single # mark.
- X c) macro calls are expanded.
- X
- XRule b) also applies to the macro name. Thus `#' can also appear in a macro
- Xname, but should be written as `##'. (Of course, when looking for a macro name
- Xin the text, this corresponds to the single character!)
- X Macro definitions starting by `%mdefine' are applied only when in math
- Xor displayed math mode; other definitions are always applicable. The program
- Xassumes that the macro body does not switch these modes.
- X Besides defining macros, you can "undefine" them, too. This comes handy
- Xwhen a macro is used only as an auxiliary in a more complicated definition,
- Xbut not needed later. A new definition "hides" the old one, undefining
- Xrestores the old meaning. This can be done by
- X
- X %undefine name
- Xor
- X %undefine name % <your comment here>
- X
- XIt is an error to undefine a macro which was not defined (or mdefined)
- Xbefore.
- X
- X 5. Auxiliary tools
- X
- X In certain cases it is essential to suppress macro substitution. This
- Xcan be done by applying the `\preserve' keyword to its single parameter:
- X
- X \preserve <anything_which_does_not_contain_whitespace_or_brace>
- Xor
- X \preserve {<any text with balanced braces>}
- X
- XIn the parameter to `\preserve' no macro substitution is made. However,
- X`\preserve' cannot be applied to macro parameters in macro definitions,
- Xsince parameter expansion is done BEFORE substitution.
- X
- X Different extensions of TeX use different macros to switch to and from
- Xmath mode. To comply with them, the following definitions are recognized:
- X
- X %mathmode <string_to_enter_math_mode> <string_leave_math_mode>
- Xand
- X %dispmode <string_to_enter_displayed_math> <string_leaving>
- X
- XThe strings cannot contain white spaces, and if only one string is given in
- Xa definition, then that is used for both entering and leaving math mode.
- XIn LaTeX the following definitions may come handy:
- X
- X %mathmode \( \) %simple math mode
- X %mathmode \math \endmath
- X %dispmode \[ \] %displayed formulas
- X %dispmode \equation \endequation %for numbered formulas
- X
- X
- X 6. Examples
- X
- Xo 6.1. The first example defines the `*16' macro, which repeats its argument
- X sixteen times:
- X
- X %define #1 *2 %#1#1% %define `*2' as an auxiliary macro
- X %define #1 *16 %#1 *2 *2 *2 *2%
- X %undefine *2 %undefine `*2', no more needed
- X
- X Texts `x 1 *16 y' and `x{1}*16 y' expand to `x1111111111111111y'. (Observe
- X that the trailing space after `*16' vanished). At the same time `x 1*16 y'
- X and `x 1 *16y' remain unchanged since the macro name `*16' cannot be
- X extracted. As another example, `x {a b} *16 y' saves the space between `a'
- X and `b', and before the open brace but not after the macro name. So the
- X result is
- X
- X `x a ba ba ba ba ba ba ba ba ba ba ba ba ba ba ba by'
- X
- X
- Xo 6.2. The next example also shows that macro definitions are expanded when
- X defined, and not when invoked. This means, for example, that subsequent
- X macro definitions have no influence on an existing macro definition. This
- X fact is used here:
- X
- X %define [[ %[% define [[ as a macro to be substituted by [
- X %define ]] %]% define ]] as a macro to be substituted by ]
- X %define [ %\{% now define [ to mean \{
- X %define ] %\}% and define ] to mean \}
- X
- X The last two definitions make a text like
- X
- X a = [ 0, 1, 2, ..., n ] + [ 2n, ..., 4n ]
- X
- X to transform to
- X
- X a =\{0, 1, 2, ..., n\}+\{2n, ..., 4n\}
- X
- X while, e.g. a reference can be put into square brackets by using double
- X brackets: ` [[ 1 ]] ' which becomes `[1]'. Changing the last two and first
- X two definitions here, the definition of `[[' becomes identical to that of
- X `[', i.e. with `\{'.
- X
- X
- Xo 6.3. Our third example defines some model-theoretical stuff:
- X
- X %mdefine /\ % \wedge % and sign
- X %mdefine \/ % \vee % or sign
- X %mdefine |-- % \vdash % syntactically follows
- X %mdefine |== % \models % semantically follows
- X %mdefine --> % \rightarrow % implies
- X %mdefine phi % \varphi %
- X %mdefine ALL % \forall %
- X %mdefine not % \neg %
- X %mdefine ... % \ldots % ellipsis notation
- X
- X Since the preprocessor does not treat the backslash as a special symbol,
- X `/\' and `\/' will be recognized without any trouble. The spaces at the
- X end of each definition are necessary because before replacing the macro
- X name, its surrounding white spaces (or braces) are deleted. So displayed
- X formulas can be written as, e.g.
- X
- X $$ |== ALL x ( phi (x) \/ not phi (x) ) $$
- X $$ |-- phi --> ( not phi --> phi ) $$
- X
- X
- Xo 6.4. Sometimes it is convenient to use `**' to denote exponentiation:
- X
- X %mdefine #1 ** #2 %#1^{#2}%
- X
- X Here ` e ** { x ** 2 / 2 } ' or ` e **{x ** 2 /2}' becomes `e^{x^{2}/ 2 } '
- X (look out for the spaces!). The braces around #2 in the definition are
- X necessary to ensure that all the second parameter shows up in the exponent.
- X Without those braces the expanded form of the first form would be
- X `e^x^2/ 2 ', evidently not what was intended.
- X
- X
- Xo 6.5. The next example shows how to use "before" parameters when they are
- X handy:
- X
- X %mdefine #1 tilde %\wildetilde{#1}%
- X %mdefine #1 hat %\wildehat{#1}%
- X
- X After these definition the following text
- X ...
- X a+b tilde = a tilde + b tilde
- X ...
- X expands to
- X ...
- X \wildetilde{a+b}=\wildetilde{a}+\wildetilde{b}
- X ...
- X Which one is easier to read?
- X
- X
- Xo 6.6. To overcome the problem corresponding to greek letters, one can define
- X
- X %define alpha %$\alpha$%
- X
- X (since greek letters are allowed in math mode only.) With this definition,
- X however, there are certain problems. Using this macro in the text `Let alpha
- X be the ...', the substitution mechanism erases ALL the spaces around the word
- X `alpha', and the result is `Let$\alpha$be the ...'. Evidently no what was
- X wanted. Changing the definition to
- X
- X %define alpha % $\alpha$ % now with spaces
- X
- X will put back the spaces both BEFORE and AFTER the word, thus giving
- X Let $\alpha$ be the ...
- X ^^^^^^^^^^-- substituted text
- X Having this latter definition, however, you cannot write alpha's without
- X intervening spaces. Another problem is that this definition cannot be used in
- X math mode! A possible solution is that the macro `alpha' will be used in math
- X mode only, now with the definition
- X
- X %mdefine alpha %\alpha %
- X
- X The above sentence can be written as `Let $alpha$ be the ...'. Also, two
- X consecutive alpha's can be produced as
- X
- X `here are two $alpha$'s: $alpha alpha$'.
- X
- X The word alpha, if found not in math mode, won't change. And, if you want
- X to use the word alpha in math (or displayed) mode, you can use the \preserve
- X keyword:
- X I can write $\preserve alpha$ in math mode.
- X
- X
- Xo 6.7. Strings used to switch to and from math mode are also subject to macro
- X replacement. Thus using the definitions
- X
- X \def\mydisplayformula#1#2{ $$ #2 \leqno #1 $$}
- X %dispmode .EQ .EN
- X %define .EQ #1 % \mydisplayformula{#1}{ %
- X %define .EN % } %
- X
- X an eqn-like construct for display formulas can be used so that the formula
- X number (written after .EQ) appears on the left of the displayed formula.
- X However, if you don't want this number to appear, you still have to submit
- X a parameter, which can be the empty string, i.e. `{}'
- X
- X
- X 7. How to use the preprocessor?
- X
- XTo compile the program on a UNIX machine, simply invoke cc by typing
- X
- X cc texpp.c -o texpp
- X
- XOn certain systems the 'strdup()' function is missing from the standard C
- Xlibrary. In this case, recompile the program by
- X
- X cc -DSTRDUP texpp.c -o texpp
- X
- XThe preprocessor works as a filter. It reads one ore more input files,
- Xprocesses them, and then produces a single output which can be the input
- Xfor TeX. The program can be invoked by typing
- X
- X texpp file1 file2 ... filen -[wa] output_file
- X
- X`file1', ..., `filen' are processed in their given order; a file definition
- Xconsisting of a single `-' sign means read from stdin. The output goes to
- X`output_file', the file is overwritten if the name is preceded by `-w', and
- Xis appended if `-a' is present. Error messages are inserted into the output
- Xand are duplicated at stderr. If no input file is given, the program reads
- Xfrom stdin; if no output file is given, then the output goes to stdout. When
- Xthe program halts, the exit value is 0 if `texpp' run successfully, if any
- Xerror occurred (cannot open a file or processing error) then the exit value
- Xis 1.
- X
- END_OF_FILE
- if test 14110 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'macro.pp' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'macro.pp'\"
- else
- echo shar: Extracting \"'macro.pp'\" \(4392 characters\)
- sed "s/^X//" >'macro.pp' <<'END_OF_FILE'
- X%% ---- TeXpp macro definitions ----
- X%% ---- for plain TeX files ----
- X%%
- X%% A macro definition should fit into a single line. If the definition is
- X%% too long, we can continue after closing the line with a backslash....
- X%%
- X%% - 1. Greek letters ----
- X%mdefine alpha %\alpha %
- X%mdefine beta %\beta %
- X%mdefine gamma %\gamma %
- X%mdefine delta %\delta %
- X%mdefine eps %\varepsilon %
- X%mdefine zeta %\zeta %
- X%mdefine eta %\eta %
- X%mdefine theta %\vartheta %
- X%mdefine iota %\iota %
- X%mdefine kappa %\kappa %
- X%mdefine pi %\pi %
- X%mdefine rho %\varrho %
- X%mdefine chi %\chi %
- X%mdefine phi %\varphi %
- X%mdefine psi %\psi %
- X%mdefine omega %\omega %
- X%mdefine GAMMA %\Gamma %
- X%mdefine DELTA %\Delta %
- X%mdefine LAMBDA %\Lambda %
- X%mdefine PHI %\Phi %
- X%mdefine SIGMA %\Sigma %
- X%%
- X%% -2. Mathematical functions names ----
- X%mdefine log %\log %
- X%mdefine sin %\sin %
- X%mdefine cos %\cos %
- X%mdefine mod %\bmod % as in "i mod 2"
- X%%
- X%% -3. Special symbols ----
- X%mdefine aleph %\aleph %
- X%mdefine l %\ell % written letter
- X%mdefine || %\|% norm sign
- X%mdefine oo %\infty % infinity
- X%mdefine not %\neg % negation sign
- X%mdefine EMPTY %\emptyset % slashed zero
- X%mdefine o|o %\clubsuit %
- X%mdefine <> %\diamondsuit %
- X%%
- X%% doubly written C,N,Q and R letters for
- X%% complex, natural, rational and real numbers
- X%mdefine IC %\hbox{\hbox{C\hskip-0.5em\lower-0.1ex\
- X \hbox{\vrule height1.34ex width0.07em }}\hskip0.50em}%
- X
- X%mdefine IN %\hbox{I\hskip-0.20em I\hskip-0.35em N}%
- X%mdefine IQ %\hbox{\hbox{Q\hskip-0.525em\lower-0.097ex\
- X \hbox{\vrule height1.47ex width0.07em}}\hskip0.50em}%
- X%mdefine IR %\hbox{I\hskip-0.23em R}%
- X%%
- X%% I don't like these thin signs, so I redefined them
- X%%mdefine ALL #1 %\forall #1 \>%
- X%%mdefine EXISTS #1 %\exists #1 \>%
- X%mdefine ALL #1 %{\leavevmode\hbox{\rm V\kern-0.53em\
- X\lower-.5ex\hbox{-}}\kern0.1em} #1 \>%
- X%mdefine EXISTS #1 %{\Xi\kern-0.37em{\bf I}} #1 \>%
- X%%
- X%% -4. Operators ----
- X%mdefine /\ %\wedge % and sign
- X%mdefine _/\_ %\bigwedge% big and sign
- X%mdefine \/ %\vee % or sign
- X%mdefine ~\/~ %\bigvee % big or sign
- X%mdefine +- %\pm % plusminus
- X%mdefine COMP %\circ % small circle (composition)
- X%mdefine CROSS %\times % cross for vectors
- X%mdefine BULL %\bullet % full small circle
- X%mdefine dot %\cdot % centered dot (multiplication)
- X%mdefine UNION %\cup % small union symbol
- X%mdefine METS %\cap % small intersection symbol
- X%% +/-/= sign and a dot on it
- X%mdefine .+. %{\mathrel{\> +\hbox{\hskip-0.565em\
- X\lower-1.8ex\hbox{.}}\hskip0.4em}}%
- X%mdefine .-. %{\mathrel{\> -\hbox{\hskip-0.55em\
- X\lower-1.2ex\hbox{.}}\hskip0.4em}}%
- X%mdefine .=. %\doteq %
- X%%
- X%% -5. Relations ----
- X%mdefine == %\equiv % equivalence
- X%mdefine !== %\not\equiv % slashed equivalence
- X%mdefine != %\not= % not equal
- X%mdefine <= %\leq % less than or equal to
- X%mdefine >= %\geq %
- X%mdefine SUBS %\subset % subset of
- X%mdefine EXTS %\supset % extension of
- X%mdefine in %\in % element
- X%mdefine !in %\notin% % not an element
- X%mdefine |-- %\vdash % proves
- X%mdefine !|-- %\not\vdash % not proves
- X%mdefine |== %\models % semantically follows
- X%mdefine !|== %\not\models %
- X%%
- X%% -6. Arrows ----
- X%mdefine --> %\rightarrow %
- X%mdefine <--> %\leftrightarrow %
- X%mdefine <-- %\leftarrow %
- X%mdefine ==> %\Rightarrow %
- X%mdefine <==> %\Leftrightarrow %
- X%mdefine ==> %\Rightarrow %
- X%mdefine |--> %\mapsto %
- X%%
- X%% -7. Miscellaneous ----
- X%mdefine ... %\ldots % ellipsis
- X%mdefine ..., %\ldots,% dots followed by a comma
- X%mdefine =def % \>{\buildrel \rm def \over =}\> %
- X%mdefine <: %\langle % left angular bracket
- X%mdefine :> %\rangle % right angular bracket
- X%mdefine [[ %[\![% double open [
- X%mdefine ]] %]\!]% double closing ]
- X%%
- X%mdefine #1 tilde %\widetilde{#1}% put a tilde
- X%mdefine #1 bar %\overline{#1}% put a line over
- X%mdefine #1 hat %\wildehat{#1}% put a hat (^)
- X%mdefine #1 vec %\overrightarrow{#1}% put a --> at the top
- X%mdefine sub #1 %_{#1}% for a subscript
- X%mdefine sup #1 %^{#1}% for a superscript
- X%%
- X\def\mydisplayformula#1#2{ $$ #2 \leqno #1 $$}
- X%define .EQ #1 %\mydisplayformula{#1}{%
- X%define .EN %}%
- X%dispmode .EQ .EN
- X%%
- X%define LEMMA #1 %\proclaim Lemma #1 %
- X%define PROOF. %\noindent{\bf Proof.} %
- X%define THEOREM #1 %\proclaim Theorem #1 %
- X%define QED % {\vrule height 7pt depth 1pt width 7pt} % back box
- X%mdefine iff %{\ \ \rm iff \ \ }%
- X
- X
- END_OF_FILE
- if test 4392 -ne `wc -c <'macro.pp'`; then
- echo shar: \"'macro.pp'\" unpacked with wrong size!
- fi
- # end of 'macro.pp'
- fi
- if test -f 'tex-mode.el' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'tex-mode.el'\"
- else
- echo shar: Extracting \"'tex-mode.el'\" \(20255 characters\)
- sed "s/^X//" >'tex-mode.el' <<'END_OF_FILE'
- X;; TeX mode commands.
- X;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
- X;; Rewritten following contributions by William F. Schelter
- X;; and Dick King (king@kestrel).
- X;; Modified August 1986 by Stephen Gildea <mit-erl!gildea> and
- X;; Michael Prange <mit-erl!prange> to add LaTeX support and enhance
- X;; TeX-region.
- X;; Added TeX-directory and reorganized somewhat gildea 21 Nov 86
- X;; Modified to handle TeX preprocessors by csirmaz@cs.rutgers.edu 21 Nov 89
- X
- X;; This file is part of GNU Emacs.
- X
- X;; GNU Emacs is distributed in the hope that it will be useful,
- X;; but WITHOUT ANY WARRANTY. No author or distributor
- X;; accepts responsibility to anyone for the consequences of using it
- X;; or for whether it serves any particular purpose or works at all,
- X;; unless he says so in writing. Refer to the GNU Emacs General Public
- X;; License for full details.
- X
- X;; Everyone is granted permission to copy, modify and redistribute
- X;; GNU Emacs, but only under the conditions described in the
- X;; GNU Emacs General Public License. A copy of this license is
- X;; supposed to have been given to you along with GNU Emacs so you
- X;; can know your rights and responsibilities. It should be in a
- X;; file named COPYING. Among other things, the copyright notice
- X;; and this notice must be preserved on all copies.
- X
- X;; Still to do:
- X;; Make TAB indent correctly for TeX code. Then we can make linefeed
- X;; do something more useful.
- X;;
- X;; Have spell understand TeX instead of assuming the entire world
- X;; uses nroff.
- X;;
- X;; The code for finding matching $ needs to be fixed.
- X
- X;;;
- X;;; To costumize TeX preprocessing, you can put the following lines
- X;;; into the .emacs init file:
- X;;; (defun set-my-TeX-filter-default ()
- X;;; (setq TeX-show-dvi-command "your favorite DVI view program")
- X;;; (setq TeX-filter "...here the filter with full path...")
- X;;; (setq TeX-filter-args '("...first macro file with full path..."
- X;;; "...second macro file with full path..."
- X;;; "-" ;;;for the buffer
- X;;; "-a")) ;;;append the output
- X;;; )
- X;;; (setq TeX-mode-hook (if (boundp 'TeX-mode-hook)
- X;;; (append TeX-mode-hook 'set-my-TeX-filter-default)
- X;;; 'set-my-TeX-filter-default)
- X;;; )
- X;;; If you want to use 'ispell' to check TeX text, use the following in
- X;;; your .emacs init file:
- X;;; (require 'ispell)
- X;;; (set-default 'ispell-filter-hook shell-file-name)
- X;;; (set-default 'ispell-filter-hook-args
- X;;; '("-f" "-c" "(detex -iw | tr -cs A-Za-z \\\\012)"))
- X
- X
- X;;;
- X
- X(provide 'tex-mode)
- X
- X(defvar TeX-directory "/tmp/"
- X "*Directory in which to run TeX subjob. Temporary files are
- Xcreated in this directory.")
- X(defvar TeX-dvi-print-command "lpr -d"
- X "*Command string used by \\[TeX-print] to print a .dvi file.")
- X(defvar TeX-show-dvi-command "texx"
- X "*Command used by \\[TeX-view-dvi] for screen view the dvi file")
- X(defvar TeX-show-queue-command "lpq"
- X "*Command string used by \\[TeX-show-print-queue] to show the print queue
- Xthat \\[TeX-print] put your job on.")
- X(defvar TeX-default-mode 'plain-TeX-mode
- X "*Mode to enter for a new file when it can't be determined whether
- Xthe file is plain TeX or LaTeX or what.")
- X
- X(defvar TeX-command nil
- X "The command to run TeX on a file. The name of the file will be appended
- Xto this string, separated by a space.")
- X(defvar TeX-filter ()
- X "*Filter to produce a file by \\[TeX-region] on which TeX is called.")
- X(defvar TeX-filter-args '()
- X "*Arguments to the filter TeX-filter")
- X(defvar TeX-trailer nil
- X "String appended after the end of a region send to TeX by \\[TeX-region].")
- X(defvar TeX-start-of-header nil
- X "String used by \\[TeX-region] to delimit the start of the file's header.")
- X(defvar TeX-end-of-header nil
- X "String used by \\[TeX-region] to delimit the end of the file's header.")
- X(defvar TeX-shell-cd-command "cd"
- X "Command to give to shell running TeX to change directory. The value of
- XTeX-directory will be appended to this, separated by a space.")
- X(defvar TeX-zap-file nil
- X "Temporary file name used for text being sent as input to TeX.
- XShould be a simple file name with no extension or directory specification.")
- X
- X(defvar TeX-mode-syntax-table nil
- X "Syntax table used while in TeX mode.")
- X
- X(defun TeX-define-common-keys (keymap)
- X "Define the keys that we want defined both in TeX-mode
- Xand in the TeX-shell."
- X (define-key keymap "\C-c\C-k" 'TeX-kill-job)
- X (define-key keymap "\C-c\C-l" 'TeX-recenter-output-buffer)
- X (define-key keymap "\C-c\C-q" 'TeX-show-print-queue)
- X (define-key keymap "\C-c\C-p" 'TeX-print)
- X (define-key keymap "\C-c\C-v" 'TeX-view-dvi)
- X )
- X
- X(defvar TeX-mode-map nil "Keymap for TeX mode")
- X
- X(if TeX-mode-map
- X nil
- X (setq TeX-mode-map (make-sparse-keymap))
- X (TeX-define-common-keys TeX-mode-map)
- X (define-key TeX-mode-map "\"" 'TeX-insert-quote)
- X (define-key TeX-mode-map "\n" 'TeX-terminate-paragraph)
- X (define-key TeX-mode-map "\e}" 'up-list)
- X (define-key TeX-mode-map "\e{" 'TeX-insert-braces)
- X (define-key TeX-mode-map "\C-c\C-r" 'TeX-region)
- X (define-key TeX-mode-map "\C-c\C-b" 'TeX-buffer)
- X (define-key TeX-mode-map "\C-c\C-f" 'TeX-close-LaTeX-block)
- X )
- X
- X(defvar TeX-shell-map nil
- X "Keymap for the TeX shell. A shell-mode-map with a few additions")
- X
- X;(fset 'TeX-mode 'tex-mode) ;in loaddefs.
- X
- X;;; This would be a lot simpler if we just used a regexp search,
- X;;; but then it would be too slow.
- X(defun tex-mode ()
- X "Major mode for editing files of input for TeX or LaTeX.
- XTrys to intuit whether this file is for plain TeX or LaTeX and
- Xcalls plain-tex-mode or latex-mode. If it cannot be determined
- X\(e.g., there are no commands in the file), the value of
- XTeX-default-mode is used."
- X (interactive)
- X (let (mode slash comment)
- X (save-excursion
- X (goto-char (point-min))
- X (while (and (setq slash (search-forward "\\" nil t))
- X (setq comment (let ((search-end (point)))
- X (save-excursion
- X (beginning-of-line)
- X (search-forward "%" search-end t))))))
- X (if (and slash (not comment))
- X (setq mode (if (looking-at "documentstyle")
- X 'latex-mode
- X 'plain-tex-mode))))
- X (if mode (funcall mode)
- X (funcall TeX-default-mode))))
- X
- X(fset 'plain-TeX-mode 'plain-tex-mode)
- X(fset 'LaTeX-mode 'latex-mode)
- X
- X(defun plain-tex-mode ()
- X "Major mode for editing files of input for plain TeX.
- XMakes $ and } display the characters they match.
- XMakes \" insert `` when it seems to be the beginning of a quotation,
- Xand '' when it appears to be the end; it inserts \" only after a \\.
- X
- XUse \\[TeX-region] to run TeX on the current region, plus a \"header\"
- Xcopied from the top of the file (containing macro definitions, etc.),
- Xrunning TeX under a special subshell. \\[TeX-buffer] does the whole buffer.
- X\\[TeX-print] prints the .dvi file made by either of these,
- X\\[TeX-view-dvi] shows a dvi view.
- X
- XUse \\[validate-TeX-buffer] to check buffer for paragraphs containing
- Xmismatched $'s or braces.
- X
- XSpecial commands:
- X\\{TeX-mode-map}
- X
- XMode variables:
- XTeX-directory
- X Directory in which to create temporary files for TeX jobs
- X run by \\[TeX-region] or \\[TeX-buffer].
- XTeX-filter
- X program (maybe with full path) to filter the region or buffer
- X before calling tex or latex.
- XTeX-filter-args
- X list of arguments to TeX-filter.
- XTeX-dvi-print-command
- X Command string used by \\[TeX-print] to print a .dvi file.
- XTeX-show-queue-command
- X Command string used by \\[TeX-show-print-queue] to show the print
- X queue that \\[TeX-print] put your job on.
- X
- XEntering plain-TeX mode calls the value of text-mode-hook,
- Xthen the value of TeX-mode-hook, and then the value
- Xof plain-TeX-mode-hook."
- X (interactive)
- X (TeX-common-initialization)
- X (setq mode-name "TeX")
- X (setq major-mode 'plain-TeX-mode)
- X (setq TeX-command "tex")
- X (setq TeX-start-of-header "%**start of header")
- X (setq TeX-end-of-header "%**end of header")
- X (setq TeX-trailer "\\bye\n")
- X (run-hooks 'text-mode-hook 'TeX-mode-hook 'plain-TeX-mode-hook))
- X
- X(defun latex-mode ()
- X "Major mode for editing files of input for LaTeX.
- XMakes $ and } display the characters they match.
- XMakes \" insert `` when it seems to be the beginning of a quotation,
- Xand '' when it appears to be the end; it inserts \" only after a \\.
- X
- XUse \\[TeX-region] to run LaTeX on the current region, plus the preamble
- Xcopied from the top of the file (containing \\documentstyle, etc.),
- Xrunning LaTeX under a special subshell. \\[TeX-buffer] does the whole buffer.
- X\\[TeX-print] prints the .dvi file made by either of these.
- X
- XUse \\[validate-TeX-buffer] to check buffer for paragraphs containing
- Xmismatched $'s or braces.
- X
- XSpecial commands:
- X\\{TeX-mode-map}
- X
- XMode variables:
- XTeX-directory
- X Directory in which to create temporary files for TeX jobs
- X run by \\[TeX-region] or \\[TeX-buffer].
- XTeX-filter
- X program (maybe with full path) to filter the region or buffer
- X before calling tex or latex.
- XTeX-filter-args
- X list of arguments to TeX-filter.
- XTeX-dvi-print-command
- X Command string used by \\[TeX-print] to print a .dvi file.
- XTeX-show-queue-command
- X Command string used by \\[TeX-show-print-queue] to show the print
- X queue that \\[TeX-print] put your job on.
- X
- XEntering LaTeX mode calls the value of text-mode-hook,
- Xthen the value of TeX-mode-hook, and then the value
- Xof LaTeX-mode-hook."
- X (interactive)
- X (TeX-common-initialization)
- X (setq mode-name "LaTeX")
- X (setq major-mode 'LaTeX-mode)
- X (setq TeX-command "latex")
- X (setq TeX-start-of-header "\\documentstyle")
- X (setq TeX-end-of-header "\\begin{document}")
- X (setq TeX-trailer "\\end{document}\n")
- X (run-hooks 'text-mode-hook 'TeX-mode-hook 'LaTeX-mode-hook))
- X
- X(defun TeX-common-initialization ()
- X (kill-all-local-variables)
- X (use-local-map TeX-mode-map)
- X (setq local-abbrev-table text-mode-abbrev-table)
- X (if (null TeX-mode-syntax-table)
- X (progn
- X (setq TeX-mode-syntax-table (make-syntax-table))
- X (set-syntax-table TeX-mode-syntax-table)
- X (modify-syntax-entry ?\\ ".")
- X (modify-syntax-entry ?\f ">")
- X (modify-syntax-entry ?\n ">")
- X (modify-syntax-entry ?$ "$$")
- X (modify-syntax-entry ?% "<")
- X (modify-syntax-entry ?\" ".")
- X (modify-syntax-entry ?& ".")
- X (modify-syntax-entry ?_ ".")
- X (modify-syntax-entry ?@ "_")
- X (modify-syntax-entry ?~ " ")
- X (modify-syntax-entry ?' "w"))
- X (set-syntax-table TeX-mode-syntax-table))
- X (make-local-variable 'paragraph-start)
- X (setq paragraph-start "^[ \t]*$\\|^[\f\\\\]")
- X (make-local-variable 'paragraph-separate)
- X (setq paragraph-separate paragraph-start)
- X (make-local-variable 'comment-start)
- X (setq comment-start "%")
- X (make-local-variable 'comment-start-skip)
- X (setq comment-start-skip "[^\\]\\(\\(\\\\\\\\\\)*\\)%+ *")
- X (make-local-variable 'comment-indent-hook)
- X (setq comment-indent-hook 'TeX-comment-indent)
- X (make-local-variable 'TeX-command)
- X (make-local-variable 'TeX-trailer))
- X
- X(defun TeX-comment-indent ()
- X (if (looking-at "%%%")
- X (current-column)
- X (skip-chars-backward " \t")
- X (max (if (bolp) 0 (1+ (current-column)))
- X comment-column)))
- X
- X(defun TeX-insert-quote (arg)
- X "Insert ``, '' or \" according to preceding character.
- XWith prefix argument, always insert \" characters."
- X (interactive "P")
- X (if arg
- X (let ((count (prefix-numeric-value arg)))
- X (if (listp arg)
- X (self-insert-command 1) ;C-u always inserts just one
- X (self-insert-command count)))
- X (insert
- X (cond
- X ((or (bobp)
- X (save-excursion
- X (forward-char -1)
- X (looking-at "[ \t\n]\\|\\s(")))
- X "``")
- X ((= (preceding-char) ?\\)
- X ?\")
- X (t "''")))))
- X
- X(defun validate-TeX-buffer ()
- X "Check current buffer for paragraphs containing mismatched $'s.
- XAs each such paragraph is found, a mark is pushed at its beginning,
- Xand the location is displayed for a few seconds."
- X (interactive)
- X (let ((opoint (point)))
- X (goto-char (point-max))
- X ;; Does not use save-excursion
- X ;; because we do not want to save the mark.
- X (unwind-protect
- X (while (and (not (input-pending-p)) (not (bobp)))
- X (let ((end (point)))
- X (search-backward "\n\n" nil 'move)
- X (or (TeX-validate-paragraph (point) end)
- X (progn
- X (push-mark (point))
- X (message "Mismatch found in pararaph starting here")
- X (sit-for 4)))))
- X (goto-char opoint))))
- X
- X(defun TeX-validate-paragraph (start end)
- X (condition-case ()
- X (save-excursion
- X (save-restriction
- X (narrow-to-region start end)
- X (goto-char start)
- X (forward-sexp (- end start))
- X t))
- X (error nil)))
- X
- X(defun TeX-terminate-paragraph (inhibit-validation)
- X "Insert two newlines, breaking a paragraph for TeX.
- XCheck for mismatched braces/$'s in paragraph being terminated.
- XA prefix arg inhibits the checking."
- X (interactive "P")
- X (or inhibit-validation
- X (TeX-validate-paragraph
- X (save-excursion
- X (search-backward "\n\n" nil 'move)
- X (point))
- X (point))
- X (message "Paragraph being closed appears to contain a mismatch"))
- X (insert "\n\n"))
- X
- X(defun TeX-insert-braces ()
- X "Make a pair of braces and be poised to type inside of them."
- X (interactive)
- X (insert ?\{)
- X (save-excursion
- X (insert ?})))
- X
- X;;; Like TeX-insert-braces, but for LaTeX.
- X(defun TeX-close-LaTeX-block ()
- X "Creates an \\end{...} to match \\begin{...} on the current line and
- Xputs point on the blank line between them."
- X (interactive "*")
- X (let ((fail-point (point)))
- X (end-of-line)
- X (if (re-search-backward "\\\\begin{\\([^}\n]*\\)}"
- X (save-excursion (beginning-of-line) (point)) t)
- X (let ((text (buffer-substring (match-beginning 1) (match-end 1)))
- X (indentation (current-column)))
- X (end-of-line)
- X (delete-horizontal-space)
- X (insert "\n\n")
- X (indent-to indentation)
- X (insert "\\end{" text "}")
- X (forward-line -1))
- X (goto-char fail-point)
- X (ding))))
- X
- X;;; Invoking TeX in an inferior shell.
- X
- X;;; Why use a shell instead of running TeX directly? Because if TeX
- X;;; gets stuck, the user can switch to the shell window and type at it.
- X
- X;;; The utility functions:
- X
- X(defun TeX-start-shell ()
- X (require 'shell)
- X (if (eq (process-status "TeX-shell") 'run) ()
- X (save-excursion
- X (let ((buffer (make-shell "TeX-shell" shell-file-name nil "-v")))
- X (process-kill-without-query (get-buffer-process buffer))
- X (set-buffer buffer)
- X (setq TeX-shell-map (copy-keymap shell-mode-map))
- X (TeX-define-common-keys TeX-shell-map)
- X (use-local-map TeX-shell-map)))))
- X
- X(defun set-buffer-directory (buffer directory)
- X "Set BUFFER's default directory to be DIRECTORY."
- X (setq directory (file-name-as-directory (expand-file-name directory)))
- X (if (not (file-directory-p directory))
- X (error "%s is not a directory" directory)
- X (save-excursion
- X (set-buffer buffer)
- X (setq default-directory directory))))
- X
- X;;; It's a kludge that we have to create a special buffer just
- X;;; to write out the TeX-trailer. It would nice if there were a
- X;;; function like write-region that would write literal strings.
- X
- X;;; write-region complains if the file is also a buffer. To overcome
- X;;; this, here is my version
- X(defun my-write-region (beg end file app)
- X"The region between BEGIN and END of the current buffer is written or
- Xappended to the FILE depending whether the fourth argument is nil or
- Xnon-nil (append in the latter case)."
- X (call-process-region beg end shell-file-name nil nil nil
- X "-F" "-c" (concat "cat " (if app ">>" ">") "\"" file "\""))
- X)
- X
- X(defun TeX-region (beg end)
- X "Run TeX on the current region. The region is filtered through the
- Xprogram given in (TeX-filter) to produce the temporary file (TeX-zap-file)
- Xin directory (TeX-directory). TeX is run in that directory. If the buffer has
- Xa header, it is written to the temporary file before the region. Also, the
- Xvalue of the TeX-trailer is appended to the file. They are NOT filtered through
- X(TeX-filter). The buffer's header is all lines between the string defined by
- XTeX-start-of-header and TeX-end-of-header inclusive."
- X (interactive "r")
- X (or TeX-zap-file (setq TeX-zap-file (make-temp-name "#tz")))
- X (let* ((tex-out-file (concat TeX-zap-file ".tex"))
- X (tex-out-buffer (get-file-buffer tex-out-file))
- X (temp-buffer (get-buffer-create " TeX-Output-Buffer"))
- X (zap-directory (expand-file-name TeX-directory))
- X (local-tex-trailer TeX-trailer))
- X (unwind-protect (save-excursion (save-restriction
- X (widen)
- X (goto-char (point-min))
- X (forward-line 100)
- X (let ((search-end (point))
- X (hbeg (point-min)) (hend (point-min))
- X (default-directory zap-directory))
- X (goto-char (point-min))
- X ;; Initialize the temp file with either the header or nothing
- X (if (search-forward TeX-start-of-header search-end t)
- X (progn
- X (forward-line -1)
- X (setq hbeg (point)) ;mark beginning of header
- X (if (search-forward TeX-end-of-header nil t)
- X (progn (forward-line 1)
- X (setq hend (min beg (point))));mark end of header
- X (setq hbeg (point-min))))) ;no header
- X (my-write-region (min hbeg beg) hend tex-out-file nil))
- X (message "Preprocessing...")
- X (narrow-to-region beg end)
- X (sit-for 0)
- X (save-excursion (set-buffer temp-buffer) (erase-buffer))
- X (if TeX-filter
- X (apply 'call-process-region
- X (append (list beg end TeX-filter nil temp-buffer nil)
- X TeX-filter-args
- X (list (concat zap-directory tex-out-file))))
- X (my-write-region beg end (concat zap-directory tex-out-file) t))
- X (message "Done...") (sit-for 0)
- X )))
- X (if (save-excursion (set-buffer temp-buffer)
- X (beginning-of-file) (eobp))
- X (progn
- X (save-excursion
- X (set-buffer temp-buffer)
- X (set-buffer-directory temp-buffer zap-directory)
- X (insert-string "\n")
- X (if local-tex-trailer (insert-string local-tex-trailer))
- X (my-write-region (point-min) (point-max) tex-out-file t))
- X (pop-to-TeX-shell zap-directory tex-out-file)
- X )
- X;;; error during preprocessing, show the error messages ...
- X (let ((buffer (current-buffer)))
- X (pop-to-buffer temp-buffer)
- X (pop-to-buffer buffer))
- X )
- X))
- X
- X(defun pop-to-TeX-shell (zap-directory tex-out-file)
- X (if (get-buffer "*TeX-shell*") (TeX-kill-job))
- X (TeX-start-shell)
- X (set-buffer-directory "*TeX-shell*" zap-directory)
- X (send-string "TeX-shell" (concat TeX-shell-cd-command " "
- X zap-directory "\n"))
- X (send-string "TeX-shell" (concat TeX-command " \""
- X tex-out-file "\"\n"))
- X (TeX-recenter-output-buffer 0)
- X)
- X
- X(defun TeX-buffer ()
- X "Run TeX on current buffer. See \\[TeX-region] for more information."
- X (interactive)
- X (TeX-region (point-min) (point-max)))
- X
- X(defun TeX-kill-job ()
- X "Kill the currently running TeX job."
- X (interactive)
- X (if (process-status "TeX-shell") ; not nil if the process exists
- X (quit-process "TeX-shell" t)))
- X
- X(defun TeX-recenter-output-buffer (linenum)
- X "Redisplay buffer of TeX job output so that most recent output can be seen.
- XThe last line of the buffer is displayed on
- Xline LINE of the window, or centered if LINE is nil."
- X (interactive "P")
- X (let ((tex-shell (get-buffer "*TeX-shell*"))
- X (old-buffer (current-buffer)))
- X (if (null tex-shell)
- X (message "No TeX output buffer")
- X (pop-to-buffer tex-shell)
- X (bury-buffer tex-shell)
- X (goto-char (point-max))
- X (recenter (if linenum
- X (prefix-numeric-value linenum)
- X (/ (window-height) 2)))
- X (pop-to-buffer old-buffer)
- X )))
- X
- X(defun TeX-print ()
- X "Print the .dvi file made by \\[TeX-region] or \\[TeX-buffer].
- XRuns the shell command defined by TeX-dvi-print-command."
- X (interactive)
- X (send-string "TeX-shell"
- X (concat TeX-dvi-print-command " \"" TeX-zap-file ".dvi\"\n"))
- X (TeX-recenter-output-buffer nil))
- X
- X(defun TeX-view-dvi ()
- X "Shows the .dvi file on the screen bu the shell command defined
- Xby TeX-show-dvi-command."
- X (interactive)
- X (send-string "TeX-shell"
- X (concat TeX-show-dvi-command " \"" TeX-zap-file ".dvi\"\n"))
- X (TeX-recenter-output-buffer nil))
- X
- X(defun TeX-show-print-queue ()
- X "Show the print queue that \\[TeX-print] put your job on.
- XRuns the shell command defined by TeX-show-queue-command."
- X (interactive)
- X (if (not (get-buffer "*TeX-shell*"))
- X (TeX-start-shell))
- X (send-string "TeX-shell" (concat TeX-show-queue-command "\n"))
- X (TeX-recenter-output-buffer nil))
- X
- END_OF_FILE
- if test 20255 -ne `wc -c <'tex-mode.el'`; then
- echo shar: \"'tex-mode.el'\" unpacked with wrong size!
- fi
- # end of 'tex-mode.el'
- fi
- echo shar: End of archive 1 \(of 2\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 2 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked both archives.
- rm -f ark[1-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-
-
-