comparison yatexprc.el @ 391:e834bbfce2ab dev

Use latex-math-preview if available. %#PREVIEWDPI
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 15 Jan 2015 23:20:31 +0900
parents ad62fb00a393
children 5aa8208fbef0
comparison
equal deleted inserted replaced
390:fa7370eb8292 391:e834bbfce2ab
1 ;;; yatexprc.el --- YaTeX process handler 1 ;;; yatexprc.el --- YaTeX process handler
2 ;;; 2 ;;;
3 ;;; (c)1993-2015 by HIROSE Yuuji.[yuuji@yatex.org] 3 ;;; (c)1993-2015 by HIROSE Yuuji.[yuuji@yatex.org]
4 ;;; Last modified Wed Jan 7 09:06:54 2015 on firestorm 4 ;;; Last modified Thu Jan 15 11:15:07 2015 on firestorm
5 ;;; $Id$ 5 ;;; $Id$
6 6
7 ;;; Code: 7 ;;; Code:
8 ;(require 'yatex) 8 ;(require 'yatex)
9 (require 'yatexlib) 9 (require 'yatexlib)
410 410
411 (defvar YaTeX-use-image-preview "png" 411 (defvar YaTeX-use-image-preview "png"
412 "*Nil means not using image preview by [prefix] t e. 412 "*Nil means not using image preview by [prefix] t e.
413 Acceptable value is one of \"jpg\" or \"png\", which specifies 413 Acceptable value is one of \"jpg\" or \"png\", which specifies
414 format of preview image. NOTE that if your system has /usr/bin/sips 414 format of preview image. NOTE that if your system has /usr/bin/sips
415 not having convert(ImageMagick), jpeg format is automatically taken 415 while not having convert(ImageMagick), jpeg format is automatically taken
416 for conversion.") 416 for conversion.")
417 (defvar YaTeX-preview-image-mode-map nil 417 (defvar YaTeX-preview-image-mode-map nil
418 "Keymap used in YaTeX-preview-image-mode") 418 "Keymap used in YaTeX-preview-image-mode")
419 (defun YaTeX-preview-image-mode () 419 (defun YaTeX-preview-image-mode ()
420 (interactive) 420 (interactive)
472 (prevname (process-name proc)) 472 (prevname (process-name proc))
473 (texput "texput") 473 (texput "texput")
474 (format YaTeX-use-image-preview) 474 (format YaTeX-use-image-preview)
475 (target (concat texput "." format)) 475 (target (concat texput "." format))
476 (math (get 'YaTeX-typeset-conv2image-chain 'math)) 476 (math (get 'YaTeX-typeset-conv2image-chain 'math))
477 (dpi (get 'YaTeX-typeset-conv2image-chain 'dpi))
477 (srctype (or (get 'YaTeX-typeset-conv2image-chain 'srctype) 478 (srctype (or (get 'YaTeX-typeset-conv2image-chain 'srctype)
478 (if (file-newer-than-file-p 479 (if (file-newer-than-file-p
479 (concat texput ".pdf") 480 (concat texput ".pdf")
480 (concat texput ".dvi")) 481 (concat texput ".dvi"))
481 'pdf 'dvi))) 482 'pdf 'dvi)))
501 (if command 502 (if command
502 (let ((cmdline (YaTeX-replace-formats 503 (let ((cmdline (YaTeX-replace-formats
503 command 504 command
504 (list (cons "b" "texput") 505 (list (cons "b" "texput")
505 (cons "f" format) 506 (cons "f" format)
506 (cons "d" (if math "300" "200")))))) 507 (cons "d" dpi)))))
507 (insert (format "Calling `%s'...\n" cmdline)) 508 (insert (format "Calling `%s'...\n" cmdline))
508 (set-process-sentinel 509 (set-process-sentinel
509 (setq YaTeX-typeset-conv2image-process 510 (setq YaTeX-typeset-conv2image-process
510 (start-process 511 (start-process
511 command 512 command
583 ;;; ((< (YaTeX-elapsed-time tm (current-time)) thresh) nil) 584 ;;; ((< (YaTeX-elapsed-time tm (current-time)) thresh) nil)
584 ;; If condition changed from last call, do it 585 ;; If condition changed from last call, do it
585 ((not (string= st (YaTeX-buffer-substring s (overlay-end overlay)))) 586 ((not (string= st (YaTeX-buffer-substring s (overlay-end overlay))))
586 (YaTeX-typeset-environment))))) 587 (YaTeX-typeset-environment)))))
587 588
589
590 (defun YaTeX-typeset-environment-by-lmp ()
591 (save-excursion
592 (let ((sw (selected-window)))
593 (goto-char opoint)
594 (latex-math-preview-expression)
595 (select-window sw))))
596
597 (defun YaTeX-typeset-environment-by-builtin ()
598 (save-excursion
599 (YaTeX-typeset-region 'YaTeX-typeset-conv2image-chain)))
600
601 (defvar YaTeX-on-the-fly-math-preview-engine
602 (if (fboundp 'latex-math-preview-expression)
603 'YaTeX-typeset-environment-by-lmp
604 'YaTeX-typeset-environment-by-builtin)
605 "Function symbol to use math-preview.
606 'YaTeX-typeset-environment-by-lmp for using latex-math-preview,
607 'YaTeX-typeset-environment-by-builtin for using yatex-builtin.")
608
588 (defun YaTeX-typeset-environment-1 () 609 (defun YaTeX-typeset-environment-1 ()
589 (let ((math (YaTeX-in-math-mode-p)) usetimer) 610 (let*((math (YaTeX-in-math-mode-p))
611 (dpi (or (YaTeX-get-builtin "PREVIEWDPI") (if math "300" "200")))
612 (opoint (point)) usetimer)
590 (cond 613 (cond
591 ((and YaTeX-on-the-fly-overlay (overlayp YaTeX-on-the-fly-overlay) 614 ((and YaTeX-on-the-fly-overlay (overlayp YaTeX-on-the-fly-overlay)
592 (member YaTeX-on-the-fly-overlay (overlays-at (point)))) 615 (member YaTeX-on-the-fly-overlay (overlays-at (point))))
593 ;; If current position is in on-the-fly overlay, 616 ;; If current position is in on-the-fly overlay,
594 ;; use that region again 617 ;; use that region again
595 (setq math (get 'YaTeX-typeset-conv2image-chain 'math)) 618 (setq math (get 'YaTeX-typeset-conv2image-chain 'math))
596 (push-mark (overlay-start YaTeX-on-the-fly-overlay)) 619 (push-mark (overlay-start YaTeX-on-the-fly-overlay))
597 (goto-char (overlay-end YaTeX-on-the-fly-overlay))) 620 (goto-char (overlay-end YaTeX-on-the-fly-overlay)))
598 ((and (fboundp 'region-active-p) (region-active-p)) 621 ((YaTeX-region-active-p)
599 nil) ;if region is active, use it 622 nil) ;if region is active, use it
600 (math (setq usetimer t) (YaTeX-mark-environment)) 623 (math (setq usetimer t) (YaTeX-mark-environment))
601 ((equal (or (YaTeX-inner-environment t) "document") "document") 624 ((equal (or (YaTeX-inner-environment t) "document") "document")
602 (mark-paragraph)) 625 (mark-paragraph))
603 (t (setq usetimer t) (YaTeX-mark-environment))) 626 (t (setq usetimer t) (YaTeX-mark-environment)))
604 (if YaTeX-use-image-preview 627 (if YaTeX-use-image-preview
605 (let ((YaTeX-typeset-buffer (concat "*bg:" YaTeX-typeset-buffer)) 628 (let ((YaTeX-typeset-buffer (concat "*bg:" YaTeX-typeset-buffer))
606 (b (region-beginning)) (e (region-end))) 629 (b (region-beginning)) (e (region-end)))
607 (put 'YaTeX-typeset-conv2image-chain 'math math) 630 (put 'YaTeX-typeset-conv2image-chain 'math math)
631 (put 'YaTeX-typeset-conv2image-chain 'dpi dpi)
608 (put 'YaTeX-typeset-conv2image-chain 'srctype nil) 632 (put 'YaTeX-typeset-conv2image-chain 'srctype nil)
609 (put 'YaTeX-typeset-conv2image-chain 'win (selected-window)) 633 (put 'YaTeX-typeset-conv2image-chain 'win (selected-window))
610 (put 'YaTeX-typeset-conv2image-chain 'start (current-time)) 634 (put 'YaTeX-typeset-conv2image-chain 'start (current-time))
611 (put 'YaTeX-typeset-environment-timer 'laststate 635 (put 'YaTeX-typeset-environment-timer 'laststate
612 (list (current-buffer) b e (preceding-char) 636 (list (current-buffer) b e (preceding-char)
613 (char-after (- (point) 2)) 637 (char-after (- (point) 2))
614 (YaTeX-buffer-substring b e) 638 (YaTeX-buffer-substring b e)
615 (current-time))) 639 (current-time)))
616 (YaTeX-typeset-region 'YaTeX-typeset-conv2image-chain) 640 (if math (funcall YaTeX-on-the-fly-math-preview-engine)
641 (YaTeX-typeset-region 'YaTeX-typeset-conv2image-chain))
617 (if usetimer 642 (if usetimer
618 (progn 643 (progn
619 (if YaTeX-on-the-fly-overlay 644 (if YaTeX-on-the-fly-overlay
620 (move-overlay YaTeX-on-the-fly-overlay b e) 645 (move-overlay YaTeX-on-the-fly-overlay b e)
621 (overlay-put 646 (overlay-put

yatex.org