
(require (quote shell))

(defvar texinfo-tex-shell-cd-command "cd" "\
Command to give to shell running TeX to change directory.")

(defvar texinfo-tex-command "tex" "\
*Command used by  texinfo-tex-region  to run tex on a region.")

(defvar texinfo-texindex-command "texindex" "\
*Command used by  texinfo-texindex  to sort unsorted index files.")

(defvar texinfo-tex-dvi-print-command "lpr -d" "\
*Command string used by \\[tex-print] to print a .dvi file.")

(defvar texinfo-show-tex-queue-command "lpq" "\
*Command string used to show the Texinfo TeX print queue.
Command is used by \\[texinfo-show-tex-print-queue] and it
should show the queue that \\[texinfo-tex-print] puts jobs on.")

(defvar texinfo-delete-from-print-queue-command "lprm" "\
*Command string used to delete a job from the line printer queue.
Command is used by \\[texinfo-delete-from-tex-print-queue] based on
number provided by a previous \\[texinfo-show-tex-print-queue]
command.")

(defvar texinfo-tex-trailer "@bye" "\
String appended after a region sent to TeX by texinfo-tex-region.")

(defvar texinfo-tex-original-file "" "\
Original name of file on which to run TeX.")

(defvar texinfo-tex-temp-file nil "\
Temporary file name used for text being sent as input to TeX.")

(defvar texinfo-tex-root-temp-file nil "\
Temporary file name used for text being sent as input to TeX.")

(defun texinfo-tex-region (beginning end) "\
Run tex on the current region. 

A temporary file is written in the default directory, and tex is run
in that directory.  The first line of the file is copied to the
temporary file; and if the buffer has a header, it is written to the
temporary file before the region itself.  The buffer's header is all
lines between the strings defined by texinfo-start-of-header and
texinfo-end-of-header inclusive.  The header must start in the first 100
lines.  The value of texinfo-tex-trailer is appended to the temporary file
after the region." (interactive "r") (byte-code "ÆˆÑÒ!ƒ ÓÔÕ!À\"‚ Ö ˆ×ØÙÚÛ !!!!‰ˆ	ÜPŠŒÝ ˆebˆÞß!ˆ`eeebˆà`ŠÞá!ˆ`)
ÆÆ%ˆÞá!ˆ`W…W `‰ˆâÀ#…} ã ˆ`‰ˆâ	ÆÀ#ƒz ã ˆ`‰‚} e‰ˆà^
ÀÆ%ˆà]

ÀÆ%ˆäå!qˆæ ˆçè!ˆ…± cˆàed
ÀÆ%*+ˆéÔÕ!ê\"ˆëÕìèR\"ˆëÕì
íR\"ˆîï!)))‡" [t texinfo-tex-root-temp-file texinfo-tex-temp-file search-end header-beginning header-end nil beginning texinfo-start-of-header texinfo-end-of-header end local-tex-trailer texinfo-tex-trailer temp-buffer texinfo-tex-shell-cd-command default-directory texinfo-tex-command get-buffer "*texinfo-tex-shell*" quit-process get-process "texinfo-tex-shell" texinfo-tex-start-shell expand-file-name make-temp-name prin1-to-string read buffer-name ".tex" widen forward-line 100 write-region 1 search-forward beginning-of-line get-buffer-create " texinfo-trailer-buffer" erase-buffer insert-string "
" set-process-sentinel texinfo-tex-shell-sentinel send-string " " "
  " texinfo-recenter-tex-output-buffer 0] 33))

(defun texinfo-tex-buffer (buffer) "\
Run TeX on current buffer.
After running TeX the first time, you may have to run \\[texinfo-texindex]
and then \\[texinfo-tex-buffer] again." (interactive (byte-code "ÂÃp!Ä\"…
 ƒ ÅÆÇ!	\"‚ ÅÆÇ!Ãp!\"C‡" [texinfo-tex-root-temp-file texinfo-tex-original-file string= buffer-name "*texinfo-tex-shell*" read-string format "Run TeX on: "] 9)) (byte-code "ÇˆÈÉp!Ê\"ƒ 
q‚ Ép!‰ˆËÊ!ƒ% ÌÍÎ!Ã\"‚' Ï ˆ?ƒ3 ÐÑ!‚p Ò ƒ> ÐÓ!‚p ÔÍÎ!Õ\"ˆÖÎ×ØÄË
!!!ÙR\"ˆÖÎ×
ÚR\"ˆ
ÛÜÝ
\"†i 
GO‰ˆÞÛ!‡" [texinfo-tex-root-temp-file texinfo-tex-original-file buffer t buffer-file-name texinfo-tex-shell-cd-command texinfo-tex-command nil string= buffer-name "*texinfo-tex-shell*" get-buffer quit-process get-process "texinfo-tex-shell" texinfo-tex-start-shell error "Buffer not visiting any file!" buffer-modified-p "Buffer has been modified since last saved!" set-process-sentinel texinfo-tex-shell-sentinel send-string " " file-name-directory "
" "
  " 0 string-match "\\.tex" texinfo-recenter-tex-output-buffer] 22))

(defun texinfo-texindex nil "\
Run texindex on unsorted index files.
The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
Runs the shell command defined by texinfo-texindex-command." (interactive) (byte-code "ÂˆÃÄÅÆ	ÇÈ%\"ˆÉÂ!‡" [texinfo-texindex-command texinfo-tex-root-temp-file nil send-string "texinfo-tex-shell" concat " " ".??" "
" texinfo-recenter-tex-output-buffer] 8))

(defun texinfo-tex-print nil "\
Print .dvi file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
Runs the shell command defined by texinfo-tex-dvi-print-command." (interactive) (byte-code "ÂˆÃÄÅÆ	ÇÈ%\"ˆÉÂ!‡" [texinfo-tex-dvi-print-command texinfo-tex-root-temp-file nil send-string "texinfo-tex-shell" concat " " ".dvi" "
" texinfo-recenter-tex-output-buffer] 8))

(defun texinfo-tex-start-shell nil (byte-code "ŠÃÄ!ˆÅÆÇÀÈ$qˆÉ
!‰ˆÊ	!ˆË	!ˆÌÍ!ˆÎÏ !…) ÐÑ!)‡" [nil texinfo-tex-shell-map shell-mode-map require texinfo make-shell "texinfo-tex-shell" "/bin/sh" "-v" copy-keymap texinfo-define-common-keys use-local-map run-hooks texinfo-tex-shell-hook zerop buffer-size sleep-for 1] 10))

(defun texinfo-quit-tex-job nil "\
Quit currently running TeX job, by sending an `x' to it." (interactive) (byte-code "ÀˆÁÂ!?… ÃÄ!ˆŠÅÆ!qˆdbˆÇcˆÈ )‡" [nil get-process "texinfo-tex-shell" error "No TeX shell running." get-buffer "*texinfo-tex-shell*" "x" shell-send-input] 5))

(defun texinfo-kill-tex-job nil "\
Kill the currently running TeX job." (interactive) (byte-code "ÀˆÁÂ!… ÃÁÂ!!‡" [nil get-process "texinfo-tex-shell" kill-process] 4))

(defun texinfo-tex-shell-sentinel (process event) "\
Restart texinfo-tex-shell after it is killed." (byte-code "ÁÂ\"… ŠÃqˆÄcˆÅ )‡" [event equal "killed
" "*texinfo-tex-shell*" "
" texinfo-tex-start-shell] 3))

(defun texinfo-recenter-tex-output-buffer (linenum) "\
Redisplay buffer of TeX job output so that most recent output can be seen.
The last line of the buffer is displayed on
line LINE of the window, or centered if LINE is nil." (interactive "P") (byte-code "ÃˆÄÅ!p?ƒ ÆÇ!‚3 È!ˆÉ!ˆdbˆÊ
ƒ) Ë
!‚. ÌÍ Î\"!ˆÈ	!*‡" [texinfo-tex-shell old-buffer linenum nil get-buffer "*texinfo-tex-shell*" message "No TeX output buffer" pop-to-buffer bury-buffer recenter prefix-numeric-value / window-height 2] 10))

(defun texinfo-show-tex-print-queue nil "\
Show the print queue that \\[texinfo-tex-print] put your job on.
Runs the shell command defined by texinfo-show-tex-queue-command." (interactive) (byte-code "ÁˆÂ ?…
 Ã ˆÄÅÆP\"ˆÇÁ!‡" [texinfo-show-tex-queue-command nil texinfo-tex-shell-running-p texinfo-tex-start-shell send-string "texinfo-tex-shell" "
" texinfo-recenter-tex-output-buffer] 6))

(defun texinfo-delete-from-tex-print-queue (job-number) "\
Delete job from the line printer spooling queue.
You are prompted for the job number (shown by a previous
\\[texinfo-show-tex-print-queue] command." (interactive "nPrinter job number for deletion: ") (byte-code "ÂˆÃ ƒ Ä ‚ Å ˆÆÇÈ	ÉR\"ˆÊÂ!‡" [texinfo-delete-from-print-queue-command job-number nil texinfo-tex-shell-running-p texinfo-kill-tex-job texinfo-tex-start-shell send-string "texinfo-tex-shell" " " "
" texinfo-recenter-tex-output-buffer] 9))

(defun texinfo-tex-shell-running-p nil (byte-code "ÀÁ!… ÂÀÁ!!Ã=‡" [get-process "texinfo-tex-shell" process-status run] 5))

(provide (quote texnfo-tex))
