ox-latex: Format-spec for hyperref and title

* ox-latex.el (org-latex--format-spec): New function with format-specs.
  (org-latex-template): Use org-latex--format-spec.
  (org-latex-hyperref-template): New defaults and use
  org-latex--format-spec.
  (org-latex-title-command): Use org-latex--format-spec.
* ORG-NEWS: Mention change.
This commit is contained in:
Rasmus 2015-02-11 02:18:09 +01:00
parent 14a9510ce1
commit 438d75c59d
2 changed files with 70 additions and 17 deletions

View File

@ -233,6 +233,9 @@ Exact heading search for links now ignore spaces and cookies. This is
the case for links of the form ~file:projects.org::*task title~, as the case for links of the form ~file:projects.org::*task title~, as
well as links of the form ~file:projects.org::some words~ well as links of the form ~file:projects.org::some words~
when ~org-link-search-must-match-exact-headline~ is not nil. when ~org-link-search-must-match-exact-headline~ is not nil.
*** ~org-latex-hyperref-template~, ~org-latex-title-command~ formatting
New formatting keys are supported. See the respective docstrings.
Note, ~org-latex-hyperref-template~ has a new default value.
* Version 8.2 * Version 8.2
** Incompatible changes ** Incompatible changes

View File

@ -383,11 +383,25 @@ are written as utf8 files."
(defcustom org-latex-title-command "\\maketitle" (defcustom org-latex-title-command "\\maketitle"
"The command used to insert the title just after \\begin{document}. "The command used to insert the title just after \\begin{document}.
If this string contains the formatting specification \"%s\" then
it will be used as a formatting string, passing the title as an This format string may contain these elements:
argument."
%a for AUTHOR keyword
%t for TITLE keyword
%k for KEYWORDS line
%d for DESCRIPTION line
%c for CREATOR line
%l for Language keyword
%L for capitalized language keyword
%D for DATE keyword
If you need to use a \"%\" character, you need to escape it
like that: \"%%\".
Setting :latex-title-command in publishing projects will take
precedence over this variable."
:group 'org-export-latex :group 'org-export-latex
:type 'string) :type '(string :tag "Format string"))
(defcustom org-latex-toc-command "\\tableofcontents\n\n" (defcustom org-latex-toc-command "\\tableofcontents\n\n"
"LaTeX command to set the table of contents, list of figures, etc. "LaTeX command to set the table of contents, list of figures, etc.
@ -397,20 +411,30 @@ the toc:nil option, not to those generated with #+TOC keyword."
:type 'string) :type 'string)
(defcustom org-latex-hyperref-template (defcustom org-latex-hyperref-template
"\\hypersetup{\n pdfkeywords={%k},\n pdfsubject={%d},\n pdfcreator={%c}}\n" "\\hypersetup{\n pdfauthor={%a},\n pdftitle={%t},\n pdfkeywords={%k},
pdfsubject={%d},\n pdfcreator={%c}, \n pdflang={%L}}\n"
"Template for hyperref package options. "Template for hyperref package options.
Value is a format string, which can contain the following placeholders: This format string may contain these elements:
%a for AUTHOR keyword
%t for TITLE keyword
%k for KEYWORDS line %k for KEYWORDS line
%d for DESCRIPTION line %d for DESCRIPTION line
%c for CREATOR line %c for CREATOR line
%l for Language keyword
%L for capitalized language keyword
%D for DATE keyword
Set it to the empty string to ignore the command completely." If you need to use a \"%\" character, you need to escape it
like that: \"%%\".
Setting :latex-hyperref-template in publishing projects will take
precedence over this variable."
:group 'org-export-latex :group 'org-export-latex
:version "25.1" :version "25.1"
:package-version '(Org . "8.3") :package-version '(Org . "8.3")
:type 'string) :type '(string :tag "Format string"))
;;;; Headline ;;;; Headline
@ -1193,6 +1217,33 @@ just outside of it."
INFO is a plist used as a communication channel." INFO is a plist used as a communication channel."
(org-export-translate s :latex info)) (org-export-translate s :latex info))
(defun org-latex--format-spec (info)
"Create a format-spec for document meta-data.
INFO is a plist used as a communication channel."
(let ((objects '(bold code entity export-snippet inline-babel-call
inline-src-block italic latex-fragment
latex-math-block link macro strike-through
subscript superscript timestamp underline
verbatim))
(language (let ((lang (plist-get info :language)))
(or (cdr (assoc lang org-latex-babel-language-alist))
lang ""))))
`((?a . ,(or (org-export-data (plist-get info :author) info) ""))
(?t . ,(or (org-export-data (plist-get info :title) info) ""))
(?k . ,(org-export-data (org-latex--wrap-latex-math-block
(org-element-parse-secondary-string
(plist-get info :keywords) objects)
info)
info))
(?d . ,(org-export-data (org-latex--wrap-latex-math-block
(org-element-parse-secondary-string
(plist-get info :description) objects)
info)
info))
(?c . ,(if (plist-get info :with-creator) (plist-get info :creator) ""))
(?l . ,language)
(?L . ,(capitalize language))
(?D . ,(org-export-get-date info)))))
;;; Template ;;; Template
@ -1201,7 +1252,8 @@ INFO is a plist used as a communication channel."
"Return complete document string after LaTeX conversion. "Return complete document string after LaTeX conversion.
CONTENTS is the transcoded contents string. INFO is a plist CONTENTS is the transcoded contents string. INFO is a plist
holding export options." holding export options."
(let ((title (org-export-data (plist-get info :title) info))) (let ((title (org-export-data (plist-get info :title) info))
(spec (org-latex--format-spec info)))
(concat (concat
;; Time-stamp. ;; Time-stamp.
(and (plist-get info :time-stamp-file) (and (plist-get info :time-stamp-file)
@ -1248,17 +1300,15 @@ holding export options."
;; Title ;; Title
(format "\\title{%s}\n" title) (format "\\title{%s}\n" title)
;; Hyperref options. ;; Hyperref options.
(format-spec (plist-get info :latex-hyperref-template) (let ((template (plist-get info :latex-hyperref-template)))
(format-spec-make (and (stringp template)
?k (or (plist-get info :keywords) "") (format-spec template spec)))
?d (or (plist-get info :description)"")
?c (if (plist-get info :with-creator)
(plist-get info :creator)
"")))
;; Document start. ;; Document start.
"\\begin{document}\n\n" "\\begin{document}\n\n"
;; Title command. ;; Title command.
(let ((command (plist-get info :latex-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 (org-element-normalize-string
(cond ((not (plist-get info :with-title)) nil) (cond ((not (plist-get info :with-title)) nil)
((string= "" title) nil) ((string= "" title) nil)