yuuji@330: ;;; yatex23.el --- YaTeX facilities for Emacs 23 or later -*- coding: sjis -*- yuuji@443: ;;; (c)2014-2017 by HIROSE Yuuji.[yuuji@yatex.org] yuuji@497: ;;; Last modified Sun Sep 17 10:23:02 2017 on firestorm yuuji@366: ;;; $Id$ yuuji@330: yuuji@433: (require 'yatex19) yuuji@330: ;;; Code: yuuji@343: (defvar YaTeX-dnd-auto-figure "figure" yuuji@343: "*If set, include dropped \\includegraphcs{} into that environment. yuuji@343: The value should be string. Set this `nil' to disable enclosing.") yuuji@361: (defvar YaTeX-dnd-auto-figure-package yuuji@361: (cons "graphicx" yuuji@361: (cond ((string-match "pdflatex" tex-command) "pdftex") yuuji@361: (t "dvipdfmx"))) yuuji@358: "*Default LaTeX package and its option for \\includegraphics") yuuji@358: yuuji@330: (defun YaTeX-dnd-handler (uri action) yuuji@330: "DnD handler for yatex-mode yuuji@330: Convert local image URI to \\includegraphcis{} and yuuji@330: .tex file names to \\include{}." yuuji@402: (let*((file (dnd-get-local-file-name uri t)) yuuji@343: (path (save-excursion yuuji@343: (YaTeX-visit-main t) yuuji@343: (file-relative-name file))) yuuji@343: (insert-file-directory nil) yuuji@343: (case-fold-search t) yuuji@343: (b nil) p1 p2 (cc (current-column)) envstart) yuuji@343: (cond yuuji@343: ((memq action '(copy link move private)) yuuji@330: (cond yuuji@343: ((string-match "\\.\\(jpe?g\\|png\\|gif\\|bmp\\|tiff?\\|e?ps\\|pdf\\)$" path) yuuji@343: (if (and (stringp YaTeX-dnd-auto-figure) yuuji@343: (not (YaTeX-in-environment-p YaTeX-dnd-auto-figure)) yuuji@343: (not (string-match "figure" yuuji@343: (or (YaTeX-inner-environment t) "body"))) yuuji@343: YaTeX-dnd-auto-figure) yuuji@343: (setq b (format "\\begin{%s}[htbp] %%\\centering\n" yuuji@343: YaTeX-dnd-auto-figure))) yuuji@343: (unwind-protect yuuji@343: (progn yuuji@343: (setq envstart (point-marker)) yuuji@343: (insert "\\includegraphics") yuuji@343: (insert "{" (YaTeX::includegraphics 1 path t) "}") yuuji@343: (save-excursion yuuji@357: (YaTeX-package-auto-usepackage yuuji@358: "includegraphics" 'section yuuji@358: (car YaTeX-dnd-auto-figure-package) yuuji@358: (cdr YaTeX-dnd-auto-figure-package))) yuuji@343: (cond yuuji@343: (b yuuji@343: (undo-boundary) yuuji@343: (save-excursion yuuji@343: (goto-char envstart) yuuji@343: (insert b)) yuuji@343: (YaTeX-indent-line) yuuji@343: (insert "\n") yuuji@343: (indent-to (1+ cc)) yuuji@343: (setq p1 (point)) yuuji@343: (insert "\\caption{") yuuji@343: (setq p2 (point)) yuuji@343: (insert (format "}\\label{%s}\n" path)) yuuji@343: (indent-to cc) yuuji@343: (insert (format "\\end{%s}\n" YaTeX-dnd-auto-figure)) yuuji@343: (goto-char p2) yuuji@343: (undo-boundary) yuuji@343: (insert (file-name-nondirectory path)) yuuji@343: (undo-boundary) yuuji@343: (goto-char p1) yuuji@343: (insert "%") yuuji@343: (end-of-line) yuuji@343: (or (get 'YaTeX-dnd-auto-figure 'guide) yuuji@343: (progn yuuji@343: (newline 1) yuuji@343: (indent-to (1+ cc)) yuuji@343: (insert (format yuuji@343: (if YaTeX-japan yuuji@343: "%% Undo(%s)するとcaptionが活きます。2度押しで空欄 3度押しで無環境" yuuji@343: "%% TYPE undo(%s) to ACTIVATE caption. Twice to clear caption. 3 to no-env") yuuji@343: (key-description yuuji@343: (car (where-is-internal 'undo))))) yuuji@343: (put 'YaTeX-dnd-auto-figure 'guide t))))) yuuji@348: (YaTeX-help "includegraphics")) yuuji@343: (set-marker envstart nil) ;;sure to reset marker yuuji@343: action)) yuuji@344: ((string-match "\\(.*\\)\\.tex$" path) yuuji@348: (insert "\\include{" (match-string 1 path) "}")) yuuji@348: ((string-match "\\(.*\\)\\.bib$" path) yuuji@348: (insert "\\bibliography{" (match-string 1 path) "}")) yuuji@348: ((string-match "\\.ind$" path) yuuji@348: (insert "\\input{" path "}")))) yuuji@343: (t (message "%s" action))))) yuuji@330: yuuji@377: (defvar YaTeX-on-the-fly-bg-face '("#f0f0c0" . "#706868") yuuji@376: "Background color of on-the-fly preview image activated environment.") yuuji@376: (defvar YaTeX-on-the-fly-overlay nil yuuji@376: "Overlay of on-the-fly preview image") yuuji@376: (defface YaTeX-on-the-fly-activated-face yuuji@376: (list yuuji@381: (list (list '(class color) '(min-colors 65536)) yuuji@376: (list ':background yuuji@376: (if (eq YaTeX-background-mode 'light) yuuji@376: (car YaTeX-on-the-fly-bg-face) yuuji@376: (cdr YaTeX-on-the-fly-bg-face)))) yuuji@376: (list t (list ':bold t))) yuuji@376: "Face of on-the-fly preview image mode") yuuji@376: yuuji@330: (provide 'yatex23)