summaryrefslogtreecommitdiff
path: root/lisp/ox-latex.el
diff options
context:
space:
mode:
authorSébastien Delafond <sdelafond@gmail.com>2014-07-13 13:35:29 +0200
committerSébastien Delafond <sdelafond@gmail.com>2014-07-13 13:35:29 +0200
commit40ce6b75e6245659a3a14622356e32e7dd1125dd (patch)
tree7d0051414493a78c84a3dfbec6143883c2ba8341 /lisp/ox-latex.el
parente32a45ed36d6000db4b39171149072d11b77af72 (diff)
Imported Upstream version 8.2.1
Diffstat (limited to 'lisp/ox-latex.el')
-rw-r--r--lisp/ox-latex.el291
1 files changed, 148 insertions, 143 deletions
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 0fffd82..e1173ef 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -143,7 +143,9 @@
("la" . "latin")
("ms" . "malay")
("nl" . "dutch")
- ("no-no" . "nynorsk")
+ ("nb" . "norsk")
+ ("nn" . "nynorsk")
+ ("no" . "norsk")
("pl" . "polish")
("pt" . "portuguese")
("ro" . "romanian")
@@ -255,12 +257,17 @@ to \\providecommand, and then place \\usepackage commands based
on the content of `org-latex-packages-alist'.
If your header, `org-latex-default-packages-alist' or
-`org-latex-packages-alist' inserts
-\"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be
-replaced with a coding system derived from
-`buffer-file-coding-system'. See also the variable
+`org-latex-packages-alist' inserts \"\\usepackage[AUTO]{inputenc}\",
+AUTO will automatically be replaced with a coding system derived
+from `buffer-file-coding-system'. See also the variable
`org-latex-inputenc-alist' for a way to influence this mechanism.
+Likewise, if your header contains \"\\usepackage[AUTO]{babel}\",
+AUTO will be replaced with the language related to the language
+code specified by `org-export-default-language', which see. Note
+that constructions such as \"\\usepackage[french,AUTO,english]{babel}\"
+are permitted.
+
The sectioning structure
------------------------
@@ -337,7 +344,6 @@ the toc:nil option, not to those generated with #+TOC keyword."
:group 'org-export-latex
:type 'boolean)
-
;;;; Headline
(defcustom org-latex-format-headline-function
@@ -420,7 +426,7 @@ environment."
:type 'string)
(defcustom org-latex-inline-image-rules
- '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\|tikz\\)\\'"))
+ '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\|tikz\\|pgf\\|svg\\)\\'"))
"Rules characterizing image files that can be inlined into LaTeX.
A rule consists in an association whose key is the type of link
@@ -658,7 +664,7 @@ into previewing problems, please consult
(fortran "fortran")
(perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
(html "HTML") (xml "XML")
- (tex "TeX") (latex "TeX")
+ (tex "TeX") (latex "[LaTeX]TeX")
(shell-script "bash")
(gnuplot "Gnuplot")
(ocaml "Caml") (caml "Caml")
@@ -745,20 +751,6 @@ options will be applied to blocks of all languages."
(string :tag "Minted option name ")
(string :tag "Minted option value"))))
-(defcustom org-latex-long-listings nil
- "When non-nil no listing will be wrapped within a float.
-
-Removing floats may break some functionalities. For example, it
-will be impossible to use cross-references to listings when using
-`minted' set-up when this variable is non-nil.
-
-This value can be locally ignored with \":long-listing t\" and
-\":long-listing nil\" LaTeX attributes."
- :group 'org-export-latex
- :version "24.4"
- :package-version '(Org . "8.0")
- :type 'boolean)
-
(defvar org-latex-custom-lang-environments nil
"Alist mapping languages to language-specific LaTeX environments.
@@ -800,8 +792,12 @@ the infamous egrep/locale bug:
http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
-then `texi2dvi' is the superior choice. Org does offer it as one
-of the customize options.
+then `texi2dvi' is the superior choice as it automates the LaTeX
+build process by calling the \"correct\" combinations of
+auxiliary programs. Org does offer `texi2dvi' as one of the
+customize options. Alternatively, `rubber' and `latexmk' also
+provide similar functionality. The latter supports `biber' out
+of the box.
Alternatively, this may be a Lisp function that does the
processing, so you could use this to apply the machinery of
@@ -839,6 +835,8 @@ file name as its single argument."
("texi2dvi -p -b -V %f"))
(const :tag "rubber"
("rubber -d --into %o %f"))
+ (const :tag "latexmk"
+ ("latexmk -g -pdf %f"))
(function)))
(defcustom org-latex-logfiles-extensions
@@ -891,8 +889,11 @@ For non-floats, see `org-latex--wrap-label'."
(format "\\label{%s}"
(org-export-solidify-link-text label))))
(main (org-export-get-caption element))
- (short (org-export-get-caption element t)))
+ (short (org-export-get-caption element t))
+ (caption-from-attr-latex (org-export-read-attribute :attr_latex element :caption)))
(cond
+ ((org-string-nw-p caption-from-attr-latex)
+ (concat caption-from-attr-latex "\n"))
((and (not main) (equal label-str "")) "")
((not main) (concat label-str "\n"))
;; Option caption format with short name.
@@ -931,6 +932,10 @@ Insertion of guessed language only happens when Babel package has
explicitly been loaded. Then it is added to the rest of
package's options.
+The argument to Babel may be \"AUTO\" which is then replaced with
+the language of the document or `org-export-default-language'
+unless language in question is already loaded.
+
Return the new header."
(let ((language-code (plist-get info :language)))
;; If no language is set or Babel package is not loaded, return
@@ -939,16 +944,19 @@ Return the new header."
(not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
header
(let ((options (save-match-data
- (org-split-string (match-string 1 header) ",")))
+ (org-split-string (match-string 1 header) ",[ \t]*")))
(language (cdr (assoc language-code
org-latex-babel-language-alist))))
- ;; If LANGUAGE is already loaded, return header. Otherwise,
- ;; append LANGUAGE to other options.
- (if (member language options) header
- (replace-match (mapconcat 'identity
- (append options (list language))
- ",")
- nil nil header 1))))))
+ ;; If LANGUAGE is already loaded, return header without AUTO.
+ ;; Otherwise, replace AUTO with language or append language if
+ ;; AUTO is not present.
+ (replace-match
+ (mapconcat (lambda (option) (if (equal "AUTO" option) language option))
+ (cond ((member language options) (delete "AUTO" options))
+ ((member "AUTO" options) options)
+ (t (append options (list language))))
+ ", ")
+ t nil header 1)))))
(defun org-latex--find-verb-separator (s)
"Return a character not used in string S.
@@ -1553,7 +1561,7 @@ contextual information."
(1- count)))))
(checkbox (case (org-element-property :checkbox item)
(on "$\\boxtimes$ ")
- (off "$\\Box$ ")
+ (off "$\\square$ ")
(trans "$\\boxminus$ ")))
(tag (let ((tag (org-element-property :tag item)))
;; Check-boxes must belong to the tag.
@@ -1656,10 +1664,12 @@ used as a communication channel."
;; Retrieve latex attributes from the element around.
(attr (org-export-read-attribute :attr_latex parent))
(float (let ((float (plist-get attr :float)))
- (cond ((string= float "wrap") 'wrap)
+ (cond ((and (not float) (plist-member attr :float)) nil)
+ ((string= float "wrap") 'wrap)
((string= float "multicolumn") 'multicolumn)
- ((or (string= float "figure")
- (org-element-property :caption parent))
+ ((or float
+ (org-element-property :caption parent)
+ (org-string-nw-p (plist-get attr :caption)))
'figure))))
(placement
(let ((place (plist-get attr :placement)))
@@ -1684,7 +1694,7 @@ used as a communication channel."
(if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt)) opt
(match-string 1 opt))))
image-code)
- (if (equal filetype "tikz")
+ (if (member filetype '("tikz" "pgf"))
;; For tikz images:
;; - use \input to read in image file.
;; - if options are present, wrap in a tikzpicture environment.
@@ -1715,7 +1725,16 @@ used as a communication channel."
((= (aref options 0) ?,)
(format "[%s]"(substring options 1)))
(t (format "[%s]" options)))
- path)))
+ path))
+ (when (equal filetype "svg")
+ (setq image-code (replace-regexp-in-string "^\\\\includegraphics"
+ "\\includesvg"
+ image-code
+ nil t))
+ (setq image-code (replace-regexp-in-string "\\.svg}"
+ "}"
+ image-code
+ nil t))))
;; Return proper string, depending on FLOAT.
(case float
(wrap (format "\\begin{wrapfigure}%s
@@ -2018,21 +2037,24 @@ contextual information."
(continued (org-export-get-loc src-block info))
(new 0)))
(retain-labels (org-element-property :retain-labels src-block))
- (long-listing
- (let ((attr (org-export-read-attribute :attr_latex src-block)))
- (if (plist-member attr :long-listing)
- (plist-get attr :long-listing)
- org-latex-long-listings))))
+ (attributes (org-export-read-attribute :attr_latex src-block))
+ (float (plist-get attributes :float)))
(cond
;; Case 1. No source fontification.
((not org-latex-listings)
(let* ((caption-str (org-latex--caption/label-string src-block info))
- (float-env (and (not long-listing)
- (or label caption)
- (format "\\begin{figure}[H]\n%s%%s\n\\end{figure}"
- caption-str))))
+ (float-env
+ (cond ((and (not float) (plist-member attributes :float)) "%s")
+ ((string= "multicolumn" float)
+ (format "\\begin{figure*}[%s]\n%%s%s\n\\end{figure*}"
+ org-latex-default-figure-position
+ caption-str))
+ ((or caption float)
+ (format "\\begin{figure}[H]\n%%s%s\n\\end{figure}"
+ caption-str))
+ (t "%s"))))
(format
- (or float-env "%s")
+ float-env
(concat (format "\\begin{verbatim}\n%s\\end{verbatim}"
(org-export-format-code-default src-block info))))))
;; Case 2. Custom environment.
@@ -2042,46 +2064,52 @@ contextual information."
custom-env))
;; Case 3. Use minted package.
((eq org-latex-listings 'minted)
- (let ((float-env
- (and (not long-listing)
- (or label caption)
- (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
- (org-latex--caption/label-string src-block info))))
- (body
- (format
- "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
- ;; Options.
- (org-latex--make-option-string
- (if (or (not num-start)
- (assoc "linenos" org-latex-minted-options))
- org-latex-minted-options
- (append `(("linenos")
- ("firstnumber" ,(number-to-string (1+ num-start))))
- org-latex-minted-options)))
- ;; Language.
- (or (cadr (assq (intern lang) org-latex-minted-langs)) lang)
- ;; Source code.
- (let* ((code-info (org-export-unravel-code src-block))
- (max-width
- (apply 'max
- (mapcar 'length
- (org-split-string (car code-info)
- "\n")))))
- (org-export-format-code
- (car code-info)
- (lambda (loc num ref)
- (concat
- loc
- (when ref
- ;; Ensure references are flushed to the right,
- ;; separated with 6 spaces from the widest line
- ;; of code.
- (concat (make-string (+ (- max-width (length loc)) 6)
- ?\s)
- (format "(%s)" ref)))))
- nil (and retain-labels (cdr code-info)))))))
+ (let* ((caption-str (org-latex--caption/label-string src-block info))
+ (float-env
+ (cond ((and (not float) (plist-member attributes :float)) "%s")
+ ((string= "multicolumn" float)
+ (format "\\begin{listing*}\n%%s\n%s\\end{listing*}"
+ caption-str))
+ ((or caption float)
+ (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
+ caption-str))
+ (t "%s")))
+ (body
+ (format
+ "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
+ ;; Options.
+ (org-latex--make-option-string
+ (if (or (not num-start)
+ (assoc "linenos" org-latex-minted-options))
+ org-latex-minted-options
+ (append
+ `(("linenos")
+ ("firstnumber" ,(number-to-string (1+ num-start))))
+ org-latex-minted-options)))
+ ;; Language.
+ (or (cadr (assq (intern lang) org-latex-minted-langs)) lang)
+ ;; Source code.
+ (let* ((code-info (org-export-unravel-code src-block))
+ (max-width
+ (apply 'max
+ (mapcar 'length
+ (org-split-string (car code-info)
+ "\n")))))
+ (org-export-format-code
+ (car code-info)
+ (lambda (loc num ref)
+ (concat
+ loc
+ (when ref
+ ;; Ensure references are flushed to the right,
+ ;; separated with 6 spaces from the widest line
+ ;; of code.
+ (concat (make-string (+ (- max-width (length loc)) 6)
+ ?\s)
+ (format "(%s)" ref)))))
+ nil (and retain-labels (cdr code-info)))))))
;; Return value.
- (if float-env (format float-env body) body)))
+ (format float-env body)))
;; Case 4. Use listings package.
(t
(let ((lst-lang
@@ -2097,19 +2125,25 @@ contextual information."
(org-export-data main info)))))))
(concat
;; Options.
- (format "\\lstset{%s}\n"
- (org-latex--make-option-string
- (append
- org-latex-listings-options
- `(("language" ,lst-lang))
- (when label `(("label" ,label)))
- (when caption-str `(("caption" ,caption-str)))
- (cond ((assoc "numbers" org-latex-listings-options) nil)
- ((not num-start) '(("numbers" "none")))
- ((zerop num-start) '(("numbers" "left")))
- (t `(("numbers" "left")
- ("firstnumber"
- ,(number-to-string (1+ num-start)))))))))
+ (format
+ "\\lstset{%s}\n"
+ (org-latex--make-option-string
+ (append
+ org-latex-listings-options
+ (cond
+ ((and (not float) (plist-member attributes :float)) nil)
+ ((string= "multicolumn" float) '(("float" "*")))
+ ((and float (not (assoc "float" org-latex-listings-options)))
+ `(("float" ,org-latex-default-figure-position))))
+ `(("language" ,lst-lang))
+ (when label `(("label" ,label)))
+ (when caption-str `(("caption" ,caption-str)))
+ (cond ((assoc "numbers" org-latex-listings-options) nil)
+ ((not num-start) '(("numbers" "none")))
+ ((zerop num-start) '(("numbers" "left")))
+ (t `(("numbers" "left")
+ ("firstnumber"
+ ,(number-to-string (1+ num-start)))))))))
;; Source code.
(format
"\\begin{lstlisting}\n%s\\end{lstlisting}"
@@ -2319,10 +2353,12 @@ This function assumes TABLE has `org' as its `:type' property and
(float-env (unless (member table-env '("longtable" "longtabu"))
(let ((float (plist-get attr :float)))
(cond
+ ((and (not float) (plist-member attr :float)) nil)
((string= float "sidewaystable") "sidewaystable")
((string= float "multicolumn") "table*")
- ((or (string= float "table")
- (org-element-property :caption table))
+ ((or float
+ (org-element-property :caption table)
+ (org-string-nw-p (plist-get attr :caption)))
"table")))))
;; Extract others display options.
(fontsize (let ((font (plist-get attr :font)))
@@ -2683,23 +2719,8 @@ Export is done in a buffer named \"*Org LATEX Export*\", which
will be displayed when `org-export-show-temporary-export-buffer'
is non-nil."
(interactive)
- (if async
- (org-export-async-start
- (lambda (output)
- (with-current-buffer (get-buffer-create "*Org LATEX Export*")
- (erase-buffer)
- (insert output)
- (goto-char (point-min))
- (LaTeX-mode)
- (org-export-add-to-stack (current-buffer) 'latex)))
- `(org-export-as 'latex ,subtreep ,visible-only ,body-only
- ',ext-plist))
- (let ((outbuf
- (org-export-to-buffer 'latex "*Org LATEX Export*"
- subtreep visible-only body-only ext-plist)))
- (with-current-buffer outbuf (LaTeX-mode))
- (when org-export-show-temporary-export-buffer
- (switch-to-buffer-other-window outbuf)))))
+ (org-export-to-buffer 'latex "*Org LATEX Export*"
+ async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
;;;###autoload
(defun org-latex-convert-region-to-latex ()
@@ -2736,19 +2757,11 @@ between \"\\begin{document}\" and \"\\end{document}\".
EXT-PLIST, when provided, is a property list with external
parameters overriding Org default settings, but still inferior to
-file-local settings.
-
-Return output file's name."
+file-local settings."
(interactive)
(let ((outfile (org-export-output-file-name ".tex" subtreep)))
- (if async
- (org-export-async-start
- (lambda (f) (org-export-add-to-stack f 'latex))
- `(expand-file-name
- (org-export-to-file
- 'latex ,outfile ,subtreep ,visible-only ,body-only ',ext-plist)))
- (org-export-to-file
- 'latex outfile subtreep visible-only body-only ext-plist))))
+ (org-export-to-file 'latex outfile
+ async subtreep visible-only body-only ext-plist)))
;;;###autoload
(defun org-latex-export-to-pdf
@@ -2780,18 +2793,10 @@ file-local settings.
Return PDF file's name."
(interactive)
- (if async
- (let ((outfile (org-export-output-file-name ".tex" subtreep)))
- (org-export-async-start
- (lambda (f) (org-export-add-to-stack f 'latex))
- `(expand-file-name
- (org-latex-compile
- (org-export-to-file
- 'latex ,outfile ,subtreep ,visible-only ,body-only
- ',ext-plist)))))
- (org-latex-compile
- (org-latex-export-to-latex
- nil subtreep visible-only body-only ext-plist))))
+ (let ((outfile (org-export-output-file-name ".tex" subtreep)))
+ (org-export-to-file 'latex outfile
+ async subtreep visible-only body-only ext-plist
+ (lambda (file) (org-latex-compile file)))))
(defun org-latex-compile (texfile &optional snippet)
"Compile a TeX file.