Mercurial > hgrepos > hgweb.cgi > yatex
comparison yatexadd.el @ 366:77a2fd4fd634
merged
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Fri, 26 Dec 2014 01:06:32 +0900 |
parents | d69fd7b1ac4d |
children | e95ae850eefb |
comparison
equal
deleted
inserted
replaced
300:30f1a2659a39 | 366:77a2fd4fd634 |
---|---|
1 ;;; yatexadd.el --- YaTeX add-in functions | 1 ;;; yatexadd.el --- YaTeX add-in functions |
2 ;;; yatexadd.el rev.20 | 2 ;;; yatexadd.el rev.21 |
3 ;;; (c)1991-2013 by HIROSE Yuuji.[yuuji@yatex.org] | 3 ;;; (c)1991-2014 by HIROSE Yuuji.[yuuji@yatex.org] |
4 ;;; Last modified Mon Apr 1 22:43:00 2013 on firestorm | 4 ;;; Last modified Sat Dec 20 14:55:10 2014 on firestorm |
5 ;;; $Id$ | 5 ;;; $Id$ |
6 | 6 |
7 ;;; Code: | 7 ;;; Code: |
8 ;;; | 8 ;;; |
9 ;;Sample functions for LaTeX environment. | 9 ;;Sample functions for LaTeX environment. |
22 "YaTeX add-in function for tabular environment. | 22 "YaTeX add-in function for tabular environment. |
23 Notice that this function refers the let-variable `env' in | 23 Notice that this function refers the let-variable `env' in |
24 YaTeX-make-begin-end." | 24 YaTeX-make-begin-end." |
25 (let ((width "") bars (rule "") (and "") (j 1) loc ans (hline "\\hline")) | 25 (let ((width "") bars (rule "") (and "") (j 1) loc ans (hline "\\hline")) |
26 (if (string= YaTeX-env-name "tabular*") | 26 (if (string= YaTeX-env-name "tabular*") |
27 (setq width (concat "{" (read-string "Width: ") "}"))) | 27 (setq width (concat "{" (YaTeX:read-length "Width: ") "}"))) |
28 (setq loc (YaTeX:read-position "tb") | 28 (setq loc (YaTeX:read-position "tb") |
29 bars (string-to-int | 29 bars (string-to-int |
30 (read-string "Number of columns(0 for default format): " "3"))) | 30 (read-string "Number of columns(0 for default format): " "3"))) |
31 (if (<= bars 0) | 31 (if (<= bars 0) |
32 (setq ;if 0, simple format | 32 (setq ;if 0, simple format |
97 (defun YaTeX:read-position (oneof) | 97 (defun YaTeX:read-position (oneof) |
98 "Read a LaTeX (optional) position format such as `[htbp]'." | 98 "Read a LaTeX (optional) position format such as `[htbp]'." |
99 (let ((pos (YaTeX:read-oneof oneof))) | 99 (let ((pos (YaTeX:read-oneof oneof))) |
100 (if (string= pos "") "" (concat "[" pos "]")))) | 100 (if (string= pos "") "" (concat "[" pos "]")))) |
101 | 101 |
102 (defun YaTeX:read-length (prompt) | |
103 "Read a LaTeX dimensional parameter with magnifying numerics prepend." | |
104 (let ((minibuffer-local-completion-map YaTeX-minibuffer-completion-map) | |
105 (delim "-0-9*+/.") | |
106 (tbl (append YaTeX:style-parameters-local | |
107 YaTeX:style-parameters-private | |
108 YaTeX:style-parameters-default))) | |
109 (YaTeX-completing-read-or-skip prompt tbl nil))) | |
110 | |
102 ;;; | 111 ;;; |
103 ;; Functions for figure environemnt | 112 ;; Functions for figure environemnt |
104 ;;; | 113 ;;; |
105 (defvar YaTeX:figure-caption-first nil | 114 (defvar YaTeX:figure-caption-first nil |
106 "Non-nil indicates put caption before figure.") | 115 "Non-nil indicates put caption before figure.") |
158 (defun YaTeX:equation () | 167 (defun YaTeX:equation () |
159 (YaTeX-jmode-off) | 168 (YaTeX-jmode-off) |
160 (if (fboundp 'YaTeX-toggle-math-mode) | 169 (if (fboundp 'YaTeX-toggle-math-mode) |
161 (YaTeX-toggle-math-mode t))) ;force math-mode ON. | 170 (YaTeX-toggle-math-mode t))) ;force math-mode ON. |
162 | 171 |
163 (mapcar '(lambda (f) (fset f 'YaTeX:equation)) | 172 (mapcar (function (lambda (f) (fset f 'YaTeX:equation))) |
164 '(YaTeX:eqnarray YaTeX:eqnarray* YaTeX:align YaTeX:align* | 173 '(YaTeX:eqnarray YaTeX:eqnarray* YaTeX:align YaTeX:align* |
165 YaTeX:split YaTeX:multline YaTeX:multline* YaTeX:gather YaTeX:gather* | 174 YaTeX:split YaTeX:multline YaTeX:multline* YaTeX:gather YaTeX:gather* |
166 YaTeX:aligned* YaTeX:gathered YaTeX:gathered* | 175 YaTeX:aligned* YaTeX:gathered YaTeX:gathered* |
167 YaTeX:alignat YaTeX:alignat* YaTeX:xalignat YaTeX:xalignat* | 176 YaTeX:alignat YaTeX:alignat* YaTeX:xalignat YaTeX:xalignat* |
168 YaTeX:xxalignat YaTeX:xxalignat*)) | 177 YaTeX:xxalignat YaTeX:xxalignat*)) |
176 (defun YaTeX:list () | 185 (defun YaTeX:list () |
177 "%\n{} %default label\n{} %formatting parameter") | 186 "%\n{} %default label\n{} %formatting parameter") |
178 | 187 |
179 (defun YaTeX:minipage () | 188 (defun YaTeX:minipage () |
180 (concat (YaTeX:read-position "cbt") | 189 (concat (YaTeX:read-position "cbt") |
181 "{" (read-string "Width: ") "}")) | 190 "{" (YaTeX:read-length "Width: ") "}")) |
182 | 191 |
183 (defun YaTeX:thebibliography () | 192 (defun YaTeX:thebibliography () |
184 (setq YaTeX-section-name "bibitem") | 193 (setq YaTeX-section-name "bibitem") |
185 (concat "{" (read-string "Longest label: ") "}")) | 194 (concat "{" (read-string "Longest label: ") "}")) |
186 | 195 |
187 (defun YaTeX:multicols () | 196 (defun YaTeX:multicols () |
188 (concat "{" (read-string "Number of columns: ") "}")) | 197 (concat "{" (read-string "Number of columns: ") "}")) |
198 | |
199 | |
200 ;; wrapfig.sty | |
201 (defun YaTeX:wrapfigure () | |
202 (YaTeX-help "wrapfigure") | |
203 (concat | |
204 (let ((lines (YaTeX-read-string-or-skip "Wrap Lines(Optional): "))) | |
205 (if (string< "" lines) | |
206 (concat "[" lines "]"))) | |
207 "{" (YaTeX:read-oneof "rlioRLIO" t) "}" | |
208 "{" (YaTeX:read-length "Image width: ") "}")) | |
209 | |
189 | 210 |
190 ;;; | 211 ;;; |
191 ;;Sample functions for section-type command. | 212 ;;Sample functions for section-type command. |
192 ;;; | 213 ;;; |
193 (defun YaTeX:multiput () | 214 (defun YaTeX:multiput () |
202 (cond | 223 (cond |
203 ((YaTeX-in-environment-p "picture") | 224 ((YaTeX-in-environment-p "picture") |
204 (concat (YaTeX:read-coordinates "Dimension") | 225 (concat (YaTeX:read-coordinates "Dimension") |
205 (YaTeX:read-position "lsrtb"))) | 226 (YaTeX:read-position "lsrtb"))) |
206 (t | 227 (t |
207 (let ((width (read-string "Width: "))) | 228 (let ((width (YaTeX:read-length "Width: "))) |
208 (if (string< "" width) | 229 (if (string< "" width) |
209 (progn | 230 (progn |
210 (or (equal (aref width 0) ?\[) | 231 (or (equal (aref width 0) ?\[) |
211 (setq width (concat "[" width "]"))) | 232 (setq width (concat "[" width "]"))) |
212 (concat width (YaTeX:read-position | 233 (concat width (YaTeX:read-position |
219 | 240 |
220 (defun YaTeX:parbox () | 241 (defun YaTeX:parbox () |
221 (YaTeX:read-position "tbc")) | 242 (YaTeX:read-position "tbc")) |
222 (defun YaTeX::parbox (argp) | 243 (defun YaTeX::parbox (argp) |
223 (cond | 244 (cond |
224 ((= argp 1) (read-string "Width: ")) | 245 ((= argp 1) (YaTeX:read-length "Width: ")) |
225 ((= argp 2) (read-string "Text: ")))) | 246 ((= argp 2) (read-string "Text: ")))) |
226 | 247 |
227 (defun YaTeX::dashbox () | 248 (defun YaTeX::dashbox () |
228 (concat "{" (read-string "Dash dimension: ") "}" | 249 (concat "{" (read-string "Dash dimension: ") "}" |
229 (YaTeX:read-coordinates "Dimension"))) | 250 (YaTeX:read-coordinates "Dimension"))) |
1246 (YaTeX::label-rename-refs old label)))) | 1267 (YaTeX::label-rename-refs old label)))) |
1247 label)))) | 1268 label)))) |
1248 | 1269 |
1249 | 1270 |
1250 (fset 'YaTeX::pageref 'YaTeX::ref) | 1271 (fset 'YaTeX::pageref 'YaTeX::ref) |
1272 (fset 'YaTeX::cref 'YaTeX::ref) | |
1251 (defun YaTeX::tabref (argp) ; For the style file of IPSJ journal | 1273 (defun YaTeX::tabref (argp) ; For the style file of IPSJ journal |
1252 (YaTeX::ref | 1274 (YaTeX::ref |
1253 argp nil nil | 1275 argp nil nil |
1254 (function | 1276 (function |
1255 (lambda () | 1277 (lambda () |
1573 ("\\partopsep") | 1595 ("\\partopsep") |
1574 ("\\rightmargin") | 1596 ("\\rightmargin") |
1575 ("\\tabcolsep") | 1597 ("\\tabcolsep") |
1576 ("\\textheight") | 1598 ("\\textheight") |
1577 ("\\textwidth") | 1599 ("\\textwidth") |
1600 ("\\columnwidth") | |
1578 ("\\topmargin") | 1601 ("\\topmargin") |
1579 ("\\topsep") | 1602 ("\\topsep") |
1580 ("\\topskip") | 1603 ("\\topskip") |
1581 ) | 1604 ) |
1582 "Alist of LaTeX style parameters.") | 1605 "Alist of LaTeX style parameters.") |
1706 (cond | 1729 (cond |
1707 ((= argp 1) | 1730 ((= argp 1) |
1708 (save-excursion | 1731 (save-excursion |
1709 (YaTeX-visit-main t) | 1732 (YaTeX-visit-main t) |
1710 (let*((insert-default-directory) | 1733 (let*((insert-default-directory) |
1711 (file (read-file-name (or prompt "Input file: ") ""))) | 1734 (default (and (boundp 'old) (stringp old) old)) |
1735 (file (read-file-name (or prompt "Input file: ") "" | |
1736 default nil default))) | |
1712 (setq file (substring file 0 (string-match "\\.tex$" file)))))))) | 1737 (setq file (substring file 0 (string-match "\\.tex$" file)))))))) |
1713 | 1738 |
1714 (fset 'YaTeX::input 'YaTeX::include) | 1739 (fset 'YaTeX::input 'YaTeX::include) |
1715 | 1740 |
1716 | 1741 |
1901 (read-string (if YaTeX-japan "テキスト: " "Text: "))))) | 1926 (read-string (if YaTeX-japan "テキスト: " "Text: "))))) |
1902 | 1927 |
1903 (defun YaTeX:includegraphics () | 1928 (defun YaTeX:includegraphics () |
1904 "Add-in for \\includegraphics's option" | 1929 "Add-in for \\includegraphics's option" |
1905 (let (width height (scale "") angle str) | 1930 (let (width height (scale "") angle str) |
1906 (setq width (YaTeX-read-string-or-skip "Width: ") | 1931 (setq width (YaTeX:read-length "Width: ") |
1907 height (YaTeX-read-string-or-skip "Height: ")) | 1932 height (YaTeX:read-length "Height: ")) |
1908 (or (string< "" width) (string< "" height) | 1933 (or (string< "" width) (string< "" height) |
1909 (setq scale (YaTeX-read-string-or-skip "Scale: "))) | 1934 (setq scale (YaTeX-read-string-or-skip "Scale: "))) |
1910 (setq angle (YaTeX-read-string-or-skip "Angle(0-359): ")) | 1935 (setq angle (YaTeX-read-string-or-skip "Angle(0-359): ")) |
1911 (setq str | 1936 (setq str |
1912 (mapconcat | 1937 (mapconcat |
1913 'concat | 1938 'concat |
1914 (delq nil | 1939 (delq nil |
1915 (mapcar '(lambda (s) | 1940 (mapcar (function (lambda (s) |
1916 (and (stringp (symbol-value s)) | 1941 (and (stringp (symbol-value s)) |
1917 (string< "" (symbol-value s)) | 1942 (string< "" (symbol-value s)) |
1918 (format "%s=%s" s (symbol-value s)))) | 1943 (format "%s=%s" s (symbol-value s))))) |
1919 '(width height scale angle))) | 1944 '(width height scale angle))) |
1920 ",")) | 1945 ",")) |
1921 (if (string= "" str) "" | 1946 (if (string= "" str) "" |
1922 (concat "[" str "]")))) | 1947 (concat "[" str "]")))) |
1923 | 1948 |
1924 (defun YaTeX::includegraphics (argp) | 1949 (defun YaTeX::get-boundingbox (file) |
1950 "Return the bound box as a string | |
1951 This function relies on gs(ghostscript) command installed." | |
1952 (let ((str (YaTeX-command-to-string | |
1953 (format "%s -sDEVICE=bbox -dBATCH -dNOPAUSE %s" | |
1954 YaTeX-cmd-gs file)))) | |
1955 (if (string-match | |
1956 "%%BoundingBox:\\s \\([0-9]+\\s [0-9]+\\s [0-9]+\\s [0-9]+\\)" | |
1957 str) | |
1958 (substring str (match-beginning 1) (match-end 1))))) | |
1959 | |
1960 (defun YaTeX::includegraphics (argp &optional file doclip) | |
1925 "Add-in for \\includegraphics" | 1961 "Add-in for \\includegraphics" |
1926 (let ((imgfile (YaTeX::include argp "Image File: ")) | 1962 (let*((imgfile (or file (YaTeX::include argp "Image File: "))) |
1963 (imgfilepath | |
1964 (save-excursion | |
1965 (YaTeX-visit-main t) | |
1966 (expand-file-name imgfile default-directory))) | |
1927 (case-fold-search t) info bb noupdate needclose c) | 1967 (case-fold-search t) info bb noupdate needclose c) |
1928 (and (string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\)$" imgfile) | 1968 (and (string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|pdf\\)$" imgfile) |
1929 (file-exists-p imgfile) | 1969 (file-exists-p imgfilepath) |
1930 (or (fboundp 'yahtml-get-image-info) | 1970 (or (fboundp 'yahtml-get-image-info) |
1931 (progn | 1971 (progn |
1932 (load "yahtml" t) (featurep 'yahtml))) ;(require 'yahtml nil t) | 1972 (load "yahtml" t) (featurep 'yahtml))) ;(require 'yahtml nil t) |
1933 (setq info (yahtml-get-image-info imgfile)) | 1973 (if (string-match "\\.pdf" imgfile) |
1934 (car info) ;if has width value | 1974 (and |
1935 (car (cdr info)) ;if has height value | 1975 (setq info (YaTeX::get-boundingbox imgfilepath)) |
1936 (setq bb (format "bb=%d %d %d %d" 0 0 (car info) (car (cdr info)))) | 1976 (stringp info) |
1977 (string< "" info) | |
1978 (setq bb (format "bb=%s" info))) | |
1979 (setq info (yahtml-get-image-info imgfilepath)) | |
1980 (car info) ;if has width value | |
1981 (car (cdr info)) ;if has height value | |
1982 (setq bb (format "bb=%d %d %d %d" 0 0 (car info) (car (cdr info))))) | |
1937 (save-excursion | 1983 (save-excursion |
1938 (cond | 1984 (cond |
1939 ((and (save-excursion | 1985 ((and (save-excursion |
1940 (YaTeX-re-search-active-backward | 1986 (YaTeX-re-search-active-backward |
1941 "\\\\\\(includegraphics\\)\\|\\(bb=[-+ \t0-9]+\\)" | 1987 "\\\\\\(includegraphics\\)\\|\\(bb=[-+ \t0-9]+\\)" |
1945 (y-or-n-p (format "Update `bb=' line to `%s'?: " bb))) | 1991 (y-or-n-p (format "Update `bb=' line to `%s'?: " bb))) |
1946 (message "") | 1992 (message "") |
1947 (replace-match bb)) | 1993 (replace-match bb)) |
1948 (noupdate nil) | 1994 (noupdate nil) |
1949 ((and (match-beginning 1) | 1995 ((and (match-beginning 1) |
1950 (prog2 | 1996 (or doclip |
1951 (message "Insert `%s'? Y)es N)o C)yes+`clip': " bb) | 1997 (prog2 |
1952 (memq (setq c (read-char)) '(?y ?Y ?\ ?c ?C)) | 1998 (message "Insert `%s'? Y)es N)o C)yes+`clip': " bb) |
1953 (message ""))) | 1999 (memq (setq c (read-char)) '(?y ?Y ?\ ?c ?C)) |
2000 (setq doclip (memq c '(?c ?C))) | |
2001 (message "")))) | |
1954 (goto-char (match-end 0)) | 2002 (goto-char (match-end 0)) |
1955 (message "") | 2003 (message "`bb=' %s" |
2004 (format | |
2005 (if YaTeX-japan | |
2006 "の値はファイル名の上で `%s' を押してファイル名を再入力して更新できます。" | |
2007 "values can be update by typing `%s' on file name.") | |
2008 (key-description | |
2009 (car (where-is-internal 'YaTeX-change-*))))) | |
1956 (if (looking-at "\\[") (forward-char 1) | 2010 (if (looking-at "\\[") (forward-char 1) |
1957 (insert-before-markers "[") | 2011 (insert-before-markers "[") |
1958 (setq needclose t)) | 2012 (setq needclose t)) |
1959 (insert-before-markers bb) | 2013 (insert-before-markers bb) |
1960 (if (memq c '(?c ?C)) (insert-before-markers ",clip")) | 2014 (if doclip (insert-before-markers ",clip")) |
1961 (if needclose (insert-before-markers "]") | 2015 (if needclose (insert-before-markers "]") |
1962 (or (looking-at "\\]") (insert-before-markers ",")))) | 2016 (or (looking-at "\\]") (insert-before-markers ",")))) |
1963 (t (YaTeX-push-to-kill-ring bb))))) | 2017 (t (YaTeX-push-to-kill-ring bb))))) |
1964 (setq YaTeX-section-name "caption") | 2018 (setq YaTeX-section-name "caption") |
1965 imgfile)) | 2019 imgfile)) |
1975 | 2029 |
1976 (defvar YaTeX::usepackage-alist-default | 2030 (defvar YaTeX::usepackage-alist-default |
1977 '(("version") ("plext") ("url") ("fancybox") ("pifont") ("longtable") | 2031 '(("version") ("plext") ("url") ("fancybox") ("pifont") ("longtable") |
1978 ("ascmac") ("bm") ("graphics") ("graphicx") ("alltt") ("misc") ("eclbkbox") | 2032 ("ascmac") ("bm") ("graphics") ("graphicx") ("alltt") ("misc") ("eclbkbox") |
1979 ("amsmath") ("amssymb") ("xymtex") ("chemist") | 2033 ("amsmath") ("amssymb") ("xymtex") ("chemist") |
1980 ("a4j") ("array") ("epsf") ("color") ("epsfig") ("floatfig") | 2034 ("a4j") ("array") ("epsf") ("color") ("xcolor") ("epsfig") ("floatfig") |
1981 ("landscape") ("path") ("supertabular") ("twocolumn") | 2035 ("landscape") ("path") ("supertabular") ("twocolumn") |
1982 ("latexsym") ("times") ("makeidx")) | 2036 ("latexsym") ("times") ("makeidx") ("geometry") ("type1cm")) |
1983 "Default completion table for arguments of \\usepackage") | 2037 "Default completion table for arguments of \\usepackage") |
1984 | 2038 |
1985 (defvar YaTeX::usepackage-alist-private nil | 2039 (defvar YaTeX::usepackage-alist-private nil |
1986 "*Private completion list of the argument for usepackage") | 2040 "*Private completion list of the argument for usepackage") |
1987 | 2041 |
2013 (format "%c" c))))) | 2067 (format "%c" c))))) |
2014 | 2068 |
2015 (defun YaTeX::maskbox (argp) | 2069 (defun YaTeX::maskbox (argp) |
2016 (cond | 2070 (cond |
2017 ((equal argp 1) | 2071 ((equal argp 1) |
2018 (read-string "Width: ")) | 2072 (YaTeX:read-length "Width: ")) |
2019 ((equal argp 2) | 2073 ((equal argp 2) |
2020 (read-string "Height: ")) | 2074 (YaTeX:read-length "Height: ")) |
2021 ((equal argp 3) | 2075 ((equal argp 3) |
2022 (let (c) | 2076 (let (c) |
2023 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K))) | 2077 (while (not (memq c '(?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K))) |
2024 (message "Mask type(A..K): ") | 2078 (message "Mask type(A..K): ") |
2025 (setq c (upcase (read-char)))) | 2079 (setq c (upcase (read-char)))) |