comparison yatexadd.el @ 254:45ea6e6e5b26 dev

Add-in for \includegraphics offers "clip" option.
author HIROSE Yuuji <yuuji@gentei.org>
date Sun, 12 Feb 2012 10:28:54 +0900
parents 73fef09ebc15
children 214702e4df54
comparison
equal deleted inserted replaced
253:90aa4b6d96e1 254:45ea6e6e5b26
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 Sat Feb 11 23:36:21 2012 on firestorm 5 ;;; Last modified Sun Feb 12 10:23:23 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 ;;;
1892 (defun YaTeX:includegraphics () 1892 (defun YaTeX:includegraphics ()
1893 "Add-in for \\includegraphics's option" 1893 "Add-in for \\includegraphics's option"
1894 (let (width height (scale "") angle str) 1894 (let (width height (scale "") angle str)
1895 (setq width (YaTeX-read-string-or-skip "Width: ") 1895 (setq width (YaTeX-read-string-or-skip "Width: ")
1896 height (YaTeX-read-string-or-skip "Height: ")) 1896 height (YaTeX-read-string-or-skip "Height: "))
1897 (or (string< width "") (string< "" height) 1897 (or (string< "" width) (string< "" height)
1898 (setq scale (YaTeX-read-string-or-skip "Scale: "))) 1898 (setq scale (YaTeX-read-string-or-skip "Scale: ")))
1899 (setq angle (YaTeX-read-string-or-skip "Angle(0-359): ")) 1899 (setq angle (YaTeX-read-string-or-skip "Angle(0-359): "))
1900 (setq str 1900 (setq str
1901 (mapconcat 1901 (mapconcat
1902 'concat 1902 'concat
1911 (concat "[" str "]")))) 1911 (concat "[" str "]"))))
1912 1912
1913 (defun YaTeX::includegraphics (argp) 1913 (defun YaTeX::includegraphics (argp)
1914 "Add-in for \\includegraphics" 1914 "Add-in for \\includegraphics"
1915 (let ((imgfile (YaTeX::include argp "Image File: ")) 1915 (let ((imgfile (YaTeX::include argp "Image File: "))
1916 (case-fold-search t) info bb noupdate needclose) 1916 (case-fold-search t) info bb noupdate needclose c)
1917 (and (string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\)$" imgfile) 1917 (and (string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\)$" imgfile)
1918 (file-exists-p imgfile) 1918 (file-exists-p imgfile)
1919 (or (fboundp 'yahtml-get-image-info) 1919 (or (fboundp 'yahtml-get-image-info)
1920 (progn 1920 (progn
1921 (load "yahtml" t) (featurep 'yahtml))) ;(require 'yahtml nil t) 1921 (load "yahtml" t) (featurep 'yahtml))) ;(require 'yahtml nil t)
1923 (car info) ;if has width value 1923 (car info) ;if has width value
1924 (car (cdr info)) ;if has height value 1924 (car (cdr info)) ;if has height value
1925 (setq bb (format "bb=%d %d %d %d" 0 0 (car info) (car (cdr info)))) 1925 (setq bb (format "bb=%d %d %d %d" 0 0 (car info) (car (cdr info))))
1926 (save-excursion 1926 (save-excursion
1927 (cond 1927 (cond
1928 ((and (YaTeX-re-search-active-backward 1928 ((and (save-excursion
1929 "\\\\\\(includegraphics\\)\\|\\(bb=[ \t0-9]+\\)" 1929 (YaTeX-re-search-active-backward
1930 YaTeX-comment-prefix nil t) 1930 "\\\\\\(includegraphics\\)\\|\\(bb=[-+ \t0-9]+\\)"
1931 YaTeX-comment-prefix nil t))
1931 (match-beginning 2) 1932 (match-beginning 2)
1932 (not (setq noupdate (equal (YaTeX-match-string 2) bb))) 1933 (not (setq noupdate (equal (YaTeX-match-string 2) bb)))
1933 (y-or-n-p (format "Update `bb=' line to `%s'?: " bb))) 1934 (y-or-n-p (format "Update `bb=' line to `%s'?: " bb)))
1934 (message "") 1935 (message "")
1935 (replace-match bb)) 1936 (replace-match bb))
1936 (noupdate nil) 1937 (noupdate nil)
1937 ((and (match-beginning 1) 1938 ((and (match-beginning 1)
1938 (y-or-n-p "Insert `bb=...' line?: ")) 1939 (prog2
1940 (message "Insert `%s'? Y)es N)o C)yes+`clip': " bb)
1941 (memq (setq c (read-char)) '(?y ?Y ?\ ?c ?C))
1942 (message "")))
1939 (goto-char (match-end 0)) 1943 (goto-char (match-end 0))
1940 (message "") 1944 (message "")
1941 (if (looking-at "\\[") (forward-char 1) 1945 (if (looking-at "\\[") (forward-char 1)
1942 (insert-before-markers "[") 1946 (insert-before-markers "[")
1943 (setq needclose t)) 1947 (setq needclose t))
1944 (insert-before-markers bb) 1948 (insert-before-markers bb)
1949 (if (memq c '(?c ?C)) (insert-before-markers ",clip"))
1945 (if needclose (insert-before-markers "]") 1950 (if needclose (insert-before-markers "]")
1946 (or (looking-at "\\]") (insert-before-markers ",")))) 1951 (or (looking-at "\\]") (insert-before-markers ","))))
1947 (t (YaTeX-push-to-kill-ring bb))))) 1952 (t (YaTeX-push-to-kill-ring bb)))))
1948 (setq YaTeX-section-name "caption") 1953 (setq YaTeX-section-name "caption")
1949 imgfile)) 1954 imgfile))

yatex.org