임의의 모드에서 TeX 공식을 인라인으로 미리 보려면 어떻게해야합니까?


14

AUCTeX 또는 org-mode 이외의 모드에서 TeX 미리보기를 얻으려면 어떻게해야합니까? jabber, erc 및 markdown에서 TeX 방정식을보고 싶습니다. 이메일을 위해 Emacs로 전환 한 경우 미리보기를보고 싶을 것입니다.


1
나는 이것을 시도하지는 않았지만 mmm-mode버퍼에서 여러 주요 모드를 허용하는 것을보고 싶을 수도있다.
Vamsi

답변:


10

AUCTeX preview-latex 를 재사용하려고 했지만 실패하고 포기했습니다.

조직 모드도 동일한 기능을 제공합니다 . 턴 아웃 weechat 다시 사용 관리가 자동으로 미리보기 라텍스 표시합니다.

나는 이 repo에서 얻을 수있는 별도의 파일로 weechat에서 미리보기 부분을 추출했습니다 . pxMELPA 의 패키지 로도 제공됩니다 (방금 제출했습니다).

대화식으로 호출 할 수있는 4 개의 진입 점이 있습니다.

  • px-preview: 현재 버퍼에서 모든 라텍스 조각을 렌더링합니다.
  • px-preview-region: 영역에서 조각을 렌더링합니다.
  • px-remove: 현재 버퍼에서 모든 미리보기를 제거합니다 (텍스트 복원).
  • px-toggle: 현재 버퍼에서 미리보기 표시를 토글합니다.

org-mode previewer가 작동하는 한이 것이 좋습니다.

코드는 여전히 작기 때문에 아래에 포함시킬 것이지만 패키지를 설치하거나 저장소를 사용하십시오.

;;; px.el --- preview inline latex -*- lexical-binding: t -*-

;; Most of this code comes from weechat-latex.el which in turn uses
;; org-mode previewer.

;; Copyright (C) 2014 Aurélien Aptel <aurelien.aptel@gmail.com>
;; Copyright (C) 2013 Rüdiger Sonderfeld <ruediger@c-plusplus.de>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

(require 'org)

(defvar px-temp-file-prefix "px-"
  "Prefix for temporary files.")

(defvar px-temp-directory-prefix "px-"
  "Prefix for temporary directory.")

(defvar px-image-program org-latex-create-formula-image-program
  "Program to convert LaTeX fragments.
See `org-latex-create-formula-image-program'")

(defvar px-temp-dir nil
  "The temporary directory used for preview images.")

(defun px--create-preview (at)
  "Wrapper for `org-format-latex'.
The parameter AT should be nil or in (TYPE . POINT) format.  With TYPE being a
string showing the matched LaTeX statement (e.g., ``$'') and POINT being the
POINT to replace.  If AT is nil replace statements everywhere."
  (org-format-latex px-temp-file-prefix
                    px-temp-dir
                    'overlays
                    "Creating images...%s"
                    at 'forbuffer
                    px-image-program))

(defun px--set-temp-dir ()
  "Set `px-temp-dir' unless it is already set."
  (unless px-temp-dir
    (setq px-temp-dir
          (make-temp-file px-temp-directory-prefix
                          'directory))))

(defun px-preview ()
  "Preview LaTeX fragments."
  (interactive)
  (save-excursion
    (let ((inhibit-read-only t))
      (px--set-temp-dir)
      (org-remove-latex-fragment-image-overlays)
      (px--create-preview nil))))

(defun px-preview-region (beg end)
  "Preview LaTeX fragments in region."
  (interactive "r")
  (let* ((math-regex (assoc "$" org-latex-regexps))
         (regex (nth 1 math-regex))
         (n (nth 2 math-regex))
         matches)
    (save-excursion
      (goto-char beg)
      (while (re-search-forward regex end t)
        (setq matches (cons (cons "$" (match-beginning n)) matches)))
      (let ((inhibit-read-only t))
        (px--set-temp-dir)
        (dolist (i matches)
          (px--create-preview i))))))


(defun px-remove ()
  "Remove LaTeX preview images."
  (interactive)
  (let ((inhibit-read-only t))
    (org-remove-latex-fragment-image-overlays)))

(defun px-is-active? ()
  "Are LaTeX Previews currently displayed?"
  org-latex-fragment-image-overlays)

(defun px-toggle ()
  "Toggle display of LaTeX preview."
  (interactive)
  (if (px-is-active?)
      (px-remove)
    (px-preview)))


(provide 'px)

0

texfrag.eldoxygen 주석에 대한 기본 기능도 prog-mode있습니다.

texfrag.elmelpa-stable통해 설치할 수 있습니다 M-x package-install RET texfrag RET.

M-x texfrag-mode RET미리보기를 활성화하려면 실행하십시오 . AUCTeX 미리보기 패키지의 모든 항목이 포함 된 미리보기 메뉴가 나타납니다.

texfraghtml 소스, eww 및 org 모드를 편집 할 때도 작동합니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.