yatex
diff yatexprc.el @ 354:5465428f5a68
`[prefix] t e' displays typesetting image in the next window, if possible.
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Mon, 22 Dec 2014 00:01:30 +0900 |
parents | ecf7b5543e65 |
children | 6c67a826f266 |
line diff
1.1 --- a/yatexprc.el Sun Dec 21 13:57:27 2014 +0900 1.2 +++ b/yatexprc.el Mon Dec 22 00:01:30 2014 +0900 1.3 @@ -1,7 +1,7 @@ 1.4 ;;; yatexprc.el --- YaTeX process handler 1.5 ;;; 1.6 ;;; (c)1993-2013 by HIROSE Yuuji.[yuuji@yatex.org] 1.7 -;;; Last modified Sun Dec 21 13:56:03 2014 on firestorm 1.8 +;;; Last modified Mon Dec 22 00:00:27 2014 on firestorm 1.9 ;;; $Id$ 1.10 1.11 ;;; Code: 1.12 @@ -64,6 +64,7 @@ 1.13 (save-excursion 1.14 (let ((p (point)) (window (selected-window)) execdir (cb (current-buffer)) 1.15 (map YaTeX-typesetting-mode-map) 1.16 + (background (string-match "\\*bg:" buffer)) 1.17 (outcode 1.18 (cond ((eq major-mode 'yatex-mode) YaTeX-coding-system) 1.19 ((eq major-mode 'yahtml-mode) yahtml-kanji-code)))) 1.20 @@ -78,8 +79,10 @@ 1.21 (setq execdir default-directory) 1.22 ;;Select lower-most window if there are more than 2 windows and 1.23 ;;typeset buffer not seen. 1.24 - (YaTeX-showup-buffer 1.25 - buffer (function (lambda (x) (nth 3 (window-edges x))))) 1.26 + (if background 1.27 + nil ;do not showup 1.28 + (YaTeX-showup-buffer 1.29 + buffer 'YaTeX-showup-buffer-bottom-most)) 1.30 (set-buffer (get-buffer-create buffer)) 1.31 (setq default-directory execdir) 1.32 (cd execdir) 1.33 @@ -137,17 +140,19 @@ 1.34 (insert " ") 1.35 (set-marker (process-mark YaTeX-typeset-process) (1- (point)))) 1.36 (if (bolp) (forward-line -1)) ;what for? 1.37 - (if (and YaTeX-emacs-19 window-system) 1.38 - (let ((win (get-buffer-window buffer t)) owin) 1.39 - (select-frame (window-frame win)) 1.40 - (setq owin (selected-window)) 1.41 - (select-window win) 1.42 - (goto-char (point-max)) 1.43 - (recenter -1) 1.44 - (select-window owin)) 1.45 - (select-window (get-buffer-window buffer)) 1.46 - (goto-char (point-max)) 1.47 - (recenter -1)) 1.48 + (cond 1.49 + (background nil) 1.50 + ((and YaTeX-emacs-19 window-system) 1.51 + (let ((win (get-buffer-window buffer t)) owin) 1.52 + (select-frame (window-frame win)) 1.53 + (setq owin (selected-window)) 1.54 + (select-window win) 1.55 + (goto-char (point-max)) 1.56 + (recenter -1) 1.57 + (select-window owin))) 1.58 + (t (select-window (get-buffer-window buffer)) 1.59 + (goto-char (point-max)) 1.60 + (recenter -1))) 1.61 (select-window window) 1.62 (switch-to-buffer cb) 1.63 (YaTeX-remove-nonstopmode)))) 1.64 @@ -250,7 +255,7 @@ 1.65 (setq tobecalled thiscmd shortname "+typeset")) 1.66 (t 1.67 nil)) ;no need to call any process 1.68 - (progn 1.69 + (progn ;;Something occurs to call next command 1.70 (insert 1.71 (format 1.72 "===!!! %s !!!===\n" 1.73 @@ -274,18 +279,20 @@ 1.74 (cond 1.75 ((and ppcmd (string-match "finish" mes)) 1.76 (insert (format "=======> Success! Calling %s\n" ppcmd)) 1.77 - (setq mode-name ; set process name 1.78 - (concat 1.79 - mode-name "+" 1.80 - (substring ppcmd 0 (string-match " " ppcmd)))) 1.81 + (if (symbolp ppcmd) 1.82 + (funcall ppcmd) 1.83 + (setq mode-name ; set process name 1.84 + (concat 1.85 + mode-name "+" 1.86 + (substring ppcmd 0 (string-match " " ppcmd)))) 1.87 ; to reach here, 'start-process exists on this emacsen 1.88 - (set-process-sentinel 1.89 - (start-process 1.90 - mode-name 1.91 - pbuf ; Use this buffer twice. 1.92 - shell-file-name YaTeX-shell-command-option 1.93 - ppcmd) 1.94 - 'YaTeX-typeset-sentinel)) 1.95 + (set-process-sentinel 1.96 + (start-process 1.97 + mode-name 1.98 + pbuf ; Use this buffer twice. 1.99 + shell-file-name YaTeX-shell-command-option 1.100 + ppcmd) 1.101 + 'YaTeX-typeset-sentinel))) 1.102 (t ;pull back original mode-name 1.103 (setq mode-name "typeset")))) 1.104 (forward-char 1)) 1.105 @@ -299,7 +306,7 @@ 1.106 (defvar YaTeX-texput-file "texput.tex" 1.107 "*File name for temporary file of typeset-region.") 1.108 1.109 -(defun YaTeX-typeset-region () 1.110 +(defun YaTeX-typeset-region (&optional pp) 1.111 "Paste the region to the file `texput.tex' and execute typesetter. 1.112 The region is specified by the rule: 1.113 (1)If keyword `%#BEGIN' is found in the upper direction from (point). 1.114 @@ -310,17 +317,21 @@ 1.115 (2)If no `%#BEGIN' usage is found before the (point), 1.116 ->Assume the text between current (point) and (mark) as region. 1.117 DON'T forget to eliminate the `%#BEGIN/%#END' notation after editing 1.118 -operation to the region." 1.119 +operation to the region. 1.120 +Optional second argument PP specifies post-processor command which will be 1.121 +called with one argument of current file name whitout extension." 1.122 (interactive) 1.123 (save-excursion 1.124 (let* 1.125 ((end "") typeout ;Type out message that tells the method of cutting. 1.126 (texput YaTeX-texput-file) 1.127 + (texputroot (substring texput 0 (string-match "\\.tex$" texput))) 1.128 (cmd (concat (YaTeX-get-latex-command nil) " " texput)) 1.129 (buffer (current-buffer)) opoint preamble (subpreamble "") main 1.130 (hilit-auto-highlight nil) ;for Emacs19 with hilit19 1.131 + ppcmd 1.132 reg-begin reg-end lineinfo) 1.133 - 1.134 + (setq ppcmd (if (stringp pp) (concat pp " " texputroot) pp)) 1.135 (save-excursion 1.136 (if (search-backward "%#BEGIN" nil t) 1.137 (progn 1.138 @@ -368,9 +379,11 @@ 1.139 (set-buffer (find-file-noselect texput))) 1.140 ;;(find-file YaTeX-texput-file) 1.141 (erase-buffer) 1.142 + (YaTeX-set-file-coding-system YaTeX-kanji-code YaTeX-coding-system) 1.143 (if (and (eq major-mode 'yatex-mode) YaTeX-need-nonstop) 1.144 (insert "\\nonstopmode{}\n")) 1.145 - (insert preamble "\n" subpreamble "\n") 1.146 + (insert preamble "\n" subpreamble "\n" 1.147 + "\\pagestyle{empty}\n\\thispagestyle{empty}\n") 1.148 (setq lineinfo (list (count-lines 1 (point-end-of-line)) lineinfo)) 1.149 (insert-buffer-substring buffer reg-begin reg-end) 1.150 (insert "\\typeout{" typeout end "}\n") ;Notice the selected method. 1.151 @@ -378,18 +391,70 @@ 1.152 (basic-save-buffer) 1.153 (kill-buffer (current-buffer)) 1.154 (set-buffer main) ;return to parent file or itself. 1.155 - (YaTeX-typeset cmd YaTeX-typeset-buffer) 1.156 + (YaTeX-typeset cmd YaTeX-typeset-buffer nil nil ppcmd) 1.157 (switch-to-buffer buffer) ;for Emacs-19 1.158 (put 'dvi2-command 'region t) 1.159 (put 'dvi2-command 'file buffer) 1.160 (put 'dvi2-command 'offset lineinfo)))) 1.161 1.162 +(defvar YaTeX-typeset-conv2image-process nil "Process of conv2image chain") 1.163 +(defun YaTeX-typeset-conv2image-chain () 1.164 + (let*((proc (or YaTeX-typeset-process YaTeX-typeset-conv2image-process)) 1.165 + (prevname (process-name proc)) 1.166 + (target "texput.jpg") 1.167 + (math (get 'YaTeX-typeset-conv2image-chain 'math)) 1.168 + (conv (format "convert -density %d - %s" (if math 250 100) target)) 1.169 + (chain (list (format "dvips -E -o - texput|%s" conv))) 1.170 + (curproc (member prevname chain)) 1.171 + img) 1.172 + (if (not (= (process-exit-status proc) 0)) 1.173 + (progn 1.174 + (YaTeX-showup-buffer ;nevers comes here(?) 1.175 + (current-buffer) 'YaTeX-showup-buffer-bottom-most) 1.176 + (message "Region typesetting FAILED")) 1.177 + (setq command 1.178 + (if curproc (car (cdr-safe curproc)) (car chain))) 1.179 + (if command 1.180 + (progn 1.181 + (insert (format "Calling `%s'...\n" command)) 1.182 + (set-process-sentinel 1.183 + (setq YaTeX-typeset-conv2image-process 1.184 + (start-process 1.185 + command 1.186 + (current-buffer) 1.187 + shell-file-name YaTeX-shell-command-option command)) 1.188 + 'YaTeX-typeset-sentinel) 1.189 + (put 'YaTeX-typeset-process 'ppcmd 1.190 + (cons (cons (get-buffer-process (current-buffer)) 1.191 + 'YaTeX-typeset-conv2image-chain) 1.192 + (get 'YaTeX-typeset-process 'ppcmd)))) 1.193 + ;; After all chain executed, display image in current window 1.194 + (YaTeX-showup-buffer 1.195 + (get-buffer-create " *YaTeX-region-image*") 1.196 + 'YaTeX-showup-buffer-bottom-most t) 1.197 + (remove-images (point-min) (point-max)) 1.198 + (erase-buffer) 1.199 + ;(put-image (create-image (expand-file-name target)) (point)) 1.200 + (insert-image-file target) 1.201 + (goto-char (point-min)) 1.202 + (setq img (plist-get (text-properties-at (point)) 'intangible)) 1.203 + (if img 1.204 + (let ((height (cdr (image-size img)))) 1.205 + (enlarge-window 1.206 + (- (ceiling (min height (/ (frame-height) 2))) 1.207 + (window-height))))))))) 1.208 + 1.209 (defun YaTeX-typeset-environment () 1.210 "Typeset current math environment" 1.211 (interactive) 1.212 (save-excursion 1.213 - (YaTeX-mark-environment) 1.214 - (YaTeX-typeset-region))) 1.215 + (let ((math (YaTeX-in-math-mode-p))) 1.216 + (YaTeX-mark-environment) 1.217 + (if (and (featurep 'image) window-system) 1.218 + (let ((YaTeX-typeset-buffer (concat "*bg:" YaTeX-typeset-buffer))) 1.219 + (put 'YaTeX-typeset-conv2image-chain 'math math) 1.220 + (YaTeX-typeset-region 'YaTeX-typeset-conv2image-chain)) 1.221 + (YaTeX-typeset-region))))) 1.222 1.223 (defun YaTeX-typeset-buffer (&optional pp) 1.224 "Typeset whole buffer. 1.225 @@ -549,8 +614,7 @@ 1.226 (setq default-directory (cd (or basedir df))) 1.227 (erase-buffer) 1.228 (insert (format "Calling `%s'..." command)) 1.229 - (YaTeX-showup-buffer 1.230 - buffer (function (lambda (x) (nth 3 (window-edges x))))) 1.231 + (YaTeX-showup-buffer buffer 'YaTeX-showup-buffer-bottom-most) 1.232 (if (not (fboundp 'start-process)) 1.233 (call-process 1.234 shell-file-name nil buffer nil YaTeX-shell-command-option command) 1.235 @@ -652,7 +716,7 @@ 1.236 (if YaTeX-dos (setq preview-file (expand-file-name preview-file))) 1.237 (let ((pbuffer "*dvi-preview*") (dir default-directory)) 1.238 (YaTeX-showup-buffer 1.239 - pbuffer (function (lambda (x) (nth 3 (window-edges x))))) 1.240 + pbuffer 'YaTeX-showup-buffer-bottom-most) 1.241 (set-buffer (get-buffer-create pbuffer)) 1.242 (erase-buffer) 1.243 (setq default-directory dir) ;for 18 1.244 @@ -1032,7 +1096,7 @@ 1.245 (YaTeX-visit-main t) ;;change execution directory 1.246 (setq dir default-directory) 1.247 (YaTeX-showup-buffer 1.248 - lbuffer (function (lambda (x) (nth 3 (window-edges x))))) 1.249 + lbuffer 'YaTeX-showup-buffer-bottom-most) 1.250 (set-buffer (get-buffer-create lbuffer)) 1.251 (erase-buffer) 1.252 (cd dir) ;for 19