1 ;;; org-e-latex.el --- LaTeX Back-End For Org Export Engine
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; This library implements a LaTeX back-end for Org generic exporter.
25 ;; Depending on the desired output format, three commands are provided
26 ;; for export: `org-e-latex-export-as-latex' (temporary buffer),
27 ;; `org-e-latex-export-to-latex' ("tex" file) and
28 ;; `org-e-latex-export-to-pdf' ("pdf" file). Also, two publishing
29 ;; functions are available: `org-e-latex-publish-to-latex' and
30 ;; `org-e-latex-publish-to-pdf'.
32 ;; The library introduces three new buffer keywords: "LATEX_CLASS",
33 ;; "LATEX_CLASS_OPTIONS" and "LATEX_HEADER", and a new OPTIONS item:
36 ;; Table export can be controlled with a number of attributes (through
37 ;; ATTR_LATEX keyword).
39 ;; - The main one is the `:mode' attribute, which can be set to
40 ;; `table', `math', `inline-math' and `verbatim'. In particular,
41 ;; when in `math' or `inline-math' mode, every cell is exported
42 ;; as-is, horizontal rules are ignored and the table will be wrapped
43 ;; in a math environment. Also, contiguous tables sharing the same
44 ;; math mode will be wrapped within the same environment. Default
45 ;; mode is stored in `org-e-latex-default-table-mode'.
47 ;; - The second most important attribute is `:environment'. It is the
48 ;; environment used for the table and defaults to
49 ;; `org-e-latex-default-table-environment' value. It can be set to
50 ;; anything, including "tabularx", "longtable", "array",
53 ;; - `:float' attribute defines a float environment for the table.
54 ;; Possible values are `sidewaystable', `multicolumn' and `table'.
56 ;; - `:align', `:font' and `:width' attributes set, respectively, the
57 ;; alignment string of the table, its font size and its width. They
58 ;; only apply on regular tables.
60 ;; - `:booktabs', `:center' and `:rmlines' values are booleans. They
61 ;; toggle, respectively "booktabs" usage (assuming the package is
62 ;; properly loaded), table centering and removal of every horizontal
63 ;; rule but the first one (in a "table.el" table only).
65 ;; - `:math-prefix', `:math-suffix' and `:math-arguments' are string
66 ;; which will be inserted, respectively, before the table within the
67 ;; math environment, after the table within the math environment,
68 ;; and between the macro name and the contents of the table. The
69 ;; latter attribute is necessary to matrix macros that require more
70 ;; than one argument (i.e. "qbordermatrix").
72 ;; Plain lists accept two optional attributes: `:environment' and
73 ;; `:options'. The first one allows to use a non-standard environment
74 ;; (i.e. "inparaenum"). The second one allows to specify optional
75 ;; arguments for that environment (square brackets are not mandatory).
77 ;; Images accept `:float', `:placement', `:comment-include', and
78 ;; `:options' as attributes. `:float' accepts a symbol among `wrap',
79 ;; `multicolumn', and `figure', which defines the float environment
80 ;; for the table (if unspecified, an image with a caption will be set
81 ;; in a "figure" environment). `:comment-include' is a boolean that
82 ;; toggles whether to comment out the \includegraphics
83 ;; call. `:placement' is a string that will be used as argument for
84 ;; the environment chosen. `:options' is a string that will be used
85 ;; as the optional argument for "includegraphics" macro.
87 ;; This back-end also offers enhanced support for footnotes. Thus, it
88 ;; handles nested footnotes, footnotes in tables and footnotes in item
93 (eval-when-compile (require 'cl
))
95 (require 'org-e-publish
)
97 (defvar org-export-latex-default-packages-alist
)
98 (defvar org-export-latex-packages-alist
)
99 (defvar orgtbl-exp-regexp
)
105 (org-export-define-backend e-latex
106 ((bold . org-e-latex-bold
)
107 (center-block . org-e-latex-center-block
)
108 (clock . org-e-latex-clock
)
109 (code . org-e-latex-code
)
110 (drawer . org-e-latex-drawer
)
111 (dynamic-block . org-e-latex-dynamic-block
)
112 (entity . org-e-latex-entity
)
113 (example-block . org-e-latex-example-block
)
114 (export-block . org-e-latex-export-block
)
115 (export-snippet . org-e-latex-export-snippet
)
116 (fixed-width . org-e-latex-fixed-width
)
117 (footnote-definition . org-e-latex-footnote-definition
)
118 (footnote-reference . org-e-latex-footnote-reference
)
119 (headline . org-e-latex-headline
)
120 (horizontal-rule . org-e-latex-horizontal-rule
)
121 (inline-src-block . org-e-latex-inline-src-block
)
122 (inlinetask . org-e-latex-inlinetask
)
123 (italic . org-e-latex-italic
)
124 (item . org-e-latex-item
)
125 (keyword . org-e-latex-keyword
)
126 (latex-environment . org-e-latex-latex-environment
)
127 (latex-fragment . org-e-latex-latex-fragment
)
128 (line-break . org-e-latex-line-break
)
129 (link . org-e-latex-link
)
130 (paragraph . org-e-latex-paragraph
)
131 (plain-list . org-e-latex-plain-list
)
132 (plain-text . org-e-latex-plain-text
)
133 (planning . org-e-latex-planning
)
134 (property-drawer . org-e-latex-property-drawer
)
135 (quote-block . org-e-latex-quote-block
)
136 (quote-section . org-e-latex-quote-section
)
137 (radio-target . org-e-latex-radio-target
)
138 (section . org-e-latex-section
)
139 (special-block . org-e-latex-special-block
)
140 (src-block . org-e-latex-src-block
)
141 (statistics-cookie . org-e-latex-statistics-cookie
)
142 (strike-through . org-e-latex-strike-through
)
143 (subscript . org-e-latex-subscript
)
144 (superscript . org-e-latex-superscript
)
145 (table . org-e-latex-table
)
146 (table-cell . org-e-latex-table-cell
)
147 (table-row . org-e-latex-table-row
)
148 (target . org-e-latex-target
)
149 (template . org-e-latex-template
)
150 (timestamp . org-e-latex-timestamp
)
151 (underline . org-e-latex-underline
)
152 (verbatim . org-e-latex-verbatim
)
153 (verse-block . org-e-latex-verse-block
))
154 :export-block
("LATEX" "TEX")
156 (?l
"Export to LaTeX"
157 ((?L
"As TEX buffer" org-e-latex-export-as-latex
)
158 (?l
"As TEX file" org-e-latex-export-to-latex
)
159 (?p
"As PDF file" org-e-latex-export-to-pdf
)
160 (?o
"As PDF file and open"
162 (if a
(org-e-latex-export-to-pdf t s v b
)
163 (org-open-file (org-e-latex-export-to-pdf nil s v b
)))))))
164 :options-alist
((:date
"DATE" nil org-e-latex-date-format t
)
165 (:latex-class
"LATEX_CLASS" nil org-e-latex-default-class t
)
166 (:latex-class-options
"LATEX_CLASS_OPTIONS" nil nil t
)
167 (:latex-header-extra
"LATEX_HEADER" nil nil newline
)
168 (:latex-hyperref-p nil
"texht" org-e-latex-with-hyperref t
)))
172 ;;; Internal Variables
174 (defconst org-e-latex-babel-language-alist
175 '(("af" .
"afrikaans")
177 ("bt-br" .
"brazilian")
183 ("de-at" .
"naustrian")
184 ("de-de" .
"ngerman")
187 ("en-au" .
"australian")
188 ("en-ca" .
"canadian")
189 ("en-gb" .
"british")
191 ("en-nz" .
"newzealand")
192 ("en-us" .
"american")
198 ("fr-ca" .
"canadien")
202 ("id" .
"indonesian")
208 ("no-no" .
"nynorsk")
210 ("pt" .
"portuguese")
214 ("sb" .
"uppersorbian")
222 ("uk" .
"ukrainian"))
223 "Alist between language code and corresponding Babel option.")
225 (defconst org-e-latex-table-matrix-macros
'(("bordermatrix" .
"\\cr")
226 ("qbordermatrix" .
"\\cr")
227 ("kbordermatrix" .
"\\\\"))
228 "Alist between matrix macros and their row ending.")
232 ;;; User Configurable Variables
234 (defgroup org-export-e-latex nil
235 "Options for exporting Org mode files to LaTeX."
236 :tag
"Org Export LaTeX"
242 (defcustom org-e-latex-default-class
"article"
243 "The default LaTeX class."
244 :group
'org-export-e-latex
245 :type
'(string :tag
"LaTeX class"))
247 (defcustom org-e-latex-classes
249 "\\documentclass[11pt]{article}"
250 ("\\section{%s}" .
"\\section*{%s}")
251 ("\\subsection{%s}" .
"\\subsection*{%s}")
252 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}")
253 ("\\paragraph{%s}" .
"\\paragraph*{%s}")
254 ("\\subparagraph{%s}" .
"\\subparagraph*{%s}"))
256 "\\documentclass[11pt]{report}"
257 ("\\part{%s}" .
"\\part*{%s}")
258 ("\\chapter{%s}" .
"\\chapter*{%s}")
259 ("\\section{%s}" .
"\\section*{%s}")
260 ("\\subsection{%s}" .
"\\subsection*{%s}")
261 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}"))
263 "\\documentclass[11pt]{book}"
264 ("\\part{%s}" .
"\\part*{%s}")
265 ("\\chapter{%s}" .
"\\chapter*{%s}")
266 ("\\section{%s}" .
"\\section*{%s}")
267 ("\\subsection{%s}" .
"\\subsection*{%s}")
268 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}")))
269 "Alist of LaTeX classes and associated header and structure.
270 If #+LaTeX_CLASS is set in the buffer, use its value and the
271 associated information. Here is the structure of each cell:
275 \(numbered-section . unnumbered-section\)
281 The HEADER-STRING is the header that will be inserted into the
282 LaTeX file. It should contain the \\documentclass macro, and
283 anything else that is needed for this setup. To this header, the
284 following commands will be added:
286 - Calls to \\usepackage for all packages mentioned in the
287 variables `org-export-latex-default-packages-alist' and
288 `org-export-latex-packages-alist'. Thus, your header
289 definitions should avoid to also request these packages.
291 - Lines specified via \"#+LaTeX_HEADER:\"
293 If you need more control about the sequence in which the header
294 is built up, or if you want to exclude one of these building
295 blocks for a particular class, you can use the following
296 macro-like placeholders.
298 [DEFAULT-PACKAGES] \\usepackage statements for default packages
299 [NO-DEFAULT-PACKAGES] do not include any of the default packages
300 [PACKAGES] \\usepackage statements for packages
301 [NO-PACKAGES] do not include the packages
302 [EXTRA] the stuff from #+LaTeX_HEADER
303 [NO-EXTRA] do not include #+LaTeX_HEADER stuff
307 \\documentclass{article}
308 [NO-DEFAULT-PACKAGES]
310 \\providecommand{\\alert}[1]{\\textbf{#1}}
313 will omit the default packages, and will include the
314 #+LaTeX_HEADER lines, then have a call to \\providecommand, and
315 then place \\usepackage commands based on the content of
316 `org-export-latex-packages-alist'.
318 If your header, `org-export-latex-default-packages-alist' or
319 `org-export-latex-packages-alist' inserts
320 \"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be
321 replaced with a coding system derived from
322 `buffer-file-coding-system'. See also the variable
323 `org-e-latex-inputenc-alist' for a way to influence this
326 The sectioning structure
327 ------------------------
329 The sectioning structure of the class is given by the elements
330 following the header string. For each sectioning level, a number
331 of strings is specified. A %s formatter is mandatory in each
332 section string and will be replaced by the title of the section.
334 Instead of a cons cell \(numbered . unnumbered\), you can also
335 provide a list of 2 or 4 elements,
337 \(numbered-open numbered-close\)
341 \(numbered-open numbered-close unnumbered-open unnumbered-close\)
343 providing opening and closing strings for a LaTeX environment
344 that should represent the document section. The opening clause
345 should have a %s to represent the section title.
347 Instead of a list of sectioning commands, you can also specify
348 a function name. That function will be called with two
349 parameters, the \(reduced) level of the headline, and a predicate
350 non-nil when the headline should be numbered. It must return
351 a format string in which the section title will be added."
352 :group
'org-export-e-latex
354 (list (string :tag
"LaTeX class")
355 (string :tag
"LaTeX header")
356 (repeat :tag
"Levels" :inline t
359 (string :tag
" numbered")
360 (string :tag
"unnumbered"))
361 (list :tag
"Environment"
362 (string :tag
"Opening (numbered)")
363 (string :tag
"Closing (numbered)")
364 (string :tag
"Opening (unnumbered)")
365 (string :tag
"Closing (unnumbered)"))
366 (function :tag
"Hook computing sectioning"))))))
368 (defcustom org-e-latex-inputenc-alist nil
369 "Alist of inputenc coding system names, and what should really be used.
370 For example, adding an entry
372 (\"utf8\" . \"utf8x\")
374 will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
375 are written as utf8 files."
376 :group
'org-export-e-latex
379 (string :tag
"Derived from buffer")
380 (string :tag
"Use this instead"))))
382 (defcustom org-e-latex-date-format
384 "Format string for \\date{...}."
385 :group
'org-export-e-latex
388 (defcustom org-e-latex-title-command
"\\maketitle"
389 "The command used to insert the title just after \\begin{document}.
390 If this string contains the formatting specification \"%s\" then
391 it will be used as a formatting string, passing the title as an
393 :group
'org-export-e-latex
396 (defcustom org-e-latex-toc-command
"\\tableofcontents\n\\vspace*{1cm}\n\n"
397 "LaTeX command to set the table of contents, list of figures...
398 This command only applies to the table of contents generated with
399 toc:nil option, not to those generated with #+TOC keyword."
400 :group
'org-export-e-latex
403 (defcustom org-e-latex-with-hyperref t
404 "Toggle insertion of \hypersetup{...} in the preamble."
405 :group
'org-export-e-latex
411 (defcustom org-e-latex-format-headline-function nil
412 "Function to format headline text.
414 This function will be called with 5 arguments:
415 TODO the todo keyword (string or nil).
416 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
417 PRIORITY the priority of the headline (integer or nil)
418 TEXT the main headline text (string).
419 TAGS the tags as a list of strings (list of strings or nil).
421 The function result will be used in the section format string.
423 As an example, one could set the variable to the following, in
424 order to reproduce the default set-up:
426 \(defun org-e-latex-format-headline (todo todo-type priority text tags)
427 \"Default format function for an headline.\"
429 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
431 \(format \"\\\\framebox{\\\\#%c} \" priority))
434 \(format \"\\\\hfill{}\\\\textsc{%s}\"
435 \(mapconcat 'identity tags \":\"))))"
436 :group
'org-export-e-latex
442 (defcustom org-e-latex-footnote-separator
"\\textsuperscript{,}\\,"
443 "Text used to separate footnotes."
444 :group
'org-export-e-latex
450 (defcustom org-e-latex-active-timestamp-format
"\\textit{%s}"
451 "A printf format string to be applied to active timestamps."
452 :group
'org-export-e-latex
455 (defcustom org-e-latex-inactive-timestamp-format
"\\textit{%s}"
456 "A printf format string to be applied to inactive timestamps."
457 :group
'org-export-e-latex
460 (defcustom org-e-latex-diary-timestamp-format
"\\textit{%s}"
461 "A printf format string to be applied to diary timestamps."
462 :group
'org-export-e-latex
468 (defcustom org-e-latex-image-default-option
"width=.9\\linewidth"
469 "Default option for images."
470 :group
'org-export-e-latex
473 (defcustom org-e-latex-default-figure-position
"htb"
474 "Default position for latex figures."
475 :group
'org-export-e-latex
478 (defcustom org-e-latex-inline-image-rules
479 '(("file" .
"\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\)\\'"))
480 "Rules characterizing image files that can be inlined into LaTeX.
482 A rule consists in an association whose key is the type of link
483 to consider, and value is a regexp that will be matched against
486 Note that, by default, the image extension *actually* allowed
487 depend on the way the LaTeX file is processed. When used with
488 pdflatex, pdf, jpg and png images are OK. When processing
489 through dvi to Postscript, only ps and eps are allowed. The
490 default we use here encompasses both."
491 :group
'org-export-e-latex
492 :type
'(alist :key-type
(string :tag
"Type")
493 :value-type
(regexp :tag
"Path")))
495 (defcustom org-e-latex-link-with-unknown-path-format
"\\texttt{%s}"
496 "Format string for links with unknown path type."
497 :group
'org-export-latex
503 (defcustom org-e-latex-default-table-environment
"tabular"
504 "Default environment used to build tables."
505 :group
'org-export-e-latex
508 (defcustom org-e-latex-default-table-mode
'table
509 "Default mode for tables.
511 Value can be a symbol among:
513 `table' Regular LaTeX table.
515 `math' In this mode, every cell is considered as being in math
516 mode and the complete table will be wrapped within a math
517 environment. It is particularly useful to write matrices.
519 `inline-math' This mode is almost the same as `math', but the
520 math environment will be inlined.
522 `verbatim' The table is exported as it appears in the Org
523 buffer, within a verbatim environment.
525 This value can be overridden locally with, i.e. \":mode math\" in
528 When modifying this variable, it may be useful to change
529 `org-e-latex-default-table-environment' accordingly."
530 :group
'org-export-e-latex
531 :type
'(choice (const :tag
"Table" table
)
532 (const :tag
"Matrix" math
)
533 (const :tag
"Inline matrix" inline-math
)
534 (const :tag
"Verbatim" verbatim
)))
536 (defcustom org-e-latex-tables-centered t
537 "When non-nil, tables are exported in a center environment."
538 :group
'org-export-e-latex
541 (defcustom org-e-latex-tables-booktabs nil
542 "When non-nil, display tables in a formal \"booktabs\" style.
543 This option assumes that the \"booktabs\" package is properly
544 loaded in the header of the document. This value can be ignored
545 locally with \":booktabs t\" and \":booktabs nil\" LaTeX
547 :group
'org-export-e-latex
550 (defcustom org-e-latex-table-caption-above t
551 "When non-nil, place caption string at the beginning of the table.
552 Otherwise, place it near the end."
553 :group
'org-export-e-latex
556 (defcustom org-e-latex-table-scientific-notation
"%s\\,(%s)"
557 "Format string to display numbers in scientific notation.
558 The format should have \"%s\" twice, for mantissa and exponent
559 \(i.e. \"%s\\\\times10^{%s}\").
561 When nil, no transformation is made."
562 :group
'org-export-e-latex
564 (string :tag
"Format string")
565 (const :tag
"No formatting")))
570 (defcustom org-e-latex-text-markup-alist
'((bold .
"\\textbf{%s}")
572 (italic .
"\\emph{%s}")
573 (strike-through .
"\\st{%s}")
574 (underline .
"\\underline{%s}")
575 (verbatim . protectedtexttt
))
576 "Alist of LaTeX expressions to convert text markup.
578 The key must be a symbol among `bold', `code', `italic',
579 `strike-through', `underline' and `verbatim'. The value is
580 a formatting string to wrap fontified text with.
582 Value can also be set to the following symbols: `verb' and
583 `protectedtexttt'. For the former, Org will use \"\\verb\" to
584 create a format string and select a delimiter character that
585 isn't in the string. For the latter, Org will use \"\\texttt\"
586 to typeset and try to protect special characters.
588 If no association can be found for a given markup, text will be
590 :group
'org-export-e-latex
592 :options
'(bold code italic strike-through underline verbatim
))
597 (defcustom org-e-latex-format-drawer-function nil
598 "Function called to format a drawer in LaTeX code.
600 The function must accept two parameters:
601 NAME the drawer name, like \"LOGBOOK\"
602 CONTENTS the contents of the drawer.
604 The function should return the string to be exported.
606 For example, the variable could be set to the following function
607 in order to mimic default behaviour:
609 \(defun org-e-latex-format-drawer-default \(name contents\)
610 \"Format a drawer element for LaTeX export.\"
612 :group
'org-export-e-latex
618 (defcustom org-e-latex-format-inlinetask-function nil
619 "Function called to format an inlinetask in LaTeX code.
621 The function must accept six parameters:
622 TODO the todo keyword, as a string
623 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
624 PRIORITY the inlinetask priority, as a string
625 NAME the inlinetask name, as a string.
626 TAGS the inlinetask tags, as a list of strings.
627 CONTENTS the contents of the inlinetask, as a string.
629 The function should return the string to be exported.
631 For example, the variable could be set to the following function
632 in order to mimic default behaviour:
634 \(defun org-e-latex-format-inlinetask \(todo type priority name tags contents\)
635 \"Format an inline task element for LaTeX export.\"
639 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo))
640 \(when priority (format \"\\\\framebox{\\\\#%c} \" priority))
643 \(format \"\\\\hfill{}\\\\textsc{:%s:}\"
644 \(mapconcat 'identity tags \":\")))))
645 \(format (concat \"\\\\begin{center}\\n\"
647 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
649 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
651 \"\\\\end{minipage}}\"
653 full-title contents))"
654 :group
'org-export-e-latex
660 (defcustom org-e-latex-listings nil
661 "Non-nil means export source code using the listings package.
662 This package will fontify source code, possibly even with color.
663 If you want to use this, you also need to make LaTeX use the
664 listings package, and if you want to have color, the color
665 package. Just add these to `org-export-latex-packages-alist',
666 for example using customize, or with something like:
668 \(require 'org-e-latex)
669 \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"listings\"))
670 \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"color\"))
674 \(setq org-e-latex-listings 'minted)
676 causes source code to be exported using the minted package as
677 opposed to listings. If you want to use minted, you need to add
678 the minted package to `org-export-latex-packages-alist', for
679 example using customize, or with
681 \(require 'org-e-latex)
682 \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"minted\"))
684 In addition, it is necessary to install pygments
685 \(http://pygments.org), and to configure the variable
686 `org-e-latex-pdf-process' so that the -shell-escape option is
688 :group
'org-export-e-latex
690 (const :tag
"Use listings" t
)
691 (const :tag
"Use minted" 'minted
)
692 (const :tag
"Export verbatim" nil
)))
694 (defcustom org-e-latex-listings-langs
695 '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
698 (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
699 (html "HTML") (xml "XML")
700 (tex "TeX") (latex "TeX")
701 (shell-script "bash")
703 (ocaml "Caml") (caml "Caml")
704 (sql "SQL") (sqlite "sql"))
705 "Alist mapping languages to their listing language counterpart.
706 The key is a symbol, the major mode symbol without the \"-mode\".
707 The value is the string that should be inserted as the language
708 parameter for the listings package. If the mode name and the
709 listings name are the same, the language does not need an entry
710 in this list - but it does not hurt if it is present."
711 :group
'org-export-e-latex
714 (symbol :tag
"Major mode ")
715 (string :tag
"Listings language"))))
717 (defcustom org-e-latex-listings-options nil
718 "Association list of options for the latex listings package.
720 These options are supplied as a comma-separated list to the
721 \\lstset command. Each element of the association list should be
722 a list containing two strings: the name of the option, and the
725 (setq org-e-latex-listings-options
726 '((\"basicstyle\" \"\\small\")
727 (\"keywordstyle\" \"\\color{black}\\bfseries\\underbar\")))
729 will typeset the code in a small size font with underlined, bold
732 Note that the same options will be applied to blocks of all
734 :group
'org-export-e-latex
737 (string :tag
"Listings option name ")
738 (string :tag
"Listings option value"))))
740 (defcustom org-e-latex-minted-langs
741 '((emacs-lisp "common-lisp")
744 (shell-script "bash")
746 "Alist mapping languages to their minted language counterpart.
747 The key is a symbol, the major mode symbol without the \"-mode\".
748 The value is the string that should be inserted as the language
749 parameter for the minted package. If the mode name and the
750 listings name are the same, the language does not need an entry
751 in this list - but it does not hurt if it is present.
753 Note that minted uses all lower case for language identifiers,
754 and that the full list of language identifiers can be obtained
757 pygmentize -L lexers"
758 :group
'org-export-e-latex
761 (symbol :tag
"Major mode ")
762 (string :tag
"Minted language"))))
764 (defcustom org-e-latex-minted-options nil
765 "Association list of options for the latex minted package.
767 These options are supplied within square brackets in
768 \\begin{minted} environments. Each element of the alist should
769 be a list containing two strings: the name of the option, and the
772 \(setq org-e-latex-minted-options
773 '\((\"bgcolor\" \"bg\") \(\"frame\" \"lines\")))
775 will result in src blocks being exported with
777 \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
779 as the start of the minted environment. Note that the same
780 options will be applied to blocks of all languages."
781 :group
'org-export-e-latex
784 (string :tag
"Minted option name ")
785 (string :tag
"Minted option value"))))
787 (defvar org-e-latex-custom-lang-environments nil
788 "Alist mapping languages to language-specific LaTeX environments.
790 It is used during export of src blocks by the listings and minted
791 latex packages. For example,
793 \(setq org-e-latex-custom-lang-environments
794 '\(\(python \"pythoncode\"\)\)\)
796 would have the effect that if org encounters begin_src python
797 during latex export it will output
806 (defcustom org-e-latex-pdf-process
807 '("pdflatex -interaction nonstopmode -output-directory %o %f"
808 "pdflatex -interaction nonstopmode -output-directory %o %f"
809 "pdflatex -interaction nonstopmode -output-directory %o %f")
810 "Commands to process a LaTeX file to a PDF file.
811 This is a list of strings, each of them will be given to the
812 shell as a command. %f in the command will be replaced by the
813 full file name, %b by the file base name (i.e. without directory
814 and extension parts) and %o by the base directory of the file.
816 The reason why this is a list is that it usually takes several
817 runs of `pdflatex', maybe mixed with a call to `bibtex'. Org
818 does not have a clever mechanism to detect which of these
819 commands have to be run to get to a stable result, and it also
820 does not do any error checking.
822 By default, Org uses 3 runs of `pdflatex' to do the processing.
823 If you have texi2dvi on your system and if that does not cause
824 the infamous egrep/locale bug:
826 http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
828 then `texi2dvi' is the superior choice. Org does offer it as one
829 of the customize options.
831 Alternatively, this may be a Lisp function that does the
832 processing, so you could use this to apply the machinery of
833 AUCTeX or the Emacs LaTeX mode. This function should accept the
834 file name as its single argument."
835 :group
'org-export-pdf
837 (repeat :tag
"Shell command sequence"
838 (string :tag
"Shell command"))
839 (const :tag
"2 runs of pdflatex"
840 ("pdflatex -interaction nonstopmode -output-directory %o %f"
841 "pdflatex -interaction nonstopmode -output-directory %o %f"))
842 (const :tag
"3 runs of pdflatex"
843 ("pdflatex -interaction nonstopmode -output-directory %o %f"
844 "pdflatex -interaction nonstopmode -output-directory %o %f"
845 "pdflatex -interaction nonstopmode -output-directory %o %f"))
846 (const :tag
"pdflatex,bibtex,pdflatex,pdflatex"
847 ("pdflatex -interaction nonstopmode -output-directory %o %f"
849 "pdflatex -interaction nonstopmode -output-directory %o %f"
850 "pdflatex -interaction nonstopmode -output-directory %o %f"))
851 (const :tag
"2 runs of xelatex"
852 ("xelatex -interaction nonstopmode -output-directory %o %f"
853 "xelatex -interaction nonstopmode -output-directory %o %f"))
854 (const :tag
"3 runs of xelatex"
855 ("xelatex -interaction nonstopmode -output-directory %o %f"
856 "xelatex -interaction nonstopmode -output-directory %o %f"
857 "xelatex -interaction nonstopmode -output-directory %o %f"))
858 (const :tag
"xelatex,bibtex,xelatex,xelatex"
859 ("xelatex -interaction nonstopmode -output-directory %o %f"
861 "xelatex -interaction nonstopmode -output-directory %o %f"
862 "xelatex -interaction nonstopmode -output-directory %o %f"))
863 (const :tag
"texi2dvi"
864 ("texi2dvi -p -b -c -V %f"))
866 ("rubber -d --into %o %f"))
869 (defcustom org-e-latex-logfiles-extensions
870 '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
871 "The list of file extensions to consider as LaTeX logfiles."
872 :group
'org-export-e-latex
873 :type
'(repeat (string :tag
"Extension")))
875 (defcustom org-e-latex-remove-logfiles t
876 "Non-nil means remove the logfiles produced by PDF production.
877 These are the .aux, .log, .out, and .toc files."
878 :group
'org-export-e-latex
881 (defcustom org-e-latex-known-errors
882 '(("Reference.*?undefined" .
"[undefined reference]")
883 ("Citation.*?undefined" .
"[undefined citation]")
884 ("Undefined control sequence" .
"[undefined control sequence]")
885 ("^! LaTeX.*?Error" .
"[LaTeX error]")
886 ("^! Package.*?Error" .
"[package error]")
887 ("Runaway argument" .
"Runaway argument"))
888 "Alist of regular expressions and associated messages for the user.
889 The regular expressions are used to find possible errors in the
891 :group
'org-export-e-latex
894 (string :tag
"Regexp")
895 (string :tag
"Message"))))
899 ;;; Internal Functions
901 (defun org-e-latex--caption/label-string
(element info
)
902 "Return caption and label LaTeX string for ELEMENT.
904 INFO is a plist holding contextual information. If there's no
905 caption nor label, return the empty string.
907 For non-floats, see `org-e-latex--wrap-label'."
908 (let* ((label (org-element-property :name element
))
909 (label-str (if (not (org-string-nw-p label
)) ""
910 (format "\\label{%s}"
911 (org-export-solidify-link-text label
))))
912 (main (org-export-get-caption element
))
913 (short (org-export-get-caption element t
)))
915 ((and (not main
) (equal label-str
"")) "")
916 ((not main
) (concat label-str
"\n"))
917 ;; Option caption format with short name.
918 (short (format "\\caption[%s]{%s%s}\n"
919 (org-export-data short info
)
921 (org-export-data main info
)))
922 ;; Standard caption format.
923 (t (format "\\caption{%s%s}\n" label-str
(org-export-data main info
))))))
925 (defun org-e-latex--guess-babel-language (header info
)
926 "Set Babel's language according to LANGUAGE keyword.
928 HEADER is the LaTeX header string. INFO is the plist used as
929 a communication channel.
931 Insertion of guessed language only happens when Babel package has
932 explicitly been loaded. Then it is added to the rest of
935 Return the new header."
936 (let ((language-code (plist-get info
:language
)))
937 ;; If no language is set or Babel package is not loaded, return
939 (if (or (not (stringp language-code
))
940 (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header
)))
942 (let ((options (save-match-data
943 (org-split-string (match-string 1 header
) ",")))
944 (language (cdr (assoc language-code
945 org-e-latex-babel-language-alist
))))
946 ;; If LANGUAGE is already loaded, return header. Otherwise,
947 ;; append LANGUAGE to other options.
948 (if (member language options
) header
949 (replace-match (mapconcat 'identity
950 (append options
(list language
))
952 nil nil header
1))))))
954 (defun org-e-latex--guess-inputenc (header)
955 "Set the coding system in inputenc to what the buffer is.
956 HEADER is the LaTeX header string. Return the new header."
957 (let* ((cs (or (ignore-errors
958 (latexenc-coding-system-to-inputenc
959 buffer-file-coding-system
))
962 ;; First translate if that is requested.
963 (setq cs
(or (cdr (assoc cs org-e-latex-inputenc-alist
)) cs
))
964 ;; Then find the \usepackage statement and replace the option.
965 (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
966 cs header t nil
1))))
968 (defun org-e-latex--find-verb-separator (s)
969 "Return a character not used in string S.
970 This is used to choose a separator for constructs like \\verb."
971 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
972 (loop for c across ll
973 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
974 return
(char-to-string c
))))
976 (defun org-e-latex--make-option-string (options)
977 "Return a comma separated string of keywords and values.
978 OPTIONS is an alist where the key is the options keyword as
979 a string, and the value a list containing the keyword value, or
981 (mapconcat (lambda (pair)
983 (when (> (length (second pair
)) 0)
984 (concat "=" (second pair
)))))
988 (defun org-e-latex--wrap-label (element output
)
989 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
990 This function shouldn't be used for floats. See
991 `org-e-latex--caption/label-string'."
992 (let ((label (org-element-property :name element
)))
993 (if (not (and (org-string-nw-p output
) (org-string-nw-p label
))) output
994 (concat (format "\\label{%s}\n" (org-export-solidify-link-text label
))
997 (defun org-e-latex--text-markup (text markup
)
998 "Format TEXT depending on MARKUP text markup.
999 See `org-e-latex-text-markup-alist' for details."
1000 (let ((fmt (cdr (assq markup org-e-latex-text-markup-alist
))))
1002 ;; No format string: Return raw text.
1004 ;; Handle the `verb' special case: Find and appropriate separator
1005 ;; and use "\\verb" command.
1007 (let ((separator (org-e-latex--find-verb-separator text
)))
1008 (concat "\\verb" separator text separator
)))
1009 ;; Handle the `protectedtexttt' special case: Protect some
1010 ;; special chars and use "\texttt{%s}" format string.
1011 ((eq 'protectedtexttt fmt
)
1013 (trans '(("\\" .
"\\textbackslash{}")
1014 ("~" .
"\\textasciitilde{}")
1015 ("^" .
"\\textasciicircum{}")))
1018 (while (string-match "[\\{}$%&_#~^]" text
)
1019 (setq char
(match-string 0 text
))
1020 (if (> (match-beginning 0) 0)
1021 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
1022 (setq text
(substring text
(1+ (match-beginning 0))))
1023 (setq char
(or (cdr (assoc char trans
)) (concat "\\" char
))
1024 rtn
(concat rtn char
)))
1025 (setq text
(concat rtn text
)
1027 (while (string-match "--" text
)
1028 (setq text
(replace-match "-{}-" t t text
)))
1030 ;; Else use format string.
1031 (t (format fmt text
)))))
1033 (defun org-e-latex--delayed-footnotes-definitions (element info
)
1034 "Return footnotes definitions in ELEMENT as a string.
1036 INFO is a plist used as a communication channel.
1038 Footnotes definitions are returned within \"\\footnotetxt{}\"
1041 This function is used within constructs that don't support
1042 \"\\footnote{}\" command (i.e. an item's tag). In that case,
1043 \"\\footnotemark\" is used within the construct and the function
1044 just outside of it."
1048 "\\footnotetext[%s]{%s}"
1049 (org-export-get-footnote-number ref info
)
1052 (org-export-get-footnote-definition ref info
) info
))))
1053 ;; Find every footnote reference in ELEMENT.
1055 search-refs
; For byte-compiler.
1059 ;; Return a list of all footnote references never seen
1062 data
'footnote-reference
1064 (when (org-export-footnote-first-reference-p ref info
)
1066 (when (eq (org-element-property :type ref
) 'standard
)
1067 (funcall search-refs
1068 (org-export-get-footnote-definition ref info
)))))
1070 (reverse all-refs
)))))
1071 (funcall search-refs element
))
1078 (defun org-e-latex-template (contents info
)
1079 "Return complete document string after LaTeX conversion.
1080 CONTENTS is the transcoded contents string. INFO is a plist
1081 holding export options."
1082 (let ((title (org-export-data (plist-get info
:title
) info
)))
1085 (and (plist-get info
:time-stamp-file
)
1086 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
1087 ;; Document class and packages.
1088 (let ((class (plist-get info
:latex-class
))
1089 (class-options (plist-get info
:latex-class-options
)))
1090 (org-element-normalize-string
1091 (let* ((header (nth 1 (assoc class org-e-latex-classes
)))
1092 (document-class-string
1093 (and (stringp header
)
1094 (if (not class-options
) header
1095 (replace-regexp-in-string
1096 "^[ \t]*\\\\documentclass\\(\\(\\[.*\\]\\)?\\)"
1097 class-options header t nil
1)))))
1098 (when document-class-string
1099 (org-e-latex--guess-babel-language
1100 (org-e-latex--guess-inputenc
1101 (org-splice-latex-header
1102 document-class-string
1103 org-export-latex-default-packages-alist
; defined in org.el
1104 org-export-latex-packages-alist nil
; defined in org.el
1105 (plist-get info
:latex-header-extra
)))
1107 ;; Possibly limit depth for headline numbering.
1108 (let ((sec-num (plist-get info
:section-numbers
)))
1109 (when (integerp sec-num
)
1110 (format "\\setcounter{secnumdepth}{%d}\n" sec-num
)))
1112 (let ((author (and (plist-get info
:with-author
)
1113 (let ((auth (plist-get info
:author
)))
1114 (and auth
(org-export-data auth info
)))))
1115 (email (and (plist-get info
:with-email
)
1116 (org-export-data (plist-get info
:email
) info
))))
1117 (cond ((and author email
(not (string= "" email
)))
1118 (format "\\author{%s\\thanks{%s}}\n" author email
))
1119 ((or author email
) (format "\\author{%s}\n" (or author email
)))))
1121 (let ((date (and (plist-get info
:with-date
)
1122 (org-export-data (plist-get info
:date
) info
))))
1123 (format "\\date{%s}\n" (or date
"")))
1125 (format "\\title{%s}\n" title
)
1126 ;; Hyperref options.
1127 (when (plist-get info
:latex-hyperref-p
)
1128 (format "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={%s}}\n"
1129 (or (plist-get info
:keywords
) "")
1130 (or (plist-get info
:description
) "")
1131 (if (not (plist-get info
:with-creator
)) ""
1132 (plist-get info
:creator
))))
1134 "\\begin{document}\n\n"
1136 (org-element-normalize-string
1137 (cond ((string= "" title
) nil
)
1138 ((not (stringp org-e-latex-title-command
)) nil
)
1139 ((string-match "\\(?:[^%]\\|^\\)%s"
1140 org-e-latex-title-command
)
1141 (format org-e-latex-title-command title
))
1142 (t org-e-latex-title-command
)))
1143 ;; Table of contents.
1144 (let ((depth (plist-get info
:with-toc
)))
1146 (concat (when (wholenump depth
)
1147 (format "\\setcounter{tocdepth}{%d}\n" depth
))
1148 org-e-latex-toc-command
)))
1152 (let ((creator-info (plist-get info
:with-creator
)))
1154 ((not creator-info
) "")
1155 ((eq creator-info
'comment
)
1156 (format "%% %s\n" (plist-get info
:creator
)))
1157 (t (concat (plist-get info
:creator
) "\n"))))
1159 "\\end{document}")))
1163 ;;; Transcode Functions
1167 (defun org-e-latex-bold (bold contents info
)
1168 "Transcode BOLD from Org to LaTeX.
1169 CONTENTS is the text with bold markup. INFO is a plist holding
1170 contextual information."
1171 (org-e-latex--text-markup contents
'bold
))
1176 (defun org-e-latex-center-block (center-block contents info
)
1177 "Transcode a CENTER-BLOCK element from Org to LaTeX.
1178 CONTENTS holds the contents of the center block. INFO is a plist
1179 holding contextual information."
1180 (org-e-latex--wrap-label
1182 (format "\\begin{center}\n%s\\end{center}" contents
)))
1187 (defun org-e-latex-clock (clock contents info
)
1188 "Transcode a CLOCK element from Org to LaTeX.
1189 CONTENTS is nil. INFO is a plist holding contextual
1193 (format "\\textbf{%s} " org-clock-string
)
1194 (format org-e-latex-inactive-timestamp-format
1195 (concat (org-translate-time
1196 (org-element-property :raw-value
1197 (org-element-property :value clock
)))
1198 (let ((time (org-element-property :duration clock
)))
1199 (and time
(format " (%s)" time
)))))
1205 (defun org-e-latex-code (code contents info
)
1206 "Transcode a CODE object from Org to LaTeX.
1207 CONTENTS is nil. INFO is a plist used as a communication
1209 (org-e-latex--text-markup (org-element-property :value code
) 'code
))
1214 (defun org-e-latex-drawer (drawer contents info
)
1215 "Transcode a DRAWER element from Org to LaTeX.
1216 CONTENTS holds the contents of the block. INFO is a plist
1217 holding contextual information."
1218 (let* ((name (org-element-property :drawer-name drawer
))
1219 (output (if (functionp org-e-latex-format-drawer-function
)
1220 (funcall org-e-latex-format-drawer-function
1222 ;; If there's no user defined function: simply
1223 ;; display contents of the drawer.
1225 (org-e-latex--wrap-label drawer output
)))
1230 (defun org-e-latex-dynamic-block (dynamic-block contents info
)
1231 "Transcode a DYNAMIC-BLOCK element from Org to LaTeX.
1232 CONTENTS holds the contents of the block. INFO is a plist
1233 holding contextual information. See `org-export-data'."
1234 (org-e-latex--wrap-label dynamic-block contents
))
1239 (defun org-e-latex-entity (entity contents info
)
1240 "Transcode an ENTITY object from Org to LaTeX.
1241 CONTENTS are the definition itself. INFO is a plist holding
1242 contextual information."
1243 (let ((ent (org-element-property :latex entity
)))
1244 (if (org-element-property :latex-math-p entity
) (format "$%s$" ent
) ent
)))
1249 (defun org-e-latex-example-block (example-block contents info
)
1250 "Transcode an EXAMPLE-BLOCK element from Org to LaTeX.
1251 CONTENTS is nil. INFO is a plist holding contextual
1253 (org-e-latex--wrap-label
1255 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1256 (org-export-format-code-default example-block info
))))
1261 (defun org-e-latex-export-block (export-block contents info
)
1262 "Transcode a EXPORT-BLOCK element from Org to LaTeX.
1263 CONTENTS is nil. INFO is a plist holding contextual information."
1264 (when (member (org-element-property :type export-block
) '("LATEX" "TEX"))
1265 (org-remove-indentation (org-element-property :value export-block
))))
1270 (defun org-e-latex-export-snippet (export-snippet contents info
)
1271 "Transcode a EXPORT-SNIPPET object from Org to LaTeX.
1272 CONTENTS is nil. INFO is a plist holding contextual information."
1273 (when (eq (org-export-snippet-backend export-snippet
) 'e-latex
)
1274 (org-element-property :value export-snippet
)))
1279 (defun org-e-latex-fixed-width (fixed-width contents info
)
1280 "Transcode a FIXED-WIDTH element from Org to LaTeX.
1281 CONTENTS is nil. INFO is a plist holding contextual information."
1282 (org-e-latex--wrap-label
1284 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1285 (org-remove-indentation
1286 (org-element-property :value fixed-width
)))))
1289 ;;;; Footnote Reference
1291 ;; Footnote reference export is handled by
1292 ;; `org-e-latex-footnote-reference'.
1294 ;; Internally, `org-e-latex--get-footnote-counter' is used to restore
1295 ;; the value of the LaTeX "footnote" counter after a jump due to
1296 ;; a reference to an already defined footnote. It is only needed in
1297 ;; item tags since the optional argument to \footnotemark is not
1300 (defun org-e-latex--get-footnote-counter (footnote-reference info
)
1301 "Return \"footnote\" counter before FOOTNOTE-REFERENCE is encountered.
1302 INFO is a plist used as a communication channel."
1303 ;; Find original counter value by counting number of footnote
1304 ;; references appearing for the first time before the current
1305 ;; footnote reference.
1306 (let* ((label (org-element-property :label footnote-reference
))
1308 search-ref
; For byte-compiler.
1312 ;; Search footnote references through DATA, filling
1313 ;; SEEN-REFS along the way.
1315 data
'footnote-reference
1317 (let ((fn-lbl (org-element-property :label fn
)))
1319 ;; Anonymous footnote match: return number.
1320 ((eq fn footnote-reference
) (length seen-refs
))
1321 ;; Anonymous footnote: it's always a new one.
1322 ;; Also, be sure to return nil from the `cond' so
1323 ;; `first-match' doesn't get us out of the loop.
1324 ((not fn-lbl
) (push 'inline seen-refs
) nil
)
1325 ;; Label not seen so far: add it so SEEN-REFS.
1327 ;; Also search for subsequent references in
1328 ;; footnote definition so numbering follows reading
1329 ;; logic. Note that we don't have to care about
1330 ;; inline definitions, since `org-element-map'
1331 ;; already traverse them at the right time.
1332 ((not (member fn-lbl seen-refs
))
1333 (push fn-lbl seen-refs
)
1335 (org-export-get-footnote-definition fn info
))))))
1336 ;; Don't enter footnote definitions since it will happen
1337 ;; when their first reference is found.
1338 info
'first-match
'footnote-definition
)))))
1339 (funcall search-ref
(plist-get info
:parse-tree
))))
1341 (defun org-e-latex-footnote-reference (footnote-reference contents info
)
1342 "Transcode a FOOTNOTE-REFERENCE element from Org to LaTeX.
1343 CONTENTS is nil. INFO is a plist holding contextual information."
1345 ;; Insert separator between two footnotes in a row.
1346 (let ((prev (org-export-get-previous-element footnote-reference info
)))
1347 (when (eq (org-element-type prev
) 'footnote-reference
)
1348 org-e-latex-footnote-separator
))
1350 ;; Use \footnotemark if reference is within an item's tag.
1351 ((eq (org-element-type (org-export-get-parent-element footnote-reference
))
1353 (if (org-export-footnote-first-reference-p footnote-reference info
)
1355 ;; Since we can't specify footnote number as an optional
1356 ;; argument within an item tag, some extra work has to be done
1357 ;; when the footnote has already been referenced. In that
1358 ;; case, set footnote counter to the desired number, use the
1359 ;; footnotemark, then set counter back to its original value.
1361 "\\setcounter{footnote}{%s}\\footnotemark\\setcounter{footnote}{%s}"
1362 (1- (org-export-get-footnote-number footnote-reference info
))
1363 (org-e-latex--get-footnote-counter footnote-reference info
))))
1364 ;; Use \footnotemark if the footnote has already been defined.
1365 ((not (org-export-footnote-first-reference-p footnote-reference info
))
1366 (format "\\footnotemark[%s]{}"
1367 (org-export-get-footnote-number footnote-reference info
)))
1368 ;; Use \footnotemark if reference is within another footnote
1369 ;; reference, footnote definition or table cell.
1370 ((loop for parent in
(org-export-get-genealogy footnote-reference
)
1371 thereis
(memq (org-element-type parent
)
1372 '(footnote-reference footnote-definition table-cell
)))
1374 ;; Otherwise, define it with \footnote command.
1376 (let ((def (org-export-get-footnote-definition footnote-reference info
)))
1377 (unless (eq (org-element-type def
) 'org-data
)
1378 (setq def
(cons 'org-data
(cons nil def
))))
1380 (format "\\footnote{%s}" (org-trim (org-export-data def info
)))
1381 ;; Retrieve all footnote references within the footnote and
1382 ;; add their definition after it, since LaTeX doesn't support
1384 (org-e-latex--delayed-footnotes-definitions def info
)))))))
1389 (defun org-e-latex-headline (headline contents info
)
1390 "Transcode an HEADLINE element from Org to LaTeX.
1391 CONTENTS holds the contents of the headline. INFO is a plist
1392 holding contextual information."
1393 (let* ((class (plist-get info
:latex-class
))
1394 (level (org-export-get-relative-level headline info
))
1395 (numberedp (org-export-numbered-headline-p headline info
))
1396 (class-sectionning (assoc class org-e-latex-classes
))
1397 ;; Section formatting will set two placeholders: one for the
1398 ;; title and the other for the contents.
1400 (let ((sec (if (and (symbolp (nth 2 class-sectionning
))
1401 (fboundp (nth 2 class-sectionning
)))
1402 (funcall (nth 2 class-sectionning
) level numberedp
)
1403 (nth (1+ level
) class-sectionning
))))
1405 ;; No section available for that LEVEL.
1407 ;; Section format directly returned by a function.
1409 ;; (numbered-section . unnumbered-section)
1410 ((not (consp (cdr sec
)))
1411 (concat (funcall (if numberedp
#'car
#'cdr
) sec
) "\n%s"))
1412 ;; (numbered-open numbered-close)
1414 (when numberedp
(concat (car sec
) "\n%s" (nth 1 sec
))))
1415 ;; (num-in num-out no-num-in no-num-out)
1417 (if numberedp
(concat (car sec
) "\n%s" (nth 1 sec
))
1418 (concat (nth 2 sec
) "\n%s" (nth 3 sec
)))))))
1419 (text (org-export-data (org-element-property :title headline
) info
))
1421 (and (plist-get info
:with-todo-keywords
)
1422 (let ((todo (org-element-property :todo-keyword headline
)))
1423 (and todo
(org-export-data todo info
)))))
1424 (todo-type (and todo
(org-element-property :todo-type headline
)))
1425 (tags (and (plist-get info
:with-tags
)
1426 (org-export-get-tags headline info
)))
1427 (priority (and (plist-get info
:with-priority
)
1428 (org-element-property :priority headline
)))
1429 ;; Create the headline text along with a no-tag version. The
1430 ;; latter is required to remove tags from table of contents.
1431 (full-text (if (functionp org-e-latex-format-headline-function
)
1432 ;; User-defined formatting function.
1433 (funcall org-e-latex-format-headline-function
1434 todo todo-type priority text tags
)
1435 ;; Default formatting.
1438 (format "\\textbf{\\textsf{\\textsc{%s}}} " todo
))
1439 (when priority
(format "\\framebox{\\#%c} " priority
))
1442 (format "\\hfill{}\\textsc{:%s:}"
1443 (mapconcat 'identity tags
":"))))))
1445 (if (functionp org-e-latex-format-headline-function
)
1446 ;; User-defined formatting function.
1447 (funcall org-e-latex-format-headline-function
1448 todo todo-type priority text nil
)
1449 ;; Default formatting.
1451 (when todo
(format "\\textbf{\\textsf{\\textsc{%s}}} " todo
))
1452 (when priority
(format "\\framebox{\\#%c} " priority
))
1454 ;; Associate some \label to the headline for internal links.
1456 (format "\\label{sec-%s}\n"
1457 (mapconcat 'number-to-string
1458 (org-export-get-headline-number headline info
)
1461 (make-string (org-element-property :pre-blank headline
) 10)))
1463 ;; Case 1: This is a footnote section: ignore it.
1464 ((org-element-property :footnote-section-p headline
) nil
)
1465 ;; Case 2. This is a deep sub-tree: export it as a list item.
1466 ;; Also export as items headlines for which no section
1467 ;; format has been found.
1468 ((or (not section-fmt
) (org-export-low-level-p headline info
))
1469 ;; Build the real contents of the sub-tree.
1470 (let ((low-level-body
1472 ;; If the headline is the first sibling, start a list.
1473 (when (org-export-first-sibling-p headline info
)
1474 (format "\\begin{%s}\n" (if numberedp
'enumerate
'itemize
)))
1476 "\\item " full-text
"\n" headline-label pre-blanks contents
)))
1477 ;; If headline is not the last sibling simply return
1478 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
1480 (if (not (org-export-last-sibling-p headline info
)) low-level-body
1481 (replace-regexp-in-string
1483 (format "\n\\\\end{%s}" (if numberedp
'enumerate
'itemize
))
1485 ;; Case 3. Standard headline. Export it as a section.
1488 ((not (and tags
(eq (plist-get info
:with-tags
) 'not-in-toc
)))
1489 ;; Regular section. Use specified format string.
1490 (format section-fmt full-text
1491 (concat headline-label pre-blanks contents
)))
1492 ((string-match "\\`\\\\\\(.*?\\){" section-fmt
)
1493 ;; If tags should be removed from table of contents, insert
1494 ;; title without tags as an alternative heading in sectioning
1496 (format (replace-match (concat (match-string 1 section-fmt
) "[%s]")
1497 nil nil section-fmt
1)
1498 ;; Replace square brackets with parenthesis since
1499 ;; square brackets are not supported in optional
1501 (replace-regexp-in-string
1503 (replace-regexp-in-string
1507 (concat headline-label pre-blanks contents
)))
1509 ;; Impossible to add an alternative heading. Fallback to
1510 ;; regular sectioning format string.
1511 (format section-fmt full-text
1512 (concat headline-label pre-blanks contents
))))))))
1515 ;;;; Horizontal Rule
1517 (defun org-e-latex-horizontal-rule (horizontal-rule contents info
)
1518 "Transcode an HORIZONTAL-RULE object from Org to LaTeX.
1519 CONTENTS is nil. INFO is a plist holding contextual information."
1520 (let ((attr (org-export-read-attribute :attr_latex horizontal-rule
))
1521 (prev (org-export-get-previous-element horizontal-rule info
)))
1523 ;; Make sure the rule doesn't start at the end of the current
1524 ;; line by separating it with a blank line from previous element.
1526 (let ((prev-blank (org-element-property :post-blank prev
)))
1527 (or (not prev-blank
) (zerop prev-blank
))))
1529 (org-e-latex--wrap-label
1531 (format "\\rule{%s}{%s}"
1532 (or (plist-get attr
:width
) "\\linewidth")
1533 (or (plist-get attr
:thickness
) "0.5pt"))))))
1536 ;;;; Inline Src Block
1538 (defun org-e-latex-inline-src-block (inline-src-block contents info
)
1539 "Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
1540 CONTENTS holds the contents of the item. INFO is a plist holding
1541 contextual information."
1542 (let* ((code (org-element-property :value inline-src-block
))
1543 (separator (org-e-latex--find-verb-separator code
)))
1545 ;; Do not use a special package: transcode it verbatim.
1546 ((not org-e-latex-listings
)
1547 (concat "\\verb" separator code separator
))
1548 ;; Use minted package.
1549 ((eq org-e-latex-listings
'minted
)
1550 (let* ((org-lang (org-element-property :language inline-src-block
))
1551 (mint-lang (or (cadr (assq (intern org-lang
)
1552 org-e-latex-minted-langs
))
1554 (options (org-e-latex--make-option-string
1555 org-e-latex-minted-options
)))
1556 (concat (format "\\mint%s{%s}"
1557 (if (string= options
"") "" (format "[%s]" options
))
1559 separator code separator
)))
1560 ;; Use listings package.
1562 ;; Maybe translate language's name.
1563 (let* ((org-lang (org-element-property :language inline-src-block
))
1564 (lst-lang (or (cadr (assq (intern org-lang
)
1565 org-e-latex-listings-langs
))
1567 (options (org-e-latex--make-option-string
1568 (append org-e-latex-listings-options
1569 `(("language" ,lst-lang
))))))
1570 (concat (format "\\lstinline[%s]" options
)
1571 separator code separator
))))))
1576 (defun org-e-latex-inlinetask (inlinetask contents info
)
1577 "Transcode an INLINETASK element from Org to LaTeX.
1578 CONTENTS holds the contents of the block. INFO is a plist
1579 holding contextual information."
1580 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1581 (todo (and (plist-get info
:with-todo-keywords
)
1582 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1583 (and todo
(org-export-data todo info
)))))
1584 (todo-type (org-element-property :todo-type inlinetask
))
1585 (tags (and (plist-get info
:with-tags
)
1586 (org-export-get-tags inlinetask info
)))
1587 (priority (and (plist-get info
:with-priority
)
1588 (org-element-property :priority inlinetask
))))
1589 ;; If `org-e-latex-format-inlinetask-function' is provided, call it
1590 ;; with appropriate arguments.
1591 (if (functionp org-e-latex-format-inlinetask-function
)
1592 (funcall org-e-latex-format-inlinetask-function
1593 todo todo-type priority title tags contents
)
1594 ;; Otherwise, use a default template.
1595 (org-e-latex--wrap-label
1599 (when todo
(format "\\textbf{\\textsf{\\textsc{%s}}} " todo
))
1600 (when priority
(format "\\framebox{\\#%c} " priority
))
1602 (when tags
(format "\\hfill{}\\textsc{:%s:}"
1603 (mapconcat 'identity tags
":"))))))
1604 (format (concat "\\begin{center}\n"
1606 "\\begin{minipage}[c]{.6\\textwidth}\n"
1608 "\\rule[.8em]{\\textwidth}{2pt}\n\n"
1613 full-title contents
))))))
1618 (defun org-e-latex-italic (italic contents info
)
1619 "Transcode ITALIC from Org to LaTeX.
1620 CONTENTS is the text with italic markup. INFO is a plist holding
1621 contextual information."
1622 (org-e-latex--text-markup contents
'italic
))
1627 (defun org-e-latex-item (item contents info
)
1628 "Transcode an ITEM element from Org to LaTeX.
1629 CONTENTS holds the contents of the item. INFO is a plist holding
1630 contextual information."
1632 (let ((count (org-element-property :counter item
))
1634 (loop for parent in
(org-export-get-genealogy item
)
1635 count
(eq (org-element-type parent
) 'plain-list
)
1636 until
(eq (org-element-type parent
) 'headline
))))
1639 (format "\\setcounter{enum%s}{%s}\n"
1640 (nth (1- level
) '("i" "ii" "iii" "iv"))
1642 (checkbox (case (org-element-property :checkbox item
)
1643 (on "$\\boxtimes$ ")
1645 (trans "$\\boxminus$ ")))
1646 (tag (let ((tag (org-element-property :tag item
)))
1647 ;; Check-boxes must belong to the tag.
1648 (and tag
(format "[%s] "
1650 (org-export-data tag info
)))))))
1651 (concat counter
"\\item" (or tag
(concat " " checkbox
))
1652 (and contents
(org-trim contents
))
1653 ;; If there are footnotes references in tag, be sure to
1654 ;; add their definition at the end of the item. This
1655 ;; workaround is necessary since "\footnote{}" command is
1656 ;; not supported in tags.
1658 (org-e-latex--delayed-footnotes-definitions
1659 (org-element-property :tag item
) info
)))))
1664 (defun org-e-latex-keyword (keyword contents info
)
1665 "Transcode a KEYWORD element from Org to LaTeX.
1666 CONTENTS is nil. INFO is a plist holding contextual information."
1667 (let ((key (org-element-property :key keyword
))
1668 (value (org-element-property :value keyword
)))
1670 ((string= key
"LATEX") value
)
1671 ((string= key
"INDEX") (format "\\index{%s}" value
))
1672 ;; Invisible targets.
1673 ((string= key
"TARGET") nil
)
1674 ((string= key
"TOC")
1675 (let ((value (downcase value
)))
1677 ((string-match "\\<headlines\\>" value
)
1678 (let ((depth (or (and (string-match "[0-9]+" value
)
1679 (string-to-number (match-string 0 value
)))
1680 (plist-get info
:with-toc
))))
1682 (when (wholenump depth
)
1683 (format "\\setcounter{tocdepth}{%s}\n" depth
))
1684 "\\tableofcontents")))
1685 ((string= "tables" value
) "\\listoftables")
1686 ((string= "figures" value
) "\\listoffigures")
1687 ((string= "listings" value
)
1689 ((eq org-e-latex-listings
'minted
) "\\listoflistings")
1690 (org-e-latex-listings "\\lstlistoflistings")
1691 ;; At the moment, src blocks with a caption are wrapped
1692 ;; into a figure environment.
1693 (t "\\listoffigures")))))))))
1696 ;;;; Latex Environment
1698 (defun org-e-latex-latex-environment (latex-environment contents info
)
1699 "Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
1700 CONTENTS is nil. INFO is a plist holding contextual information."
1701 (let ((label (org-element-property :name latex-environment
))
1702 (value (org-remove-indentation
1703 (org-element-property :value latex-environment
))))
1704 (if (not (org-string-nw-p label
)) value
1705 ;; Environment is labelled: label must be within the environment
1706 ;; (otherwise, a reference pointing to that element will count
1707 ;; the section instead).
1710 (goto-char (point-min))
1712 (insert (format "\\label{%s}\n" (org-export-solidify-link-text label
)))
1718 (defun org-e-latex-latex-fragment (latex-fragment contents info
)
1719 "Transcode a LATEX-FRAGMENT object from Org to LaTeX.
1720 CONTENTS is nil. INFO is a plist holding contextual information."
1721 (org-element-property :value latex-fragment
))
1726 (defun org-e-latex-line-break (line-break contents info
)
1727 "Transcode a LINE-BREAK object from Org to LaTeX.
1728 CONTENTS is nil. INFO is a plist holding contextual information."
1734 (defun org-e-latex--inline-image (link info
)
1735 "Return LaTeX code for an inline image.
1736 LINK is the link pointing to the inline image. INFO is a plist
1737 used as a communication channel."
1738 (let* ((parent (org-export-get-parent-element link
))
1739 (path (let ((raw-path (org-element-property :path link
)))
1740 (if (not (file-name-absolute-p raw-path
)) raw-path
1741 (expand-file-name raw-path
))))
1742 (caption (org-e-latex--caption/label-string parent info
))
1743 ;; Retrieve latex attributes from the element around.
1744 (attr (org-export-read-attribute :attr_latex parent
))
1745 (float (let ((float (plist-get attr
:float
)))
1746 (cond ((string= float
"wrap") 'wrap
)
1747 ((string= float
"multicolumn") 'multicolumn
)
1748 ((or (string= float
"figure")
1749 (org-element-property :caption parent
))
1752 (let ((place (plist-get attr
:placement
)))
1753 (cond (place (format "%s" place
))
1754 ((eq float
'wrap
) "{l}{0.5\\textwidth}")
1756 (format "[%s]" org-e-latex-default-figure-position
))
1758 (comment-include (if (plist-get attr
:comment-include
) "%" ""))
1759 ;; Options for "includegraphics" macro. Make sure it is
1760 ;; a string with square brackets when non empty. Default to
1761 ;; `org-e-latex-image-default-option' when possible.
1762 (options (let ((opt (format "%s"
1763 (or (plist-get attr
:options
)
1764 org-e-latex-image-default-option
))))
1765 (cond ((string-match "\\`\\[.*\\]" opt
) opt
)
1766 ((org-string-nw-p opt
) (format "[%s]" opt
))
1767 ((eq float
'float
) "[width=0.7\\textwidth]")
1768 ((eq float
'wrap
) "[width=0.48\\textwidth]")
1770 ;; Return proper string, depending on FLOAT.
1772 (wrap (format "\\begin{wrapfigure}%s
1774 %s\\includegraphics%s{%s}
1775 %s\\end{wrapfigure}" placement comment-include options path caption
))
1776 (multicolumn (format "\\begin{figure*}%s
1778 %s\\includegraphics%s{%s}
1779 %s\\end{figure*}" placement comment-include options path caption
))
1780 (figure (format "\\begin{figure}%s
1782 %s\\includegraphics%s{%s}
1783 %s\\end{figure}" placement comment-include options path caption
))
1784 (t (format "\\includegraphics%s{%s}" options path
)))))
1786 (defun org-e-latex-link (link desc info
)
1787 "Transcode a LINK object from Org to LaTeX.
1789 DESC is the description part of the link, or the empty string.
1790 INFO is a plist holding contextual information. See
1792 (let* ((type (org-element-property :type link
))
1793 (raw-path (org-element-property :path link
))
1794 ;; Ensure DESC really exists, or set it to nil.
1795 (desc (and (not (string= desc
"")) desc
))
1796 (imagep (org-export-inline-image-p
1797 link org-e-latex-inline-image-rules
))
1799 ((member type
'("http" "https" "ftp" "mailto"))
1800 (concat type
":" raw-path
))
1801 ((string= type
"file")
1802 (if (file-name-absolute-p raw-path
)
1803 (concat "file://" (expand-file-name raw-path
))
1804 (concat "file://" raw-path
)))
1809 (imagep (org-e-latex--inline-image link info
))
1810 ;; Radio link: Transcode target's contents and use them as link's
1812 ((string= type
"radio")
1813 (let ((destination (org-export-resolve-radio-link link info
)))
1815 (format "\\hyperref[%s]{%s}"
1816 (org-export-solidify-link-text path
)
1817 (org-export-data (org-element-contents destination
) info
)))))
1818 ;; Links pointing to an headline: Find destination and build
1819 ;; appropriate referencing command.
1820 ((member type
'("custom-id" "fuzzy" "id"))
1821 (let ((destination (if (string= type
"fuzzy")
1822 (org-export-resolve-fuzzy-link link info
)
1823 (org-export-resolve-id-link link info
))))
1824 (case (org-element-type destination
)
1825 ;; Id link points to an external file.
1827 (if desc
(format "\\href{file://%s}{%s}" destination desc
)
1828 (format "\\url{file://%s}" destination
)))
1829 ;; Fuzzy link points nowhere.
1831 (format org-e-latex-link-with-unknown-path-format
1834 (org-element-property :raw-link link
) info
))))
1835 ;; Fuzzy link points to an invisible target.
1837 ;; LINK points to an headline. If headlines are numbered
1838 ;; and the link has no description, display headline's
1839 ;; number. Otherwise, display description or headline's
1846 (org-export-get-headline-number destination info
)
1848 (if (and (plist-get info
:section-numbers
) (not desc
))
1849 (format "\\ref{%s}" label
)
1850 (format "\\hyperref[%s]{%s}" label
1853 (org-element-property :title destination
) info
))))))
1854 ;; Fuzzy link points to a target. Do as above.
1856 (let ((path (org-export-solidify-link-text path
)))
1857 (if (not desc
) (format "\\ref{%s}" path
)
1858 (format "\\hyperref[%s]{%s}" path desc
)))))))
1859 ;; Coderef: replace link with the reference name or the
1860 ;; equivalent line number.
1861 ((string= type
"coderef")
1862 (format (org-export-get-coderef-format path desc
)
1863 (org-export-resolve-coderef path info
)))
1864 ;; Link type is handled by a special function.
1865 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
1866 (funcall protocol
(org-link-unescape path
) desc
'latex
))
1867 ;; External link with a description part.
1868 ((and path desc
) (format "\\href{%s}{%s}" path desc
))
1869 ;; External link without a description part.
1870 (path (format "\\url{%s}" path
))
1871 ;; No path, only description. Try to do something useful.
1872 (t (format org-e-latex-link-with-unknown-path-format desc
)))))
1877 (defun org-e-latex-paragraph (paragraph contents info
)
1878 "Transcode a PARAGRAPH element from Org to LaTeX.
1879 CONTENTS is the contents of the paragraph, as a string. INFO is
1880 the plist used as a communication channel."
1886 (defun org-e-latex-plain-list (plain-list contents info
)
1887 "Transcode a PLAIN-LIST element from Org to LaTeX.
1888 CONTENTS is the contents of the list. INFO is a plist holding
1889 contextual information."
1890 (let* ((type (org-element-property :type plain-list
))
1891 (attr (org-export-read-attribute :attr_latex plain-list
))
1892 (latex-type (let ((env (plist-get attr
:environment
)))
1893 (cond (env (format "%s" env
))
1894 ((eq type
'ordered
) "enumerate")
1895 ((eq type
'unordered
) "itemize")
1896 ((eq type
'descriptive
) "description")))))
1897 (org-e-latex--wrap-label
1899 (format "\\begin{%s}%s\n%s\\end{%s}"
1901 ;; Put optional arguments, if any inside square brackets
1903 (let ((options (format "%s" (or (plist-get attr
:options
) ""))))
1904 (cond ((equal options
"") "")
1905 ((string-match "\\`\\[.*\\]\\'" options
) options
)
1906 (t (format "[%s]" options
))))
1913 (defun org-e-latex-plain-text (text info
)
1914 "Transcode a TEXT string from Org to LaTeX.
1915 TEXT is the string to transcode. INFO is a plist holding
1916 contextual information."
1917 (let ((specialp (plist-get info
:with-special-strings
))
1919 ;; Protect %, #, &, $, ~, ^, _, { and }.
1920 (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" output
)
1923 (format "\\%s" (match-string 2 output
)) nil t output
2)))
1924 ;; Protect \. If special strings are used, be careful not to
1925 ;; protect "\" in "\-" constructs.
1926 (let ((symbols (if specialp
"-%$#&{}~^_\\" "%$#&{}~^_\\")))
1928 (replace-regexp-in-string
1929 (format "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%s]\\|$\\)" symbols
)
1930 "$\\backslash$" output nil t
1)))
1931 ;; Activate smart quotes. Be sure to provide original TEXT string
1932 ;; since OUTPUT may have been modified.
1933 (when (plist-get info
:with-smart-quotes
)
1934 (setq output
(org-export-activate-smart-quotes output
:latex info text
)))
1935 ;; LaTeX into \LaTeX{} and TeX into \TeX{}.
1936 (let ((case-fold-search nil
)
1938 (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" output start
)
1939 (setq output
(replace-match
1940 (format "\\%s{}" (match-string 1 output
)) nil t output
)
1941 start
(match-end 0))))
1942 ;; Convert special strings.
1945 (replace-regexp-in-string "\\.\\.\\." "\\ldots{}" output nil t
)))
1946 ;; Handle break preservation if required.
1947 (when (plist-get info
:preserve-breaks
)
1948 (setq output
(replace-regexp-in-string
1949 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" output
)))
1956 (defun org-e-latex-planning (planning contents info
)
1957 "Transcode a PLANNING element from Org to LaTeX.
1958 CONTENTS is nil. INFO is a plist holding contextual
1966 (let ((closed (org-element-property :closed planning
)))
1969 (format "\\textbf{%s} " org-closed-string
)
1970 (format org-e-latex-inactive-timestamp-format
1972 (org-element-property :raw-value closed
))))))
1973 (let ((deadline (org-element-property :deadline planning
)))
1976 (format "\\textbf{%s} " org-deadline-string
)
1977 (format org-e-latex-active-timestamp-format
1979 (org-element-property :raw-value deadline
))))))
1980 (let ((scheduled (org-element-property :scheduled planning
)))
1983 (format "\\textbf{%s} " org-scheduled-string
)
1984 (format org-e-latex-active-timestamp-format
1986 (org-element-property :raw-value scheduled
))))))))
1991 ;;;; Property Drawer
1993 (defun org-e-latex-property-drawer (property-drawer contents info
)
1994 "Transcode a PROPERTY-DRAWER element from Org to LaTeX.
1995 CONTENTS is nil. INFO is a plist holding contextual
1997 ;; The property drawer isn't exported but we want separating blank
1998 ;; lines nonetheless.
2004 (defun org-e-latex-quote-block (quote-block contents info
)
2005 "Transcode a QUOTE-BLOCK element from Org to LaTeX.
2006 CONTENTS holds the contents of the block. INFO is a plist
2007 holding contextual information."
2008 (org-e-latex--wrap-label
2010 (format "\\begin{quote}\n%s\\end{quote}" contents
)))
2015 (defun org-e-latex-quote-section (quote-section contents info
)
2016 "Transcode a QUOTE-SECTION element from Org to LaTeX.
2017 CONTENTS is nil. INFO is a plist holding contextual information."
2018 (let ((value (org-remove-indentation
2019 (org-element-property :value quote-section
))))
2020 (when value
(format "\\begin{verbatim}\n%s\\end{verbatim}" value
))))
2025 (defun org-e-latex-radio-target (radio-target text info
)
2026 "Transcode a RADIO-TARGET object from Org to LaTeX.
2027 TEXT is the text of the target. INFO is a plist holding
2028 contextual information."
2029 (format "\\label{%s}%s"
2030 (org-export-solidify-link-text
2031 (org-element-property :value radio-target
))
2037 (defun org-e-latex-section (section contents info
)
2038 "Transcode a SECTION element from Org to LaTeX.
2039 CONTENTS holds the contents of the section. INFO is a plist
2040 holding contextual information."
2046 (defun org-e-latex-special-block (special-block contents info
)
2047 "Transcode a SPECIAL-BLOCK element from Org to LaTeX.
2048 CONTENTS holds the contents of the block. INFO is a plist
2049 holding contextual information."
2050 (let ((type (downcase (org-element-property :type special-block
))))
2051 (concat (format "\\begin{%s}\n" type
)
2052 ;; Insert any label or caption within the block
2053 ;; (otherwise, a reference pointing to that element will
2054 ;; count the section instead).
2055 (org-e-latex--caption/label-string special-block info
)
2057 (format "\\end{%s}" type
))))
2062 (defun org-e-latex-src-block (src-block contents info
)
2063 "Transcode a SRC-BLOCK element from Org to LaTeX.
2064 CONTENTS holds the contents of the item. INFO is a plist holding
2065 contextual information."
2066 (let* ((lang (org-element-property :language src-block
))
2067 (caption (org-element-property :caption src-block
))
2068 (label (org-element-property :name src-block
))
2069 (custom-env (and lang
2070 (cadr (assq (intern lang
)
2071 org-e-latex-custom-lang-environments
))))
2072 (num-start (case (org-element-property :number-lines src-block
)
2073 (continued (org-export-get-loc src-block info
))
2075 (retain-labels (org-element-property :retain-labels src-block
)))
2077 ;; Case 1. No source fontification.
2078 ((not org-e-latex-listings
)
2079 (let ((caption-str (org-e-latex--caption/label-string src-block info
))
2080 (float-env (when caption
"\\begin{figure}[H]\n%s\n\\end{figure}")))
2084 (format "\\begin{verbatim}\n%s\\end{verbatim}"
2085 (org-export-format-code-default src-block info
))))))
2086 ;; Case 2. Custom environment.
2087 (custom-env (format "\\begin{%s}\n%s\\end{%s}\n"
2089 (org-export-format-code-default src-block info
)
2091 ;; Case 3. Use minted package.
2092 ((eq org-e-latex-listings
'minted
)
2094 (when (or label caption
)
2095 (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
2096 (org-e-latex--caption/label-string src-block info
))))
2099 "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
2101 (org-e-latex--make-option-string
2102 (if (not num-start
) org-e-latex-minted-options
2103 (append `(("linenos")
2104 ("firstnumber" ,(number-to-string (1+ num-start
))))
2105 org-e-latex-minted-options
)))
2107 (or (cadr (assq (intern lang
) org-e-latex-minted-langs
)) lang
)
2109 (let* ((code-info (org-export-unravel-code src-block
))
2113 (org-split-string (car code-info
) "\n")))))
2114 (org-export-format-code
2116 (lambda (loc num ref
)
2120 ;; Ensure references are flushed to the right,
2121 ;; separated with 6 spaces from the widest line
2123 (concat (make-string (+ (- max-width
(length loc
)) 6) ?
)
2124 (format "(%s)" ref
)))))
2125 nil
(and retain-labels
(cdr code-info
)))))))
2127 (if float-env
(format float-env body
) body
)))
2128 ;; Case 4. Use listings package.
2131 (or (cadr (assq (intern lang
) org-e-latex-listings-langs
)) lang
))
2134 (let ((main (org-export-get-caption src-block
))
2135 (secondary (org-export-get-caption src-block t
)))
2136 (if (not secondary
) (format "{%s}" (org-export-data main info
))
2138 (org-export-data secondary info
)
2139 (org-export-data main info
)))))))
2142 (format "\\lstset{%s}\n"
2143 (org-e-latex--make-option-string
2144 (append org-e-latex-listings-options
2145 `(("language" ,lst-lang
))
2146 (when label
`(("label" ,label
)))
2147 (when caption-str
`(("caption" ,caption-str
)))
2148 (cond ((not num-start
) '(("numbers" "none")))
2149 ((zerop num-start
) '(("numbers" "left")))
2150 (t `(("numbers" "left")
2152 ,(number-to-string (1+ num-start
)))))))))
2155 "\\begin{lstlisting}\n%s\\end{lstlisting}"
2156 (let* ((code-info (org-export-unravel-code src-block
))
2160 (org-split-string (car code-info
) "\n")))))
2161 (org-export-format-code
2163 (lambda (loc num ref
)
2167 ;; Ensure references are flushed to the right,
2168 ;; separated with 6 spaces from the widest line of
2170 (concat (make-string (+ (- max-width
(length loc
)) 6) ?
)
2171 (format "(%s)" ref
)))))
2172 nil
(and retain-labels
(cdr code-info
)))))))))))
2175 ;;;; Statistics Cookie
2177 (defun org-e-latex-statistics-cookie (statistics-cookie contents info
)
2178 "Transcode a STATISTICS-COOKIE object from Org to LaTeX.
2179 CONTENTS is nil. INFO is a plist holding contextual information."
2180 (replace-regexp-in-string
2181 "%" "\\%" (org-element-property :value statistics-cookie
) nil t
))
2186 (defun org-e-latex-strike-through (strike-through contents info
)
2187 "Transcode STRIKE-THROUGH from Org to LaTeX.
2188 CONTENTS is the text with strike-through markup. INFO is a plist
2189 holding contextual information."
2190 (org-e-latex--text-markup contents
'strike-through
))
2195 (defun org-e-latex-subscript (subscript contents info
)
2196 "Transcode a SUBSCRIPT object from Org to LaTeX.
2197 CONTENTS is the contents of the object. INFO is a plist holding
2198 contextual information."
2199 (if (= (length contents
) 1) (format "$_%s$" contents
)
2200 ;; Handle multiple objects in SUBSCRIPT by creating a subscript
2201 ;; command for each of them.
2202 (let ((prev-blanks 0))
2205 (case (org-element-type obj
)
2206 ((entity latex-fragment
)
2207 (setq prev-blanks
(org-element-property :post-blank obj
))
2208 (let ((data (org-trim (org-export-data obj info
))))
2210 "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
2212 (format "$_{%s}$" (match-string 1 data
))))
2214 (format "$_\\mathrm{%s}$"
2215 (concat (make-string prev-blanks ?
)
2216 ;; mathrm command doesn't handle spaces,
2217 ;; so we have to enforce them.
2218 (replace-regexp-in-string
2219 " " "\\\\ " (org-export-data obj info
)))))
2221 (setq prev-blanks
(org-element-property :post-blank obj
))
2222 (format "$_{%s}$" (org-export-data obj info
)))))
2223 (org-element-contents subscript
) ""))))
2228 (defun org-e-latex-superscript (superscript contents info
)
2229 "Transcode a SUPERSCRIPT object from Org to LaTeX.
2230 CONTENTS is the contents of the object. INFO is a plist holding
2231 contextual information."
2232 (if (= (length contents
) 1) (format "$^%s$" contents
)
2233 ;; Handle multiple objects in SUPERSCRIPT by creating
2234 ;; a superscript command for each of them.
2235 (let ((prev-blanks 0))
2238 (case (org-element-type obj
)
2239 ((entity latex-fragment
)
2240 (setq prev-blanks
(org-element-property :post-blank obj
))
2241 (let ((data (org-trim (org-export-data obj info
))))
2243 "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
2245 (format "$^{%s}$" (match-string 1 data
))))
2247 (format "$^\\mathrm{%s}$"
2248 (concat (make-string prev-blanks ?
)
2249 ;; mathrm command doesn't handle spaces,
2250 ;; so we have to enforce them.
2251 (replace-regexp-in-string
2252 " " "\\\\ " (org-export-data obj info
)))))
2254 (setq prev-blanks
(org-element-property :post-blank obj
))
2255 (format "$^{%s}$" (org-export-data obj info
)))))
2256 (org-element-contents superscript
) ""))))
2261 ;; `org-e-latex-table' is the entry point for table transcoding. It
2262 ;; takes care of tables with a "verbatim" mode. Otherwise, it
2263 ;; delegates the job to either `org-e-latex--table.el-table',
2264 ;; `org-e-latex--org-table' or `org-e-latex--math-table' functions,
2265 ;; depending of the type of the table and the mode requested.
2267 ;; `org-e-latex--align-string' is a subroutine used to build alignment
2268 ;; string for Org tables.
2270 (defun org-e-latex-table (table contents info
)
2271 "Transcode a TABLE element from Org to LaTeX.
2272 CONTENTS is the contents of the table. INFO is a plist holding
2273 contextual information."
2274 (if (eq (org-element-property :type table
) 'table.el
)
2275 ;; "table.el" table. Convert it using appropriate tools.
2276 (org-e-latex--table.el-table table info
)
2277 (let ((type (or (org-export-read-attribute :attr_latex table
:mode
)
2278 org-e-latex-default-table-mode
)))
2280 ;; Case 1: Verbatim table.
2281 ((string= type
"verbatim")
2282 (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
2283 ;; Re-create table, without affiliated keywords.
2284 (org-trim (org-element-interpret-data
2285 `(table nil
,@(org-element-contents table
))))))
2287 ((or (string= type
"math") (string= type
"inline-math"))
2288 (org-e-latex--math-table table info
))
2289 ;; Case 3: Standard table.
2290 (t (concat (org-e-latex--org-table table contents info
)
2291 ;; When there are footnote references within the
2292 ;; table, insert their definition just after it.
2293 (org-e-latex--delayed-footnotes-definitions table info
)))))))
2295 (defun org-e-latex--align-string (table info
)
2296 "Return an appropriate LaTeX alignment string.
2297 TABLE is the considered table. INFO is a plist used as
2298 a communication channel."
2299 (or (org-export-read-attribute :attr_latex table
:align
)
2301 ;; Extract column groups and alignment from first (non-rule)
2307 (and (eq (org-element-property :type row
) 'standard
) row
))
2311 (let ((borders (org-export-table-cell-borders cell info
)))
2312 ;; Check left border for the first cell only.
2313 (when (and (memq 'left borders
) (not align
))
2315 (push (case (org-export-table-cell-alignment cell info
)
2320 (when (memq 'right borders
) (push "|" align
))))
2322 (apply 'concat
(nreverse align
)))))
2324 (defun org-e-latex--org-table (table contents info
)
2325 "Return appropriate LaTeX code for an Org table.
2327 TABLE is the table type element to transcode. CONTENTS is its
2328 contents, as a string. INFO is a plist used as a communication
2331 This function assumes TABLE has `org' as its `:type' property and
2332 `table' as its `:mode' attribute."
2333 (let* ((caption (org-e-latex--caption/label-string table info
))
2334 (attr (org-export-read-attribute :attr_latex table
))
2335 ;; Determine alignment string.
2336 (alignment (org-e-latex--align-string table info
))
2337 ;; Determine environment for the table: longtable, tabular...
2338 (table-env (let ((env (plist-get attr
:environment
)))
2339 (if env
(format "%s" env
)
2340 org-e-latex-default-table-environment
)))
2341 ;; If table is a float, determine environment: table, table*
2342 ;; or sidewaystable.
2343 (float-env (unless (equal "longtable" table-env
)
2344 (let ((float (plist-get attr
:float
)))
2346 ((string= float
"sidewaystable") "sidewaystable")
2347 ((string= float
"multicolumn") "table*")
2348 ((or (string= float
"table")
2349 (org-element-property :caption table
))
2351 ;; Extract others display options.
2352 (fontsize (let ((font (plist-get attr
:font
)))
2353 (and font
(concat (org-trim (format "%s" font
)) "\n"))))
2354 (width (plist-get attr
:width
))
2355 (placement (or (plist-get attr
:placement
)
2356 (format "[%s]" org-e-latex-default-figure-position
)))
2357 (centerp (if (plist-member attr
:center
) (plist-get attr
:center
)
2358 org-e-latex-tables-centered
)))
2359 ;; Prepare the final format string for the table.
2362 ((equal "longtable" table-env
)
2363 (concat (and fontsize
(concat "{" fontsize
))
2364 (format "\\begin{longtable}{%s}\n" alignment
)
2365 (and org-e-latex-table-caption-above
2366 (org-string-nw-p caption
)
2367 (concat caption
"\\\\\n"))
2369 (and (not org-e-latex-table-caption-above
)
2370 (org-string-nw-p caption
)
2371 (concat caption
"\\\\\n"))
2372 "\\end{longtable}\n"
2373 (and fontsize
"}")))
2377 (concat (format "\\begin{%s}%s\n" float-env placement
)
2378 (if org-e-latex-table-caption-above caption
"")
2379 (when centerp
"\\centering\n")
2381 (centerp (concat "\\begin{center}\n" fontsize
))
2382 (fontsize (concat "{" fontsize
)))
2383 (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
2385 (if width
(format "{%s}" width
) "")
2391 (concat (if org-e-latex-table-caption-above
"" caption
)
2392 (format "\n\\end{%s}" float-env
)))
2393 (centerp "\n\\end{center}")
2394 (fontsize "}")))))))
2396 (defun org-e-latex--table.el-table
(table info
)
2397 "Return appropriate LaTeX code for a table.el table.
2399 TABLE is the table type element to transcode. INFO is a plist
2400 used as a communication channel.
2402 This function assumes TABLE has `table.el' as its `:type'
2405 ;; Ensure "*org-export-table*" buffer is empty.
2406 (with-current-buffer (get-buffer-create "*org-export-table*")
2408 (let ((output (with-temp-buffer
2409 (insert (org-element-property :value table
))
2411 (re-search-forward "^[ \t]*|[^|]" nil t
)
2412 (table-generate-source 'latex
"*org-export-table*")
2413 (with-current-buffer "*org-export-table*"
2414 (org-trim (buffer-string))))))
2415 (kill-buffer (get-buffer "*org-export-table*"))
2416 ;; Remove left out comments.
2417 (while (string-match "^%.*\n" output
)
2418 (setq output
(replace-match "" t t output
)))
2419 (let ((attr (org-export-read-attribute :attr_latex table
)))
2420 (when (plist-get attr
:rmlines
)
2421 ;; When the "rmlines" attribute is provided, remove all hlines
2422 ;; but the the one separating heading from the table body.
2423 (let ((n 0) (pos 0))
2424 (while (and (< (length output
) pos
)
2425 (setq pos
(string-match "^\\\\hline\n?" output pos
)))
2427 (unless (= n
2) (setq output
(replace-match "" nil nil output
))))))
2428 (let ((centerp (if (plist-member attr
:center
) (plist-get attr
:center
)
2429 org-e-latex-tables-centered
)))
2430 (if (not centerp
) output
2431 (format "\\begin{center}\n%s\n\\end{center}" output
))))))
2433 (defun org-e-latex--math-table (table info
)
2434 "Return appropriate LaTeX code for a matrix.
2436 TABLE is the table type element to transcode. INFO is a plist
2437 used as a communication channel.
2439 This function assumes TABLE has `org' as its `:type' property and
2440 `inline-math' or `math' as its `:mode' attribute.."
2441 (let* ((caption (org-e-latex--caption/label-string table info
))
2442 (attr (org-export-read-attribute :attr_latex table
))
2443 (inlinep (eq (plist-get attr
:mode
) 'inline-math
))
2444 (env (let ((env (plist-get attr
:environment
)))
2445 (if env
(format "%s" env
)
2446 org-e-latex-default-table-environment
)))
2450 ;; Ignore horizontal rules.
2451 (when (eq (org-element-property :type row
) 'standard
)
2452 ;; Return each cell unmodified.
2456 (substring (org-element-interpret-data cell
) 0 -
1))
2457 (org-element-map row
'table-cell
'identity info
) "&")
2458 (or (cdr (assoc env org-e-latex-table-matrix-macros
)) "\\\\")
2460 (org-element-map table
'table-row
'identity info
) ""))
2461 ;; Variables related to math clusters (contiguous math tables
2462 ;; of the same type).
2463 (mode (org-export-read-attribute :attr_latex table
:mode
))
2464 (prev (org-export-get-previous-element table info
))
2465 (next (org-export-get-next-element table info
))
2468 ;; Non-nil when TABLE has the same mode as current table.
2469 (string= (or (org-export-read-attribute :attr_latex table
:mode
)
2470 org-e-latex-default-table-mode
)
2473 ;; Opening string. If TABLE is in the middle of a table cluster,
2474 ;; do not insert any.
2476 (eq (org-element-type prev
) 'table
)
2477 (memq (org-element-property :post-blank prev
) '(0 nil
))
2478 (funcall same-mode-p prev
))
2481 ((org-string-nw-p caption
) (concat "\\begin{equation}\n" caption
))
2483 ;; Prefix (make sure it is a string).
2484 (format "%s" (or (plist-get attr
:math-prefix
) ""))
2485 ;; Environment. Also treat special cases.
2486 (cond ((equal env
"array")
2487 (let ((align (org-e-latex--align-string table info
)))
2488 (format "\\begin{array}{%s}\n%s\\end{array}" align contents
)))
2489 ((assoc env org-e-latex-table-matrix-macros
)
2490 (format "\\%s%s{\n%s}" env
2491 (format "%s" (or (plist-get attr
:math-arguments
) ""))
2493 (t (format "\\begin{%s}\n%s\\end{%s}" env contents env
)))
2494 ;; Suffix (make sure it is a string).
2495 (format "%s" (or (plist-get attr
:math-suffix
) ""))
2496 ;; Closing string. If TABLE is in the middle of a table cluster,
2497 ;; do not insert any. If it closes such a cluster, be sure to
2498 ;; close the cluster with a string matching the opening string.
2500 (eq (org-element-type next
) 'table
)
2501 (memq (org-element-property :post-blank table
) '(0 nil
))
2502 (funcall same-mode-p next
))
2505 ;; Find cluster beginning to know which environment to use.
2506 ((let ((cluster-beg table
) prev
)
2507 (while (and (setq prev
(org-export-get-previous-element
2509 (memq (org-element-property :post-blank prev
)
2511 (funcall same-mode-p prev
))
2512 (setq cluster-beg prev
))
2513 (and (or (org-element-property :caption cluster-beg
)
2514 (org-element-property :name cluster-beg
))
2515 "\n\\end{equation}")))
2521 (defun org-e-latex-table-cell (table-cell contents info
)
2522 "Transcode a TABLE-CELL element from Org to LaTeX.
2523 CONTENTS is the cell contents. INFO is a plist used as
2524 a communication channel."
2525 (concat (if (and contents
2526 org-e-latex-table-scientific-notation
2527 (string-match orgtbl-exp-regexp contents
))
2528 ;; Use appropriate format string for scientific
2530 (format org-e-latex-table-scientific-notation
2531 (match-string 1 contents
)
2532 (match-string 2 contents
))
2534 (when (org-export-get-next-element table-cell info
) " & ")))
2539 (defun org-e-latex-table-row (table-row contents info
)
2540 "Transcode a TABLE-ROW element from Org to LaTeX.
2541 CONTENTS is the contents of the row. INFO is a plist used as
2542 a communication channel."
2543 ;; Rules are ignored since table separators are deduced from
2544 ;; borders of the current row.
2545 (when (eq (org-element-property :type table-row
) 'standard
)
2546 (let* ((attr (org-export-read-attribute :attr_latex
2547 (org-export-get-parent table-row
)))
2548 (longtablep (string= (or (plist-get attr
:environment
)
2549 org-e-latex-default-table-environment
)
2551 (booktabsp (if (plist-member attr
:booktabs
)
2552 (plist-get attr
:booktabs
)
2553 org-e-latex-tables-booktabs
))
2554 ;; TABLE-ROW's borders are extracted from its first cell.
2555 (borders (org-export-table-cell-borders
2556 (car (org-element-contents table-row
)) info
)))
2558 ;; When BOOKTABS are activated enforce top-rule even when no
2559 ;; hline was specifically marked.
2560 (cond ((and booktabsp
(memq 'top borders
)) "\\toprule\n")
2561 ((and (memq 'top borders
) (memq 'above borders
)) "\\hline\n"))
2564 ;; Special case for long tables. Define header and footers.
2565 ((and longtablep
(org-export-table-row-ends-header-p table-row info
))
2568 %s\\multicolumn{%d}{r}{Continued on next page} \\\\
2571 (if booktabsp
"\\midrule" "\\hline")
2572 (if booktabsp
"\\midrule" "\\hline")
2573 ;; Number of columns.
2574 (cdr (org-export-table-dimensions
2575 (org-export-get-parent-table table-row
) info
))))
2576 ;; When BOOKTABS are activated enforce bottom rule even when
2577 ;; no hline was specifically marked.
2578 ((and booktabsp
(memq 'bottom borders
)) "\\bottomrule")
2579 ((and (memq 'bottom borders
) (memq 'below borders
)) "\\hline")
2580 ((memq 'below borders
) (if booktabsp
"\\midrule" "\\hline")))))))
2585 (defun org-e-latex-target (target contents info
)
2586 "Transcode a TARGET object from Org to LaTeX.
2587 CONTENTS is nil. INFO is a plist holding contextual
2589 (format "\\label{%s}"
2590 (org-export-solidify-link-text (org-element-property :value target
))))
2595 (defun org-e-latex-timestamp (timestamp contents info
)
2596 "Transcode a TIMESTAMP object from Org to LaTeX.
2597 CONTENTS is nil. INFO is a plist holding contextual
2599 (let ((value (org-e-latex-plain-text
2600 (org-timestamp-translate timestamp
) info
)))
2601 (case (org-element-property :type timestamp
)
2602 ((active active-range
) (format org-e-latex-active-timestamp-format value
))
2603 ((inactive inactive-range
)
2604 (format org-e-latex-inactive-timestamp-format value
))
2605 (otherwise (format org-e-latex-diary-timestamp-format value
)))))
2610 (defun org-e-latex-underline (underline contents info
)
2611 "Transcode UNDERLINE from Org to LaTeX.
2612 CONTENTS is the text with underline markup. INFO is a plist
2613 holding contextual information."
2614 (org-e-latex--text-markup contents
'underline
))
2619 (defun org-e-latex-verbatim (verbatim contents info
)
2620 "Transcode a VERBATIM object from Org to LaTeX.
2621 CONTENTS is nil. INFO is a plist used as a communication
2623 (org-e-latex--text-markup (org-element-property :value verbatim
) 'verbatim
))
2628 (defun org-e-latex-verse-block (verse-block contents info
)
2629 "Transcode a VERSE-BLOCK element from Org to LaTeX.
2630 CONTENTS is verse block contents. INFO is a plist holding
2631 contextual information."
2632 (org-e-latex--wrap-label
2634 ;; In a verse environment, add a line break to each newline
2635 ;; character and change each white space at beginning of a line
2636 ;; into a space of 1 em. Also change each blank line with
2637 ;; a vertical space of 1 em.
2639 (setq contents
(replace-regexp-in-string
2640 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
2641 (replace-regexp-in-string
2642 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" contents
)))
2643 (while (string-match "^[ \t]+" contents
)
2644 (let ((new-str (format "\\hspace*{%dem}"
2645 (length (match-string 0 contents
)))))
2646 (setq contents
(replace-match new-str nil t contents
))))
2647 (format "\\begin{verse}\n%s\\end{verse}" contents
))))
2651 ;;; End-user functions
2654 (defun org-e-latex-export-as-latex
2655 (&optional async subtreep visible-only body-only ext-plist
)
2656 "Export current buffer as a LaTeX buffer.
2658 If narrowing is active in the current buffer, only export its
2661 If a region is active, export that region.
2663 A non-nil optional argument ASYNC means the process should happen
2664 asynchronously. The resulting buffer should be accessible
2665 through the `org-export-stack' interface.
2667 When optional argument SUBTREEP is non-nil, export the sub-tree
2668 at point, extracting information from the headline properties
2671 When optional argument VISIBLE-ONLY is non-nil, don't export
2672 contents of hidden elements.
2674 When optional argument BODY-ONLY is non-nil, only write code
2675 between \"\\begin{document}\" and \"\\end{document}\".
2677 EXT-PLIST, when provided, is a property list with external
2678 parameters overriding Org default settings, but still inferior to
2679 file-local settings.
2681 Export is done in a buffer named \"*Org E-LATEX Export*\", which
2682 will be displayed when `org-export-show-temporary-export-buffer'
2686 (org-export-async-start
2688 (with-current-buffer (get-buffer-create "*Org E-LATEX Export*")
2691 (goto-char (point-min))
2693 (org-export-add-to-stack (current-buffer) 'e-latex
)))
2694 `(org-export-as 'e-latex
,subtreep
,visible-only
,body-only
2697 (org-export-to-buffer 'e-latex
"*Org E-LATEX Export*"
2698 subtreep visible-only body-only ext-plist
)))
2699 (with-current-buffer outbuf
(LaTeX-mode))
2700 (when org-export-show-temporary-export-buffer
2701 (switch-to-buffer-other-window outbuf
)))))
2704 (defun org-e-latex-export-to-latex
2705 (&optional async subtreep visible-only body-only ext-plist
)
2706 "Export current buffer to a LaTeX file.
2708 If narrowing is active in the current buffer, only export its
2711 If a region is active, export that region.
2713 A non-nil optional argument ASYNC means the process should happen
2714 asynchronously. The resulting file should be accessible through
2715 the `org-export-stack' interface.
2717 When optional argument SUBTREEP is non-nil, export the sub-tree
2718 at point, extracting information from the headline properties
2721 When optional argument VISIBLE-ONLY is non-nil, don't export
2722 contents of hidden elements.
2724 When optional argument BODY-ONLY is non-nil, only write code
2725 between \"\\begin{document}\" and \"\\end{document}\".
2727 EXT-PLIST, when provided, is a property list with external
2728 parameters overriding Org default settings, but still inferior to
2729 file-local settings.
2731 Return output file's name."
2733 (let ((outfile (org-export-output-file-name ".tex" subtreep
)))
2735 (org-export-async-start
2736 (lambda (f) (org-export-add-to-stack f
'e-latex
))
2739 'e-latex
,outfile
,subtreep
,visible-only
,body-only
',ext-plist
)))
2741 'e-latex outfile subtreep visible-only body-only ext-plist
))))
2744 (defun org-e-latex-export-to-pdf
2745 (&optional async subtreep visible-only body-only ext-plist
)
2746 "Export current buffer to LaTeX then process through to PDF.
2748 If narrowing is active in the current buffer, only export its
2751 If a region is active, export that region.
2753 A non-nil optional argument ASYNC means the process should happen
2754 asynchronously. The resulting file should be accessible through
2755 the `org-export-stack' interface.
2757 When optional argument SUBTREEP is non-nil, export the sub-tree
2758 at point, extracting information from the headline properties
2761 When optional argument VISIBLE-ONLY is non-nil, don't export
2762 contents of hidden elements.
2764 When optional argument BODY-ONLY is non-nil, only write code
2765 between \"\\begin{document}\" and \"\\end{document}\".
2767 EXT-PLIST, when provided, is a property list with external
2768 parameters overriding Org default settings, but still inferior to
2769 file-local settings.
2771 Return PDF file's name."
2774 (let ((outfile (org-export-output-file-name ".tex" subtreep
)))
2775 (org-export-async-start
2776 (lambda (f) (org-export-add-to-stack f
'e-latex
))
2778 (org-e-latex-compile
2780 'e-latex
,outfile
,subtreep
,visible-only
,body-only
2782 (org-e-latex-compile
2783 (org-e-latex-export-to-latex
2784 nil subtreep visible-only body-only ext-plist
))))
2786 (defun org-e-latex-compile (texfile)
2787 "Compile a TeX file.
2789 TEXFILE is the name of the file being compiled. Processing is
2790 done through the command specified in `org-e-latex-pdf-process'.
2792 Return PDF file name or an error if it couldn't be produced."
2793 (let* ((base-name (file-name-sans-extension (file-name-nondirectory texfile
)))
2794 (full-name (file-truename texfile
))
2795 (out-dir (file-name-directory texfile
))
2796 ;; Make sure `default-directory' is set to TEXFILE directory,
2797 ;; not to whatever value the current buffer may have.
2798 (default-directory (file-name-directory full-name
))
2800 (message (format "Processing LaTeX file %s ..." texfile
))
2801 (save-window-excursion
2803 ;; A function is provided: Apply it.
2804 ((functionp org-e-latex-pdf-process
)
2805 (funcall org-e-latex-pdf-process
(shell-quote-argument texfile
)))
2806 ;; A list is provided: Replace %b, %f and %o with appropriate
2807 ;; values in each command before applying it. Output is
2808 ;; redirected to "*Org PDF LaTeX Output*" buffer.
2809 ((consp org-e-latex-pdf-process
)
2810 (let ((outbuf (get-buffer-create "*Org PDF LaTeX Output*")))
2814 (replace-regexp-in-string
2815 "%b" (shell-quote-argument base-name
)
2816 (replace-regexp-in-string
2817 "%f" (shell-quote-argument full-name
)
2818 (replace-regexp-in-string
2819 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
2821 org-e-latex-pdf-process
)
2822 ;; Collect standard errors from output buffer.
2823 (setq errors
(org-e-latex--collect-errors outbuf
))))
2824 (t (error "No valid command to process to PDF")))
2825 (let ((pdffile (concat out-dir base-name
".pdf")))
2826 ;; Check for process failure. Provide collected errors if
2828 (if (not (file-exists-p pdffile
))
2829 (error (concat (format "PDF file %s wasn't produced" pdffile
)
2830 (when errors
(concat ": " errors
))))
2831 ;; Else remove log files, when specified, and signal end of
2832 ;; process to user, along with any error encountered.
2833 (when org-e-latex-remove-logfiles
2834 (dolist (ext org-e-latex-logfiles-extensions
)
2835 (let ((file (concat out-dir base-name
"." ext
)))
2836 (when (file-exists-p file
) (delete-file file
)))))
2837 (message (concat "Process completed"
2838 (if (not errors
) "."
2839 (concat " with errors: " errors
)))))
2840 ;; Return output file name.
2843 (defun org-e-latex--collect-errors (buffer)
2844 "Collect some kind of errors from \"pdflatex\" command output.
2846 BUFFER is the buffer containing output.
2848 Return collected error types as a string, or nil if there was
2850 (with-current-buffer buffer
2852 (goto-char (point-max))
2853 (when (re-search-backward "^[ \t]*This is .*?TeX.*?Version" nil t
)
2854 (let ((case-fold-search t
)
2856 (dolist (latex-error org-e-latex-known-errors
)
2857 (when (save-excursion (re-search-forward (car latex-error
) nil t
))
2858 (setq errors
(concat errors
" " (cdr latex-error
)))))
2859 (and (org-string-nw-p errors
) (org-trim errors
)))))))
2862 (defun org-e-latex-publish-to-latex (plist filename pub-dir
)
2863 "Publish an Org file to LaTeX.
2865 FILENAME is the filename of the Org file to be published. PLIST
2866 is the property list for the given project. PUB-DIR is the
2867 publishing directory.
2869 Return output file name."
2870 (org-e-publish-org-to 'e-latex filename
".tex" plist pub-dir
))
2873 (defun org-e-latex-publish-to-pdf (plist filename pub-dir
)
2874 "Publish an Org file to PDF (via LaTeX).
2876 FILENAME is the filename of the Org file to be published. PLIST
2877 is the property list for the given project. PUB-DIR is the
2878 publishing directory.
2880 Return output file name."
2881 ;; Unlike to `org-e-latex-publish-to-latex', PDF file is generated
2882 ;; in working directory and then moved to publishing directory.
2883 (org-e-publish-attachment
2885 (org-e-latex-compile (org-e-publish-org-to 'e-latex filename
".tex" plist
))
2889 (provide 'org-e-latex
)
2890 ;;; org-e-latex.el ends here