平衡点


2022/02/18

_ ox-beamer の拡張

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 〜}

となる.


連絡先など
最近の日記
一覧
2006|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|02|03|04|08|09|10|11|12|
2013|01|02|03|04|05|06|08|09|10|11|12|
2014|01|02|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|09|10|
2016|02|03|
2017|01|02|03|05|06|07|09|11|12|
2018|03|06|07|10|11|12|
2019|01|02|03|04|05|07|10|12|
2020|01|02|03|04|05|08|09|10|11|12|
2021|01|02|03|05|06|07|08|09|11|12|
2022|01|02|03|04|05|06|08|10|11|12|
2023|02|03|04|06|08|09|11|12|
2024|01|02|03|
Back to Top ▲