yatex

changeset 308:5c0f3d315bf9 dev

Automatic `bb=...' insertion also works on PDF files
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 21 Nov 2013 15:52:24 +0900
parents 326bd21ad995
children 774935c77366
files yatexadd.el
diffstat 1 files changed, 30 insertions(+), 8 deletions(-) [+]
line diff
     1.1 --- a/yatexadd.el	Wed Nov 20 21:47:51 2013 +0900
     1.2 +++ b/yatexadd.el	Thu Nov 21 15:52:24 2013 +0900
     1.3 @@ -1,7 +1,7 @@
     1.4  ;;; yatexadd.el --- YaTeX add-in functions
     1.5  ;;; yatexadd.el rev.20
     1.6  ;;; (c)1991-2013 by HIROSE Yuuji.[yuuji@yatex.org]
     1.7 -;;; Last modified Mon Apr  1 22:43:00 2013 on firestorm
     1.8 +;;; Last modified Thu Nov 21 15:50:56 2013 on firestorm
     1.9  ;;; $Id$
    1.10  
    1.11  ;;; Code:
    1.12 @@ -1921,19 +1921,35 @@
    1.13      (if (string= "" str) ""
    1.14        (concat "[" str "]"))))
    1.15  
    1.16 +(defun YaTeX::get-boundingbox (file)
    1.17 +  "Return the bound box as a string
    1.18 +This function relies on gs(ghostscript) command installed."
    1.19 +  (let ((str (YaTeX-command-to-string
    1.20 +	      (format "gs -sDEVICE=bbox -dBATCH -dNOPAUSE %s" file))))
    1.21 +    (if (string-match
    1.22 +	 "%%BoundingBox:\\s \\([0-9]+\\s [0-9]+\\s [0-9]+\\s [0-9]+\\)"
    1.23 +	 str)
    1.24 +	(substring str (match-beginning 1) (match-end 1)))))
    1.25 +
    1.26  (defun YaTeX::includegraphics (argp)
    1.27    "Add-in for \\includegraphics"
    1.28    (let ((imgfile (YaTeX::include argp "Image File: "))
    1.29  	(case-fold-search t) info bb noupdate needclose c)
    1.30 -    (and (string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\)$" imgfile)
    1.31 +    (and (string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|pdf\\)$" imgfile)
    1.32  	 (file-exists-p imgfile)
    1.33  	 (or (fboundp 'yahtml-get-image-info)
    1.34  	     (progn
    1.35  	       (load "yahtml" t) (featurep 'yahtml))) ;(require 'yahtml nil t)
    1.36 -	 (setq info (yahtml-get-image-info imgfile))
    1.37 -	 (car info)			;if has width value
    1.38 -	 (car (cdr info))		;if has height value
    1.39 -	 (setq bb (format "bb=%d %d %d %d" 0 0 (car info) (car (cdr info))))
    1.40 +	 (if (string-match "\\.pdf" imgfile)
    1.41 +	     (and
    1.42 +	      (setq info (YaTeX::get-boundingbox imgfile))
    1.43 +	      (stringp info)
    1.44 +	      (string< "" info)
    1.45 +	      (setq bb (format "bb=%s" info)))
    1.46 +	   (setq info (yahtml-get-image-info imgfile))
    1.47 +	   (car info)			;if has width value
    1.48 +	   (car (cdr info))		;if has height value
    1.49 +	   (setq bb (format "bb=%d %d %d %d" 0 0 (car info) (car (cdr info)))))
    1.50  	 (save-excursion
    1.51  	   (cond
    1.52  	    ((and (save-excursion
    1.53 @@ -1952,7 +1968,13 @@
    1.54  		      (memq (setq c (read-char)) '(?y ?Y ?\  ?c ?C))
    1.55  		    (message "")))
    1.56  	     (goto-char (match-end 0))
    1.57 -	     (message "")
    1.58 +	     (message "`bb=' %s"
    1.59 +		      (format
    1.60 +		       (if YaTeX-japan
    1.61 +			   "の値はファイル名の上で `%s' を押してファイル名を再入力して更新できます。"
    1.62 +			 "values can be update by typing `%s' on file name.")
    1.63 +		       (key-description
    1.64 +			(car (where-is-internal 'YaTeX-change-*)))))
    1.65  	     (if (looking-at "\\[") (forward-char 1)
    1.66  	       (insert-before-markers "[")
    1.67  	       (setq needclose t))
    1.68 @@ -1977,7 +1999,7 @@
    1.69    '(("version") ("plext") ("url") ("fancybox") ("pifont") ("longtable")
    1.70      ("ascmac") ("bm") ("graphics") ("graphicx") ("alltt") ("misc") ("eclbkbox")
    1.71      ("amsmath") ("amssymb") ("xymtex") ("chemist")
    1.72 -    ("a4j") ("array") ("epsf") ("color") ("epsfig") ("floatfig")
    1.73 +    ("a4j") ("array") ("epsf") ("color") ("xcolor") ("epsfig") ("floatfig")
    1.74      ("landscape") ("path") ("supertabular") ("twocolumn")
    1.75      ("latexsym") ("times") ("makeidx"))
    1.76    "Default completion table for arguments of \\usepackage")