]> code.delx.au - gnu-emacs-elpa/blob - packages/auctex/tex-buf.el
Remove version numbers in packages/ directory
[gnu-emacs-elpa] / packages / auctex / tex-buf.el
1 ;;; tex-buf.el --- External commands for AUCTeX.
2
3 ;; Copyright (C) 1991, 1993, 1996, 2001, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008, 2009 Free Software Foundation, Inc.
5
6 ;; Maintainer: auctex-devel@gnu.org
7 ;; Keywords: tex, wp
8
9 ;; This file is part of AUCTeX.
10
11 ;; AUCTeX is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; AUCTeX is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with AUCTeX; see the file COPYING. If not, write to the Free
23 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 ;; 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; This file provides support for external commands.
29
30 ;;; Code:
31
32 (require 'tex)
33
34 ;;; Customization:
35
36 (defcustom TeX-process-asynchronous (not (eq system-type 'ms-dos))
37 "*Use asynchronous processes."
38 :group 'TeX-command
39 :type 'boolean)
40
41 (defcustom TeX-shell
42 (if (memq system-type '(ms-dos emx windows-nt))
43 shell-file-name
44 "/bin/sh")
45 "Name of shell used to parse TeX commands."
46 :group 'TeX-command
47 :type 'file)
48
49 (defcustom TeX-shell-command-option
50 (cond ((memq system-type '(ms-dos emx windows-nt) )
51 (cond ((boundp 'shell-command-option)
52 shell-command-option)
53 ((boundp 'shell-command-switch)
54 shell-command-switch)
55 (t
56 "/c")))
57 (t ;Unix & EMX (Emacs 19 port to OS/2)
58 "-c"))
59 "Shell argument indicating that next argument is the command."
60 :group 'TeX-command
61 :type 'string)
62
63 ;;; Interactive Commands
64 ;;
65 ;; The general idea is, that there is one process and process buffer
66 ;; associated with each master file, and one process and process buffer
67 ;; for running TeX on a region. Thus, if you have N master files, you
68 ;; can run N + 1 processes simultaneously.
69 ;;
70 ;; Some user commands operates on ``the'' process. The following
71 ;; algorithm determine what ``the'' process is.
72 ;;
73 ;; IF last process started was on a region
74 ;; THEN ``the'' process is the region process
75 ;; ELSE ``the'' process is the master file (of the current buffer) process
76
77 (defun TeX-save-document (name)
78 "Save all files belonging to the current document.
79 Return non-nil if document need to be re-TeX'ed."
80 (interactive (list (TeX-master-file)))
81 (if (string-equal name "")
82 (setq name (TeX-master-file)))
83
84 (TeX-check-files (concat name "." (TeX-output-extension))
85 (cons name (TeX-style-list))
86 TeX-file-extensions))
87
88 (defun TeX-command-master (&optional override-confirm)
89 "Run command on the current document.
90
91 If a prefix argument OVERRIDE-CONFIRM is given, confirmation will
92 depend on it being positive instead of the entry in `TeX-command-list'."
93 (interactive "P")
94 (TeX-command (TeX-command-query (TeX-master-file)) 'TeX-master-file
95 override-confirm))
96
97 (defvar TeX-command-region-begin nil)
98 (defvar TeX-command-region-end nil)
99 ;; Used for marking the last region.
100
101 (make-variable-buffer-local 'TeX-command-region-begin)
102 (make-variable-buffer-local 'TeX-command-region-end)
103
104 (defun TeX-current-offset (&optional pos)
105 "Calculate line offset of POS, or of point if POS is nil."
106 (save-restriction
107 (widen)
108 (save-excursion
109 (let ((inhibit-point-motion-hooks t)
110 (inhibit-field-text-motion t))
111 (if pos (goto-char pos))
112 (+ (count-lines (point-min) (point))
113 (if (bolp) 0 -1))))))
114
115 (defun TeX-pin-region (begin end)
116 "Pin the TeX region specified by BEGIN and END.
117 If BEGIN is nil, the region is unpinned.
118
119 In interactive use, a positive prefix arg will pin the region,
120 a non-positive one will unpin it. Without a prefix arg, if
121 a region is actively marked, it will get pinned. If not, a
122 pinned region will get unpinned and vice versa."
123 (interactive
124 (if
125 (if current-prefix-arg
126 (> (prefix-numeric-value current-prefix-arg) 0)
127 (or (TeX-active-mark)
128 (null TeX-command-region-begin)))
129 (list (region-beginning) (region-end))
130 '(nil nil)))
131 (if begin
132 (progn
133 (unless (markerp TeX-command-region-begin)
134 (setq TeX-command-region-begin (make-marker))
135 (setq TeX-command-region-end (make-marker)))
136 (set-marker TeX-command-region-begin begin)
137 (set-marker TeX-command-region-end end)
138 (message "TeX region pinned."))
139 (when (markerp TeX-command-region-begin)
140 (set-marker TeX-command-region-begin nil)
141 (set-marker TeX-command-region-end nil))
142 (setq TeX-command-region-begin nil)
143 (setq TeX-command-region-end nil)
144 (message "TeX region unpinned.")))
145
146 (defun TeX-command-region (&optional override-confirm)
147 "Run TeX on the current region.
148
149 Query the user for a command to run on the temporary file specified by
150 the variable `TeX-region'. If there is an explicitly active region,
151 it is stored for later commands. If not, a previously stored region
152 \(can be also be set with `TeX-pin-region') overrides the current region,
153 if present.
154
155 If a prefix argument OVERRIDE-CONFIRM is given, prompting will
156 ignore the prompting flag from `TeX-command-list' and instead
157 will prompt iff the prefix is positive.
158
159 If the master file for the document has a header, it is written to the
160 temporary file before the region itself. The document's header is all
161 text before `TeX-header-end'.
162
163 If the master file for the document has a trailer, it is written to
164 the temporary file before the region itself. The document's trailer is
165 all text after `TeX-trailer-start'."
166 (interactive "P")
167 ;; Note that TeX-command-region-begin is not a marker when called
168 ;; from TeX-command-buffer.
169 (and (or (null TeX-command-region-begin)
170 (markerp TeX-command-region-begin))
171 (TeX-active-mark)
172 (TeX-pin-region (region-beginning) (region-end)))
173 (let ((begin (or TeX-command-region-begin (region-beginning)))
174 (end (or TeX-command-region-end (region-end))))
175 (TeX-region-create (TeX-region-file TeX-default-extension)
176 (buffer-substring begin end)
177 (file-name-nondirectory (buffer-file-name))
178 (TeX-current-offset begin)))
179 (TeX-command (TeX-command-query (TeX-region-file nil t)) 'TeX-region-file
180 override-confirm))
181
182 (defun TeX-command-buffer (&optional override-confirm)
183 "Run TeX on the current buffer.
184
185 Query the user for a command to run on the temporary file specified by
186 the variable `TeX-region'. The region file will be recreated from the
187 visible part of the buffer.
188
189 If a prefix argument OVERRIDE-CONFIRM is given, confirmation will
190 depend on it being positive instead of the entry in `TeX-command-list'."
191 (interactive "P")
192 (let ((TeX-command-region-begin (point-min))
193 (TeX-command-region-end (point-max)))
194 (TeX-command-region override-confirm)))
195
196 (unless (featurep 'xemacs)
197 ;; This variable is not defined in XEmacs because XEmacs' version of
198 ;; `pop-to-buffer' doesn't support the optional NORECORD argument. In
199 ;; XEmacs, the third arg is ON-FRAME (Emacs: NORECORD).
200 (defcustom TeX-record-buffer nil
201 "Whether to record buffer names of generated TeX buffers.
202 When non-nil, these buffers are put at the front of the list of
203 recently selected ones."
204 :group 'TeX-command
205 :type 'boolean))
206
207 (defun TeX-pop-to-buffer (buffer &optional other-window norecord)
208 "Compatibility wrapper for `pop-to-buffer'.
209
210 Select buffer BUFFER in some window, preferably a different one.
211 BUFFER may be a buffer, a string (a buffer name), or nil.
212 If BUFFER is a string which is not the name of an existing buffer,
213 then this function creates a buffer with that name.
214 If BUFFER is nil, then it chooses some other buffer.
215 If `pop-up-windows' is non-nil, windows can be split to do this.
216 If optional second arg OTHER-WINDOW is non-nil, insist on finding another
217 window even if BUFFER is already visible in the selected window,
218 and ignore `same-window-regexps' and `same-window-buffer-names'.
219 This function returns the buffer it switched to.
220 This uses the function `display-buffer' as a subroutine; see the documentation
221 of `display-buffer' for additional customization information.
222
223 Optional third arg NORECORD non-nil means do not put this buffer
224 at the front of the list of recently selected ones.
225
226 NORECORD is ignored in XEmacs."
227 ;; Make sure not to use third arg in XEmacs. In XEmacs, the third arg is
228 ;; ON-FRAME (Emacs: NORECORD), so we set it to nil.
229 (pop-to-buffer buffer other-window (and norecord
230 (boundp 'TeX-record-buffer)
231 TeX-record-buffer)))
232
233 (defun TeX-recenter-output-buffer (line)
234 "Redisplay buffer of TeX job output so that most recent output can be seen.
235 The last line of the buffer is displayed on line LINE of the window, or
236 at bottom if LINE is nil."
237 (interactive "P")
238 (let ((buffer (TeX-active-buffer)))
239 (if buffer
240 (let ((old-buffer (current-buffer)))
241 (TeX-pop-to-buffer buffer t t)
242 (bury-buffer buffer)
243 (goto-char (point-max))
244 (recenter (if line
245 (prefix-numeric-value line)
246 (/ (window-height) 2)))
247 (TeX-pop-to-buffer old-buffer nil t))
248 (message "No process for this document."))))
249
250 (defun TeX-kill-job ()
251 "Kill the currently running TeX job."
252 (interactive)
253 (let ((process (TeX-active-process)))
254 (if process
255 (kill-process process)
256 ;; Should test for TeX background process here.
257 (error "No TeX process to kill"))))
258
259 (defun TeX-home-buffer ()
260 "Go to the buffer where you last issued a TeX command.
261 If there is no such buffer, or you already are in that buffer, find
262 the master file."
263 (interactive)
264 (if (or (null TeX-command-buffer)
265 (null (buffer-name TeX-command-buffer))
266 (eq TeX-command-buffer (current-buffer)))
267 (find-file (TeX-master-file TeX-default-extension))
268 (switch-to-buffer TeX-command-buffer)))
269
270 (defun TeX-next-error (reparse)
271 "Find the next error in the TeX output buffer.
272 With \\[universal-argument] prefix, start from the beginning of the errors."
273 (interactive "P")
274 (if (null (TeX-active-buffer))
275 (next-error reparse)
276 (funcall (TeX-process-get-variable (with-current-buffer TeX-command-buffer
277 (TeX-active-master))
278 'TeX-parse-function)
279 reparse)))
280
281 (defun TeX-previous-error (arg)
282 "Find the previous error in the TeX output buffer."
283 (interactive "P")
284 (if (null (TeX-active-buffer))
285 (previous-error arg)
286 (error "Jumping to previous error not supported")))
287
288 ;;; Command Query
289
290 (defun TeX-command (name file &optional override-confirm)
291 "Run command NAME on the file returned by calling FILE.
292
293 FILE is the symbol of a function returning a file name. The
294 function has one optional argument, the extension to use on the
295 file.
296
297 Use the information in `TeX-command-list' to determine how to run
298 the command.
299
300 If OVERRIDE-CONFIRM is a prefix argument, confirmation will be
301 asked if it is positive, and suppressed if it is not."
302 (cond ((eq file 'TeX-region-file)
303 (setq TeX-current-process-region-p t))
304 ((eq file 'TeX-master-file)
305 (setq TeX-current-process-region-p nil)))
306 (let ((command (TeX-command-expand (nth 1 (assoc name TeX-command-list))
307 file))
308 (hook (nth 2 (assoc name TeX-command-list)))
309 (confirm (if override-confirm
310 (> (prefix-numeric-value override-confirm) 0)
311 (nth 3 (assoc name TeX-command-list)))))
312
313 ;; Verify the expanded command
314 (if confirm
315 (setq command
316 (read-from-minibuffer (concat name " command: ") command
317 nil nil)))
318
319 ;; Now start the process
320 (setq file (funcall file))
321 (TeX-process-set-variable file 'TeX-command-next TeX-command-Show)
322 (funcall hook name command file)))
323
324 (defun TeX-command-expand (command file &optional list)
325 "Expand COMMAND for FILE as described in LIST.
326 LIST default to `TeX-expand-list'. As a special exception,
327 `%%' can be used to produce a single `%' sign in the output
328 without further expansion."
329 (let (pat
330 pos
331 entry TeX-command-text TeX-command-pos
332 (file `(lambda (&rest args)
333 (shell-quote-argument
334 (concat (and (stringp TeX-command-pos) TeX-command-pos)
335 (apply ',file args)
336 (and (stringp TeX-command-pos) TeX-command-pos)))))
337 case-fold-search string expansion arguments)
338 (setq list (cons
339 (list "%%" (lambda nil
340 (setq pos (1+ pos))
341 "%"))
342 (or list TeX-expand-list))
343 pat (regexp-opt (mapcar #'car list)))
344 (while (setq pos (string-match pat command pos))
345 (setq string (match-string 0 command)
346 entry (assoc string list)
347 expansion (car (cdr entry)) ;Second element
348 arguments (cdr (cdr entry)) ;Remaining elements
349 string (save-match-data
350 ;; Note regarding the special casing of `file':
351 ;; `file' is prevented from being evaluated as a
352 ;; function because inside of AUCTeX it only has
353 ;; a meaning as a variable. This makes sure that
354 ;; a function definition made by an external
355 ;; package (e.g. icicles) is not picked up.
356 (cond ((and (not (eq expansion 'file))
357 (TeX-function-p expansion))
358 (apply expansion arguments))
359 ((boundp expansion)
360 (apply (eval expansion) arguments))
361 (t
362 (error "Nonexpansion %s" expansion)))))
363 (if (stringp string)
364 (setq command
365 (replace-match string t t command)))))
366 command)
367
368 (defun TeX-check-files (derived originals extensions)
369 "Check that DERIVED is newer than any of the ORIGINALS.
370 Try each original with each member of EXTENSIONS, in all directories
371 in `TeX-check-path'."
372 (let ((found nil)
373 (regexp (concat "\\`\\("
374 (mapconcat (lambda (dir)
375 (regexp-quote
376 (expand-file-name
377 (file-name-as-directory dir))))
378 TeX-check-path "\\|")
379 "\\).*\\("
380 (mapconcat 'regexp-quote originals "\\|")
381 "\\)\\.\\("
382 (mapconcat 'regexp-quote extensions "\\|")
383 "\\)\\'"))
384 (buffers (buffer-list)))
385 (while buffers
386 (let* ((buffer (car buffers))
387 (name (buffer-file-name buffer)))
388 (setq buffers (cdr buffers))
389 (if (and name (string-match regexp name))
390 (progn
391 (and (buffer-modified-p buffer)
392 (or (not TeX-save-query)
393 (y-or-n-p (concat "Save file "
394 (buffer-file-name buffer)
395 "? ")))
396 (save-excursion (set-buffer buffer) (save-buffer)))
397 (if (file-newer-than-file-p name derived)
398 (setq found t))))))
399 found))
400
401 (defcustom TeX-save-query t
402 "*If non-nil, ask user for permission to save files before starting TeX."
403 :group 'TeX-command
404 :type 'boolean)
405
406 (defvar TeX-command-history nil)
407
408 (defun TeX-command-query (name)
409 "Query the user for what TeX command to use."
410 (let* ((default (cond ((if (string-equal name TeX-region)
411 (TeX-check-files (concat name "." (TeX-output-extension))
412 (list name)
413 TeX-file-extensions)
414 (TeX-save-document (TeX-master-file)))
415 TeX-command-default)
416 ((and (memq major-mode '(doctex-mode latex-mode))
417 (TeX-check-files (concat name ".bbl")
418 (mapcar 'car
419 (LaTeX-bibliography-list))
420 BibTeX-file-extensions))
421 ;; We should check for bst files here as well.
422 TeX-command-BibTeX)
423 ((TeX-process-get-variable name
424 'TeX-command-next
425 TeX-command-Show))
426 (TeX-command-Show)))
427 (completion-ignore-case t)
428 (answer (or TeX-command-force
429 (completing-read
430 (concat "Command: (default " default ") ")
431 (TeX-mode-specific-command-list major-mode) nil t
432 nil 'TeX-command-history))))
433 ;; If the answer "latex" it will not be expanded to "LaTeX"
434 (setq answer (car-safe (TeX-assoc answer TeX-command-list)))
435 (if (and answer
436 (not (string-equal answer "")))
437 answer
438 default)))
439
440 (defvar TeX-command-next nil
441 "The default command next time `TeX-command' is invoked.")
442
443 (make-variable-buffer-local 'TeX-command-next)
444
445 (defun TeX-printer-query (&optional queue)
446 "Query the user for a printer name.
447 QUEUE is non-nil when we are checking for the printer queue."
448 (let (command element printer)
449 (if queue
450 (unless (setq element 2 command TeX-queue-command)
451 (error "Need to customize `TeX-queue-command'"))
452 (unless (setq element 1 command TeX-print-command)
453 (error "Need to customize `TeX-print-command'")))
454 (while (progn
455 (setq printer (if TeX-printer-list
456 (let ((completion-ignore-case t))
457 (completing-read
458 (concat "Printer: "
459 (and TeX-printer-default
460 (concat "(default "
461 TeX-printer-default ") ")))
462 TeX-printer-list))
463 ""))
464 (setq printer (or (car-safe (TeX-assoc printer TeX-printer-list))
465 printer))
466 (not (if (or (null printer) (string-equal "" printer))
467 (setq printer TeX-printer-default)
468 (setq TeX-printer-default printer)))))
469
470 (let ((expansion (let ((entry (assoc printer TeX-printer-list)))
471 (or (nth element entry)
472 command))))
473 (if (string-match "%p" printer)
474 (error "Don't use %s in printer names" "%p"))
475 (while (string-match "%p" expansion)
476 (setq expansion (replace-match printer t t expansion 0)))
477 expansion)))
478
479 (defun TeX-style-check (styles)
480 "Check STYLES compared to the current style options."
481 (let ((files (TeX-style-list)))
482 (while (and styles
483 (not (TeX-member (car (car styles)) files 'string-match)))
484 (setq styles (cdr styles))))
485 (if styles
486 (nth 1 (car styles))
487 ""))
488
489 (defun TeX-output-extension ()
490 "Get the extension of the current TeX output file."
491 (if (listp TeX-output-extension)
492 (car TeX-output-extension)
493 (or (TeX-process-get-variable (TeX-active-master)
494 'TeX-output-extension
495 TeX-output-extension)
496 TeX-output-extension)))
497
498 (defun TeX-view-mouse (event)
499 "Start `TeX-view' at mouse position."
500 (interactive "e")
501 (save-excursion
502 (set-buffer (window-buffer (posn-window (event-start event))))
503 (goto-char (posn-point (event-start event)))
504 (TeX-view)))
505
506 (defun TeX-view ()
507 "Start a viewer without confirmation.
508 The viewer is started either on region or master file,
509 depending on the last command issued."
510 (interactive)
511 (let ((output-file (TeX-active-master (TeX-output-extension))))
512 (if (file-exists-p output-file)
513 (TeX-command "View" 'TeX-active-master 0)
514 (message "Output file %S does not exist." output-file))))
515
516 (defun TeX-output-style-check (styles)
517 "Check STYLES compared to the current view output file extension and
518 the current style options."
519 (let ((ext (TeX-output-extension))
520 (files (TeX-style-list)))
521 (while (and
522 styles
523 (or
524 (not (string-match (car (car styles)) ext))
525 (let ((style (nth 1 (car styles))))
526 (cond
527 ((listp style)
528 (while
529 (and style
530 (TeX-member (car style) files 'string-match))
531 (setq style (cdr style)))
532 style)
533 ((not (TeX-member style files 'string-match)))))))
534 (setq styles (cdr styles)))
535 (if styles
536 (nth 2 (car styles))
537 "%v")))
538
539 ;;; Command Hooks
540
541 (defvar TeX-after-start-process-function nil
542 "Hooks to run after starting an asynchronous process.
543 Used by Japanese TeX to set the coding system.")
544
545 (defcustom TeX-show-compilation nil
546 "*If non-nil, show output of TeX compilation in other window."
547 :group 'TeX-command
548 :type 'boolean)
549
550 (defun TeX-run-command (name command file)
551 "Create a process for NAME using COMMAND to process FILE.
552 Return the new process."
553 (let ((default TeX-command-default)
554 (buffer (TeX-process-buffer-name file))
555 (dir (TeX-master-directory))
556 (command-buff (current-buffer)))
557 (TeX-process-check file) ; Check that no process is running
558 (setq-default TeX-command-buffer command-buff)
559 (get-buffer-create buffer)
560 (set-buffer buffer)
561 (buffer-disable-undo)
562 (erase-buffer)
563 (set (make-local-variable 'line-number-display-limit) 0)
564 (setq TeX-output-extension nil)
565 (set (make-local-variable 'TeX-command-buffer) command-buff)
566 (if dir (cd dir))
567 (insert "Running `" name "' on `" file "' with ``" command "''\n")
568 (setq mode-name name)
569 (if TeX-show-compilation
570 (display-buffer buffer)
571 (message "Type `%s' to display results of compilation."
572 (substitute-command-keys
573 "\\<TeX-mode-map>\\[TeX-recenter-output-buffer]")))
574 (setq TeX-parse-function 'TeX-parse-command)
575 (setq TeX-command-default default)
576 (setq TeX-sentinel-function
577 (lambda (process name)
578 (message (concat name ": done."))))
579 (if TeX-process-asynchronous
580 (let ((process (start-process name buffer TeX-shell
581 TeX-shell-command-option command)))
582 (if TeX-after-start-process-function
583 (funcall TeX-after-start-process-function process))
584 (TeX-command-mode-line process)
585 (set-process-filter process 'TeX-command-filter)
586 (set-process-sentinel process 'TeX-command-sentinel)
587 (set-marker (process-mark process) (point-max))
588 (setq compilation-in-progress (cons process compilation-in-progress))
589 process)
590 (setq mode-line-process ": run")
591 (set-buffer-modified-p (buffer-modified-p))
592 (sit-for 0) ; redisplay
593 (call-process TeX-shell nil buffer nil
594 TeX-shell-command-option command))))
595
596 (defun TeX-run-set-command (name command)
597 "Remember TeX command to use to NAME and set corresponding output extension."
598 (setq TeX-command-default name
599 TeX-output-extension (if TeX-PDF-mode "pdf" "dvi"))
600 (let ((case-fold-search t)
601 (lst TeX-command-output-list))
602 (while lst
603 (if (string-match (car (car lst)) command)
604 (setq TeX-output-extension (car (cdr (car lst)))
605 lst nil)
606 (setq lst (cdr lst))))))
607
608 (defun TeX-run-format (name command file)
609 "Create a process for NAME using COMMAND to format FILE with TeX."
610 (TeX-run-set-command name command)
611 (let ((buffer (TeX-process-buffer-name file))
612 (process (TeX-run-command name command file)))
613 ;; Hook to TeX debuger.
614 (save-excursion
615 (set-buffer buffer)
616 (TeX-parse-reset)
617 (setq TeX-parse-function 'TeX-parse-TeX)
618 (setq TeX-sentinel-function 'TeX-TeX-sentinel)
619 (if TeX-process-asynchronous
620 (progn
621 ;; Updating the mode line.
622 (setq TeX-current-page "[0]")
623 (TeX-format-mode-line process)
624 (set-process-filter process 'TeX-format-filter)))
625 process)))
626
627 (defvar TeX-error-report-switches nil
628 "Reports presence of errors after `TeX-run-TeX'.
629 To test whether the current buffer has an compile error from last
630 run of `TeX-run-TeX', use
631 (plist-get TeX-error-report-switches (intern (TeX-master-file)))")
632
633 (defun TeX-run-TeX (name command file)
634 "Create a process for NAME using COMMAND to format FILE with TeX."
635
636 ;; Save information in TeX-error-report-switches
637 ;; Initialize error to nil (no error) for current master.
638 ;; Presence of error is reported inside `TeX-TeX-sentinel-check'
639 (let ((current-master (TeX-master-file)))
640 ;; the current master file is saved because error routines are
641 ;; parsed in other buffers;
642 (setq TeX-error-report-switches
643 (plist-put TeX-error-report-switches
644 'TeX-current-master current-master))
645 ;; reset error to nil (no error)
646 (setq TeX-error-report-switches
647 (plist-put TeX-error-report-switches
648 (intern current-master) nil)))
649
650 ;; can we assume that TeX-sentinel-function will not be changed
651 ;; during (TeX-run-format ..)? --pg
652 ;; rather use let* ? --pg
653
654 (if TeX-interactive-mode
655 (TeX-run-interactive name command file)
656 (let ((sentinel-function TeX-sentinel-default-function))
657 (let ((process (TeX-run-format name command file)))
658 (setq TeX-sentinel-function sentinel-function)
659 (if TeX-process-asynchronous
660 process
661 (TeX-synchronous-sentinel name file process))))))
662
663 ;; backward compatibilty
664
665 (defalias 'TeX-run-LaTeX 'TeX-run-TeX)
666
667
668 (defun TeX-run-BibTeX (name command file)
669 "Create a process for NAME using COMMAND to format FILE with BibTeX."
670 (let ((process (TeX-run-command name command file)))
671 (setq TeX-sentinel-function 'TeX-BibTeX-sentinel)
672 (if TeX-process-asynchronous
673 process
674 (TeX-synchronous-sentinel name file process))))
675
676 (defun TeX-run-compile (name command file)
677 "Ignore first and third argument, start compile with second argument."
678 (compile command))
679
680 (defun TeX-run-shell (name command file)
681 "Ignore first and third argument, start shell-command with second argument."
682 (let ((default-directory (TeX-master-directory)))
683 (shell-command command)
684 (if (eq system-type 'ms-dos)
685 (redraw-display))))
686
687 (defun TeX-run-discard (name command file)
688 "Start COMMAND as process, discarding its output.
689 NAME and FILE are ignored."
690 (let ((default-directory (TeX-master-directory)))
691 (call-process TeX-shell
692 nil 0 nil
693 TeX-shell-command-option
694 command)))
695
696 (defun TeX-run-discard-foreground (name command file)
697 "Call process with second argument in the foreground, discarding its output.
698 With support for MS-DOS, especially when dviout is used with PC-9801 series."
699 (if (and (boundp 'dos-machine-type) (eq dos-machine-type 'pc98)) ;if PC-9801
700 (send-string-to-terminal "\e[2J")) ; clear screen
701 (call-process TeX-shell (if (eq system-type 'ms-dos) "con") nil nil
702 TeX-shell-command-option command)
703 (if (eq system-type 'ms-dos)
704 (redraw-display)))
705 (defalias 'TeX-run-dviout 'TeX-run-discard-foreground)
706
707 (defun TeX-run-background (name command file)
708 "Start process with second argument, show output when and if it arrives."
709 (let ((dir (TeX-master-directory)))
710 (set-buffer (get-buffer-create "*TeX background*"))
711 (if dir (cd dir))
712 (erase-buffer)
713 (let ((process (start-process (concat name " background")
714 nil TeX-shell
715 TeX-shell-command-option command)))
716 (if TeX-after-start-process-function
717 (funcall TeX-after-start-process-function process))
718 (set-process-filter process 'TeX-background-filter)
719 (process-kill-without-query process))))
720
721 (defun TeX-run-silent (name command file)
722 "Start process with second argument."
723 (let ((dir (TeX-master-directory)))
724 (set-buffer (get-buffer-create "*TeX silent*"))
725 (if dir (cd dir))
726 (erase-buffer)
727 (let ((process (start-process (concat name " silent")
728 nil TeX-shell
729 TeX-shell-command-option command)))
730 (if TeX-after-start-process-function
731 (funcall TeX-after-start-process-function process))
732 (process-kill-without-query process))))
733
734 (defun TeX-run-interactive (name command file)
735 "Run TeX interactively.
736 Run command in a buffer (in comint-shell-mode) so that it accepts user
737 interaction. If you return to the file buffer after the TeX run,
738 Error parsing on \\[next-error] should work with a bit of luck."
739 (TeX-run-set-command name command)
740 (require 'comint)
741 (let ((default TeX-command-default)
742 (buffer (TeX-process-buffer-name file))
743 (process nil)
744 (dir (TeX-master-directory))
745 (command-buff (current-buffer))
746 (sentinel-function TeX-sentinel-default-function)) ; inherit from major mode
747 (TeX-process-check file) ; Check that no process is running
748 (setq-default TeX-command-buffer command-buff)
749 (with-output-to-temp-buffer buffer)
750 (set-buffer buffer)
751 (set (make-local-variable 'TeX-command-buffer) command-buff)
752 (setq buffer-read-only nil)
753 (if dir (cd dir))
754 (insert "Running `" name "' on `" file "' with ``" command "''\n")
755 (comint-exec buffer name TeX-shell nil
756 (list TeX-shell-command-option command))
757 (comint-mode)
758 (add-hook 'comint-output-filter-functions 'TeX-interactive-goto-prompt)
759 (setq mode-name name)
760 (setq TeX-command-default default)
761 (setq process (get-buffer-process buffer))
762 (if TeX-after-start-process-function
763 (funcall TeX-after-start-process-function process))
764 (TeX-command-mode-line process)
765 (set-process-sentinel process 'TeX-command-sentinel)
766 (set-marker (process-mark process) (point-max))
767 (setq compilation-in-progress (cons process compilation-in-progress))
768 (TeX-parse-reset)
769 (setq TeX-parse-function 'TeX-parse-TeX)
770 ;; use the sentinel-function that the major mode sets, not the LaTeX one
771 (setq TeX-sentinel-function sentinel-function)))
772
773 (defun TeX-run-function (name command file)
774 "Execute Lisp function or function call given as the string COMMAND.
775 Parameters NAME and FILE are ignored."
776 (let ((fun (car (read-from-string command))))
777 (if (functionp fun) (funcall fun) (eval fun))))
778
779 (defun TeX-run-discard-or-function (name command file)
780 "Start COMMAND as process or execute it as a Lisp function.
781 If run as a process, the output is discarded. COMMAND is
782 expected to be a string. NAME and FILE are ignored."
783 (if (functionp (car (read-from-string command)))
784 (TeX-run-function name command file)
785 (TeX-run-discard name command file)))
786
787 (defun TeX-run-ispell-on-document (command ignored name)
788 "Run ispell on all open files belonging to the current document.
789 This function is *obsolete* and only here for compatibility
790 reasons. Use `TeX-run-function' instead."
791 (interactive)
792 (TeX-ispell-document ""))
793
794
795 ;;; Command Sentinels
796
797 (defun TeX-synchronous-sentinel (name file result)
798 "Process TeX command output buffer after the process dies."
799 (let* ((buffer (TeX-process-buffer file)))
800 (save-excursion
801 (set-buffer buffer)
802
803 ;; Append post-mortem information to the buffer
804 (goto-char (point-max))
805 (insert "\n" mode-name (if (and result (zerop result))
806 " finished" " exited") " at "
807 (substring (current-time-string) 0 -5))
808 (setq mode-line-process ": exit")
809
810 ;; Do command specific actions.
811 (setq TeX-command-next TeX-command-Show)
812 (goto-char (point-min))
813 (apply TeX-sentinel-function nil name nil)
814
815 ;; Force mode line redisplay soon
816 (set-buffer-modified-p (buffer-modified-p)))))
817
818 (defun TeX-command-sentinel (process msg)
819 "Process TeX command output buffer after the process dies."
820 ;; Set `TeX-transient-master' here because `preview-parse-messages'
821 ;; may open files and thereby trigger master file questions which we
822 ;; don't want and need because we already know the master. Use
823 ;; `TeX-master-file' instead of `TeX-active-master' to determine the
824 ;; master because the region file should never be the master.
825 (let* ((TeX-transient-master (TeX-master-file))
826 (buffer (process-buffer process))
827 (name (process-name process)))
828 (cond ((null (buffer-name buffer)) ; buffer killed
829 (set-process-buffer process nil)
830 (set-process-sentinel process nil))
831 ((memq (process-status process) '(signal exit))
832 (save-excursion
833 (set-buffer buffer)
834
835 ;; Append post-mortem information to the buffer
836 (goto-char (point-max))
837 (insert-before-markers "\n" mode-name " " msg)
838 (forward-char -1)
839 (insert " at "
840 (substring (current-time-string) 0 -5))
841 (forward-char 1)
842
843 ;; Do command specific actions.
844 (TeX-command-mode-line process)
845 (setq TeX-command-next TeX-command-Show)
846 (goto-char (point-min))
847 (apply TeX-sentinel-function process name nil)
848
849
850 ;; If buffer and mode line will show that the process
851 ;; is dead, we can delete it now. Otherwise it
852 ;; will stay around until M-x list-processes.
853 (delete-process process)
854
855 ;; Force mode line redisplay soon
856 (set-buffer-modified-p (buffer-modified-p))))))
857 (setq compilation-in-progress (delq process compilation-in-progress)))
858
859
860 (defvar TeX-sentinel-function (lambda (process name))
861 "Hook to cleanup TeX command buffer after temination of PROCESS.
862 NAME is the name of the process.")
863
864 (make-variable-buffer-local 'TeX-sentinel-function)
865
866
867 (defvar TeX-sentinel-default-function (lambda (process name))
868 "Default for `TeX-sentinel-function'. To be set in major mode.
869 Hook to cleanup TeX command buffer after temination of PROCESS.
870 NAME is the name of the process.")
871
872 (make-variable-buffer-local 'TeX-sentinel-default-function)
873
874 (defun TeX-TeX-sentinel (process name)
875 "Cleanup TeX output buffer after running TeX."
876 (if (TeX-TeX-sentinel-check process name)
877 ()
878 (message (concat name ": formatted " (TeX-current-pages)))
879 (setq TeX-command-next TeX-command-Show)))
880
881 (defun TeX-current-pages ()
882 "Return string indicating the number of pages formatted."
883 (cond ((null TeX-current-page)
884 "some pages")
885 ((string-match "[^0-9]1[^0-9]" TeX-current-page)
886 (concat TeX-current-page " page"))
887 (t
888 (concat TeX-current-page " pages"))))
889
890 (defun TeX-TeX-sentinel-check (process name)
891 "Cleanup TeX output buffer after running TeX.
892 Return nil ifs no errors were found."
893 (save-excursion
894 (goto-char (point-max))
895 (if (re-search-backward "^Output written on \\(.*?\\) (\\([0-9]+\\) page"
896 nil t)
897 (let ((output-file (TeX-match-buffer 1)))
898 (setq TeX-current-page (concat "{" (TeX-match-buffer 2) "}"))
899 ;; Shave off quotation marks if present.
900 (when (string-match "\\`\"\\(.*\\)\"\\'" output-file)
901 (setq output-file (match-string 1 output-file)))
902 (setq TeX-output-extension
903 (if (string-match "\\.\\([^.]*\\)$" output-file)
904 (match-string 1 output-file)
905 "dvi")))))
906 (if process (TeX-format-mode-line process))
907 (if (re-search-forward "^\\(!\\|.*:[0-9]+:\\) " nil t)
908 (progn
909 (message "%s errors in `%s'. Use %s to display." name (buffer-name)
910 (substitute-command-keys
911 "\\<TeX-mode-map>\\[TeX-next-error]"))
912 (setq TeX-command-next TeX-command-default)
913 ;; error reported to TeX-error-report-switches
914 (setq TeX-error-report-switches
915 (plist-put TeX-error-report-switches
916 (intern (plist-get TeX-error-report-switches
917 'TeX-current-master))
918 t))
919 t)
920 (setq TeX-command-next TeX-command-Show)
921 nil))
922
923 (defun TeX-LaTeX-sentinel-has-warnings ()
924 "Return non-nil, if the output buffer contains warnings.
925 Warnings can be indicated by LaTeX or packages."
926 (save-excursion
927 (goto-char (point-min))
928 (re-search-forward
929 "^\\(LaTeX [A-Za-z]*\\|Package [A-Za-z]+ \\)Warning:" nil t)))
930
931 (defun TeX-LaTeX-sentinel-has-bad-boxes ()
932 "Return non-nil, if LaTeX output indicates overfull or underfull boxes."
933 (save-excursion
934 (goto-char (point-min))
935 (re-search-forward "^\\(Ov\\|Und\\)erfull \\\\" nil t)))
936
937 ;; should go into latex.el? --pg
938 (defun TeX-LaTeX-sentinel (process name)
939 "Cleanup TeX output buffer after running LaTeX."
940 (cond ((TeX-TeX-sentinel-check process name))
941 ((and (save-excursion
942 (re-search-forward
943 "^\\(?:LaTeX\\|Package natbib\\) Warning: Citation" nil t))
944 (with-current-buffer TeX-command-buffer
945 (and (LaTeX-bibliography-list)
946 (TeX-check-files (TeX-master-file "bbl")
947 (TeX-style-list)
948 (append TeX-file-extensions
949 BibTeX-file-extensions)))))
950 (message "%s%s" "You should run BibTeX to get citations right, "
951 (TeX-current-pages))
952 (setq TeX-command-next (with-current-buffer TeX-command-buffer
953 TeX-command-BibTeX)))
954 ((re-search-forward "^\\(?:LaTeX Warning: Label(s)\\|\
955 Package natbib Warning: Citation(s)\\)" nil t)
956 (message "%s%s" "You should run LaTeX again to get references right, "
957 (TeX-current-pages))
958 (setq TeX-command-next TeX-command-default))
959 ((re-search-forward "^LaTeX Warning: Reference" nil t)
960 (message "%s%s%s" name ": there were unresolved references, "
961 (TeX-current-pages))
962 (setq TeX-command-next TeX-command-Show))
963 ((re-search-forward "^\\(?:LaTeX Warning: Citation\\|\
964 Package natbib Warning:.*undefined citations\\)" nil t)
965 (message "%s%s%s" name ": there were unresolved citations, "
966 (TeX-current-pages))
967 (setq TeX-command-next TeX-command-Show))
968 ((re-search-forward "Package longtable Warning: Table widths have \
969 changed\\. Rerun LaTeX\\." nil t)
970 (message
971 "%s" "You should run LaTeX again to get table formatting right")
972 (setq TeX-command-next TeX-command-default))
973 ((re-search-forward
974 "^\\(\\*\\* \\)?J?I?p?\\(La\\|Sli\\)TeX\\(2e\\)? \
975 \\(Version\\|ver\\.\\|<[0-9/]*>\\)" nil t)
976 (let* ((warnings (and TeX-debug-warnings
977 (TeX-LaTeX-sentinel-has-warnings)))
978 (bad-boxes (and TeX-debug-bad-boxes
979 (TeX-LaTeX-sentinel-has-bad-boxes)))
980 (add-info (when (or warnings bad-boxes)
981 (concat " (with "
982 (when warnings "warnings")
983 (when (and warnings bad-boxes) " and ")
984 (when bad-boxes "bad boxes")
985 ")"))))
986 (message "%s" (concat name ": successfully formatted "
987 (TeX-current-pages) add-info)))
988 (setq TeX-command-next TeX-command-Show))
989 (t
990 (message "%s%s%s" name ": problems after " (TeX-current-pages))
991 (setq TeX-command-next TeX-command-default))))
992
993 ;; should go into latex.el? --pg
994 (defun TeX-BibTeX-sentinel (process name)
995 "Cleanup TeX output buffer after running BibTeX."
996 (goto-char (point-max))
997 (cond
998 ;; Check whether BibTeX reports any warnings or errors.
999 ((re-search-backward (concat
1000 "^(There \\(?:was\\|were\\) \\([0-9]+\\) "
1001 "\\(warnings?\\|error messages?\\))") nil t)
1002 ;; Tell the user their number so that she sees whether the
1003 ;; situation is getting better or worse.
1004 (message (concat "BibTeX finished with %s %s. "
1005 "Type `%s' to display output.")
1006 (match-string 1) (match-string 2)
1007 (substitute-command-keys
1008 "\\<TeX-mode-map>\\[TeX-recenter-output-buffer]")))
1009 (t
1010 (message (concat "BibTeX finished successfully. "
1011 "Run LaTeX again to get citations right."))))
1012 (setq TeX-command-next TeX-command-default))
1013
1014 ;;; Process Control
1015
1016
1017 ;; This variable is chared with `compile.el'.
1018 (defvar compilation-in-progress nil
1019 "List of compilation processes now running.")
1020
1021 (or (assq 'compilation-in-progress minor-mode-alist)
1022 (setq minor-mode-alist (cons '(compilation-in-progress " Compiling")
1023 minor-mode-alist)))
1024
1025 (defun TeX-process-get-variable (name symbol &optional default)
1026 "Return the value in the process buffer for NAME of SYMBOL.
1027
1028 Return DEFAULT if the process buffer does not exist or SYMBOL is not
1029 defined."
1030 (let ((buffer (TeX-process-buffer name)))
1031 (if (and buffer
1032 (local-variable-p symbol buffer))
1033 (save-excursion
1034 (set-buffer buffer)
1035 (symbol-value symbol))
1036 default)))
1037
1038 (defun TeX-process-set-variable (name symbol value)
1039 "Set the variable SYMBOL in the process buffer to VALUE.
1040 Return nil iff no process buffer exist."
1041 (let ((buffer (TeX-process-buffer name)))
1042 (if buffer
1043 (save-excursion
1044 (set-buffer buffer)
1045 (set symbol value)
1046 t)
1047 nil)))
1048
1049 (defun TeX-process-check (name)
1050 "Check if a process for the TeX document NAME already exist.
1051 If so, give the user the choice of aborting the process or the current
1052 command."
1053 (let (process)
1054 (while (and (setq process (TeX-process name))
1055 (eq (process-status process) 'run))
1056 (cond
1057 ((yes-or-no-p (concat "Process `"
1058 (process-name process)
1059 "' for document `"
1060 name
1061 "' running, kill it? "))
1062 (delete-process process))
1063 ((eq (process-status process) 'run)
1064 (error "Cannot have two processes for the same document"))))))
1065
1066 (defun TeX-process-buffer-name (name)
1067 "Return name of AUCTeX buffer associated with the document NAME."
1068 (concat "*" (abbreviate-file-name (expand-file-name name)) " output*"))
1069
1070 (defun TeX-process-buffer (name)
1071 "Return the AUCTeX buffer associated with the document NAME."
1072 (get-buffer (TeX-process-buffer-name name)))
1073
1074 (defun TeX-process (name)
1075 "Return AUCTeX process associated with the document NAME."
1076 (and TeX-process-asynchronous
1077 (get-buffer-process (TeX-process-buffer name))))
1078
1079 ;;; Process Filters
1080
1081 (defun TeX-command-mode-line (process)
1082 "Format the mode line for a buffer containing output from PROCESS."
1083 (setq mode-line-process (concat ": "
1084 (symbol-name (process-status process))))
1085 (set-buffer-modified-p (buffer-modified-p)))
1086
1087 (defun TeX-command-filter (process string)
1088 "Filter to process normal output."
1089 (with-current-buffer (process-buffer process)
1090 (save-excursion
1091 (goto-char (process-mark process))
1092 (insert-before-markers string)
1093 (set-marker (process-mark process) (point)))))
1094
1095 (defvar TeX-current-page nil
1096 "The page number currently being formatted, enclosed in brackets.")
1097
1098 (make-variable-buffer-local 'TeX-current-page)
1099
1100 (defun TeX-format-mode-line (process)
1101 "Format the mode line for a buffer containing TeX output from PROCESS."
1102 (setq mode-line-process (concat " " TeX-current-page ": "
1103 (symbol-name (process-status process))))
1104 (set-buffer-modified-p (buffer-modified-p)))
1105
1106 (defun TeX-format-filter (process string)
1107 "Filter to process TeX output."
1108 (with-current-buffer (process-buffer process)
1109 (let (str pos end (pt (marker-position (process-mark process))))
1110 (save-excursion
1111 (goto-char pt)
1112 (insert-before-markers string)
1113 (set-marker (process-mark process) (point))
1114 ;; Remove line breaks at column 79
1115 (while (> (point) pt)
1116 (end-of-line 0)
1117 (when (and (= (current-column) 79)
1118 ;; Heuristic: Don't delete the linebreak if the
1119 ;; next line is empty or starts with an opening
1120 ;; parenthesis or if point is located after a period.
1121 (not (memq (char-after (1+ (point))) '(?\n ?\()))
1122 (not (eq (char-before) ?.)))
1123 (delete-char 1)))
1124 (goto-char (marker-position (process-mark process)))
1125 ;; Determine current page
1126 (while (and pt
1127 (skip-chars-backward "^]" pt)
1128 (> (point) pt))
1129 (setq end (point))
1130 (backward-char)
1131 (skip-chars-backward "-0-9\n." (max (point-min) (- pt 128)))
1132 (when (and (eq ?\[ (char-before))
1133 (not (eq ?\] (char-after)))
1134 (progn
1135 (setq str (buffer-substring (1- (point)) end)
1136 pos nil)
1137 (while (setq pos (string-match "\n" str pos))
1138 (setq str (replace-match "" t t str)))
1139 (string-match
1140 "\\`\\[-?[0-9]+\\(\\.-?[0-9]+\\)\\{0,9\\}\\]\\'"
1141 str)))
1142 (setq TeX-current-page str
1143 pt nil)
1144 (TeX-format-mode-line process)))))))
1145
1146 (defvar TeX-parse-function nil
1147 "Function to call to parse content of TeX output buffer.")
1148 (make-variable-buffer-local 'TeX-parse-function)
1149
1150 (defun TeX-background-filter (process string)
1151 "Filter to process background output."
1152 (let ((old-window (selected-window))
1153 (pop-up-windows t))
1154 (TeX-pop-to-buffer "*TeX background*" nil t)
1155 (goto-char (point-max))
1156 (insert string)
1157 (select-window old-window)))
1158
1159 ;; Copy and adaption of `comint-postoutput-scroll-to-bottom' from CVS
1160 ;; Emacs of 2005-04-24.
1161 (defun TeX-interactive-goto-prompt (string)
1162 "Move point to prompt of an interactive TeX run."
1163 (let* ((selected (selected-window))
1164 (current (current-buffer))
1165 (process (get-buffer-process current)))
1166 (unwind-protect
1167 (when process
1168 (walk-windows
1169 (lambda (window)
1170 (when (eq (window-buffer window) current)
1171 (select-window window)
1172 (when (and (< (point) (process-mark process))
1173 (string-match "^\\? $" string))
1174 (goto-char (process-mark process)))
1175 (select-window selected)))
1176 nil t))
1177 (set-buffer current))))
1178
1179
1180 ;;; Active Process
1181
1182 (defvar TeX-current-process-region-p nil
1183 "This variable is set to t iff the last TeX command is on a region.")
1184
1185 (defun TeX-active-process ()
1186 "Return the active process for the current buffer."
1187 (TeX-process (TeX-active-master)))
1188
1189 (defun TeX-active-buffer ()
1190 "Return the buffer of the active process for this buffer."
1191 (and TeX-command-buffer
1192 (TeX-process-buffer (with-current-buffer TeX-command-buffer
1193 (TeX-active-master)))))
1194
1195 (defun TeX-active-master (&optional extension nondirectory)
1196 "The master file currently being compiled.
1197
1198 If optional argument EXTENSION is non-nil, add that file extension to
1199 the name. Special value t means use `TeX-default-extension'.
1200
1201 If optional second argument NONDIRECTORY is non-nil, do not include
1202 the directory."
1203 (if TeX-current-process-region-p
1204 (TeX-region-file extension nondirectory)
1205 (TeX-master-file extension nondirectory)))
1206
1207 (defvar TeX-command-buffer nil
1208 "The buffer from where the last TeX command was issued.")
1209
1210 ;;; Region File
1211
1212 (defcustom TeX-region-extra ""
1213 "*String to insert in the region file between the header and the text."
1214 :group 'TeX-command
1215 :type 'string)
1216
1217 ;; This was "{\\makeatletter\\gdef\\AucTeX@cite#1[#2]#3{[#3#1#2]}\
1218 ;; \\gdef\\cite{\\@ifnextchar[{\\AucTeX@cite{, }}\
1219 ;; {\\AucTeX@cite{}[]}}}\n"
1220 ;; However, that string is inappropriate for plain TeX and ConTeXt.
1221 ;; This needs reconsideration.
1222
1223
1224 (defvar TeX-region-hook nil
1225 "List of hooks to run before the region file is saved.
1226 The hooks are run in the region buffer, you may use the variable
1227 `master-buffer' to access the buffer of the master file and
1228 `orig-buffer' to access the buffer where \\[TeX-command-region] or
1229 \\[TeX-command-buffer] is invoked from.")
1230
1231 (defun TeX-quote-filename (file)
1232 "Convert file name into a form acceptable to TeX."
1233 (let (pos)
1234 (while (setq pos (string-match "\\\\" file pos))
1235 (setq file (replace-match "/" t t file 0)
1236 pos (1+ pos)))
1237 (while (setq pos (string-match "[~#]" file pos))
1238 (setq file (replace-match "\\\\string\\&" t nil file 0)
1239 pos (+ pos 8))))
1240 file)
1241
1242 (defun TeX-region-create (file region original offset)
1243 "Create a new file named FILE with the string REGION.
1244 The region is taken from ORIGINAL starting at line OFFSET.
1245
1246 The current buffer and master file is searched, in order to ensure
1247 that the TeX header and trailer information is also included.
1248
1249 The OFFSET is used to provide the debugger with information about the
1250 original file."
1251 (let* (;; We shift buffer a lot, so we must keep track of the buffer
1252 ;; local variables.
1253 (header-end TeX-header-end)
1254 (trailer-start TeX-trailer-start)
1255
1256 ;; We seach for header and trailer in the master file.
1257 (orig-buffer (current-buffer))
1258 (master-name (TeX-master-file TeX-default-extension))
1259 (master-buffer (find-file-noselect master-name))
1260
1261 ;; Attempt to disable font lock.
1262 (font-lock-defaults-alist nil)
1263 (font-lock-defaults nil)
1264 (font-lock-maximum-size 0)
1265 (font-lock-mode-hook nil)
1266 (font-lock-auto-fontify nil)
1267 (font-lock-mode-enable-list nil)
1268 ;; And insert them into the FILE buffer.
1269 (file-buffer (let ((TeX-transient-master t))
1270 (find-file-noselect file)))
1271 ;; But remember original content.
1272 original-content
1273
1274 ;; We search for the header from the master file, if it is
1275 ;; not present in the region.
1276 (header (if (string-match header-end region)
1277 ""
1278 (save-excursion
1279 (save-restriction
1280 (set-buffer master-buffer)
1281 (save-excursion
1282 (save-restriction
1283 (widen)
1284 (goto-char (point-min))
1285 ;; NOTE: We use the local value of
1286 ;; TeX-header-end from the master file.
1287 (if (not (re-search-forward TeX-header-end nil t))
1288 ""
1289 (re-search-forward "[\r\n]" nil t)
1290 (buffer-substring (point-min) (point)))))))))
1291
1292 ;; We search for the trailer from the master file, if it is
1293 ;; not present in the region.
1294 (trailer-offset 0)
1295 (trailer (if (string-match trailer-start region)
1296 ""
1297 (save-excursion
1298 (save-restriction
1299 (set-buffer master-buffer)
1300 (save-excursion
1301 (save-restriction
1302 (widen)
1303 (goto-char (point-max))
1304 ;; NOTE: We use the local value of
1305 ;; TeX-trailer-start from the master file.
1306 (if (not (re-search-backward TeX-trailer-start nil t))
1307 ""
1308 ;;(beginning-of-line 1)
1309 (re-search-backward "[\r\n]" nil t)
1310 (setq trailer-offset (TeX-current-offset))
1311 (buffer-substring (point) (point-max))))))))))
1312 ;; file name should be relative to master
1313 (setq original (TeX-quote-filename (file-relative-name
1314 original (TeX-master-directory)))
1315 master-name (TeX-quote-filename master-name))
1316 (save-excursion
1317 (set-buffer file-buffer)
1318 (setq buffer-undo-list t)
1319 (setq original-content (buffer-string))
1320 (erase-buffer)
1321 (when (boundp 'buffer-file-coding-system)
1322 (setq buffer-file-coding-system
1323 (with-current-buffer master-buffer buffer-file-coding-system)))
1324 (insert "\\message{ !name(" master-name ")}"
1325 header
1326 TeX-region-extra
1327 "\n\\message{ !name(" original ") !offset(")
1328 (insert (int-to-string (- offset
1329 (1+ (TeX-current-offset))))
1330 ") }\n"
1331 region
1332 "\n\\message{ !name(" master-name ") !offset(")
1333 (insert (int-to-string (- trailer-offset
1334 (1+ (TeX-current-offset))))
1335 ") }\n"
1336 trailer)
1337 (run-hooks 'TeX-region-hook)
1338 (if (string-equal (buffer-string) original-content)
1339 (set-buffer-modified-p nil)
1340 (save-buffer 0)))))
1341
1342 (defun TeX-region-file (&optional extension nondirectory)
1343 "Return TeX-region file name with EXTENSION.
1344 If optional second argument NONDIRECTORY is non-nil, do not include
1345 the directory."
1346 (concat (if nondirectory "" (TeX-master-directory))
1347 (cond ((eq extension t)
1348 (concat TeX-region "." TeX-default-extension))
1349 (extension
1350 (concat TeX-region "." extension))
1351 (t
1352 TeX-region))))
1353
1354 (defcustom TeX-region "_region_"
1355 "*Base name of temporary file for `TeX-command-region' and `TeX-command-buffer'."
1356 :group 'TeX-command
1357 :type 'string)
1358
1359 ;;; Parsing
1360
1361 ;;; - Global Parser Variables
1362
1363 (defvar TeX-error-point nil
1364 "How far we have parsed until now.")
1365
1366 (make-variable-buffer-local 'TeX-error-point)
1367
1368 (defvar TeX-error-file nil
1369 "Stack of files in which errors have occured.")
1370
1371 (make-variable-buffer-local 'TeX-error-file)
1372
1373 (defvar TeX-error-offset nil
1374 "Add this to any line numbers from TeX. Stack like `TeX-error-file'.")
1375
1376 (make-variable-buffer-local 'TeX-error-offset)
1377
1378 (defun TeX-parse-reset ()
1379 "Reset all variables used for parsing TeX output."
1380 (setq TeX-error-point (point-min))
1381 (setq TeX-error-offset nil)
1382 (setq TeX-error-file nil))
1383
1384 ;;; - Parsers Hooks
1385
1386 (defun TeX-parse-command (reparse)
1387 "We can't parse anything but TeX."
1388 (error "I cannot parse %s output, sorry"
1389 (if (TeX-active-process)
1390 (process-name (TeX-active-process))
1391 "this")))
1392
1393 (defun TeX-parse-TeX (reparse)
1394 "Find the next error produced by running TeX.
1395 With \\[universal-argument] prefix, start from the beginning of the errors.
1396
1397 If the file occurs in an included file, the file is loaded (if not
1398 already in an Emacs buffer) and the cursor is placed at the error."
1399 (let ((old-buffer (current-buffer))
1400 (default-major-mode major-mode))
1401 (with-current-buffer (TeX-active-buffer)
1402 (if reparse
1403 (TeX-parse-reset))
1404 (goto-char TeX-error-point)
1405 (TeX-parse-error old-buffer))))
1406
1407 ;;; - Parsing (La)TeX
1408
1409 (defvar TeX-translate-location-hook nil
1410 "List of functions to be called before showing an error or warning.
1411
1412 You might want to examine and modify the free variables `file',
1413 `offset', `line', `string', `error', and `context' from this hook.")
1414
1415 (defun TeX-parse-error (old)
1416 "Goto next error. Pop to OLD buffer if no more errors are found."
1417 (let ((regexp
1418 (concat
1419 ;; TeX error
1420 "^\\(!\\|\\(.*?\\):[0-9]+:\\) \\|"
1421 ;; New file
1422 "(\\(\"[^\"]*?\"\\|/*\
1423 \\(?:\\.+[^()\r\n{} \\/]*\\|[^()\r\n{} .\\/]+\
1424 \\(?: [^()\r\n{} .\\/]+\\)*\\(?:\\.[-0-9a-zA-Z_.]*\\)?\\)\
1425 \\(?:[\\/]+\\(?:\\.+[^()\r\n{} \\/]*\\|[^()\r\n{} .\\/]+\
1426 \\(?: [^()\r\n{} .\\/]+\\)*\\(?:\\.[-0-9a-zA-Z_.]*\\)?\\)?\\)*\\)\
1427 )*\\(?: \\|\r?$\\)\\|"
1428 ;; End of file
1429 "\\()\\))*\\|"
1430 ;; Hook to change line numbers
1431 " !\\(?:offset(\\([---0-9]+\\))\\|"
1432 ;; Hook to change file name
1433 "name(\\([^)]+\\))\\)\\|"
1434 ;; LaTeX bad box
1435 "^\\(\\(?:Overfull\\|Underfull\\|Tight\\|Loose\\)\
1436 \\\\.*?[0-9]+--[0-9]+\\)\\|"
1437 ;; LaTeX warning
1438 "^\\(LaTeX [A-Za-z]*\\|Package [A-Za-z]+ \\)Warning:.*")))
1439 (while
1440 (cond
1441 ((null
1442 (re-search-forward regexp nil t))
1443 ;; No more errors.
1444 (message "No more errors.")
1445 (beep)
1446 (TeX-pop-to-buffer old)
1447 nil)
1448 ;; TeX error
1449 ((match-beginning 1)
1450 (when (match-beginning 2)
1451 (unless TeX-error-file
1452 (push nil TeX-error-file)
1453 (push nil TeX-error-offset))
1454 (unless (car TeX-error-offset)
1455 (rplaca TeX-error-file (TeX-match-buffer 2))))
1456 (if (looking-at "Preview ")
1457 t
1458 (TeX-error)
1459 nil))
1460 ;; LaTeX bad box
1461 ((match-beginning 7)
1462 (if TeX-debug-bad-boxes
1463 (progn
1464 (TeX-warning (TeX-match-buffer 7))
1465 nil)
1466 (re-search-forward "\r?\n\
1467 \\(?:.\\{79\\}\r?\n\
1468 \\)*.*\r?$")
1469 t))
1470 ;; LaTeX warning
1471 ((match-beginning 8)
1472 (if TeX-debug-warnings
1473 (progn
1474 (TeX-warning (TeX-match-buffer 8))
1475 nil)
1476 t))
1477
1478 ;; New file -- Push on stack
1479 ((match-beginning 3)
1480 (let ((file (TeX-match-buffer 3))
1481 (end (match-end 3)))
1482 ;; Strip quotation marks and remove newlines if necessary
1483 (when (or (eq (string-to-char file) ?\")
1484 (string-match "\n" file))
1485 (setq file
1486 (mapconcat 'identity (split-string file "[\"\n]+") "")))
1487 (push file TeX-error-file)
1488 (push nil TeX-error-offset)
1489 (goto-char end))
1490 t)
1491
1492 ;; End of file -- Pop from stack
1493 ((match-beginning 4)
1494 (when (> (length TeX-error-file) 1)
1495 (pop TeX-error-file)
1496 (pop TeX-error-offset))
1497 (goto-char (match-end 4))
1498 t)
1499
1500 ;; Hook to change line numbers
1501 ((match-beginning 5)
1502 (setq TeX-error-offset
1503 (list (string-to-number (TeX-match-buffer 5))))
1504 t)
1505
1506 ;; Hook to change file name
1507 ((match-beginning 6)
1508 (setq TeX-error-file
1509 (list (TeX-match-buffer 6)))
1510 t)))))
1511
1512 (defun TeX-error ()
1513 "Display an error."
1514
1515 (let* (;; We need the error message to show the user.
1516 (error (progn
1517 (re-search-forward "\\(.*\\)")
1518 (TeX-match-buffer 1)))
1519
1520 ;; And the context for the help window.
1521 (context-start (point))
1522 context-available
1523
1524 ;; And the line number to position the cursor.
1525 (line (cond
1526 ;; regular style
1527 ((re-search-forward "l\\.\\([0-9]+\\)" nil t)
1528 (setq context-available t)
1529 (string-to-number (TeX-match-buffer 1)))
1530 ;; file:line:error style
1531 ((save-excursion
1532 (re-search-backward ":\\([0-9]+\\): "
1533 (line-beginning-position) t))
1534 (string-to-number (TeX-match-buffer 1)))
1535 ;; nothing found
1536 (t 1)))
1537
1538 ;; And a string of the context to search for.
1539 (string (progn
1540 (beginning-of-line)
1541 (re-search-forward " \\(\\([^ \t]*$\\)\\|\\($\\)\\)")
1542 (TeX-match-buffer 1)))
1543
1544 ;; And we have now found to the end of the context.
1545 (context (if context-available
1546 (buffer-substring context-start (progn (forward-line 1)
1547 (end-of-line)
1548 (point)))
1549 ;; There is no real context available, so we
1550 ;; simply show the line with the error message.
1551 (buffer-substring (1- (line-beginning-position))
1552 context-start)))
1553 ;; We may use these in another buffer.
1554 (offset (or (car TeX-error-offset) 0))
1555 (file (car TeX-error-file)))
1556
1557 ;; Remember where we was.
1558 (setq TeX-error-point (point))
1559
1560 ;; Find the error.
1561 (if (null file)
1562 (error "Error occured after last TeX file closed"))
1563 (let ((runbuf (current-buffer))
1564 (master (with-current-buffer
1565 TeX-command-buffer
1566 (expand-file-name (TeX-master-file))))
1567 (command-buffer TeX-command-buffer)
1568 error-file-buffer)
1569 (run-hooks 'TeX-translate-location-hook)
1570 (setq error-file-buffer (find-file file))
1571 ;; Set the value of `TeX-command-buffer' in the next file with an
1572 ;; error to be displayed to the value it has in the current buffer.
1573 (with-current-buffer error-file-buffer
1574 (set (make-local-variable 'TeX-command-buffer) command-buffer))
1575 (goto-line (+ offset line))
1576 (if (not (string= string " "))
1577 (search-forward string nil t))
1578
1579 ;; Explain the error.
1580 (cond ((eq TeX-display-help 'expert)
1581 (TeX-pop-to-buffer runbuf nil t)
1582 (goto-char TeX-error-point)
1583 (TeX-pop-to-buffer error-file-buffer nil t))
1584 (TeX-display-help
1585 (TeX-help-error error context runbuf))
1586 (t
1587 (message (concat "! " error)))))))
1588
1589 (defun TeX-warning (string)
1590 "Display a warning for STRING."
1591
1592 (let* ((error (concat "** " string))
1593
1594 ;; bad-box is nil if this is a "LaTeX Warning"
1595 (bad-box (string-match "\\\\[vh]box.*[0-9]*--[0-9]*" string))
1596 ;; line-string: match 1 is beginning line, match 2 is end line
1597 (line-string (if bad-box " \\([0-9]*\\)--\\([0-9]*\\)"
1598 "on input line \\([0-9]*\\)\\."))
1599 ;; word-string: match 1 is the word
1600 (word-string (if bad-box "[][\\W() ---]\\(\\w+\\)[][\\W() ---]*$"
1601 "`\\(\\w+\\)'"))
1602
1603 ;; Get error-line (warning)
1604 (line (when (re-search-backward line-string nil t)
1605 (string-to-number (TeX-match-buffer 1))))
1606 (line-end (if bad-box (string-to-number (TeX-match-buffer 2))
1607 line))
1608
1609 ;; Find the context
1610 (context-start (progn (if bad-box (end-of-line)
1611 (beginning-of-line))
1612 (point)))
1613
1614 (context (progn
1615 (forward-line 1)
1616 (end-of-line)
1617 (while (equal (current-column) 79)
1618 (forward-line 1)
1619 (end-of-line))
1620 (buffer-substring context-start (point))))
1621
1622 ;; This is where we want to be.
1623 (error-point (point))
1624
1625 ;; Now find the error word.
1626 (string (when (re-search-backward word-string context-start t)
1627 (TeX-match-buffer 1)))
1628
1629 ;; We might use these in another file.
1630 (offset (or (car TeX-error-offset) 0))
1631 (file (car TeX-error-file)))
1632
1633 ;; This is where we start next time.
1634 (goto-char error-point)
1635 (setq TeX-error-point (point))
1636
1637 ;; Go back to TeX-buffer
1638 (let ((runbuf (current-buffer))
1639 (master (with-current-buffer
1640 TeX-command-buffer
1641 (expand-file-name (TeX-master-file))))
1642 (command-buffer TeX-command-buffer)
1643 error-file-buffer)
1644 (run-hooks 'TeX-translate-location-hook)
1645 (setq error-file-buffer (find-file file))
1646 ;; Set the value of `TeX-command-buffer' in the next file with an
1647 ;; error to be displayed to the value it has in the current buffer.
1648 (with-current-buffer error-file-buffer
1649 (set (make-local-variable 'TeX-command-buffer) command-buffer))
1650 ;; Find line and string
1651 (when line
1652 (goto-line (+ offset line))
1653 (beginning-of-line 0)
1654 (let ((start (point)))
1655 (goto-line (+ offset line-end))
1656 (end-of-line)
1657 (when string
1658 (search-backward string start t)
1659 (search-forward string nil t))))
1660 ;; Display help
1661 (cond ((eq TeX-display-help 'expert)
1662 (TeX-pop-to-buffer runbuf nil t)
1663 (goto-char TeX-error-point)
1664 (TeX-pop-to-buffer error-file-buffer nil t))
1665 (TeX-display-help
1666 (TeX-help-error error (if bad-box context (concat "\n" context))
1667 runbuf))
1668 (t
1669 (message (concat "! " error)))))))
1670
1671 ;;; - Help
1672
1673 (defun TeX-help-error (error output runbuffer)
1674 "Print ERROR in context OUTPUT from RUNBUFFER in another window."
1675
1676 (let ((old-buffer (current-buffer))
1677 (log-file (with-current-buffer runbuffer
1678 (with-current-buffer TeX-command-buffer
1679 (expand-file-name (TeX-active-master "log")))))
1680 (TeX-error-pointer 0))
1681
1682 ;; Find help text entry.
1683 (while (not (string-match (car (nth TeX-error-pointer
1684 TeX-error-description-list))
1685 error))
1686 (setq TeX-error-pointer (+ TeX-error-pointer 1)))
1687
1688 (TeX-pop-to-buffer (get-buffer-create "*TeX Help*") nil t)
1689 (erase-buffer)
1690 (insert "ERROR: " error
1691 "\n\n--- TeX said ---"
1692 output
1693 "\n--- HELP ---\n"
1694 (let ((help (cdr (nth TeX-error-pointer
1695 TeX-error-description-list))))
1696 (save-excursion
1697 (if (and (string= help "No help available")
1698 (let* ((log-buffer (find-buffer-visiting log-file)))
1699 (if log-buffer
1700 (progn
1701 (set-buffer log-buffer)
1702 (revert-buffer t t))
1703 (setq log-buffer
1704 (find-file-noselect log-file))
1705 (set-buffer log-buffer))
1706 (auto-save-mode nil)
1707 (setq buffer-read-only t)
1708 (goto-line (point-min))
1709 (search-forward error nil t 1))
1710 (re-search-forward "^l\\." nil t)
1711 (re-search-forward "^ [^\n]+$" nil t))
1712 (let ((start (1+ (point))))
1713 (forward-char 1)
1714 (re-search-forward "^$")
1715 (concat "From the .log file...\n\n"
1716 (buffer-substring start (point))))
1717 help))))
1718 (goto-char (point-min))
1719 (TeX-pop-to-buffer old-buffer nil t)))
1720
1721 ;;; Error Messages
1722
1723 (defcustom TeX-error-description-list
1724 '(("\\(?:Package Preview Error\\|Preview\\):.*" .
1725 "The `auctex' option to `preview' should not be applied manually.
1726 If you see this error message outside of a preview run, either
1727 you did something too clever, or AUCTeX something too stupid.")
1728
1729 ("Bad \\\\line or \\\\vector argument.*" .
1730 "The first argument of a \\line or \\vector command, which specifies the
1731 slope, is illegal\.")
1732
1733 ("Bad math environment delimiter.*" .
1734 "TeX has found either a math-mode-starting command such as \\[ or \\(
1735 when it is already in math mode, or else a math-mode-ending command
1736 such as \\) or \\] while in LR or paragraph mode. The problem is caused
1737 by either unmatched math mode delimiters or unbalanced braces\.")
1738
1739 ("Bad use of \\\\\\\\.*" .
1740 "A \\\\ command appears between paragraphs, where it makes no sense. This
1741 error message occurs when the \\\\ is used in a centering or flushing
1742 environment or else in the scope of a centering or flushing
1743 declaration.")
1744
1745 ("\\\\begin{[^ ]*} ended by \\\\end{[^ ]*}." .
1746 "LaTeX has found an \\end command that doesn't match the corresponding
1747 \\begin command. You probably misspelled the environment name in the
1748 \\end command, have an extra \\begin, or else forgot an \\end.")
1749
1750 ("Can be used only in preamble." .
1751 "LaTeX has encountered, after the \\begin{document}, one of the
1752 following commands that should appear only in the preamble:
1753 \\documentclass, \\nofiles, \\includeonly, \\makeindex, or
1754 \\makeglossary. The error is also caused by an extra \\begin{document}
1755 command.")
1756
1757 ("Command name [^ ]* already used.*" .
1758 "You are using \\newcommand, \\newenvironment, \\newlength, \\newsavebox,
1759 or \\newtheorem to define a command or environment name that is
1760 already defined, or \\newcounter to define a counter that already
1761 exists. (Defining an environment named gnu automatically defines the
1762 command \\gnu.) You'll have to choose a new name or, in the case of
1763 \\newcommand or \\newenvironment, switch to the \\renew ... command.")
1764
1765 ("Counter too large." .
1766 "1. Some object that is numbered with letters, probably an item in a
1767 enumerated list, has received a number greater than 26. Either you're
1768 making a very long list or you've been resetting counter values.
1769
1770 2. Footnotes are being ``numbered'' with letters or footnote symbols
1771 and LaTeX has run out of letters or symbols. This is probably caused
1772 by too many \\thanks commands.")
1773
1774 ("Environment [^ ]* undefined." .
1775 "LaTeX has encountered a \\begin command for a nonexistent environment.
1776 You probably misspelled the environment name. ")
1777
1778 ("Float(s) lost." .
1779 "You put a figure or table environment or a \\marginpar command inside a
1780 parbox---either one made with a minipage environment or \\parbox
1781 command, or one constructed by LaTeX in making a footnote, figure,
1782 etc. This is an outputting error, and the offending environment or
1783 command may be quite a way back from the point where LaTeX discovered
1784 the problem. One or more figures, tables, and/or marginal notes have
1785 been lost, but not necessarily the one that caused the error.")
1786
1787 ("Illegal character in array arg." .
1788 "There is an illegal character in the argument of an array or tabular
1789 environment, or in the second argument of a \\multicolumn command.")
1790
1791 ("Missing \\\\begin{document}." .
1792 "LaTeX produced printed output before encountering a \\begin{document}
1793 command. Either you forgot the \\begin{document} command or there is
1794 something wrong in the preamble. The problem may be a stray character
1795 or an error in a declaration---for example, omitting the braces around
1796 an argument or forgetting the \\ in a command name.")
1797
1798 ("Missing p-arg in array arg.*" .
1799 "There is a p that is not followed by an expression in braces in the
1800 argument of an array or tabular environment, or in the second argument
1801 of a \\multicolumn command.")
1802
1803 ("Missing @-exp in array arg." .
1804 "There is an @ character not followed by an @-expression in the
1805 argument of an array or tabular environment, or in the second argument
1806 of a \\multicolumn command.")
1807
1808 ("No such counter." .
1809 "You have specified a nonexistent counter in a \\setcounter or
1810 \\addtocounter command. This is probably caused by a simple typing
1811 error. However, if the error occurred while a file with the extension
1812 aux is being read, then you probably used a \\newcounter command
1813 outside the preamble.")
1814
1815 ("Not in outer par mode." .
1816 "You had a figure or table environment or a \\marginpar command in math
1817 mode or inside a parbox.")
1818
1819 ("\\\\pushtabs and \\\\poptabs don't match." .
1820 "LaTeX found a \\poptabs with no matching \\pushtabs, or has come to the
1821 \\end{tabbing} command with one or more unmatched \\pushtabs commands.")
1822
1823 ("Something's wrong--perhaps a missing \\\\item." .
1824 "The most probable cause is an omitted \\item command in a list-making
1825 environment. It is also caused by forgetting the argument of a
1826 thebibliography environment.")
1827
1828 ("Tab overflow." .
1829 "A \\= command has exceeded the maximum number of tab stops that LaTeX
1830 permits.")
1831
1832 ("There's no line here to end." .
1833 "A \\newline or \\\\ command appears between paragraphs, where it makes no
1834 sense. If you're trying to ``leave a blank line'', use a \\vspace
1835 command.")
1836
1837 ("This may be a LaTeX bug." .
1838 "LaTeX has become thoroughly confused. This is probably due to a
1839 previously detected error, but it is possible that you have found an
1840 error in LaTeX itself. If this is the first error message produced by
1841 the input file and you can't find anything wrong, save the file and
1842 contact the person listed in your Local Guide.")
1843
1844 ("Too deeply nested." .
1845 "There are too many list-making environments nested within one another.
1846 How many levels of nesting are permitted may depend upon what computer
1847 you are using, but at least four levels are provided, which should be
1848 enough.")
1849
1850 ("Too many unprocessed floats." .
1851 "While this error can result from having too many \\marginpar commands
1852 on a page, a more likely cause is forcing LaTeX to save more figures
1853 and tables than it has room for. When typesetting its continuous
1854 scroll, LaTeX saves figures and tables separately and inserts them as
1855 it cuts off pages. This error occurs when LaTeX finds too many figure
1856 and/or table environments before it is time to cut off a page, a
1857 problem that is solved by moving some of the environments farther
1858 towards the end of the input file. The error can also be caused by a
1859 ``logjam''---a figure or table that cannot be printed causing others
1860 to pile up behind it, since LaTeX will not print figures or tables out
1861 of order. The jam can be started by a figure or table that either is
1862 too large to fit on a page or won't fit where its optional placement
1863 argument says it must go. This is likely to happen if the argument
1864 does not contain a p option.")
1865
1866 ("Undefined tab position." .
1867 "A \\>, \\+, \\-, or \\< command is trying to go to a nonexistent tab
1868 position---one not defined by a \\= command.")
1869
1870 ("\\\\< in mid line." .
1871 "A \\< command appears in the middle of a line in a tabbing environment.
1872 This command should come only at the beginning of a line.")
1873
1874 ("Double subscript." .
1875 "There are two subscripts in a row in a mathematical
1876 formula---something like x_{2}_{3}, which makes no sense.")
1877
1878 ("Double superscript." .
1879 "There are two superscripts in a row in a mathematical
1880 formula---something like x^{2}^{3}, which makes no sense.")
1881
1882 ("Extra alignment tab has been changed to \\\\cr." .
1883 "There are too many separate items (column entries) in a single row of
1884 an array or tabular environment. In other words, there were too many &
1885 's before the end of the row. You probably forgot the \\\\ at the end of
1886 the preceding row.")
1887
1888 ("Extra \\}, or forgotten \\$." .
1889 "The braces or math mode delimiters don't match properly. You probably
1890 forgot a {, \\[, \\(, or $.")
1891
1892 ("Font [^ ]* not loaded: Not enough room left." .
1893 "The document uses more fonts than TeX has room for. If different parts
1894 of the document use different fonts, then you can get around the
1895 problem by processing it in parts.")
1896
1897 ("I can't find file `.*'." .
1898 "TeX can't find a file that it needs. If the name of the missing file
1899 has the extension tex, then it is looking for an input file that you
1900 specified---either your main file or another file inserted with an
1901 \\input or \\include command. If the missing file has the extension sty
1902 , then you have specified a nonexistent document style or style
1903 option.")
1904
1905 ("Illegal parameter number in definition of .*" .
1906 "This is probably caused by a \\newcommand, \\renewcommand,
1907 \\newenvironment, or \\renewenvironment command in which a # is used
1908 incorrectly. A # character, except as part of the command name \\#,
1909 can be used only to indicate an argument parameter, as in #2, which
1910 denotes the second argument. This error is also caused by nesting one
1911 of the above four commands inside another, or by putting a parameter
1912 like #2 in the last argument of a \\newenvironment or \\renewenvironment
1913 command.")
1914
1915 ("Illegal unit of measure ([^ ]* inserted)." .
1916 "If you just got a
1917
1918 ! Missing number, treated as zero.
1919
1920 error, then this is part of the same problem. If not, it means that
1921 LaTeX was expecting a length as an argument and found a number
1922 instead. The most common cause of this error is writing 0 instead of
1923 something like 0in for a length of zero, in which case typing return
1924 should result in correct output. However, the error can also be caused
1925 by omitting a command argument.")
1926
1927 ("Misplaced alignment tab character \\&." .
1928 "The special character &, which should be used only to separate items
1929 in an array or tabular environment, appeared in ordinary text. You
1930 probably meant to type \\&.")
1931
1932 ("Missing control sequence inserted." .
1933 "This is probably caused by a \\newcommand, \\renewcommand, \\newlength,
1934 or \\newsavebox command whose first argument is not a command name.")
1935
1936 ("Missing number, treated as zero." .
1937 "This is usually caused by a LaTeX command expecting but not finding
1938 either a number or a length as an argument. You may have omitted an
1939 argument, or a square bracket in the text may have been mistaken for
1940 the beginning of an optional argument. This error is also caused by
1941 putting \\protect in front of either a length command or a command such
1942 as \\value that produces a number.")
1943
1944 ("Missing [{}] inserted." .
1945 "TeX has become confused. The position indicated by the error locator
1946 is probably beyond the point where the incorrect input is.")
1947
1948 ("Missing \\$ inserted." .
1949 "TeX probably found a command that can be used only in math mode when
1950 it wasn't in math mode. Remember that unless stated otherwise, all
1951 all the commands of Section 3.3 in LaTeX Book (Lamport) can be used
1952 only in math mode. TeX is not in math mode when it begins processing
1953 the argument of a box-making command, even if that command is inside a
1954 math environment. This error also occurs if TeX encounters a blank
1955 line when it is in math mode.")
1956
1957 ("Not a letter." .
1958 "Something appears in the argument of a \\hyphenation command that
1959 doesn't belong there.")
1960
1961 ("Paragraph ended before [^ ]* was complete." .
1962 "A blank line occurred in a command argument that shouldn't contain
1963 one. You probably forgot the right brace at the end of an argument.")
1964
1965 ("\\\\[^ ]*font [^ ]* is undefined .*" .
1966 "These errors occur when an uncommon font is used in math mode---for
1967 example, if you use a \\sc command in a formula inside a footnote,
1968 calling for a footnote-sized small caps font. This problem is solved
1969 by using a \\load command.")
1970
1971 ("Font .* not found." .
1972 "You requested a family/series/shape/size combination that is totally
1973 unknown. There are two cases in which this error can occur:
1974 1) You used the \\size macro to select a size that is not available.
1975 2) If you did not do that, go to your local `wizard' and
1976 complain fiercely that the font selection tables are corrupted!")
1977
1978 ("TeX capacity exceeded, sorry .*" .
1979 "TeX has just run out of space and aborted its execution. Before you
1980 panic, remember that the least likely cause of this error is TeX not
1981 having the capacity to process your document. It was probably an
1982 error in your input file that caused TeX to run out of room. The
1983 following discussion explains how to decide whether you've really
1984 exceeded TeX's capacity and, if so, what to do. If the problem is an
1985 error in the input, you may have to use the divide and conquer method
1986 described previously to locate it. LaTeX seldom runs out of space on a
1987 short input file, so if running it on the last few pages before the
1988 error indicator's position still produces the error, then there's
1989 almost certainly something wrong in the input file.
1990
1991 The end of the error indicator tells what kind of space TeX ran out
1992 of. The more common ones are listed below, with an explanation of
1993 their probable causes.
1994
1995 buffer size
1996 ===========
1997 Can be caused by too long a piece of text as the argument
1998 of a sectioning, \\caption, \\addcontentsline, or \\addtocontents
1999 command. This error will probably occur when the \\end{document} is
2000 being processed, but it could happen when a \\tableofcontents,
2001 \\listoffigures, or \\listoftables command is executed. To solve this
2002 problem, use a shorter optional argument. Even if you're producing a
2003 table of contents or a list of figures or tables, such a long entry
2004 won't help the reader.
2005
2006 exception dictionary
2007 ====================
2008 You have used \\hyphenation commands to give TeX
2009 more hyphenation information than it has room for. Remove some of the
2010 less frequently used words from the \\hyphenation commands and insert
2011 \\- commands instead.
2012
2013 hash size
2014 =========
2015 Your input file defines too many command names and/or uses
2016 too many cross-ref- erencing labels.
2017
2018 input stack size
2019 ================
2020 This is probably caused by an error in a command
2021 definition. For example, the following command makes a circular
2022 definition, defining \\gnu in terms of itself:
2023
2024 \\newcommand{\\gnu}{a \\gnu} % This is wrong!
2025
2026 When TeX encounters this \\gnu command, it will keep chasing its tail
2027 trying to figure out what \\gnu should produce, and eventually run out
2028 of ``input stack''.
2029
2030 main memory size
2031 ================
2032 This is one kind of space that TeX can run out of when processing a
2033 short file. There are three ways you can run TeX out of main memory
2034 space: (1) defining a lot of very long, complicated commands, (2)
2035 making an index or glossary and having too many \\index or \\glossary
2036 commands on a single page, and (3) creating so complicated a page of
2037 output that TeX can't hold all the information needed to generate it.
2038 The solution to the first two problems is obvious: define fewer
2039 commands or use fewer \\index and \\glossary commands. The third problem
2040 is nastier. It can be caused by large tabbing, tabular, array, and
2041 picture environments. TeX's space may also be filled up with figures
2042 and tables waiting for a place to go. To find out if you've really
2043 exceeded TeX's capacity in this way, put a \\clearpage command in your
2044 input file right before the place where TeX ran out of room and try
2045 running it again. If it doesn't run out of room with the \\clearpage
2046 command there, then you did exceed TeX's capacity. If it still runs
2047 out of room, then there's probably an error in your file. If TeX is
2048 really out of room, you must give it some help. Remember that TeX
2049 processes a complete paragraph before deciding whether to cut the
2050 page. Inserting a \\newpage command in the middle of the paragraph,
2051 where TeX should break the page, may save the day by letting TeX write
2052 the current page before processing the rest of the paragraph. (A
2053 \\pagebreak command won't help.) If the problem is caused by
2054 accumulated figures and tables, you can try to prevent them from
2055 accumulating---either by moving them further towards the end of the
2056 document or by trying to get them to come out sooner. If you are
2057 still writing the document, simply add a \\clearpage command and forget
2058 about the problem until you're ready to produce the final version.
2059 Changes to the input file are likely to make the problem go away.
2060
2061 pool size
2062 =========
2063 You probably used too many cross-ref-erencing \\labels and/or defined
2064 too many new command names. More precisely, the labels and command
2065 names that you define have too many characters, so this problem can be
2066 solved by using shorter names. However, the error can also be caused
2067 by omitting the right brace that ends the argument of either a counter
2068 command such as \\setcounter, or a \\newenvironment or \\newtheorem
2069 command.
2070
2071 save size
2072 =========
2073 This occurs when commands, environments, and the scopes of
2074 declarations are nested too deeply---for example, by having the
2075 argument of a \\multiput command contain a picture environment that in
2076 turn has a \\footnotesize declaration whose scope contains a \\multiput
2077 command containing a ....")
2078
2079 ("Text line contains an invalid character." .
2080 "The input contains some strange character that it shouldn't. A mistake
2081 when creating the file probably caused your text editor to insert this
2082 character. Exactly what could have happened depends upon what text
2083 editor you used. If examining the input file doesn't reveal the
2084 offending character, consult the Local Guide for suggestions.")
2085
2086 ("Undefined control sequence." .
2087 "TeX encountered an unknown command name. You probably misspelled the
2088 name. If this message occurs when a LaTeX command is being processed,
2089 the command is probably in the wrong place---for example, the error
2090 can be produced by an \\item command that's not inside a list-making
2091 environment. The error can also be caused by a missing \\documentclass
2092 command.")
2093
2094 ("Use of [^ ]* doesn't match its definition." .
2095 "It's probably one of the picture-drawing commands, and you have used
2096 the wrong syntax for specifying an argument. If it's \\@array that
2097 doesn't match its definition, then there is something wrong in an
2098 @-expression in the argument of an array or tabular
2099 environment---perhaps a fragile command that is not \\protect'ed.")
2100
2101 ("You can't use `macro parameter character \\#' in [^ ]* mode." .
2102 "The special character # has appeared in ordinary text. You probably
2103 meant to type \\#.")
2104
2105 ("Overfull \\\\hbox .*" .
2106 "Because it couldn't find a good place for a line break, TeX put more
2107 on this line than it should.")
2108
2109 ("Overfull \\\\vbox .*" .
2110 "Because it couldn't find a good place for a page break, TeX put more
2111 on the page than it should. ")
2112
2113 ("Underfull \\\\hbox .*" .
2114 "Check your output for extra vertical space. If you find some, it was
2115 probably caused by a problem with a \\\\ or \\newline command---for
2116 example, two \\\\ commands in succession. This warning can also be
2117 caused by using the sloppypar environment or \\sloppy declaration, or
2118 by inserting a \\linebreak command.")
2119
2120 ("Underfull \\\\vbox .*" .
2121 "TeX could not find a good place to break the page, so it produced a
2122 page without enough text on it. ")
2123
2124 ;; New list items should be placed here
2125 ;;
2126 ;; ("err-regexp" . "context")
2127 ;;
2128 ;; the err-regexp item should match anything
2129
2130 (".*" . "No help available")) ; end definition
2131 "A list of the form (\"err-regexp\" . \"context\") used by function
2132 `TeX-help-error' to display help-text on an error message or warning.
2133 err-regexp should be a regular expression matching the error message
2134 given from TeX/LaTeX, and context should be some lines describing that
2135 error."
2136 :group 'TeX-output
2137 :type '(repeat (cons :tag "Entry"
2138 (regexp :tag "Match")
2139 (string :format "Description:\n%v"))))
2140
2141 (provide 'tex-buf)
2142
2143 ;;; tex-buf.el ends here