X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/18b35e2c7a3ff95fb4a07e58c3f57c70c65c0701..26bd978d87dfbf9baa115cd961a67d42b416c4bf:/lisp/org/ox-latex.el diff --git a/lisp/org/ox-latex.el b/lisp/org/ox-latex.el index 6766b8583f..cea02ff454 100644 --- a/lisp/org/ox-latex.el +++ b/lisp/org/ox-latex.el @@ -1,6 +1,6 @@ ;;; ox-latex.el --- LaTeX Back-End for Org Export Engine -;; Copyright (C) 2011-2013 Free Software Foundation, Inc. +;; Copyright (C) 2011-2015 Free Software Foundation, Inc. ;; Author: Nicolas Goaziou ;; Keywords: outlines, hypermedia, calendar, wp @@ -524,7 +524,7 @@ When nil, no transformation is made." :package-version '(Org . "8.0") :type '(choice (string :tag "Format string") - (const :tag "No formatting"))) + (const :tag "No formatting" nil))) ;;;; Text markup @@ -556,7 +556,8 @@ returned as-is." ;;;; Drawers -(defcustom org-latex-format-drawer-function nil +(defcustom org-latex-format-drawer-function + (lambda (name contents) contents) "Function called to format a drawer in LaTeX code. The function must accept two parameters: @@ -565,19 +566,16 @@ The function must accept two parameters: The function should return the string to be exported. -For example, the variable could be set to the following function -in order to mimic default behaviour: - -\(defun org-latex-format-drawer-default \(name contents\) - \"Format a drawer element for LaTeX export.\" - contents\)" +The default function simply returns the value of CONTENTS." :group 'org-export-latex + :version "24.4" + :package-version '(Org . "8.3") :type 'function) ;;;; Inlinetasks -(defcustom org-latex-format-inlinetask-function nil +(defcustom org-latex-format-inlinetask-function 'ignore "Function called to format an inlinetask in LaTeX code. The function must accept six parameters: @@ -591,7 +589,7 @@ The function must accept six parameters: The function should return the string to be exported. For example, the variable could be set to the following function -in order to mimic default behaviour: +in order to mimic default behavior: \(defun org-latex-format-inlinetask \(todo type priority name tags contents\) \"Format an inline task element for LaTeX export.\" @@ -603,7 +601,7 @@ in order to mimic default behaviour: title \(when tags \(format \"\\\\hfill{}\\\\textsc{:%s:}\" - \(mapconcat 'identity tags \":\"))))) + \(mapconcat \\='identity tags \":\"))))) \(format (concat \"\\\\begin{center}\\n\" \"\\\\fbox{\\n\" \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\" @@ -628,21 +626,21 @@ listings package, and if you want to have color, the color package. Just add these to `org-latex-packages-alist', for example using customize, or with something like: - \(require 'ox-latex) - \(add-to-list 'org-latex-packages-alist '(\"\" \"listings\")) - \(add-to-list 'org-latex-packages-alist '(\"\" \"color\")) + \(require \\='ox-latex) + \(add-to-list \\='org-latex-packages-alist \\='(\"\" \"listings\")) + \(add-to-list \\='org-latex-packages-alist \\='(\"\" \"color\")) Alternatively, - \(setq org-latex-listings 'minted) + \(setq org-latex-listings \\='minted) causes source code to be exported using the minted package as opposed to listings. If you want to use minted, you need to add the minted package to `org-latex-packages-alist', for example using customize, or with - \(require 'ox-latex) - \(add-to-list 'org-latex-packages-alist '(\"\" \"minted\")) + \(require \\='ox-latex) + \(add-to-list \\='org-latex-packages-alist \\='(\"\" \"minted\")) In addition, it is necessary to install pygments \(http://pygments.org), and to configure the variable @@ -691,9 +689,9 @@ These options are supplied as a comma-separated list to the a list containing two strings: the name of the option, and the value. For example, - (setq org-latex-listings-options + \(setq org-latex-listings-options '((\"basicstyle\" \"\\\\small\") - (\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\"))) + \(\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\"))) will typeset the code in a small size font with underlined, bold black keywords. @@ -1000,7 +998,9 @@ See `org-latex-text-markup-alist' for details." ;; and use "\\verb" command. ((eq 'verb fmt) (let ((separator (org-latex--find-verb-separator text))) - (concat "\\verb" separator text separator))) + (concat "\\verb" separator + (replace-regexp-in-string "\n" " " text) + separator))) ;; Handle the `protectedtexttt' special case: Protect some ;; special chars and use "\texttt{%s}" format string. ((eq 'protectedtexttt fmt) @@ -1212,12 +1212,8 @@ channel." CONTENTS holds the contents of the block. INFO is a plist holding contextual information." (let* ((name (org-element-property :drawer-name drawer)) - (output (if (functionp org-latex-format-drawer-function) - (funcall org-latex-format-drawer-function - name contents) - ;; If there's no user defined function: simply - ;; display contents of the drawer. - contents))) + (output (funcall org-latex-format-drawer-function + name contents))) (org-latex--wrap-label drawer output))) @@ -1348,7 +1344,16 @@ holding contextual information." ((= (length sec) 4) (if numberedp (concat (car sec) "\n%s" (nth 1 sec)) (concat (nth 2 sec) "\n%s" (nth 3 sec))))))) - (text (org-export-data (org-element-property :title headline) info)) + ;; Create a temporary export back-end that hard-codes + ;; "\underline" within "\section" and alike. + (section-back-end + (org-export-create-backend + :parent 'latex + :transcoders + '((underline . (lambda (o c i) (format "\\underline{%s}" c)))))) + (text + (org-export-data-with-backend + (org-element-property :title headline) section-back-end info)) (todo (and (plist-get info :with-todo-keywords) (let ((todo (org-element-property :todo-keyword headline))) @@ -1380,7 +1385,13 @@ holding contextual information." (when (org-export-first-sibling-p headline info) (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize))) ;; Itemize headline - "\\item " full-text "\n" headline-label pre-blanks contents))) + "\\item" + (and full-text (org-string-match-p "\\`[ \t]*\\[" full-text) + "\\relax") + " " full-text "\n" + headline-label + pre-blanks + contents))) ;; If headline is not the last sibling simply return ;; LOW-LEVEL-BODY. Otherwise, also close the list, before ;; any blank line. @@ -1395,8 +1406,9 @@ holding contextual information." (let ((opt-title (funcall org-latex-format-headline-function todo todo-type priority - (org-export-data - (org-export-get-alt-title headline info) info) + (org-export-data-with-backend + (org-export-get-alt-title headline info) + section-back-end info) (and (eq (plist-get info :with-tags) t) tags)))) (if (and numberedp opt-title (not (equal opt-title full-text)) @@ -1464,7 +1476,7 @@ contextual information." (let* ((org-lang (org-element-property :language inline-src-block)) (mint-lang (or (cadr (assq (intern org-lang) org-latex-minted-langs)) - org-lang)) + (downcase org-lang))) (options (org-latex--make-option-string org-latex-minted-options))) (concat (format "\\mint%s{%s}" @@ -1502,7 +1514,7 @@ holding contextual information." (org-element-property :priority inlinetask)))) ;; If `org-latex-format-inlinetask-function' is provided, call it ;; with appropriate arguments. - (if (functionp org-latex-format-inlinetask-function) + (if (not (eq org-latex-format-inlinetask-function 'ignore)) (funcall org-latex-format-inlinetask-function todo todo-type priority title tags contents) ;; Otherwise, use a default template. @@ -1514,17 +1526,16 @@ holding contextual information." (when priority (format "\\framebox{\\#%c} " priority)) title (when tags (format "\\hfill{}\\textsc{:%s:}" - (mapconcat 'identity tags ":")))))) - (format (concat "\\begin{center}\n" - "\\fbox{\n" - "\\begin{minipage}[c]{.6\\textwidth}\n" - "%s\n\n" - "\\rule[.8em]{\\textwidth}{2pt}\n\n" - "%s" - "\\end{minipage}\n" - "}\n" - "\\end{center}") - full-title contents)))))) + (mapconcat #'identity tags ":")))))) + (concat "\\begin{center}\n" + "\\fbox{\n" + "\\begin{minipage}[c]{.6\\textwidth}\n" + full-title "\n\n" + (and (org-string-nw-p contents) + (concat "\\rule[.8em]{\\textwidth}{2pt}\n\n" contents)) + "\\end{minipage}\n" + "}\n" + "\\end{center}")))))) ;;;; Italic @@ -1570,7 +1581,25 @@ contextual information." (and tag (format "[{%s}] " (concat checkbox (org-export-data tag info))))))) - (concat counter "\\item" (or tag (concat " " checkbox)) + (concat counter + "\\item" + (cond + (tag) + (checkbox (concat " " checkbox)) + ;; Without a tag or a check-box, if CONTENTS starts with + ;; an opening square bracket, add "\relax" to "\item", + ;; unless the brackets comes from an initial export + ;; snippet (i.e. it is inserted willingly by the user). + ((and contents + (org-string-match-p "\\`[ \t]*\\[" contents) + (not (let ((e (car (org-element-contents item)))) + (and (eq (org-element-type e) 'paragraph) + (let ((o (car (org-element-contents e)))) + (and (eq (org-element-type o) 'export-snippet) + (eq (org-export-snippet-backend o) + 'latex))))))) + "\\relax ") + (t " ")) (and contents (org-trim contents)) ;; If there are footnotes references in tag, be sure to ;; add their definition at the end of the item. This @@ -1760,7 +1789,8 @@ DESC is the description part of the link, or the empty string. INFO is a plist holding contextual information. See `org-export-data'." (let* ((type (org-element-property :type link)) - (raw-path (org-element-property :path link)) + (raw-path (replace-regexp-in-string + "%" "\\%" (org-element-property :path link) nil t)) ;; Ensure DESC really exists, or set it to nil. (desc (and (not (string= desc "")) desc)) (imagep (org-export-inline-image-p @@ -1768,9 +1798,8 @@ INFO is a plist holding contextual information. See (path (cond ((member type '("http" "https" "ftp" "mailto")) (concat type ":" raw-path)) - ((string= type "file") - (if (not (file-name-absolute-p raw-path)) raw-path - (concat "file://" (expand-file-name raw-path)))) + ((and (string= type "file") (file-name-absolute-p raw-path)) + (concat "file:" raw-path)) (t raw-path))) protocol) (cond @@ -1780,10 +1809,11 @@ INFO is a plist holding contextual information. See ;; description. ((string= type "radio") (let ((destination (org-export-resolve-radio-link link info))) - (when destination + (if (not destination) desc (format "\\hyperref[%s]{%s}" - (org-export-solidify-link-text path) - (org-export-data (org-element-contents destination) info))))) + (org-export-solidify-link-text + (org-element-property :value destination)) + desc)))) ;; Links pointing to a headline: Find destination and build ;; appropriate referencing command. ((member type '("custom-id" "fuzzy" "id")) @@ -1812,7 +1842,8 @@ INFO is a plist holding contextual information. See 'number-to-string (org-export-get-headline-number destination info) "-")))) - (if (and (plist-get info :section-numbers) (not desc)) + (if (and (not desc) + (org-export-numbered-headline-p destination info)) (format "\\ref{%s}" label) (format "\\hyperref[%s]{%s}" label (or desc @@ -1859,18 +1890,13 @@ contextual information." (latex-type (let ((env (plist-get attr :environment))) (cond (env (format "%s" env)) ((eq type 'ordered) "enumerate") - ((eq type 'unordered) "itemize") - ((eq type 'descriptive) "description"))))) + ((eq type 'descriptive) "description") + (t "itemize"))))) (org-latex--wrap-label plain-list (format "\\begin{%s}%s\n%s\\end{%s}" latex-type - ;; Put optional arguments, if any inside square brackets - ;; when necessary. - (let ((options (format "%s" (or (plist-get attr :options) "")))) - (cond ((equal options "") "") - ((string-match "\\`\\[.*\\]\\'" options) options) - (t (format "[%s]" options)))) + (or (plist-get attr :options) "") contents latex-type)))) @@ -2089,7 +2115,8 @@ contextual information." ("firstnumber" ,(number-to-string (1+ num-start)))) org-latex-minted-options))) ;; Language. - (or (cadr (assq (intern lang) org-latex-minted-langs)) lang) + (or (cadr (assq (intern lang) org-latex-minted-langs)) + (downcase lang)) ;; Source code. (let* ((code-info (org-export-unravel-code src-block)) (max-width @@ -2138,8 +2165,8 @@ contextual information." ((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))) + (if label `(("label" ,label)) '(("label" " "))) + (if caption-str `(("caption" ,caption-str)) '(("caption" " "))) (cond ((assoc "numbers" org-latex-listings-options) nil) ((not num-start) '(("numbers" "none"))) ((zerop num-start) '(("numbers" "left"))) @@ -2819,7 +2846,7 @@ Return PDF file name or an error if it couldn't be produced." (file-name-directory full-name) default-directory)) errors) - (unless snippet (message (format "Processing LaTeX file %s..." texfile))) + (unless snippet (message "Processing LaTeX file %s..." texfile)) (save-window-excursion (cond ;; A function is provided: Apply it. @@ -2909,7 +2936,9 @@ Return output file name." ;; in working directory and then moved to publishing directory. (org-publish-attachment plist - (org-latex-compile (org-publish-org-to 'latex filename ".tex" plist)) + (org-latex-compile + (org-publish-org-to + 'latex filename ".tex" plist (file-name-directory filename))) pub-dir))