yatex

annotate yatex23.el @ 357:4ea63809a0ca

Insert `\includegraphics[dvipdfmx]{graphics}' without query
author HIROSE Yuuji <yuuji@gentei.org>
date Mon, 22 Dec 2014 11:16:46 +0900
parents 3478a327ae41
children 2c2b70f41fb3
rev   line source
yuuji@330 1 ;;; yatex23.el --- YaTeX facilities for Emacs 23 or later -*- coding: sjis -*-
yuuji@330 2 ;;; (c)2014 by HIROSE Yuuji.[yuuji@yatex.org]
yuuji@357 3 ;;; Last modified Mon Dec 22 11:15:48 2014 on firestorm
yuuji@330 4 ;;; $Id:$
yuuji@330 5
yuuji@330 6 ;;; Code:
yuuji@343 7 (defvar YaTeX-dnd-auto-figure "figure"
yuuji@343 8 "*If set, include dropped \\includegraphcs{} into that environment.
yuuji@343 9 The value should be string. Set this `nil' to disable enclosing.")
yuuji@330 10 (defun YaTeX-dnd-handler (uri action)
yuuji@330 11 "DnD handler for yatex-mode
yuuji@330 12 Convert local image URI to \\includegraphcis{} and
yuuji@330 13 .tex file names to \\include{}."
yuuji@343 14 (let*((file (dnd-get-local-file-name uri))
yuuji@343 15 (path (save-excursion
yuuji@343 16 (YaTeX-visit-main t)
yuuji@343 17 (file-relative-name file)))
yuuji@343 18 (insert-file-directory nil)
yuuji@343 19 (case-fold-search t)
yuuji@343 20 (b nil) p1 p2 (cc (current-column)) envstart)
yuuji@343 21 (cond
yuuji@343 22 ((memq action '(copy link move private))
yuuji@330 23 (cond
yuuji@343 24 ((string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|tiff?\\|e?ps\\|pdf\\)$" path)
yuuji@343 25 (if (and (stringp YaTeX-dnd-auto-figure)
yuuji@343 26 (not (YaTeX-in-environment-p YaTeX-dnd-auto-figure))
yuuji@343 27 (not (string-match "figure"
yuuji@343 28 (or (YaTeX-inner-environment t) "body")))
yuuji@343 29 YaTeX-dnd-auto-figure)
yuuji@343 30 (setq b (format "\\begin{%s}[htbp] %%\\centering\n"
yuuji@343 31 YaTeX-dnd-auto-figure)))
yuuji@343 32 (unwind-protect
yuuji@343 33 (progn
yuuji@343 34 (setq envstart (point-marker))
yuuji@343 35 (insert "\\includegraphics")
yuuji@343 36 (insert "{" (YaTeX::includegraphics 1 path t) "}")
yuuji@343 37 (save-excursion
yuuji@357 38 (YaTeX-package-auto-usepackage
yuuji@357 39 "includegraphics" 'section "graphicx" "dvipdfmx"))
yuuji@343 40 (cond
yuuji@343 41 (b
yuuji@343 42 (undo-boundary)
yuuji@343 43 (save-excursion
yuuji@343 44 (goto-char envstart)
yuuji@343 45 (insert b))
yuuji@343 46 (YaTeX-indent-line)
yuuji@343 47 (insert "\n")
yuuji@343 48 (indent-to (1+ cc))
yuuji@343 49 (setq p1 (point))
yuuji@343 50 (insert "\\caption{")
yuuji@343 51 (setq p2 (point))
yuuji@343 52 (insert (format "}\\label{%s}\n" path))
yuuji@343 53 (indent-to cc)
yuuji@343 54 (insert (format "\\end{%s}\n" YaTeX-dnd-auto-figure))
yuuji@343 55 (goto-char p2)
yuuji@343 56 (undo-boundary)
yuuji@343 57 (insert (file-name-nondirectory path))
yuuji@343 58 (undo-boundary)
yuuji@343 59 (goto-char p1)
yuuji@343 60 (insert "%")
yuuji@343 61 (end-of-line)
yuuji@343 62 (or (get 'YaTeX-dnd-auto-figure 'guide)
yuuji@343 63 (progn
yuuji@343 64 (newline 1)
yuuji@343 65 (indent-to (1+ cc))
yuuji@343 66 (insert (format
yuuji@343 67 (if YaTeX-japan
yuuji@343 68 "%% Undo(%s)するとcaptionが活きます。2度押しで空欄 3度押しで無環境"
yuuji@343 69 "%% TYPE undo(%s) to ACTIVATE caption. Twice to clear caption. 3 to no-env")
yuuji@343 70 (key-description
yuuji@343 71 (car (where-is-internal 'undo)))))
yuuji@343 72 (put 'YaTeX-dnd-auto-figure 'guide t)))))
yuuji@348 73 (YaTeX-help "includegraphics"))
yuuji@343 74 (set-marker envstart nil) ;;sure to reset marker
yuuji@343 75 action))
yuuji@344 76 ((string-match "\\(.*\\)\\.tex$" path)
yuuji@348 77 (insert "\\include{" (match-string 1 path) "}"))
yuuji@348 78 ((string-match "\\(.*\\)\\.bib$" path)
yuuji@348 79 (insert "\\bibliography{" (match-string 1 path) "}"))
yuuji@348 80 ((string-match "\\.ind$" path)
yuuji@348 81 (insert "\\input{" path "}"))))
yuuji@343 82 (t (message "%s" action)))))
yuuji@330 83
yuuji@330 84 (provide 'yatex23)
yuuji@330 85
yuuji@330 86 ; Local variables:
yuuji@330 87 ; fill-prefix: ";;; "
yuuji@330 88 ; paragraph-start: "^$\\| \\|;;;$"
yuuji@330 89 ; paragraph-separate: "^$\\| \\|;;;$"
yuuji@330 90 ; coding: sjis
yuuji@330 91 ; End: