最終更新:2018-04-01 (日) 01:35:57 (110d)

xyzzy > KaTeX

KaTeX is an intelligent, acquisitive and integrated package which reduces your efforts of composing LaTeX source on xyzzy.

KaTeX (花鳥) は Emacs の LaTeX 統合支援環境である YaTeX を xyzzy に移植したもの



Download

xyzzy-ce06f32a83a7a1b696aafc27634228c8019102f0.zip を展開すると xyzzy-ce06f32a83a7a1b696aafc27634228c8019102f0\site-lisp\katex\ に KaTeX Version 1.67.1.12 ファイル一式が含まれている

Installing KaTeX

KaTeX Version 1.67.1.12 ファイル一式が含まれている katex フォルダーを %XYZZYHOME%\site-lisp\ (例えば %XYZZYHOME% を C:\xyzzy に設定している場合は C:\xyzzy\site-lisp\) にコピーする

Repository

Changelog

Settings

;;
;; KaTeX
;;
(push (merge-pathnames "site-lisp/katex" (si:system-root)) *load-path*)
(require "elisp")
(push '("\\.\\(tex\\|ltx\\|cls\\|sty\\|clo\\|bbl\\)$" . elisp::katex-mode) *auto-mode-alist*)
(autoload 'elisp::katex-mode "katex" t)
(setq elisp::KaTeX-inhibit-prefix-letter t)
(setq elisp::KaTeX-kanji-code nil)
(setq elisp::KaTeX-latex-message-code *encoding-utf8n*)
(setq elisp::KaTeX-use-AMS-LaTeX t)
(setq elisp::KaTeX-default-documentclass "bxjsarticle")
(setq elisp::tex-command "lualatex -synctex=1")
;(setq elisp::tex-command "luajitlatex -synctex=1")
;(setq elisp::tex-command "xelatex -synctex=1")
;(setq elisp::tex-command "pdflatex -synctex=1")
;(setq elisp::tex-command "platex-ng -synctex=1")
;(setq elisp::tex-command "ptex2pdf -u -l -ot \"-kanji=utf8 -no-guess-input-enc -synctex=1\"")
;(setq elisp::tex-command "latexmk")
;(setq elisp::tex-command "latexmk -e \"$lualatex=q/lualatex %O -synctex=1 %S/\" -e \"$bibtex=q/upbibtex %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -norc -gg -pdflua")
;(setq elisp::tex-command "latexmk -e \"$lualatex=q/luajitlatex %O -synctex=1 %S/\" -e \"$bibtex=q/upbibtex %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -norc -gg -pdflua")
;(setq elisp::tex-command "latexmk -e \"$xelatex=q/xelatex %O -synctex=1 %S/\" -e \"$bibtex=q/upbibtex %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -norc -gg -pdfxe")
;(setq elisp::tex-command "latexmk -e \"$pdflatex=q/pdflatex %O -synctex=1 %S/\" -e \"$bibtex=q/bibtex %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/makeindex %O -o %D %S/\" -norc -gg -pdf")
;(setq elisp::tex-command "latexmk -e \"$pdflatex=q/platex-ng %O -synctex=1 %S/\" -e \"$bibtex=q/upbibtex %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -norc -gg -pdf")
;(setq elisp::tex-command "latexmk -e \"$latex=q/uplatex %O -kanji=utf8 -no-guess-input-enc -synctex=1 %S/\" -e \"$bibtex=q/upbibtex %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -e \"$dvipdf=q/dvipdfmx %O -o %D %S/\" -norc -gg -pdfdvi")
;(setq elisp::tex-command "latexmk -e \"$latex=q/uplatex %O -kanji=utf8 -no-guess-input-enc -synctex=1 %S/\" -e \"$bibtex=q/upbibtex %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -e \"$dvips=q/dvips %O -z -f %S | convbkmk -u > %D/\" -e \"$ps2pdf=q/ps2pdf.exe %O %S %D/\" -norc -gg -pdfps")
(setq elisp::bibtex-command "latexmk -e \"$lualatex=q/lualatex %O -synctex=1 %S/\" -e \"$bibtex=q/upbibtex %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -norc -gg -pdflua")
(setq elisp::makeindex-command "latexmk -e \"$lualatex=q/lualatex %O -synctex=1 %S/\" -e \"$bibtex=q/upbibtex %O %B/\" -e \"$biber=q/biber %O --bblencoding=utf8 -u -U --output_safechars %B/\" -e \"$makeindex=q/upmendex %O -o %D %S/\" -norc -gg -pdflua")
(setq elisp::dvi2-command "rundll32 shell32,ShellExec_RunDLL SumatraPDF -reuse-instance")
;(setq elisp::dvi2-command "texworks")
;(setq elisp::dvi2-command "rundll32 shell32,ShellExec_RunDLL firefox -new-window")
;(setq elisp::dvi2-command "powershell -Command \"& {$p = [System.String]::Concat('\"\"\"',[System.IO.Path]::GetFullPath($args),'\"\"\"');Start-Process chrome -ArgumentList ('--new-window',$p)}\"")
(setq elisp::dviprint-command-format "powershell -Command \"& {$r = Write-Output %s;$p = [System.String]::Concat('\"\"\"',[System.IO.Path]::GetFileNameWithoutExtension($r),'.pdf','\"\"\"');Start-Process AcroRd32 -ArgumentList ($p)}\"")
(setq elisp::*KaTeX-use-toolbar* t)
(set-extended-key-translate-table exkey-M-return #\M-RET)

(defun user::katex-mode ()
  (interactive)
  (elisp::katex-mode))

(defun sumatrapdf-forward-search ()
  (interactive)
  (let* ((tex-file (get-buffer-file-name))
         (pdf-file (concat (el::KaTeX-get-preview-file-name) ".pdf"))
         (line (format nil "~D" (current-line-number)))
         (cmd "rundll32 shell32,ShellExec_RunDLL SumatraPDF")
         (args))
    (setq args (concat "-reuse-instance \"" pdf-file "\" -forward-search \"" tex-file "\" " line))
    (message (concat cmd " " args))
    (call-process (concat cmd " " args)
                  :exec-directory (directory-namestring tex-file))))

(add-hook 'elisp::katex-mode-hook
          #'(lambda ()
              (define-key elisp::*KaTeX-mode-map* '(#\C-c #\C-g) 'sumatrapdf-forward-search)))

(defun fwdsumatrapdf-forward-search ()
  (interactive)
  (let* ((tex-file (get-buffer-file-name))
         (pdf-file (concat (el::KaTeX-get-preview-file-name) ".pdf"))
         (line (format nil "~D" (current-line-number)))
         (cmd "fwdsumatrapdf")
         (args))
    (setq args (concat "\"" pdf-file "\" \"" tex-file "\" " line))
    (message (concat cmd " " args))
    (call-process (concat cmd " " args)
                  :exec-directory (directory-namestring tex-file))))

(add-hook 'elisp::katex-mode-hook
          #'(lambda ()
              (define-key elisp::*KaTeX-mode-map* '(#\C-c #\s) 'fwdsumatrapdf-forward-search)))

(add-hook 'elisp::katex-mode-hook
          #'(lambda ()
              (auto-fill-mode nil)))

(require "katex")
(require "katexlib")
(require "katexprc")

(defun elisp::KaTeX-preview (preview-command preview-file)
  "Execute xdvi (or other) to tex-preview."
  (interactive
      (list
       (elisp::read-string-with-history
	"Preview command: "
	(or (elisp::KaTeX-get-builtin "PREVIEW") elisp::dvi2-command)
	'elisp::KaTeX-preview-command-history)
       (elisp::read-string-with-history
	;"Preview file[.dvi]: "
	"Preview file: "
	(if (get 'dvi2-command 'region)
	    (substring KaTeX-texput-file
		       0 (rindex KaTeX-texput-file #\.))
	  (elisp::KaTeX-get-preview-file-name))
	'elisp::KaTeX-preview-file-history)))
  (setq dvi2-command preview-command)	;`dvi2command' is buffer local
  ;(unless (string-matchp "\.dvi$" preview-file)
  ;    (setq preview-file (concat preview-file ".dvi")))
  (if (string-matchp "dviout" elisp::dvi2-command)
      (setq preview-file (concat preview-file ".dvi"))
    (setq preview-file (concat preview-file ".pdf")))
  (cond
   ((file-exist-p preview-file)  ;m.m
    (save-excursion
      (elisp::KaTeX-visit-main t)
      (let ((pbuffer "*dvi-preview*") (dir default-directory))
;;;          (KaTeX-showup-buffer                     ;-> m.m
;;;            pbuffer (function (lambda (x) (nth 3 (window-edges x)))))
;;;	(set-buffer (get-buffer-create pbuffer))
;;;	(erase-buffer)
	(make-local-variable 'need-not-save)
	(setq need-not-save t) ;m.m <-
	(setq default-directory dir)	;for 18
	(cd dir)				;for 19
	(setq preview-command (concat preview-command " " preview-file))
	(when elisp::*typeset-with-shell-command*
	  (setq preview-command (concat *shell* " " KaTeX-shell-command-option
					" " preview-command)))
        (editor::call-process preview-command :no-std-handles t :show :show)
	(message
	 (concat "Starting " preview-command
		 " to preview " preview-file))
	(refresh-screen) ;m.m (redraw-display)
	)))
   (elisp::*preview-with-typeset*  ;m.m ->
    (setq *typeset-and-preview* t
	  *last-preview-command* preview-command
	  *last-preview-file* preview-file)
    (KaTeX-typeset-buffer))
   (t
    nil)))

(defun elisp::KaTeX-typeset (command buffer &optional prcname modename)
  "Execute jlatex (or other) to LaTeX typeset."
  (interactive)
  (save-excursion
    (let ((p (point)) (window (selected-window)) execdir (cb (elisp::current-buffer))
	  (map elisp::KaTeX-typesetting-mode-map)
	  (outcode
	   (cond ((eq buffer-mode 'katex-mode) KaTeX-coding-system)
		 ((eq buffer-mode 'yahtml-mode) yahtml-kanji-code))))
      (if (and elisp::KaTeX-typeset-process
	       (eq (process-status elisp::KaTeX-typeset-process) 'run))
	  ;; if tex command is halting.
	(KaTeX-kill-typeset-process elisp::KaTeX-typeset-process))
      (elisp::KaTeX-put-nonstopmode)
      (setq prcname (or prcname "LaTeX")
	    modename (or modename "typeset"))
      (if (eq buffer-mode 'katex-mode) (KaTeX-visit-main t)) ;;execution dir
      (setq execdir default-directory)
      ;;Select lower-most window if there are more than 2 windows and
      ;;typeset buffer not seen.
      (elisp::KaTeX-showup-buffer
       buffer (function (lambda (x) (nth 3 (window-edges x)))) t) ;m.m
;;;    (elisp::KaTeX-showup-buffer
;;;     buffer (function (lambda (x) (nth 3 (window-edges x)))))
      (set-buffer (get-buffer-create buffer))
      (setq default-directory execdir)
      (cd execdir)
      (elisp::erase-buffer)
      (make-local-variable 'need-not-save) ;m.m
      (setq need-not-save t) ;m.m
      (when elisp::*typeset-with-shell-command*
	(setq command (concat *shell* " " KaTeX-shell-command-option " " command)))
      (setq elisp::KaTeX-typeset-process ; *shell* " " KaTeX-shell-command-option " "
	    (make-process command
;			  :output buffer :outcode elisp::KaTeX-latex-message-code))
			  :output buffer :incode elisp::KaTeX-latex-message-code :outcode elisp::KaTeX-latex-message-code))
      (set-process-sentinel elisp::KaTeX-typeset-process 'KaTeX-typeset-sentinel)
      (set-process-filter elisp::KaTeX-typeset-process 'elisp::KaTeX-typeset-process-filter)
      (message "Calling `~A'..." command)
      (setq KaTeX-current-TeX-buffer (elisp::buffer-name))
      (elisp::use-local-map map)		;map may be localized
      (elisp::set-syntax-table elisp::KaTeX-typeset-buffer-syntax)
      (setq mode-name modename)
      (set-marker (elisp::process-mark elisp::KaTeX-typeset-process) (1- (point)))
      (if (bolp) (forward-line -1))	;what for?
      (elisp::select-window (get-buffer-window buffer))
;;;   (if (and KaTeX-emacs-19 window-system) ;m.m ->
;;;     (let ((win (get-buffer-window buffer t)) owin)
;;;	    (select-frame (window-frame win))
;;;	    (setq owin (selected-window))
;;;	    (elisp::select-window win)
;;;	    (goto-char (point-max))
;;;	    (recenter -1)
;;;	    (elisp::select-window owin))
;;;	(progn
;;;	  (elisp::select-window (get-buffer-window buffer))
;;;	  (goto-char (point-max))
;;;	  (recenter -1))) ;m.m <-
      ;(message "Done.")
      (set-buffer-modified-p nil)
      (elisp::select-window window)
      (switch-to-buffer cb)
      (elisp::KaTeX-remove-nonstopmode))))

Usage

Typeset
C-c C-t j
BibTeX
C-c C-t b RET
MakeIndex
C-c C-t i RET
Preview
C-c C-t p RET RET
Print
C-c C-t l RET
Forward search
C-c C-g