平衡点


2022/02/18

_ =ox-beamer= の拡張[Emacs

ox-beamer をちょっと拡張して \institute なんかを使える様にしてみた. 元の関数の深い所を advice で書き換えることを試みるも上手くできなかったので まるっとコピーして処理を追加したり.

(leaf ox-beamer
  :after ox-latex
  :init
  (add-to-list 'org-export-options-alist
               '(:shortdate     "SHORT_DATE"       nil nil))
  (add-to-list 'org-export-options-alist
               '(:shorttitle    "SHORT_TITLE"      nil nil))
  (add-to-list 'org-export-options-alist
               '(:shortauthor   "SHORT_AUTHOR"     nil nil))
  (add-to-list 'org-export-options-alist
               '(:institute      "INSTITUTE"       nil nil))
  (add-to-list 'org-export-options-alist
               '(:shortinstitute "SHORT_INSTITUTE" nil nil))
  (add-to-list 'org-latex-classes
               '("my:beamer"
                 "\\RequirePackage{plautopatch}\n\\documentclass[dvipdfmx,presentation]{beamer}
             [NO-DEFAULT-PACKAGES] [NO-PACKAGES] [EXTRA]"
                 ("\\section\{%s\}" . "\\section*\{%s\}")
                 ("\\subsection\{%s\}" . "\\subsection*\{%s\}")
                 ("\\subsubsection\{%s\}" . "\\subsubsection*\{%s\}")))
  ;; customize
  (defun my:org-beamer-template (contents info)
    "Custom: support shortdate, shorttile, shortauthor, institute for beamer export"
    (let ((title (org-export-data (plist-get info :title) info))
	      (subtitle (org-export-data (plist-get info :subtitle) info)))
      (concat
       ;; Time-stamp.
       (and (plist-get info :time-stamp-file)
	        (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
       ;; LaTeX compiler
       (org-latex--insert-compiler info)
       ;; Document class and packages.
       (org-latex-make-preamble info)
       ;; Insert themes.
       (let ((format-theme
	          (lambda (prop command)
	            (let ((theme (plist-get info prop)))
		          (when theme
		            (concat command
			                (if (not (string-match "\\[.*\\]" theme))
			                    (format "{%s}\n" theme)
			                  (format "%s{%s}\n"
				                      (match-string 0 theme)
				                      (org-trim
				                       (replace-match "" nil nil theme))))))))))
         (mapconcat (lambda (args) (apply format-theme args))
		            '((:beamer-theme "\\usetheme")
		              (:beamer-color-theme "\\usecolortheme")
		              (:beamer-font-theme "\\usefonttheme")
		              (:beamer-inner-theme "\\useinnertheme")
		              (:beamer-outer-theme "\\useoutertheme"))
		            ""))
       ;; Possibly limit depth for headline numbering.
       (let ((sec-num (plist-get info :section-numbers)))
         (when (integerp sec-num)
	       (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
       ;; Author.
       (let ((author (and (plist-get info :with-author)
			              (let ((auth (plist-get info :author)))
			                (and auth (org-export-data auth info)))))
             (shortauthor (plist-get info :shortauthor))
	         (email (and (plist-get info :with-email)
		                 (org-export-data (plist-get info :email) info))))
         (cond ((and author shortauthor) (format "\\author[%s]{%s}\n" shortauthor author))
               ((and author shortauthor email (not (string= "" email)))
                (format "\\author[%s]{%s\\thanks{%s}}\n" shortauthor author email))
               ((and author email (not (string= "" email)))
	            (format "\\author{%s\\thanks{%s}}\n" author email))
	           ((or author email) (format "\\author{%s}\n" (or author email)))))
       ;; Date.
       (let ((date (and (plist-get info :with-date) (org-export-get-date info)))
             (shortdate (plist-get info :shortdate)))
         (cond ((and date shortdate)
                (format "\\date[%s]{%s}\n" shortdate (org-export-data date info)))
               (t (format "\\date{%s}\n" (org-export-data date info)))))
       ;; Title
       (let ((shorttitle (plist-get info :shorttitle)))
         (cond ((and title shorttitle) (format "\\title[%s]{%s}\n" shorttitle title))
               (t (format "\\title{%s}\n" title))))
       ;; institute
       (let ((institute (plist-get info :institute))
             (shortinstitute (plist-get info :shortinstitute)))
         (cond ((and institute shortinstitute)
                (format "\\institute[%s]{%s}\n" shortinstitute institute))
               ((or institute shortinstitute)
                (format "\\institute{%s}\n" (or shortinstitute institute)))))
       (when (org-string-nw-p subtitle)
         (concat (format (plist-get info :beamer-subtitle-format) subtitle) "\n"))
       ;; Beamer-header
       (let ((beamer-header (plist-get info :beamer-header)))
         (when beamer-header
	       (format "%s\n" (plist-get info :beamer-header))))
       ;; 9. Hyperref options.
       (let ((template (plist-get info :latex-hyperref-template)))
         (and (stringp template)
	          (format-spec template (org-latex--format-spec info))))
       ;; Document start.
       "\\begin{document}\n\n"
       ;; Title command.
       (org-element-normalize-string
        (cond ((not (plist-get info :with-title)) nil)
	          ((string= "" title) nil)
	          ((not (stringp org-latex-title-command)) nil)
	          ((string-match "\\(?:[^%]\\|^\\)%s"
			                 org-latex-title-command)
	           (format org-latex-title-command title))
	          (t org-latex-title-command)))
       ;; Table of contents.
       (let ((depth (plist-get info :with-toc)))
         (when depth
	       (concat
	        (format "\\begin{frame}%s{%s}\n"
		            (org-beamer--normalize-argument
		             (plist-get info :beamer-outline-frame-options) 'option)
		            (plist-get info :beamer-outline-frame-title))
	        (when (wholenump depth)
	          (format "\\setcounter{tocdepth}{%d}\n" depth))
	        "\\tableofcontents\n"
	        "\\end{frame}\n\n")))
       ;; Document's body.
       contents
       ;; Creator.
       (if (plist-get info :with-creator)
	       (concat (plist-get info :creator) "\n")
         "")
       ;; Document end.
       "\\end{document}")))
  ;;
  :advice ((:override org-beamer-template
                      my:org-beamer-template))
  :custom
  `((org-beamer-frame-level . 2)
    (org-beamer-frame-default-options . "fragile,squeeze,c")
    (org-latex-compiler . "latexmk -pvc")
    )
  )

いまいちカッコ良くないけれど

#+AUTHOR: 担当: 佐々木洋平
#+SHORT_AUTHOR: 佐々木
#+STARTUP: overview beamer
#+INSTITUTE: 正式な所属の長い表示
#+SHORT_INSTITUTE: 短いやつ.
#+DATE: 2022年 2 月 18日(金) 17:00 〜
#+SHORT_DATE: 2022/02/18
#+LATEX_CLASS: beamer

なんて書いておくと, beamer に export した時に

\author[佐々木]{担当: 佐々木洋平}
\institute[短いやつ.]{正式な所属の長い表示}
\date[2022/02/18]{2022年 2 月 18日(金) 17:00 〜}

となる.


2026/02/18

_ AUCTeX と latexmk の連携(2026年版)[Computer] [Emacs

昔の話は以下

最近は typeset のコマンド調整などは latexmk に処理を任せてしまい, AUCTeXは編集補助にしか使っていなかったのだけれど, Emacs から latexmk を走らせても良いよね, という気分になったので.

AUCTeX の本体の方では以下のコミットで LaTeXMk のサポートが入った模様

しかしながら, Debian パッケージ版はちょっと古いので, じたばたと.

最終的には, 以下の様な感じで.

(leaf auctex
  :if (and (executable-find "uplatex")
           (executable-find "latexmk"))
  :preface
  ;; -------------------------------------------------------------------------
  ;; Debian パッケージを利用するための調整
  (add-to-list 'my:package-menu-exclude-packages "auctex")
  (if (and (not (featurep 'text-site))
           (file-directory-p "/usr/share/auctex"))
      (progn
        (add-to-list 'load-path "/usr/share/auctex")
        (add-to-list 'load-path "/usr/share/emacs/site-lisp/auctex")))
  ;; -------------------------------------------------------------------------
  (unless (file-directory-p (expand-file-name "auctex/auto" my:d:tmp))
    (make-directory (expand-file-name "auctex/auto" my:d:tmp) t)
    (make-directory (expand-file-name "auctex/style" my:d:tmp) t))
  ;; -------------------------------------------------------------------------
  :mode  ("\\.tex\\'" . japanese-latex-mode)
  ;; -------------------------------------------------------------------------
  :hook
  ((emacs-startup-hook . (lambda ()
                           (load "auctex.el" nil t)
                           ;; (load "preview-latex.el" nil t)
                           ))
   (LaTeX-mode-hook    . (lambda ()
                           (add-to-list 'TeX-expand-list
                                        '("%(-PDF)"
                                          (lambda ()
                                            (if TeX-PDF-mode
                                                (cond
                                                 ((eq TeX-engine 'default) "-pdf")
                                                 ((eq TeX-engine 'uptex)   "-pdfdvi")
                                                 ((eq TeX-engine 'ptex)    "-pdfdvi")
                                                 ((eq TeX-engine 'xetex)   "-pdfxe")
                                                 ((eq TeX-engine 'luatex)  "-pdflua")) ""))))
                           (add-to-list 'TeX-command-list
                                        '("LaTeXmk" "latexmk %(-PDF) -pvc  %(output-dir) %t"
                                          TeX-run-format nil (latex-mode doctex-mode) :help "Run Latexmk"))
                           (setq TeX-command-output-list
                                 '(("LaTeXmk" ("pdf"))))
                           (setq TeX-command-default "LaTeXmk")
                           (eglot-ensure)
                           (turn-on-reftex)
                           (TeX-source-correlate-mode)
                           (TeX-PDF-mode)
                           (LaTeX-math-mode)
                           ))
   )
  :init
  ;; -------------------------------------------------------------------------
  ;; 基本設定
  (setq TeX-auto-local (expand-file-name "auctex/auto" my:d:tmp)
        TeX-style-local (expand-file-name "auctex/style" my:d:tmp)
        TeX-auto-untabify t
        TeX-engine 'uptex
        TeX-source-correlate-method 'synctex
        TeX-source-correlate-start-server t
        TeX-source-correlate-mode t
        TeX-ispell-extend-skip-list t
        TeX-electric-sub-and-superscript t
        ;; -------------------------------------------------------------------
        LaTeX-math-mode t
        LaTeX-figure-label "fig:"
        LaTeX-table-label "tab:"
        LaTeX-section-label "sec:"
        ;; -------------------------------------------------------------------
        reftex-plug-into-AUCTeX t
        reftex-cite-prompt-optional-args t
        ;; -------------------------------------------------------------------
        font-latex-fontify-script nil
        font-latex-script-display nil
        font-latex-fontify-sectioning  1.0
        ;; -------------------------------------------------------------------
        ;; TeX-auto-save t
        ;; TeX-parse-self t
        ;; TeX-master nil
        )
  )

ちなみにこれだと Emacs の裏でずっと latexmk が走り続けるので, どこかのタイミングでプロセスを止めなきゃだめなんだが, どうすっかなぁ.

あと TeX-command-listTeX-expand-listdefcustom な変数のハズなのに, tex ファイルを開くと, 設定が全て無視されて初期値に戻る. これはいったいどういう処理なんだろうか…


連絡先など

portrait

最近の日記

一覧

Back to Top ▲