From 00afe229520b0ef8f14221481b54f57cbbda6c11 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Sun, 4 Apr 2010 08:32:55 +0200 Subject: [PATCH] Specify the position where the packages are inserted in the LaTeX header. --- doc/ChangeLog | 4 ++++ doc/org.texi | 17 +++++++++----- lisp/ChangeLog | 8 +++++++ lisp/org-latex.el | 38 ++++++++++++------------------ lisp/org.el | 59 ++++++++++++++++++++++++++++++----------------- 5 files changed, 76 insertions(+), 50 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index f2a5121ae..799e4df93 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2010-04-04 Carsten Dominik + + * org.texi (Sectioning structure): Update. + 2010-04-01 Carsten Dominik * org.texi (The export dispatcher): Renamed from ASCII export. diff --git a/doc/org.texi b/doc/org.texi index 34c152094..a95bd089b 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -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-classes +@vindex org-export-latex-default-packages-alist +@vindex org-export-latex-packages-alist @cindex #+LATEX_HEADER @cindex #+LATEX_CLASS @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{#+LaTeX_CLASS: myclass} in your file, or with a @code{:LaTeX_CLASS:} 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 -also define the sectioning structure for each class, as well as defining -additional classes. In a similar way, @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. +The class must be listed in @code{org-export-latex-classes}. This variable +defines a header template for each class@footnote{Into which the values of +@code{org-export-latex-default-packages-alist} and +@code{org-export-latex-packages-alist} are spliced.}, and allows you to +define the sectioning structure for each class. You can also define your own +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 @subsection Tables in La@TeX{} export diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 31741526a..c55c123fd 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,13 @@ 2010-04-04 Carsten Dominik + * 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. 2010-04-03 Carsten Dominik diff --git a/lisp/org-latex.el b/lisp/org-latex.el index b9342aa69..55a457351 100644 --- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -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 call to \\usepackage for all packages mentioned in the variables `org-export-latex-default-packages-alist' and -`org-export-latex-packages-alist'. Lines specified via \"#+LaTeX_HEADER:\" -are also added. -`org-export-latex-default-packages-alist' contains +`org-export-latex-packages-alist'. Normally these package definitions will +appear at the end of HEADER-STRING, but if HEADER-STRING contains the +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 a coding system derived from `buffer-file-coding-system'. See also the 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 (if (plist-get opt-plist :time-stamp-file) (format-time-string "%% Created %Y-%m-%d %a %H:%M\n")) - ;; insert LaTeX custom header - (org-export-apply-macros-in-string org-export-latex-header) - "\n" - ;; insert information on LaTeX packages - (when (or org-export-latex-default-packages-alist - org-export-latex-packages-alist) - (concat - (mapconcat (lambda(p) - (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)) + ;; insert LaTeX custom header and packages from the list + (org-splice-latex-header + (org-export-apply-macros-in-string org-export-latex-header) + org-export-latex-default-packages-alist + org-export-latex-packages-alist + (org-export-apply-macros-in-string + (plist-get opt-plist :latex-header-extra))) + ;; append another special variable (org-export-apply-macros-in-string org-export-latex-append-header) ;; define align if not yet defined - "\\providecommand{\\alert}[1]{\\textbf{#1}}" + "\n\\providecommand{\\alert}[1]{\\textbf{#1}}" ;; insert the title (format "\n\n\\title{%s}\n" diff --git a/lisp/org.el b/lisp/org.el index ee8cf3315..ddad45f12 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -2926,7 +2926,10 @@ When nil, just push out a message." \\addtolength{\\topmargin}{-2.54cm}" "The document header used for processing LaTeX fragments. 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 :type 'string) @@ -2976,9 +2979,14 @@ Each cell is of the format \( \"options\" \"package\" \)." (string :tag "package")))) (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'. -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 :type '(repeat (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 bg 'default) (setq bg (org-dvipng-color :background))) (with-temp-file texfile - (insert org-format-latex-header - (if (or org-export-latex-default-packages-alist - org-export-latex-packages-alist) - (concat "\n" - (mapconcat (lambda(p) - (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")) - "") - (if org-format-latex-header-extra - (concat "\n" org-format-latex-header-extra) - "") - "\n\\begin{document}\n" string "\n\\end{document}\n") + (insert (org-splice-latex-header + org-format-latex-header + org-export-latex-default-packages-alist + org-export-latex-packages-alist + org-format-latex-header-extra)) + (insert "\n\\begin{document}\n" string "\n\\end{document}\n") (org-export-latex-fix-inputenc)) (let ((dir default-directory)) (condition-case nil @@ -15300,6 +15296,27 @@ Some of the options can be changed using the variable (delete-file (concat texfilebase e))) 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) "Return an rgb color specification for dvipng." (apply 'format "rgb %s %s %s"