comparison yatexadd.el @ 248:b9771459243e dev

Automatic `bb=...' generation for jpg/png/gif/bmp files.
author yuuji@gentei.org
date Fri, 10 Feb 2012 16:45:04 +0900
parents 3e3ccba06ca1
children c2aa2457a74b
comparison
equal deleted inserted replaced
247:3e3ccba06ca1 248:b9771459243e
1 ;;; -*- Emacs-Lisp -*- 1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX add-in functions. 2 ;;; YaTeX add-in functions.
3 ;;; yatexadd.el rev.20 3 ;;; yatexadd.el rev.20
4 ;;; (c)1991-2012 by HIROSE Yuuji.[yuuji@yatex.org] 4 ;;; (c)1991-2012 by HIROSE Yuuji.[yuuji@yatex.org]
5 ;;; Last modified Fri Feb 10 09:50:00 2012 on firestorm 5 ;;; Last modified Fri Feb 10 16:30:39 2012 on firestorm
6 ;;; $Id$ 6 ;;; $Id$
7 7
8 ;;; 8 ;;;
9 ;;Sample functions for LaTeX environment. 9 ;;Sample functions for LaTeX environment.
10 ;;; 10 ;;;
1883 (and (stringp (symbol-value s)) 1883 (and (stringp (symbol-value s))
1884 (string< "" (symbol-value s)) 1884 (string< "" (symbol-value s))
1885 (format "%s=%s" s (symbol-value s)))) 1885 (format "%s=%s" s (symbol-value s))))
1886 '(width height scale angle))) 1886 '(width height scale angle)))
1887 ",")) 1887 ","))
1888 (setq YaTeX-section-name "caption")
1889 (if (string= "" str) "" 1888 (if (string= "" str) ""
1890 (concat "[" str "]")))) 1889 (concat "[" str "]"))))
1891 1890
1892 (defun YaTeX::includegraphics (argp) 1891 (defun YaTeX::includegraphics (argp)
1893 "Add-in for \\includegraphics" 1892 "Add-in for \\includegraphics"
1894 (let ((imgfile (YaTeX::include argp "Image File: ")) 1893 (let ((imgfile (YaTeX::include argp "Image File: "))
1895 (case-fold-search t) info bb) 1894 (case-fold-search t) info bb noupdate needclose)
1896 (and (string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\)$" imgfile) 1895 (and (string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\)$" imgfile)
1897 (file-exists-p imgfile) 1896 (file-exists-p imgfile)
1898 (or (fboundp 'yahtml-get-image-info) 1897 (or (fboundp 'yahtml-get-image-info)
1899 (progn 1898 (progn
1900 (load "yahtml" t) (featurep 'yahtml))) ;(require 'yahtml nil t) 1899 (load "yahtml" t) (featurep 'yahtml))) ;(require 'yahtml nil t)
1901 (setq info (yahtml-get-image-info imgfile)) 1900 (setq info (yahtml-get-image-info imgfile))
1902 (car info) ;if has width value 1901 (car info) ;if has width value
1903 (car (cdr info)) ;if has height value 1902 (car (cdr info)) ;if has height value
1904 (setq bb (format "bb=%d %d %d %d" 0 0 (car info) (car (cdr info)))) 1903 (setq bb (format "bb=%d %d %d %d" 0 0 (car info) (car (cdr info))))
1905 (YaTeX-push-to-kill-ring bb)) 1904 (save-excursion
1905 (cond
1906 ((and (YaTeX-re-search-active-backward
1907 "\\\\\\(includegraphics\\)\\|\\(bb=[ \t0-9]+\\)"
1908 YaTeX-comment-prefix nil t)
1909 (match-beginning 2)
1910 (not (setq noupdate (equal (YaTeX-match-string 2) bb)))
1911 (y-or-n-p (format "Update `bb=' line to `%s'?: " bb)))
1912 (message "")
1913 (replace-match bb))
1914 (noupdate nil)
1915 ((and (match-beginning 1)
1916 (y-or-n-p "Insert `bb=...' line?: "))
1917 (goto-char (match-end 0))
1918 (message "")
1919 (if (looking-at "\\[") (forward-char 1)
1920 (insert-before-markers "[")
1921 (setq needclose t))
1922 (insert-before-markers bb)
1923 (if needclose (insert-before-markers "]")
1924 (or (looking-at "\\]") (insert-before-markers ","))))
1925 (t (YaTeX-push-to-kill-ring bb)))))
1926 (setq YaTeX-section-name "caption")
1906 imgfile)) 1927 imgfile))
1907 1928
1908 (defun YaTeX::verbfile (argp) 1929 (defun YaTeX::verbfile (argp)
1909 "Add-in for \\verbfile" 1930 "Add-in for \\verbfile"
1910 (YaTeX::include argp "Virbatim File: ")) 1931 (YaTeX::include argp "Virbatim File: "))

yatex.org