2018-03-29 17:28:55 +00:00
|
|
|
;;; ox-moderncv.el --- LaTeX moderncv Back-End for Org Export Engine -*- lexical-binding: t; -*-
|
2018-03-29 15:32:39 +00:00
|
|
|
|
|
|
|
;; Copyright (C) 2018 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
;; Author: Oscar Najera <hi AT oscarnajera.com DOT com>
|
|
|
|
;; Keywords: org, wp, tex
|
|
|
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
;; any later version.
|
|
|
|
;;
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; This library implements a LaTeX moderncv back-end, derived from the
|
|
|
|
;; LaTeX one.
|
|
|
|
|
|
|
|
;;; Code:
|
2018-03-22 17:04:26 +00:00
|
|
|
(require 'cl-lib)
|
|
|
|
(require 'ox-latex)
|
2019-02-02 17:50:46 +00:00
|
|
|
(require 'org-cv-utils)
|
2018-03-22 17:04:26 +00:00
|
|
|
|
2018-03-29 15:32:39 +00:00
|
|
|
;; Install a default set-up for moderncv export.
|
2018-03-29 17:28:55 +00:00
|
|
|
(unless (assoc "moderncv" org-latex-classes)
|
2018-03-22 17:04:26 +00:00
|
|
|
(add-to-list 'org-latex-classes
|
2019-02-02 15:48:03 +00:00
|
|
|
'("moderncv"
|
2019-02-02 19:08:27 +00:00
|
|
|
"\\documentclass{moderncv}"
|
2019-02-02 15:48:03 +00:00
|
|
|
("\\section{%s}" . "\\section*{%s}")
|
|
|
|
("\\subsection{%s}" . "\\subsection*{%s}")
|
|
|
|
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
|
2018-03-22 17:04:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; 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-29 17:28:55 +00:00
|
|
|
(org-export-define-derived-backend 'moderncv 'latex
|
2018-03-22 23:40:15 +00:00
|
|
|
:options-alist
|
2018-03-29 23:39:07 +00:00
|
|
|
'((:latex-class "LATEX_CLASS" nil "moderncv" t)
|
2018-03-23 01:05:30 +00:00
|
|
|
(:cvstyle "CVSTYLE" nil "classic" t)
|
2023-10-27 13:49:29 +00:00
|
|
|
(:cvcolor "CVCOLOR" nil "blue" t)
|
2018-03-23 01:05:30 +00:00
|
|
|
(:mobile "MOBILE" nil nil parse)
|
2018-03-22 23:51:23 +00:00
|
|
|
(:homepage "HOMEPAGE" nil nil parse)
|
2018-03-23 01:04:36 +00:00
|
|
|
(:address "ADDRESS" nil nil newline)
|
2018-03-24 00:42:52 +00:00
|
|
|
(:photo "PHOTO" nil nil parse)
|
2018-03-22 23:51:23 +00:00
|
|
|
(:gitlab "GITLAB" nil nil parse)
|
|
|
|
(:github "GITHUB" nil nil parse)
|
|
|
|
(:linkedin "LINKEDIN" nil nil parse)
|
2018-03-24 00:42:52 +00:00
|
|
|
(:with-email nil "email" t t)
|
2018-03-22 23:51:23 +00:00
|
|
|
)
|
2018-03-29 15:32:39 +00:00
|
|
|
:translate-alist '((template . org-moderncv-template)
|
2019-02-02 15:48:03 +00:00
|
|
|
(headline . org-moderncv-headline)))
|
2018-03-29 15:32:39 +00:00
|
|
|
|
2018-03-23 01:04:36 +00:00
|
|
|
|
2018-03-22 23:09:40 +00:00
|
|
|
;;;; Template
|
|
|
|
;;
|
|
|
|
;; Template used is similar to the one used in `latex' back-end,
|
2018-03-29 15:32:39 +00:00
|
|
|
;; excepted for the table of contents and moderncv themes.
|
2018-03-22 23:09:40 +00:00
|
|
|
|
2018-03-29 15:32:39 +00:00
|
|
|
(defun org-moderncv-template (contents info)
|
2018-03-22 23:09:40 +00:00
|
|
|
"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))
|
2019-02-02 15:48:03 +00:00
|
|
|
(spec (org-latex--format-spec info)))
|
2018-03-22 23:09:40 +00:00
|
|
|
(concat
|
|
|
|
;; Time-stamp.
|
|
|
|
(and (plist-get info :time-stamp-file)
|
2019-02-02 15:48:03 +00:00
|
|
|
(format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
|
2018-03-22 23:09:40 +00:00
|
|
|
;; LaTeX compiler.
|
2018-03-24 00:56:58 +00:00
|
|
|
(org-latex--insert-compiler info)
|
2018-03-22 23:09:40 +00:00
|
|
|
;; Document class and packages.
|
|
|
|
(org-latex-make-preamble info)
|
2018-03-23 01:05:30 +00:00
|
|
|
;; cvstyle
|
|
|
|
(let ((cvstyle (org-export-data (plist-get info :cvstyle) info)))
|
|
|
|
(when cvstyle (format "\\moderncvstyle{%s}\n" cvstyle)))
|
|
|
|
;; cvcolor
|
|
|
|
(let ((cvcolor (org-export-data (plist-get info :cvcolor) info)))
|
2018-09-14 09:13:44 +00:00
|
|
|
(when (not (string-empty-p cvcolor)) (format "\\moderncvcolor{%s}\n" cvcolor)))
|
2018-03-22 23:09:40 +00:00
|
|
|
;; Possibly limit depth for headline numbering.
|
|
|
|
(let ((sec-num (plist-get info :section-numbers)))
|
|
|
|
(when (integerp sec-num)
|
2019-02-02 15:48:03 +00:00
|
|
|
(format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
|
2018-03-22 23:09:40 +00:00
|
|
|
;; Author.
|
|
|
|
(let ((author (and (plist-get info :with-author)
|
2019-02-02 15:48:03 +00:00
|
|
|
(let ((auth (plist-get info :author)))
|
|
|
|
(and auth (org-export-data auth info))))))
|
2018-03-22 23:09:40 +00:00
|
|
|
(format "\\name{%s}{}\n" author))
|
2018-03-24 00:42:52 +00:00
|
|
|
;; photo
|
|
|
|
(let ((photo (org-export-data (plist-get info :photo) info)))
|
2019-02-02 16:47:47 +00:00
|
|
|
(when (org-string-nw-p photo)
|
|
|
|
(format "\\photo{%s}\n" photo)))
|
2018-03-22 23:40:15 +00:00
|
|
|
;; email
|
2018-03-22 23:09:40 +00:00
|
|
|
(let ((email (and (plist-get info :with-email)
|
2019-02-02 15:48:03 +00:00
|
|
|
(org-export-data (plist-get info :email) info))))
|
2019-02-02 16:47:47 +00:00
|
|
|
(when (org-string-nw-p email)
|
|
|
|
(format "\\email{%s}\n" email)))
|
2018-03-22 23:40:15 +00:00
|
|
|
;; phone
|
|
|
|
(let ((mobile (org-export-data (plist-get info :mobile) info)))
|
2019-02-02 16:47:47 +00:00
|
|
|
(when (org-string-nw-p mobile)
|
|
|
|
(format "\\phone[mobile]{%s}\n" mobile)))
|
2018-03-22 23:40:15 +00:00
|
|
|
;; homepage
|
|
|
|
(let ((homepage (org-export-data (plist-get info :homepage) info)))
|
2019-02-02 16:47:47 +00:00
|
|
|
(when (org-string-nw-p homepage)
|
|
|
|
(format "\\homepage{%s}\n" homepage)))
|
2018-03-23 00:44:30 +00:00
|
|
|
;; address
|
|
|
|
(let ((address (org-export-data (plist-get info :address) info)))
|
2019-02-02 16:47:47 +00:00
|
|
|
(when (org-string-nw-p address)
|
|
|
|
(format "\\address%s\n" (mapconcat (lambda (line)
|
|
|
|
(format "{%s}" line))
|
|
|
|
(split-string address "\n") ""))))
|
2018-03-23 14:13:59 +00:00
|
|
|
(mapconcat (lambda (social-network)
|
2019-02-02 16:47:47 +00:00
|
|
|
(let ((network (org-export-data
|
|
|
|
(plist-get info (car social-network)) info)))
|
|
|
|
(when (org-string-nw-p network)
|
|
|
|
(format "\\social[%s]{%s}\n"
|
|
|
|
(nth 1 social-network) network))))
|
2019-02-02 15:48:03 +00:00
|
|
|
'((:github "github")
|
|
|
|
(:gitlab "gitlab")
|
|
|
|
(:linkedin "linkedin"))
|
|
|
|
"")
|
2018-03-23 14:13:59 +00:00
|
|
|
|
2018-03-22 23:09:40 +00:00
|
|
|
;; Date.
|
|
|
|
(let ((date (and (plist-get info :with-date) (org-export-get-date info))))
|
|
|
|
(format "\\date{%s}\n" (org-export-data date info)))
|
2018-03-22 23:40:15 +00:00
|
|
|
|
2018-03-22 23:09:40 +00:00
|
|
|
;; Title and subtitle.
|
|
|
|
(let* ((subtitle (plist-get info :subtitle))
|
2019-02-02 15:48:03 +00:00
|
|
|
(formatted-subtitle
|
|
|
|
(when subtitle
|
|
|
|
(format (plist-get info :latex-subtitle-format)
|
|
|
|
(org-export-data subtitle info))))
|
|
|
|
(separate (plist-get info :latex-subtitle-separate)))
|
2018-03-22 23:09:40 +00:00
|
|
|
(concat
|
2019-02-02 15:48:03 +00:00
|
|
|
(format "\\title{%s%s}\n" title
|
|
|
|
(if separate "" (or formatted-subtitle "")))
|
|
|
|
(when (and separate subtitle)
|
|
|
|
(concat formatted-subtitle "\n"))))
|
2018-03-22 23:09:40 +00:00
|
|
|
;; 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
|
2019-02-02 15:48:03 +00:00
|
|
|
(cond ((not (plist-get info :with-title)) nil)
|
|
|
|
((string= "" title) nil)
|
|
|
|
((not (stringp command)) nil)
|
|
|
|
((string-match "\\(?:[^%]\\|^\\)%s" command)
|
|
|
|
(format command title))
|
|
|
|
(t command))))
|
2018-03-22 23:09:40 +00:00
|
|
|
;; Document's body.
|
|
|
|
contents
|
|
|
|
;; Creator.
|
|
|
|
(and (plist-get info :with-creator)
|
2019-02-02 15:48:03 +00:00
|
|
|
(concat (plist-get info :creator) "\n"))
|
2018-03-22 23:09:40 +00:00
|
|
|
;; Document end.
|
|
|
|
"\\end{document}")))
|
2018-03-23 18:05:11 +00:00
|
|
|
|
2018-03-23 22:00:17 +00:00
|
|
|
|
2018-03-29 15:32:39 +00:00
|
|
|
(defun org-moderncv--format-cventry (headline contents info)
|
|
|
|
"Format HEADLINE as as cventry.
|
|
|
|
CONTENTS holds the contents of the headline. INFO is a plist used
|
|
|
|
as a communication channel."
|
2020-06-01 17:54:47 +00:00
|
|
|
(let* ((entry (org-cv-utils--parse-cventry headline info))
|
2018-09-14 09:17:06 +00:00
|
|
|
(note (or (org-element-property :NOTE headline) "")))
|
2023-10-21 22:53:19 +00:00
|
|
|
(format "\\cventry{%s}{%s}{%s}{%s}{%s}{%s}\n"
|
|
|
|
(alist-get 'date entry)
|
2020-06-01 17:54:47 +00:00
|
|
|
(alist-get 'title entry)
|
2023-10-21 22:53:19 +00:00
|
|
|
(alist-get 'host entry)
|
2020-06-01 17:54:47 +00:00
|
|
|
(alist-get 'location entry)
|
|
|
|
note contents)))
|
2018-03-23 18:05:11 +00:00
|
|
|
|
|
|
|
;;;; Headline
|
2018-03-29 15:32:39 +00:00
|
|
|
(defun org-moderncv-headline (headline contents info)
|
|
|
|
"Transcode HEADLINE element into moderncv code.
|
2018-03-23 18:05:11 +00:00
|
|
|
CONTENTS is the contents of the headline. INFO is a plist used
|
|
|
|
as a communication channel."
|
|
|
|
(unless (org-element-property :footnote-section-p headline)
|
2023-10-22 01:19:18 +00:00
|
|
|
(let ((environment (cons (org-element-property :CV_ENV headline)
|
|
|
|
(org-export-get-tags headline info))))
|
2018-03-23 22:06:31 +00:00
|
|
|
(cond
|
|
|
|
;; is a cv entry
|
2023-10-22 01:19:18 +00:00
|
|
|
((member "cventry" environment)
|
2018-03-29 15:32:39 +00:00
|
|
|
(org-moderncv--format-cventry headline contents info))
|
2018-03-23 23:19:49 +00:00
|
|
|
((org-export-with-backend 'latex headline contents info))))))
|
2018-03-29 15:32:39 +00:00
|
|
|
|
|
|
|
(provide 'ox-moderncv)
|
|
|
|
;;; ox-moderncv ends here
|