2018-03-22 17:04:26 +00:00
|
|
|
(require 'cl-lib)
|
|
|
|
(require 'ox-latex)
|
|
|
|
|
|
|
|
;; Install a default set-up for Beamer export.
|
|
|
|
(unless (assoc "orgcv" org-latex-classes)
|
|
|
|
(add-to-list 'org-latex-classes
|
|
|
|
'("orgcv"
|
|
|
|
"\\documentclass{moderncv}"
|
|
|
|
("\\section{%s}" . "\\section*{%s}")
|
|
|
|
("\\subsection{%s}" . "\\subsection*{%s}")
|
|
|
|
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; User-Configurable Variables
|
|
|
|
|
|
|
|
(defgroup org-export-cv nil
|
|
|
|
"Options specific for using the moderncv class in LaTeX export."
|
|
|
|
:tag "Org moderncv"
|
|
|
|
:group 'org-export
|
|
|
|
:version "25.3")
|
2018-03-22 17:23:22 +00:00
|
|
|
|
|
|
|
;;; Define Back-End
|
2018-03-22 23:09:40 +00:00
|
|
|
(org-export-define-derived-backend 'orgcv 'latex
|
|
|
|
:translate-alist '((template . org-cv-template)))
|
|
|
|
|
|
|
|
;;;; Template
|
|
|
|
;;
|
|
|
|
;; Template used is similar to the one used in `latex' back-end,
|
|
|
|
;; excepted for the table of contents and Beamer themes.
|
|
|
|
|
|
|
|
(defun org-cv-template (contents info)
|
|
|
|
"Return complete document string after LaTeX conversion.
|
|
|
|
CONTENTS is the transcoded contents string. INFO is a plist
|
|
|
|
holding export options."
|
|
|
|
(let ((title (org-export-data (plist-get info :title) info))
|
|
|
|
(spec (org-latex--format-spec 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)
|
|
|
|
;; 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))))))
|
|
|
|
(format "\\name{%s}{}\n" author))
|
|
|
|
(let ((email (and (plist-get info :with-email)
|
|
|
|
(org-export-data (plist-get info :email) info))))
|
|
|
|
(when email (format "\\email{%s}\n" email)))
|
|
|
|
;; Date.
|
|
|
|
(let ((date (and (plist-get info :with-date) (org-export-get-date info))))
|
|
|
|
(format "\\date{%s}\n" (org-export-data date info)))
|
|
|
|
;; Title and subtitle.
|
|
|
|
(let* ((subtitle (plist-get info :subtitle))
|
|
|
|
(formatted-subtitle
|
|
|
|
(when subtitle
|
|
|
|
(format (plist-get info :latex-subtitle-format)
|
|
|
|
(org-export-data subtitle info))))
|
|
|
|
(separate (plist-get info :latex-subtitle-separate)))
|
|
|
|
(concat
|
|
|
|
(format "\\title{%s%s}\n" title
|
|
|
|
(if separate "" (or formatted-subtitle "")))
|
|
|
|
(when (and separate subtitle)
|
|
|
|
(concat formatted-subtitle "\n"))))
|
|
|
|
;; Hyperref options.
|
|
|
|
(let ((template (plist-get info :latex-hyperref-template)))
|
|
|
|
(and (stringp template)
|
|
|
|
(format-spec template spec)))
|
|
|
|
;; Document start.
|
|
|
|
"\\begin{document}\n\n"
|
|
|
|
;; Title command.
|
|
|
|
(let* ((title-command (plist-get info :latex-title-command))
|
|
|
|
(command (and (stringp title-command)
|
|
|
|
(format-spec title-command spec))))
|
|
|
|
(org-element-normalize-string
|
|
|
|
(cond ((not (plist-get info :with-title)) nil)
|
|
|
|
((string= "" title) nil)
|
|
|
|
((not (stringp command)) nil)
|
|
|
|
((string-match "\\(?:[^%]\\|^\\)%s" command)
|
|
|
|
(format command title))
|
|
|
|
(t command))))
|
|
|
|
;; Table of contents.
|
|
|
|
(let ((depth (plist-get info :with-toc)))
|
|
|
|
(when depth
|
|
|
|
(concat (when (integerp depth)
|
|
|
|
(format "\\setcounter{tocdepth}{%d}\n" depth))
|
|
|
|
(plist-get info :latex-toc-command))))
|
|
|
|
;; Document's body.
|
|
|
|
contents
|
|
|
|
;; Creator.
|
|
|
|
(and (plist-get info :with-creator)
|
|
|
|
(concat (plist-get info :creator) "\n"))
|
|
|
|
;; Document end.
|
|
|
|
"\\end{document}")))
|