1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-12-28 10:56:57 +00:00

LaTeX Export: Define TeX macros for in-buffer settings

This commit implements the possibility to import the in-buffer export
options as TeX macros, like \orgTITLE, \orgAUTHOR etc.

Requested by Russel Adams.
This commit is contained in:
Carsten Dominik 2009-02-20 07:55:05 +01:00
parent dc6de43ae4
commit 933d88ef3e
2 changed files with 49 additions and 3 deletions

View File

@ -1,3 +1,14 @@
2009-02-20 Carsten Dominik <carsten.dominik@gmail.com>
* org-export-latex.el (org-export-latex-import-inbuffer-stuff):
New option.
(org-export-as-latex): Import in-buffer settings as TeX macros.
(org-export-latex-make-header): Additional parameter OPT-DEFS.
(org-export-latex-collect-header-macros): New function.
* org.el (org-refile-get-location): Turn off
`partial-completion-mode'.
2009-02-19 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-block-todo-from-checkboxes): Announce that

View File

@ -6,7 +6,7 @@
;; Filename: org-export-latex.el
;; Version: 6.22trans
;; Author: Bastien Guerry <bzg AT altern DOT org>
;; Maintainer: Bastien Guerry <bzg AT altern DOT org>
;; Maintainer: Carsten Dominik <carsten.dominik AT gmail DOT com>
;; Keywords: org, wp, tex
;; Description: Converts an org-mode buffer into LaTeX
;; URL: http://www.cognition.ens.fr/~guerry/u/org-export-latex.el
@ -184,6 +184,12 @@ argument."
:group 'org-export-latex
:type 'string)
(defcustom org-export-latex-import-inbuffer-stuff nil
"Non-nil means define TeX macros for Org's inbuffer definitions.
For example \orgTITLE for #+TITLE."
:group 'org-export-latex
:type 'boolean)
(defcustom org-export-latex-date-format
"%d %B %Y"
"Format string for \\date{...}."
@ -409,6 +415,8 @@ when PUB-DIR is set, use this as the publishing directory."
(org-export-grab-title-from-buffer))
(file-name-sans-extension
(file-name-nondirectory buffer-file-name))))
(option-defs (and org-export-latex-import-inbuffer-stuff
(org-export-latex-collect-header-macros title)))
(filename (concat (file-name-as-directory
(or pub-dir
(org-export-directory :LaTeX ext-plist)))
@ -429,7 +437,7 @@ when PUB-DIR is set, use this as the publishing directory."
(t (get-buffer-create to-buffer)))
(find-file-noselect filename)))
(odd org-odd-levels-only)
(header (org-export-latex-make-header title opt-plist))
(header (org-export-latex-make-header title opt-plist option-defs))
(skip (cond (subtree-p nil)
(region-p nil)
(t (plist-get opt-plist :skip-before-1st-heading))))
@ -716,7 +724,7 @@ LEVEL indicates the default depth for export."
(sec-depth (length org-export-latex-sectioning)))
(if (> hl-levels sec-depth) sec-depth hl-levels)))))
(defun org-export-latex-make-header (title opt-plist)
(defun org-export-latex-make-header (title opt-plist &optional opt-defs)
"Make the LaTeX header and return it as a string.
TITLE is the current title from the buffer or region.
OPT-PLIST is the options plist for current buffer."
@ -739,6 +747,7 @@ OPT-PLIST is the options plist for current buffer."
;; insert additional commands in the header
(plist-get opt-plist :latex-header-extra)
org-export-latex-append-header
option-defs
;; insert the title
(format
"\n\n\\title{%s}\n"
@ -797,6 +806,32 @@ If BEG is non-nil, the is the beginning of he region."
(add-text-properties pt (max pt (1- end))
'(:org-license-to-kill t))))))
(defun org-export-latex-collect-header-macros (&optional title)
"Find the various definitions in #+... lines and define TeX macros for them."
(let ((re (org-make-options-regexp
'("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
"LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
"EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")))
out key val a)
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(while (re-search-forward re nil t)
(setq key (upcase (match-string 1))
value (match-string 2))
(if (and title (equal key "TITLE"))
(setq value title))
(while (string-match "_" key)
(setq key (replace-match "" t t key)))
(if (setq a (assoc key out))
(setcdr a (concat (cdr a) "\n" value))
(push (cons key value) out))))
(mapconcat
(lambda (x) (concat "\\def\\org" (car x) "{" (cdr x) "}"))
out
"\n"))))
(defun org-export-latex-content (content &optional exclude-list)
"Convert CONTENT string to LaTeX.
Don't perform conversions that are in EXCLUDE-LIST. Recognized