emacs/layers.personal/orgtools/local/org-tufte-theme/org-tufte-theme.el
2018-04-07 10:54:04 +08:00

98 lines
3.7 KiB
EmacsLisp

(defun org-tufte-get-theme (docinfo)
(let ((theme (cdr (assoc "THEME" docinfo))))
(cond
((string= "tufte-handout" theme) theme)
((string= "tufte-book" theme) theme)
(t ""))))
(defun org-tufte-have-toc (docinfo)
(let ((toc (assoc "TOC" docinfo)))
(if toc
(let ((toc-value (cdr toc)))
(if toc-value
(cond
((string= toc-value "no") nil)
((string= toc-value "NO") nil)
(t t))
t))
t)))
(defun org-tufte-gen-header (docinfo)
(concat "\\usepackage{etex}\n"
"\\reserveinserts{36}\n"
"\\usepackage[maxfloats=48]{morefloats}\n"
"\\usepackage[style=verbose-trad1, backend=bibtex]{biblatex}\n"
"\\addbibresource{local.bib}\n"
"\\usepackage{booktabs,graphicx,microtype,hyphenat,marginfix,amsmath}\n"
"\\geometry{paperheight=10.5in,paperwidth=8.5in,textwidth=4.375in}\n"
"\\titleformat{\\part}[display]{\\relax\\itshape\\huge}{}{0pt}{\\huge\\rmfamily\\itshape}[]\n"
"\\usepackage{xparse}\n"
"\\usepackage{xpatch}\n"
"\\makeatletter\n"
"\\xpatchcmd{\\@footnotetext}%\n"
" {\\color@begingroup}\n"
" {\\colomythemesr@begingroup\\toggletrue{blx@footnote}}\n"
" {}\n"
" {}\n"
"\\makeatother\n"
"\n"
"\\DeclareCiteCommand{\\sidecitehelper}\n"
" {\\usebibmacro{prenote}}\n"
" {\\usebibmacro{citeindex}%\n"
" \\usebibmacro{cite}}\n"
" {\\multicitedelim}\n"
" {\\usebibmacro{cite:postnote}}\n"
"\n"
"\\ExplSyntaxOn\n"
"\\NewDocumentCommand\\sidecite{D<>{}O{}om}{%\n"
" \\iftoggle{blx@footnote}\n"
" {\\cs_set_protected_nopar:Npn \\__sct_wrapper:nn ##1 ##2 {\\mkbibparens{##2}}}\n"
" {\\cs_set_protected_nopar:Npn \\__sct_wrapper:nn ##1 ##2 {\\sidenote[][##1]{##2}}}\n"
" {\\IfNoValueTF{#3}\n"
" {\\__sct_wrapper:nn{#1}{\\sidecitehelper[#2]{#4}}}\n"
" {\\__sct_wrapper:nn{#1}{\\sidecitehelper[#2][#3]{#4}}}}\n"
"}\n"
"\\ExplSyntaxOff\n"
"\n"))
(defun org-tufte-put-info (info docinfo)
(let ((theme (org-tufte-get-theme docinfo))
(toc (org-tufte-have-toc docinfo)))
(unless (string= "theme" "")
(plist-put info :latex-class theme))
(if toc
(plist-put info :latex-toc-command
"\\newpage\\tableofcontents")
(plist-put info :latex-toc-command
"\\relax"))
(plist-put info :latex-header
(concat (org-tufte-gen-header docinfo)
"\n"
(plist-get :latex-header docinfo))))
info)
;;;###autoload
(defun org-tufte-register-classes ()
(unless (assoc "tufte-handout" org-latex-classes)
(add-to-list 'org-latex-classes
'("tufte-handout"
"\\documentclass[nobib]{tufte-handout} "
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")))
(add-to-list 'org-latex-classes
'("tufte-book"
"\\documentclass[twoside,nobib]{tufte-book} "
("\\part{%s}" . "\\part*{%s}")
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")))))
;;;###autoload
(defun org-tufte-theme-latex-template (content info docinfo)
(org-tufte-register-classes)
(list (concat "\\newpage\n" content)
(org-tufte-put-info info docinfo)))
(provide 'org-tufte-theme)