home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / SLAKWARE / AP5 / TEXINFO.TGZ / TEXINFO.tar / usr / share / emacs / site-lisp / texnfo-tex.el < prev    next >
Lisp/Scheme  |  1996-07-19  |  14KB  |  347 lines

  1. ;;;; texnfo-tex.el
  2.  
  3. ;;; Texinfo mode TeX and hardcopy printing commands.
  4.  
  5. ;; These commands are for running TeX on a region of a Texinfo file in
  6. ;; GNU Emacs, or on the whole buffer, and for printing the resulting
  7. ;; DVI file.
  8.  
  9. ;;; Version 2.07    22 October 1991
  10. ;;; Robert J. Chassell      
  11. ;;; Please send bug reports to:  bug-texinfo@prep.ai.mit.edu
  12.  
  13. ;;; Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
  14.  
  15.  
  16. ;;; This file is part of GNU Emacs.
  17.  
  18. ;; GNU Emacs is free software; you can redistribute it and/or modify
  19. ;; it under the terms of the GNU General Public License as published by
  20. ;; the Free Software Foundation; either version 2, or (at your option)
  21. ;; any later version.
  22.  
  23. ;; GNU Emacs is distributed in the hope that it will be useful,
  24. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. ;; GNU General Public License for more details.
  27.  
  28. ;; You should have received a copy of the GNU General Public License
  29. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  30. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  31.  
  32.  
  33. ;;; The Texinfo mode TeX related commands are:
  34.  
  35. ; texinfo-tex-region        to run tex on the current region.
  36. ; texinfo-tex-buffer        to run tex on the current buffer.
  37. ; texinfo-texindex          to sort unsorted index files.
  38. ; texinfo-tex-print         to print the .dvi file made by tex.
  39. ; texinfo-kill-tex-job      to kill the currently running tex job.
  40. ; texinfo-recenter-tex-output-buffer    to redisplay tex output buffer.
  41. ; texinfo-show-tex-print-queue          to show the print queue.
  42.  
  43.  
  44. ;;; Keys common both to Texinfo mode and to TeX shell.
  45.  
  46. ;; Defined in `texinfo.el'
  47. ; (defun texinfo-define-common-keys (keymap)
  48. ;   "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
  49. ;   (define-key keymap "\C-c\C-t\C-k"    'texinfo-kill-tex-job)
  50. ;   (define-key keymap "\C-c\C-t\C-x"    'texinfo-quit-tex-job)
  51. ;   (define-key keymap "\C-c\C-t\C-l"    'texinfo-recenter-tex-output-buffer)
  52. ;   (define-key keymap "\C-c\C-t\C-d"    'texinfo-delete-from-tex-print-queue)
  53. ;   (define-key keymap "\C-c\C-t\C-q"    'texinfo-show-tex-print-queue)
  54. ;   (define-key keymap "\C-c\C-t\C-p"    'texinfo-tex-print)
  55. ;   (define-key keymap "\C-c\C-t\C-i"    'texinfo-texindex)
  56. ;   (define-key keymap "\C-c\C-t\C-r"    'texinfo-tex-region)
  57. ;   (define-key keymap "\C-c\C-t\C-b"    'texinfo-tex-buffer))
  58.  
  59. ;; See also texinfo-tex-start-shell. 
  60. ;; The following is executed in the `texinfo.el' file
  61. ;(texinfo-define-common-keys texinfo-mode-map)
  62.  
  63.  
  64. ;;; Variable definitions:
  65.  
  66. (require 'shell)
  67.  
  68. (defvar texinfo-tex-shell-cd-command "cd"
  69.   "Command to give to shell running TeX to change directory.")
  70.  
  71. (defvar texinfo-tex-command "tex"
  72.   "*Command used by  texinfo-tex-region  to run tex on a region.")
  73.  
  74. (defvar texinfo-texindex-command "texindex"
  75.   "*Command used by  texinfo-texindex  to sort unsorted index files.")
  76.  
  77. (defvar texinfo-tex-dvi-print-command "lpr -d"
  78.   "*Command string used by \\[tex-print] to print a .dvi file.")
  79.  
  80. (defvar texinfo-show-tex-queue-command "lpq"
  81.   "*Command string used to show the Texinfo TeX print queue.
  82. Command is used by \\[texinfo-show-tex-print-queue] and it
  83. should show the queue that \\[texinfo-tex-print] puts jobs on.")
  84.  
  85. (defvar texinfo-delete-from-print-queue-command "lprm"
  86.   "*Command string used to delete a job from the line printer queue.
  87. Command is used by \\[texinfo-delete-from-tex-print-queue] based on
  88. number provided by a previous \\[texinfo-show-tex-print-queue]
  89. command.")
  90.  
  91. (defvar texinfo-tex-trailer "@bye"
  92.   "String appended after a region sent to TeX by texinfo-tex-region.")
  93.  
  94. (defvar texinfo-tex-original-file ""
  95.   "Original name of file on which to run TeX.")
  96.  
  97. (defvar texinfo-tex-temp-file nil
  98.   "Temporary file name used for text being sent as input to TeX.")
  99.  
  100. (defvar texinfo-tex-root-temp-file nil
  101.   "Temporary file name used for text being sent as input to TeX.")
  102.  
  103.  
  104. ;;; Texinfo TeX main functions
  105.  
  106. (defun texinfo-tex-region (beginning end)
  107.   "Run tex on the current region. 
  108.  
  109. A temporary file is written in the default directory, and tex is run
  110. in that directory.  The first line of the file is copied to the
  111. temporary file; and if the buffer has a header, it is written to the
  112. temporary file before the region itself.  The buffer's header is all
  113. lines between the strings defined by texinfo-start-of-header and
  114. texinfo-end-of-header inclusive.  The header must start in the first 100
  115. lines.  The value of texinfo-tex-trailer is appended to the temporary file
  116. after the region."
  117.   
  118.   (interactive "r")
  119.   (if (get-buffer "*texinfo-tex-shell*")
  120.       (quit-process (get-process "texinfo-tex-shell") t)
  121.     (texinfo-tex-start-shell))
  122.   
  123.   (setq texinfo-tex-root-temp-file
  124.         (expand-file-name 
  125.          (make-temp-name
  126.           (prin1-to-string (read (buffer-name))))))
  127.   
  128.   (let ((texinfo-tex-temp-file (concat texinfo-tex-root-temp-file ".tex")))
  129.     (save-excursion
  130.       (save-restriction
  131.         (widen)
  132.         (goto-char (point-min))
  133.         (forward-line 100)
  134.         (let ((search-end (point))
  135.               (header-beginning (point-min)) (header-end (point-min)))
  136.           (goto-char (point-min))
  137.           ;; Copy first line, the `\input texinfo' line, to temp file
  138.           (write-region (point) 
  139.                         (save-excursion (forward-line 1) (point))
  140.                         texinfo-tex-temp-file nil nil)
  141.           ;; Don't copy first line twice if region includes it.
  142.           (forward-line 1)
  143.           (if (< beginning  (point)) (setq beginning  (point)))
  144.           ;; Initialize the temp file with either the header or nothing
  145.           (if (search-forward texinfo-start-of-header search-end t)
  146.               (progn
  147.                 (beginning-of-line)
  148.                 (setq header-beginning (point)) ; Mark beginning of header.
  149.                 (if (search-forward texinfo-end-of-header nil t)
  150.                     (progn (beginning-of-line)
  151.                            (setq header-end (point)))   ; Mark end of header.
  152.                   (setq header-beginning (point-min))))) ; Else no header.
  153.           ;; Copy  header  to temp file.
  154.           (write-region
  155.            (min header-beginning beginning )
  156.            header-end
  157.            texinfo-tex-temp-file t nil)
  158.           ;; Copy  region  to temp file.
  159.           (write-region
  160.            (max beginning  header-end)
  161.            end
  162.            texinfo-tex-temp-file t nil)
  163.           ;; This is a kludge to insert the texinfo-tex-trailer into the
  164.           ;; texinfo-tex-temp-file.  We have to create a special buffer
  165.           ;; in which to insert the texinfo-tex-trailer first because there is
  166.           ;; no function with which to append a literal string directly
  167.           ;; to a file.
  168.           (let ((local-tex-trailer texinfo-tex-trailer)
  169.                 (temp-buffer (get-buffer-create " texinfo-trailer-buffer")))
  170.             (set-buffer temp-buffer)
  171.             (erase-buffer)
  172.             ;; make sure trailer isn't hidden by a comment
  173.             (insert-string "\n")
  174.             (if local-tex-trailer (insert local-tex-trailer))
  175.             (write-region (point-min) (point-max) 
  176.                           texinfo-tex-temp-file t nil)))
  177.         (set-process-sentinel (get-process "texinfo-tex-shell") 
  178.                               'texinfo-tex-shell-sentinel)
  179.         (send-string "texinfo-tex-shell"
  180.                      (concat texinfo-tex-shell-cd-command " "
  181.                              default-directory "\n"))
  182.         (send-string "texinfo-tex-shell"
  183.                      (concat texinfo-tex-command " "
  184.                              texinfo-tex-temp-file "\n  "))
  185.         (texinfo-recenter-tex-output-buffer 0)))))
  186.  
  187. (defun texinfo-tex-buffer (buffer)
  188.   "Run TeX on current buffer.
  189. After running TeX the first time, you may have to run \\[texinfo-texindex]
  190. and then \\[texinfo-tex-buffer] again."
  191.   (interactive 
  192.    (list
  193.     ;; Sometimes you put point into *texinfo-tex-shell*; this prompts
  194.     ;; you for the correct file regardless.
  195.     (if (and 
  196.          (string= (buffer-name (current-buffer)) "*texinfo-tex-shell*")
  197.          texinfo-tex-root-temp-file)
  198.         (read-stri