yatex
changeset 371:f5b8e7415a25 dev
Experimental code to split conv2img into dvi2png and pdf2png
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Mon, 29 Dec 2014 22:14:08 +0900 |
parents | 037f8d4c3c70 |
children | e8f95c375526 |
files | yatexprc.el |
diffstat | 1 files changed, 82 insertions(+), 32 deletions(-) [+] |
line diff
1.1 --- a/yatexprc.el Mon Dec 29 00:20:21 2014 +0900 1.2 +++ b/yatexprc.el Mon Dec 29 22:14:08 2014 +0900 1.3 @@ -1,7 +1,7 @@ 1.4 ;;; yatexprc.el --- YaTeX process handler 1.5 ;;; 1.6 ;;; (c)1993-2014 by HIROSE Yuuji.[yuuji@yatex.org] 1.7 -;;; Last modified Sun Dec 28 23:35:01 2014 on firestorm 1.8 +;;; Last modified Mon Dec 29 18:04:06 2014 on sdr 1.9 ;;; $Id$ 1.10 1.11 ;;; Code: 1.12 @@ -179,7 +179,7 @@ 1.13 tobecalled shortname 1.14 (thiscmd (get 'YaTeX-typeset-process 'thiscmd)) 1.15 (ppprop (get 'YaTeX-typeset-process 'ppcmd)) 1.16 - (ppcmd (cdr (assq proc ppprop))) 1.17 +z (ppcmd (cdr (assq proc ppprop))) 1.18 (bcprop (get 'YaTeX-typeset-process 'bibcmd)) 1.19 (bibcmd (cdr (assq proc bcprop)))) 1.20 (put 'YaTeX-typeset-process 'ppcmd ;erase ppcmd 1.21 @@ -279,23 +279,28 @@ 1.22 (put 'YaTeX-typeset-process 'thiscmd thiscmd))) 1.23 ;; If ppcmd is active, call it. 1.24 (cond 1.25 + ((and ppcmd (symbolp ppcmd) (fboundp ppcmd)) 1.26 + ;; If ppcmd is set and it is a function symbol, 1.27 + ;; call it whenever command succeeded or not 1.28 + (funcall ppcmd)) 1.29 ((and ppcmd (string-match "finish" mes)) 1.30 (insert (format "=======> Success! Calling %s\n" ppcmd)) 1.31 - (if (symbolp ppcmd) 1.32 - (funcall ppcmd) 1.33 - (setq mode-name ; set process name 1.34 - (concat 1.35 - mode-name "+" 1.36 - (substring ppcmd 0 (string-match " " ppcmd)))) 1.37 + (setq mode-name ; set process name 1.38 + (concat 1.39 + mode-name "+" 1.40 + (substring ppcmd 0 (string-match " " ppcmd)))) 1.41 ; to reach here, 'start-process exists on this emacsen 1.42 - (set-process-sentinel 1.43 - (start-process 1.44 - mode-name 1.45 - pbuf ; Use this buffer twice. 1.46 - shell-file-name YaTeX-shell-command-option 1.47 - ppcmd) 1.48 - 'YaTeX-typeset-sentinel))) 1.49 + (set-process-sentinel 1.50 + (start-process 1.51 + mode-name 1.52 + pbuf ; Use this buffer twice. 1.53 + shell-file-name YaTeX-shell-command-option 1.54 + ppcmd) 1.55 + 'YaTeX-typeset-sentinel)) 1.56 (t ;pull back original mode-name 1.57 + ;;Confirm process buffer to be shown when error occured 1.58 + (YaTeX-showup-buffer pbuf 'YaTeX-showup-buffer-bottom-most) 1.59 + (message "Command FAILED!") 1.60 (setq mode-name "typeset")))) 1.61 (forward-char 1)) 1.62 (setq YaTeX-typeset-process nil) 1.63 @@ -417,6 +422,40 @@ 1.64 (define-key map "k" (lambda()(interactive) (scroll-up -1))))) 1.65 (use-local-map YaTeX-preview-image-mode-map)) 1.66 1.67 +(defvar YaTeX-typeset-pdf2image-chain 1.68 + (cond 1.69 + ((YaTeX-executable-find "pdfcrop") ;Mac OS X 1.70 + (list 1.71 + "pdfcrop --clip %b.pdf tmp.pdf" 1.72 + (if (YaTeX-executable-find "convert") 1.73 + "convert -density %d tmp.pdf %b.%f" 1.74 + "sips -s format %f -s dpiWidth %d -s dpiHeight %d %b.pdf --out %b.%f") 1.75 + "rm -f tmp.pdf"))) 1.76 + "*Pipe line of command as a list to create image file from PDF. 1.77 +See also doc-string of YaTeX-typeset-dvi2image-chain.") 1.78 + 1.79 +(defvar YaTeX-typeset-dvi2image-chain 1.80 + (cond 1.81 + ((YaTeX-executable-find "dvipng") 1.82 + (list "dvipng %b")) 1.83 + ((YaTeX-executable-find YaTeX-cmd-dvips) 1.84 + (list 1.85 + (format "%s -E -o %%b.eps %%b.dvi" YaTeX-cmd-dvips) 1.86 + "convert -alpha off -density %d %b.eps %b.png"))) 1.87 + "*Pipe line of command as a list to create png file from DVI or PDF. 1.88 +%-notation rewritten list: 1.89 + %b basename of target file(\"texput\") 1.90 + %f Output format(\"png\") 1.91 + %d DPI 1.92 +") 1.93 + 1.94 +(defvar YaTeX-typeset-conv2image-chain-alist 1.95 + (list (cons 'pdf YaTeX-typeset-pdf2image-chain) 1.96 + (cons 'dvi YaTeX-typeset-dvi2image-chain)) 1.97 + "Default alist for creating image files from DVI/PDF. 1.98 +The value is generated from YaTeX-typeset-pdf2image-chain and 1.99 +YaTeX-typeset-dvi2image-chain.") 1.100 + 1.101 (defvar YaTeX-typeset-conv2image-process nil "Process of conv2image chain") 1.102 (defun YaTeX-typeset-conv2image-chain () 1.103 (let*((proc (or YaTeX-typeset-process YaTeX-typeset-conv2image-process)) 1.104 @@ -425,22 +464,25 @@ 1.105 (math (get 'YaTeX-typeset-conv2image-chain 'math)) 1.106 ;(conv (format "convert -density %d - %s" (if math 250 100) target)) 1.107 ;(chain (list (format "dvips -E -o - texput|%s" conv))) 1.108 - (conv (format "convert -alpha off - %s" target)) 1.109 - (chain (list (format "%s -x %d -E -o - texput|%s" 1.110 - ;; This function is the first evaluation code. 1.111 - ;; If you find these command line does not work 1.112 - ;; on your system, please tell the author 1.113 - ;; which commands should be taken to achieve 1.114 - ;; one-shot png previewing on your system 1.115 - ;; before publishing patch on the Web. 1.116 - ;; Please please please please please. 1.117 - YaTeX-cmd-dvips 1.118 - (if math 3000 2000) 1.119 - conv))) 1.120 + ;(conv (format "convert -alpha off - %s" target)) 1.121 + (case-fold-search t) 1.122 + (srctype (or (get 'YaTeX-typeset-conv2image-chain 'srctype) 1.123 + (if (save-excursion 1.124 + (re-search-backward "this is pdftex" nil t)) 1.125 + 'pdf 'dvi))) 1.126 + (chain (cdr (assq srctype YaTeX-typeset-conv2image-chain-alist))) 1.127 + ;; This function is the first evaluation code. 1.128 + ;; If you find these command line does not work 1.129 + ;; on your system, please tell the author 1.130 + ;; which commands should be taken to achieve 1.131 + ;; one-shot png previewing on your system 1.132 + ;; before publishing patch on the Web. 1.133 + ;; Please please please please please. 1.134 (curproc (member prevname chain)) 1.135 (w (get 'YaTeX-typeset-conv2image-chain 'win)) 1.136 (pwd default-directory) 1.137 img) 1.138 + (setq foo (cons (cons prevname (process-exit-status proc)) foo)) 1.139 (if (not (= (process-exit-status proc) 0)) 1.140 (progn 1.141 (YaTeX-showup-buffer ;never comes here(?) 1.142 @@ -449,14 +491,19 @@ 1.143 (setq command 1.144 (if curproc (car (cdr-safe curproc)) (car chain))) 1.145 (if command 1.146 - (progn 1.147 - (insert (format "Calling `%s'...\n" command)) 1.148 + (let ((cmdline (YaTeX-replace-formats 1.149 + command 1.150 + (list (cons "b" "texput") 1.151 + (cons "f" "png") 1.152 + (cons "d" (if math "300" "200")))))) 1.153 + (insert (format "Calling `%s'...\n" cmdline)) 1.154 (set-process-sentinel 1.155 (setq YaTeX-typeset-conv2image-process 1.156 (start-process 1.157 command 1.158 (current-buffer) 1.159 - shell-file-name YaTeX-shell-command-option command)) 1.160 + shell-file-name YaTeX-shell-command-option 1.161 + cmdline)) 1.162 'YaTeX-typeset-sentinel) 1.163 (put 'YaTeX-typeset-process 'ppcmd 1.164 (cons (cons (get-buffer-process (current-buffer)) 1.165 @@ -468,7 +515,7 @@ 1.166 ;; If direct image displaying available in running Emacs, 1.167 ;; display target image into the next window in Emacs. 1.168 (select-window w) 1.169 - (setq foo (selected-window)) 1.170 + ;(setq foo (selected-window)) 1.171 (YaTeX-showup-buffer 1.172 (get-buffer-create " *YaTeX-region-image*") 1.173 'YaTeX-showup-buffer-bottom-most t) 1.174 @@ -494,19 +541,22 @@ 1.175 ))))) 1.176 1.177 (defun YaTeX-typeset-environment () 1.178 - "Typeset current math environment" 1.179 + "Typeset current environment or paragraph. 1.180 +If region activated, use it." 1.181 (interactive) 1.182 (save-excursion 1.183 (let ((math (YaTeX-in-math-mode-p))) 1.184 (cond 1.185 ((and (fboundp 'region-active-p) (region-active-p)) 1.186 nil) ;if region is active, use it 1.187 + (math (YaTeX-mark-environment)) 1.188 ((equal (or (YaTeX-inner-environment t) "document") "document") 1.189 (mark-paragraph)) 1.190 (t (YaTeX-mark-environment))) 1.191 (if YaTeX-use-image-preview 1.192 (let ((YaTeX-typeset-buffer (concat "*bg:" YaTeX-typeset-buffer))) 1.193 (put 'YaTeX-typeset-conv2image-chain 'math math) 1.194 + (put 'YaTeX-typeset-conv2image-chain 'srctype nil) 1.195 (put 'YaTeX-typeset-conv2image-chain 'win (selected-window)) 1.196 (YaTeX-typeset-region 'YaTeX-typeset-conv2image-chain)) 1.197 (YaTeX-typeset-region)))))