Specify the position where the packages are inserted in the LaTeX header.

This commit is contained in:
Carsten Dominik 2010-04-04 08:32:55 +02:00
parent 33dbb46fc2
commit 00afe22952
5 changed files with 76 additions and 50 deletions

View File

@ -1,3 +1,7 @@
2010-04-04 Carsten Dominik <carsten.dominik@gmail.com>
* org.texi (Sectioning structure): Update.
2010-04-01 Carsten Dominik <carsten.dominik@gmail.com> 2010-04-01 Carsten Dominik <carsten.dominik@gmail.com>
* org.texi (The export dispatcher): Renamed from ASCII export. * org.texi (The export dispatcher): Renamed from ASCII export.

View File

@ -9600,6 +9600,8 @@ By default, the La@TeX{} output uses the class @code{article}.
@vindex org-export-latex-default-class @vindex org-export-latex-default-class
@vindex org-export-latex-classes @vindex org-export-latex-classes
@vindex org-export-latex-default-packages-alist
@vindex org-export-latex-packages-alist
@cindex #+LATEX_HEADER @cindex #+LATEX_HEADER
@cindex #+LATEX_CLASS @cindex #+LATEX_CLASS
@cindex #+LATEX_CLASS_OPTIONS @cindex #+LATEX_CLASS_OPTIONS
@ -9609,12 +9611,15 @@ You can change this globally by setting a different value for
@code{org-export-latex-default-class} or locally by adding an option like @code{org-export-latex-default-class} or locally by adding an option like
@code{#+LaTeX_CLASS: myclass} in your file, or with a @code{:LaTeX_CLASS:} @code{#+LaTeX_CLASS: myclass} in your file, or with a @code{:LaTeX_CLASS:}
property that applies when exporting a region containing only this (sub)tree. property that applies when exporting a region containing only this (sub)tree.
The class should be listed in @code{org-export-latex-classes}, where you can The class must be listed in @code{org-export-latex-classes}. This variable
also define the sectioning structure for each class, as well as defining defines a header template for each class@footnote{Into which the values of
additional classes. In a similar way, @code{#+LaTeX_CLASS_OPTIONS} or a @code{org-export-latex-default-packages-alist} and
@code{LaTeX_CLASS_OPTIONS} property can specify the options for the @code{org-export-latex-packages-alist} are spliced.}, and allows you to
@code{\documentclass} macro. You can also use @code{#+LATEX_HEADER: define the sectioning structure for each class. You can also define your own
\usepackage@{xyz@}} to add lines to the header. classes there. @code{#+LaTeX_CLASS_OPTIONS} or a @code{LaTeX_CLASS_OPTIONS}
property can specify the options for the @code{\documentclass} macro.
You can also use @code{#+LATEX_HEADER: \usepackage@{xyz@}} to add lines to
the header.
@node Tables in LaTeX export, Images in LaTeX export, Sectioning structure, LaTeX and PDF export @node Tables in LaTeX export, Images in LaTeX export, Sectioning structure, LaTeX and PDF export
@subsection Tables in La@TeX{} export @subsection Tables in La@TeX{} export

View File

@ -1,5 +1,13 @@
2010-04-04 Carsten Dominik <carsten.dominik@gmail.com> 2010-04-04 Carsten Dominik <carsten.dominik@gmail.com>
* org-latex.el (org-export-latex-make-header): Use
`org-splice-latex-header' to build the header.
(org-export-latex-classes): Update docstring.
* org.el (org-splice-latex-header): New function.
(org-create-formula-image): Use `org-splice-latex-header' to build
the header.
* org-gnus.el (org-gnus-follow-link): Handle nndoc backend. * org-gnus.el (org-gnus-follow-link): Handle nndoc backend.
2010-04-03 Carsten Dominik <carsten.dominik@gmail.com> 2010-04-03 Carsten Dominik <carsten.dominik@gmail.com>

View File

@ -132,9 +132,12 @@ It should really only contain the contain the \\documentclass macro, and
setup code that is specific to this class. This will be augmented by setup code that is specific to this class. This will be augmented by
call to \\usepackage for all packages mentioned in the variables call to \\usepackage for all packages mentioned in the variables
`org-export-latex-default-packages-alist' and `org-export-latex-default-packages-alist' and
`org-export-latex-packages-alist'. Lines specified via \"#+LaTeX_HEADER:\" `org-export-latex-packages-alist'. Normally these package definitions will
are also added. appear at the end of HEADER-STRING, but if HEADER-STRING contains the
`org-export-latex-default-packages-alist' contains string \"[PACKAGES]\", it will be replaced by the usepackage definitions.
Lines specified via \"#+LaTeX_HEADER:\" are also added, at the end.
If `org-export-latex-default-packages-alist' contains
\"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be replaced with \"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be replaced with
a coding system derived from `buffer-file-coding-system'. See also the a coding system derived from `buffer-file-coding-system'. See also the
variable `org-export-latex-inputenc-alist' for a way to influence this variable `org-export-latex-inputenc-alist' for a way to influence this
@ -1113,28 +1116,17 @@ OPT-PLIST is the options plist for current buffer."
(concat (concat
(if (plist-get opt-plist :time-stamp-file) (if (plist-get opt-plist :time-stamp-file)
(format-time-string "%% Created %Y-%m-%d %a %H:%M\n")) (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
;; insert LaTeX custom header ;; insert LaTeX custom header and packages from the list
(org-export-apply-macros-in-string org-export-latex-header) (org-splice-latex-header
"\n" (org-export-apply-macros-in-string org-export-latex-header)
;; insert information on LaTeX packages org-export-latex-default-packages-alist
(when (or org-export-latex-default-packages-alist org-export-latex-packages-alist
org-export-latex-packages-alist) (org-export-apply-macros-in-string
(concat (plist-get opt-plist :latex-header-extra)))
(mapconcat (lambda(p) ;; append another special variable
(if (equal "" (car p))
(format "\\usepackage{%s}" (cadr p))
(format "\\usepackage[%s]{%s}"
(car p) (cadr p))))
(append org-export-latex-default-packages-alist
org-export-latex-packages-alist)
"\n")
"\n"))
;; insert additional commands in the header
(org-export-apply-macros-in-string
(plist-get opt-plist :latex-header-extra))
(org-export-apply-macros-in-string org-export-latex-append-header) (org-export-apply-macros-in-string org-export-latex-append-header)
;; define align if not yet defined ;; define align if not yet defined
"\\providecommand{\\alert}[1]{\\textbf{#1}}" "\n\\providecommand{\\alert}[1]{\\textbf{#1}}"
;; insert the title ;; insert the title
(format (format
"\n\n\\title{%s}\n" "\n\n\\title{%s}\n"

View File

@ -2926,7 +2926,10 @@ When nil, just push out a message."
\\addtolength{\\topmargin}{-2.54cm}" \\addtolength{\\topmargin}{-2.54cm}"
"The document header used for processing LaTeX fragments. "The document header used for processing LaTeX fragments.
It is imperative that this header make sure that no page number It is imperative that this header make sure that no page number
appears on the page." appears on the page. The package defined in the variables
`org-export-latex-default-packages-alist' and `org-export-latex-packages-alist'
will either replace the placeholder \"[PACKAGES]\" in this header, or they
will be appended."
:group 'org-latex :group 'org-latex
:type 'string) :type 'string)
@ -2976,9 +2979,14 @@ Each cell is of the format \( \"options\" \"package\" \)."
(string :tag "package")))) (string :tag "package"))))
(defcustom org-export-latex-packages-alist nil (defcustom org-export-latex-packages-alist nil
"Alist of packages to be inserted in the header. "Alist of packages to be inserted in every LaTeX the header.
These will be inserted after `org-export-latex-default-packages-alist'. These will be inserted after `org-export-latex-default-packages-alist'.
Each cell is of the format \( \"options\" \"package\" \)." Each cell is of the format \( \"options\" \"package\" \).
Make sure that you only lis packages here which:
- you want in every file
- do not conflict with the default packages in
`org-export-latex-default-packages-alist'
- do not conflict with the setup in `org-format-latex-header'."
:group 'org-export-latex :group 'org-export-latex
:type '(repeat :type '(repeat
(list (list
@ -15252,24 +15260,12 @@ Some of the options can be changed using the variable
(if (eq fg 'default) (setq fg (org-dvipng-color :foreground))) (if (eq fg 'default) (setq fg (org-dvipng-color :foreground)))
(if (eq bg 'default) (setq bg (org-dvipng-color :background))) (if (eq bg 'default) (setq bg (org-dvipng-color :background)))
(with-temp-file texfile (with-temp-file texfile
(insert org-format-latex-header (insert (org-splice-latex-header
(if (or org-export-latex-default-packages-alist org-format-latex-header
org-export-latex-packages-alist) org-export-latex-default-packages-alist
(concat "\n" org-export-latex-packages-alist
(mapconcat (lambda(p) org-format-latex-header-extra))
(if (equal "" (car p)) (insert "\n\\begin{document}\n" string "\n\\end{document}\n")
(format "\\usepackage{%s}" (cadr p))
(format "\\usepackage[%s]{%s}"
(car p) (cadr p))))
(append
org-export-latex-default-packages-alist
org-export-latex-packages-alist)
"\n"))
"")
(if org-format-latex-header-extra
(concat "\n" org-format-latex-header-extra)
"")
"\n\\begin{document}\n" string "\n\\end{document}\n")
(org-export-latex-fix-inputenc)) (org-export-latex-fix-inputenc))
(let ((dir default-directory)) (let ((dir default-directory))
(condition-case nil (condition-case nil
@ -15300,6 +15296,27 @@ Some of the options can be changed using the variable
(delete-file (concat texfilebase e))) (delete-file (concat texfilebase e)))
pngfile)))) pngfile))))
(defun org-splice-latex-header (template packages-1 packages-2 &optional extra)
"Fill a LaTeX header template.
If TEMPLATE contains the string \"[PACKAGES]\", this is where the packages
in the lists PACKAGES-1 and PACKAGES-2 will be inserted, otherwise the come
at the end. If EXTRA is a string, it is also appended."
(let ((packages
(and (or packages-1 packages-2)
(mapconcat (lambda(p)
(if (equal "" (car p))
(format "\\usepackage{%s}" (cadr p))
(format "\\usepackage[%s]{%s}"
(car p) (cadr p))))
(append packages-1 packages-2)
"\n"))))
(if (string-match "\\[PACKAGES\\]" template)
(setq template (replace-match (or packages "") t t template))
(setq template (concat template "\n" packages)))
(if (and extra (sring-match "\\S-" extra))
(concat template "\n" extra)
template)))
(defun org-dvipng-color (attr) (defun org-dvipng-color (attr)
"Return an rgb color specification for dvipng." "Return an rgb color specification for dvipng."
(apply 'format "rgb %s %s %s" (apply 'format "rgb %s %s %s"