Merge branch 'maint'
[org-mode.git] / lisp / ox-latex.el
blobcea21bea740798be957ff8a2b826516573d582d9
1 ;;; ox-latex.el --- LaTeX Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; See Org manual for details.
27 ;;; Code:
29 (eval-when-compile (require 'cl))
30 (require 'ox)
31 (require 'ox-publish)
33 (defvar org-latex-default-packages-alist)
34 (defvar org-latex-packages-alist)
35 (defvar orgtbl-exp-regexp)
39 ;;; Define Back-End
41 (org-export-define-backend 'latex
42 '((bold . org-latex-bold)
43 (center-block . org-latex-center-block)
44 (clock . org-latex-clock)
45 (code . org-latex-code)
46 (comment . (lambda (&rest args) ""))
47 (comment-block . (lambda (&rest args) ""))
48 (drawer . org-latex-drawer)
49 (dynamic-block . org-latex-dynamic-block)
50 (entity . org-latex-entity)
51 (example-block . org-latex-example-block)
52 (export-block . org-latex-export-block)
53 (export-snippet . org-latex-export-snippet)
54 (fixed-width . org-latex-fixed-width)
55 (footnote-definition . org-latex-footnote-definition)
56 (footnote-reference . org-latex-footnote-reference)
57 (headline . org-latex-headline)
58 (horizontal-rule . org-latex-horizontal-rule)
59 (inline-src-block . org-latex-inline-src-block)
60 (inlinetask . org-latex-inlinetask)
61 (italic . org-latex-italic)
62 (item . org-latex-item)
63 (keyword . org-latex-keyword)
64 (latex-environment . org-latex-latex-environment)
65 (latex-fragment . org-latex-latex-fragment)
66 (line-break . org-latex-line-break)
67 (link . org-latex-link)
68 (node-property . org-latex-node-property)
69 (paragraph . org-latex-paragraph)
70 (plain-list . org-latex-plain-list)
71 (plain-text . org-latex-plain-text)
72 (planning . org-latex-planning)
73 (property-drawer . org-latex-property-drawer)
74 (quote-block . org-latex-quote-block)
75 (radio-target . org-latex-radio-target)
76 (section . org-latex-section)
77 (special-block . org-latex-special-block)
78 (src-block . org-latex-src-block)
79 (statistics-cookie . org-latex-statistics-cookie)
80 (strike-through . org-latex-strike-through)
81 (subscript . org-latex-subscript)
82 (superscript . org-latex-superscript)
83 (table . org-latex-table)
84 (table-cell . org-latex-table-cell)
85 (table-row . org-latex-table-row)
86 (target . org-latex-target)
87 (template . org-latex-template)
88 (timestamp . org-latex-timestamp)
89 (underline . org-latex-underline)
90 (verbatim . org-latex-verbatim)
91 (verse-block . org-latex-verse-block)
92 ;; Pseudo objects.
93 (latex-math-block . org-latex-math-block))
94 :export-block '("LATEX" "TEX")
95 :menu-entry
96 '(?l "Export to LaTeX"
97 ((?L "As LaTeX buffer" org-latex-export-as-latex)
98 (?l "As LaTeX file" org-latex-export-to-latex)
99 (?p "As PDF file" org-latex-export-to-pdf)
100 (?o "As PDF file and open"
101 (lambda (a s v b)
102 (if a (org-latex-export-to-pdf t s v b)
103 (org-open-file (org-latex-export-to-pdf nil s v b)))))))
104 :options-alist '((:date "DATE" nil "\\today" t)
105 (:latex-class "LATEX_CLASS" nil org-latex-default-class t)
106 (:latex-class-options "LATEX_CLASS_OPTIONS" nil nil t)
107 (:latex-header "LATEX_HEADER" nil nil newline)
108 (:latex-header-extra "LATEX_HEADER_EXTRA" nil nil newline)
109 (:latex-hyperref nil nil org-latex-hyperref-template t)
110 (:latex-custom-id-labels nil nil org-latex-custom-id-as-label))
111 :filters-alist '((:filter-options . org-latex-math-block-options-filter)
112 (:filter-parse-tree . org-latex-math-block-tree-filter)))
116 ;;; Internal Variables
118 (defconst org-latex-babel-language-alist
119 '(("af" . "afrikaans")
120 ("bg" . "bulgarian")
121 ("bt-br" . "brazilian")
122 ("ca" . "catalan")
123 ("cs" . "czech")
124 ("cy" . "welsh")
125 ("da" . "danish")
126 ("de" . "germanb")
127 ("de-at" . "naustrian")
128 ("de-de" . "ngerman")
129 ("el" . "greek")
130 ("en" . "english")
131 ("en-au" . "australian")
132 ("en-ca" . "canadian")
133 ("en-gb" . "british")
134 ("en-ie" . "irish")
135 ("en-nz" . "newzealand")
136 ("en-us" . "american")
137 ("es" . "spanish")
138 ("et" . "estonian")
139 ("eu" . "basque")
140 ("fi" . "finnish")
141 ("fr" . "frenchb")
142 ("fr-ca" . "canadien")
143 ("gl" . "galician")
144 ("hr" . "croatian")
145 ("hu" . "hungarian")
146 ("id" . "indonesian")
147 ("is" . "icelandic")
148 ("it" . "italian")
149 ("la" . "latin")
150 ("ms" . "malay")
151 ("nl" . "dutch")
152 ("nb" . "norsk")
153 ("nn" . "nynorsk")
154 ("no" . "norsk")
155 ("pl" . "polish")
156 ("pt" . "portuguese")
157 ("ro" . "romanian")
158 ("ru" . "russian")
159 ("sa" . "sanskrit")
160 ("sb" . "uppersorbian")
161 ("sk" . "slovak")
162 ("sl" . "slovene")
163 ("sq" . "albanian")
164 ("sr" . "serbian")
165 ("sv" . "swedish")
166 ("ta" . "tamil")
167 ("tr" . "turkish")
168 ("uk" . "ukrainian"))
169 "Alist between language code and corresponding Babel option.")
171 (defconst org-latex-table-matrix-macros '(("bordermatrix" . "\\cr")
172 ("qbordermatrix" . "\\cr")
173 ("kbordermatrix" . "\\\\"))
174 "Alist between matrix macros and their row ending.")
176 (defconst org-latex-pseudo-objects '(latex-math-block)
177 "List of pseudo-object types introduced in the back-end.")
181 ;;; User Configurable Variables
183 (defgroup org-export-latex nil
184 "Options for exporting Org mode files to LaTeX."
185 :tag "Org Export LaTeX"
186 :group 'org-export)
189 ;;;; Preamble
191 (defcustom org-latex-default-class "article"
192 "The default LaTeX class."
193 :group 'org-export-latex
194 :type '(string :tag "LaTeX class"))
196 (defcustom org-latex-classes
197 '(("article"
198 "\\documentclass[11pt]{article}"
199 ("\\section{%s}" . "\\section*{%s}")
200 ("\\subsection{%s}" . "\\subsection*{%s}")
201 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
202 ("\\paragraph{%s}" . "\\paragraph*{%s}")
203 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
204 ("report"
205 "\\documentclass[11pt]{report}"
206 ("\\part{%s}" . "\\part*{%s}")
207 ("\\chapter{%s}" . "\\chapter*{%s}")
208 ("\\section{%s}" . "\\section*{%s}")
209 ("\\subsection{%s}" . "\\subsection*{%s}")
210 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
211 ("book"
212 "\\documentclass[11pt]{book}"
213 ("\\part{%s}" . "\\part*{%s}")
214 ("\\chapter{%s}" . "\\chapter*{%s}")
215 ("\\section{%s}" . "\\section*{%s}")
216 ("\\subsection{%s}" . "\\subsection*{%s}")
217 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
218 "Alist of LaTeX classes and associated header and structure.
219 If #+LATEX_CLASS is set in the buffer, use its value and the
220 associated information. Here is the structure of each cell:
222 \(class-name
223 header-string
224 \(numbered-section . unnumbered-section)
225 ...)
227 The header string
228 -----------------
230 The HEADER-STRING is the header that will be inserted into the
231 LaTeX file. It should contain the \\documentclass macro, and
232 anything else that is needed for this setup. To this header, the
233 following commands will be added:
235 - Calls to \\usepackage for all packages mentioned in the
236 variables `org-latex-default-packages-alist' and
237 `org-latex-packages-alist'. Thus, your header definitions
238 should avoid to also request these packages.
240 - Lines specified via \"#+LATEX_HEADER:\" and
241 \"#+LATEX_HEADER_EXTRA:\" keywords.
243 If you need more control about the sequence in which the header
244 is built up, or if you want to exclude one of these building
245 blocks for a particular class, you can use the following
246 macro-like placeholders.
248 [DEFAULT-PACKAGES] \\usepackage statements for default packages
249 [NO-DEFAULT-PACKAGES] do not include any of the default packages
250 [PACKAGES] \\usepackage statements for packages
251 [NO-PACKAGES] do not include the packages
252 [EXTRA] the stuff from #+LATEX_HEADER(_EXTRA)
253 [NO-EXTRA] do not include #+LATEX_HEADER(_EXTRA) stuff
255 So a header like
257 \\documentclass{article}
258 [NO-DEFAULT-PACKAGES]
259 [EXTRA]
260 \\providecommand{\\alert}[1]{\\textbf{#1}}
261 [PACKAGES]
263 will omit the default packages, and will include the
264 #+LATEX_HEADER and #+LATEX_HEADER_EXTRA lines, then have a call
265 to \\providecommand, and then place \\usepackage commands based
266 on the content of `org-latex-packages-alist'.
268 If your header, `org-latex-default-packages-alist' or
269 `org-latex-packages-alist' inserts \"\\usepackage[AUTO]{inputenc}\",
270 AUTO will automatically be replaced with a coding system derived
271 from `buffer-file-coding-system'. See also the variable
272 `org-latex-inputenc-alist' for a way to influence this mechanism.
274 Likewise, if your header contains \"\\usepackage[AUTO]{babel}\",
275 AUTO will be replaced with the language related to the language
276 code specified by `org-export-default-language', which see. Note
277 that constructions such as \"\\usepackage[french,AUTO,english]{babel}\"
278 are permitted.
280 The sectioning structure
281 ------------------------
283 The sectioning structure of the class is given by the elements
284 following the header string. For each sectioning level, a number
285 of strings is specified. A %s formatter is mandatory in each
286 section string and will be replaced by the title of the section.
288 Instead of a cons cell (numbered . unnumbered), you can also
289 provide a list of 2 or 4 elements,
291 \(numbered-open numbered-close)
295 \(numbered-open numbered-close unnumbered-open unnumbered-close)
297 providing opening and closing strings for a LaTeX environment
298 that should represent the document section. The opening clause
299 should have a %s to represent the section title.
301 Instead of a list of sectioning commands, you can also specify
302 a function name. That function will be called with two
303 parameters, the (reduced) level of the headline, and a predicate
304 non-nil when the headline should be numbered. It must return
305 a format string in which the section title will be added."
306 :group 'org-export-latex
307 :type '(repeat
308 (list (string :tag "LaTeX class")
309 (string :tag "LaTeX header")
310 (repeat :tag "Levels" :inline t
311 (choice
312 (cons :tag "Heading"
313 (string :tag " numbered")
314 (string :tag "unnumbered"))
315 (list :tag "Environment"
316 (string :tag "Opening (numbered)")
317 (string :tag "Closing (numbered)")
318 (string :tag "Opening (unnumbered)")
319 (string :tag "Closing (unnumbered)"))
320 (function :tag "Hook computing sectioning"))))))
322 (defcustom org-latex-inputenc-alist nil
323 "Alist of inputenc coding system names, and what should really be used.
324 For example, adding an entry
326 (\"utf8\" . \"utf8x\")
328 will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
329 are written as utf8 files."
330 :group 'org-export-latex
331 :type '(repeat
332 (cons
333 (string :tag "Derived from buffer")
334 (string :tag "Use this instead"))))
336 (defcustom org-latex-title-command "\\maketitle"
337 "The command used to insert the title just after \\begin{document}.
338 If this string contains the formatting specification \"%s\" then
339 it will be used as a formatting string, passing the title as an
340 argument."
341 :group 'org-export-latex
342 :type 'string)
344 (defcustom org-latex-toc-command "\\tableofcontents\n\n"
345 "LaTeX command to set the table of contents, list of figures, etc.
346 This command only applies to the table of contents generated with
347 the toc:nil option, not to those generated with #+TOC keyword."
348 :group 'org-export-latex
349 :type 'string)
351 (defcustom org-latex-hyperref-template
352 "\\hypersetup{\n pdfkeywords={%k},\n pdfsubject={%d},\n pdfcreator={%c}}\n"
353 "Template for hyperref package options.
355 Value is a format string, which can contain the following placeholders:
357 %k for KEYWORDS line
358 %d for DESCRIPTION line
359 %c for CREATOR line
361 Set it to the empty string to ignore the command completely."
362 :group 'org-export-latex
363 :version "24.5"
364 :package-version '(Org . "8.3")
365 :type 'string)
367 ;;;; Headline
369 (defcustom org-latex-format-headline-function
370 'org-latex-format-headline-default-function
371 "Function for formatting the headline's text.
373 This function will be called with 5 arguments:
374 TODO the todo keyword (string or nil).
375 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
376 PRIORITY the priority of the headline (integer or nil)
377 TEXT the main headline text (string).
378 TAGS the tags as a list of strings (list of strings or nil).
380 The function result will be used in the section format string.
382 Use `org-latex-format-headline-default-function' by default,
383 which format headlines like for Org version prior to 8.0."
384 :group 'org-export-latex
385 :version "24.4"
386 :package-version '(Org . "8.0")
387 :type 'function)
389 (defcustom org-latex-custom-id-as-label nil
390 "Toggle use of CUSTOM_ID properties for generating section labels.
392 When this variable is non-nil, Org will use the value of a
393 headline's CUSTOM_ID property as the key for the \\label command
394 for the LaTeX section corresponding to the headline.
396 By default, Org generates its own internal section labels for all
397 headlines during LaTeX export. This process ensures that the
398 \\label keys are unique and valid, but it means the keys are not
399 available in advance of the export process.
401 Setting this variable gives you control over how Org generates
402 labels for sections during LaTeX export, so that you may know
403 their keys in advance. One reason to do this is that it allows
404 you to refer to headlines using a single label both in Org's link
405 syntax and in embedded LaTeX code.
407 For example, when this variable is non-nil, a headline like this:
409 ** Some section
410 :PROPERTIES:
411 :CUSTOM_ID: sec:foo
412 :END:
413 This is section [[#sec:foo]].
414 #+BEGIN_LATEX
415 And this is still section \\ref{sec:foo}.
416 #+END_LATEX
418 will be exported to LaTeX as:
420 \\subsection{Some section}
421 \\label{sec:foo}
422 This is section \\ref{sec:foo}.
423 And this is still section \\ref{sec:foo}.
425 Note, however, that setting this variable introduces a limitation
426 on the possible values for CUSTOM_ID. When this variable is
427 non-nil and a headline defines a CUSTOM_ID value, Org simply
428 passes this value to \\label unchanged. You are responsible for
429 ensuring that the value is a valid LaTeX \\label key, and that no
430 other \\label commands with the same key appear elsewhere in your
431 document. (Keys may contain letters, numbers, and the following
432 punctuation: '_' '.' '-' ':'.) There are no such limitations on
433 CUSTOM_ID when this variable is nil.
435 For headlines that do not define the CUSTOM_ID property, Org will
436 continue to use its default labeling scheme to generate labels
437 and resolve links into section references."
438 :group 'org-export-latex
439 :type 'boolean
440 :version "24.5"
441 :package-version '(Org . "8.3"))
443 ;;;; Footnotes
445 (defcustom org-latex-footnote-separator "\\textsuperscript{,}\\,"
446 "Text used to separate footnotes."
447 :group 'org-export-latex
448 :type 'string)
451 ;;;; Timestamps
453 (defcustom org-latex-active-timestamp-format "\\textit{%s}"
454 "A printf format string to be applied to active timestamps."
455 :group 'org-export-latex
456 :type 'string)
458 (defcustom org-latex-inactive-timestamp-format "\\textit{%s}"
459 "A printf format string to be applied to inactive timestamps."
460 :group 'org-export-latex
461 :type 'string)
463 (defcustom org-latex-diary-timestamp-format "\\textit{%s}"
464 "A printf format string to be applied to diary timestamps."
465 :group 'org-export-latex
466 :type 'string)
469 ;;;; Links
471 (defcustom org-latex-image-default-option ""
472 "Default option for images."
473 :group 'org-export-latex
474 :version "24.4"
475 :package-version '(Org . "8.0")
476 :type 'string)
478 (defcustom org-latex-image-default-width ".9\\linewidth"
479 "Default width for images.
480 This value will not be used if a height is provided."
481 :group 'org-export-latex
482 :version "24.4"
483 :package-version '(Org . "8.0")
484 :type 'string)
486 (defcustom org-latex-image-default-height ""
487 "Default height for images.
488 This value will not be used if a width is provided, or if the
489 image is wrapped within a \"figure\" or \"wrapfigure\"
490 environment."
491 :group 'org-export-latex
492 :version "24.4"
493 :package-version '(Org . "8.0")
494 :type 'string)
496 (defcustom org-latex-default-figure-position "htb"
497 "Default position for latex figures."
498 :group 'org-export-latex
499 :type 'string)
501 (defcustom org-latex-inline-image-rules
502 '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\|tikz\\|pgf\\|svg\\)\\'"))
503 "Rules characterizing image files that can be inlined into LaTeX.
505 A rule consists in an association whose key is the type of link
506 to consider, and value is a regexp that will be matched against
507 link's path.
509 Note that, by default, the image extension *actually* allowed
510 depend on the way the LaTeX file is processed. When used with
511 pdflatex, pdf, jpg and png images are OK. When processing
512 through dvi to Postscript, only ps and eps are allowed. The
513 default we use here encompasses both."
514 :group 'org-export-latex
515 :version "24.4"
516 :package-version '(Org . "8.0")
517 :type '(alist :key-type (string :tag "Type")
518 :value-type (regexp :tag "Path")))
520 (defcustom org-latex-link-with-unknown-path-format "\\texttt{%s}"
521 "Format string for links with unknown path type."
522 :group 'org-export-latex
523 :type 'string)
526 ;;;; Tables
528 (defcustom org-latex-default-table-environment "tabular"
529 "Default environment used to build tables."
530 :group 'org-export-latex
531 :version "24.4"
532 :package-version '(Org . "8.0")
533 :type 'string)
535 (defcustom org-latex-default-table-mode 'table
536 "Default mode for tables.
538 Value can be a symbol among:
540 `table' Regular LaTeX table.
542 `math' In this mode, every cell is considered as being in math
543 mode and the complete table will be wrapped within a math
544 environment. It is particularly useful to write matrices.
546 `inline-math' This mode is almost the same as `math', but the
547 math environment will be inlined.
549 `verbatim' The table is exported as it appears in the Org
550 buffer, within a verbatim environment.
552 This value can be overridden locally with, i.e. \":mode math\" in
553 LaTeX attributes.
555 When modifying this variable, it may be useful to change
556 `org-latex-default-table-environment' accordingly."
557 :group 'org-export-latex
558 :version "24.4"
559 :package-version '(Org . "8.0")
560 :type '(choice (const :tag "Table" table)
561 (const :tag "Matrix" math)
562 (const :tag "Inline matrix" inline-math)
563 (const :tag "Verbatim" verbatim))
564 :safe (lambda (s) (memq s '(table math inline-math verbatim))))
566 (defcustom org-latex-tables-centered t
567 "When non-nil, tables are exported in a center environment."
568 :group 'org-export-latex
569 :type 'boolean
570 :safe #'booleanp)
572 (defcustom org-latex-tables-booktabs nil
573 "When non-nil, display tables in a formal \"booktabs\" style.
574 This option assumes that the \"booktabs\" package is properly
575 loaded in the header of the document. This value can be ignored
576 locally with \":booktabs t\" and \":booktabs nil\" LaTeX
577 attributes."
578 :group 'org-export-latex
579 :version "24.4"
580 :package-version '(Org . "8.0")
581 :type 'boolean
582 :safe #'booleanp)
584 (defcustom org-latex-table-caption-above t
585 "When non-nil, place caption string at the beginning of the table.
586 Otherwise, place it near the end."
587 :group 'org-export-latex
588 :type 'boolean
589 :safe #'booleanp)
591 (defcustom org-latex-table-scientific-notation "%s\\,(%s)"
592 "Format string to display numbers in scientific notation.
593 The format should have \"%s\" twice, for mantissa and exponent
594 \(i.e., \"%s\\\\times10^{%s}\").
596 When nil, no transformation is made."
597 :group 'org-export-latex
598 :version "24.4"
599 :package-version '(Org . "8.0")
600 :type '(choice
601 (string :tag "Format string")
602 (const :tag "No formatting")))
604 ;;;; Text markup
606 (defcustom org-latex-text-markup-alist '((bold . "\\textbf{%s}")
607 (code . verb)
608 (italic . "\\emph{%s}")
609 (strike-through . "\\sout{%s}")
610 (underline . "\\uline{%s}")
611 (verbatim . protectedtexttt))
612 "Alist of LaTeX expressions to convert text markup.
614 The key must be a symbol among `bold', `code', `italic',
615 `strike-through', `underline' and `verbatim'. The value is
616 a formatting string to wrap fontified text with.
618 Value can also be set to the following symbols: `verb' and
619 `protectedtexttt'. For the former, Org will use \"\\verb\" to
620 create a format string and select a delimiter character that
621 isn't in the string. For the latter, Org will use \"\\texttt\"
622 to typeset and try to protect special characters.
624 If no association can be found for a given markup, text will be
625 returned as-is."
626 :group 'org-export-latex
627 :type 'alist
628 :options '(bold code italic strike-through underline verbatim))
631 ;;;; Drawers
633 (defcustom org-latex-format-drawer-function
634 (lambda (name contents) contents)
635 "Function called to format a drawer in LaTeX code.
637 The function must accept two parameters:
638 NAME the drawer name, like \"LOGBOOK\"
639 CONTENTS the contents of the drawer.
641 The function should return the string to be exported.
643 The default function simply returns the value of CONTENTS."
644 :group 'org-export-latex
645 :version "24.4"
646 :package-version '(Org . "8.3")
647 :type 'function)
650 ;;;; Inlinetasks
652 (defcustom org-latex-format-inlinetask-function 'ignore
653 "Function called to format an inlinetask in LaTeX code.
655 The function must accept six parameters:
656 TODO the todo keyword, as a string
657 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
658 PRIORITY the inlinetask priority, as a string
659 NAME the inlinetask name, as a string.
660 TAGS the inlinetask tags, as a list of strings.
661 CONTENTS the contents of the inlinetask, as a string.
663 The function should return the string to be exported.
665 For example, the variable could be set to the following function
666 in order to mimic default behaviour:
668 \(defun org-latex-format-inlinetask \(todo type priority name tags contents\)
669 \"Format an inline task element for LaTeX export.\"
670 \(let ((full-title
671 \(concat
672 \(when todo
673 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo))
674 \(when priority (format \"\\\\framebox{\\\\#%c} \" priority))
675 title
676 \(when tags
677 \(format \"\\\\hfill{}\\\\textsc{:%s:}\"
678 \(mapconcat 'identity tags \":\")))))
679 \(format (concat \"\\\\begin{center}\\n\"
680 \"\\\\fbox{\\n\"
681 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
682 \"%s\\n\\n\"
683 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
684 \"%s\"
685 \"\\\\end{minipage}}\"
686 \"\\\\end{center}\")
687 full-title contents))"
688 :group 'org-export-latex
689 :type 'function)
692 ;; Src blocks
694 (defcustom org-latex-listings nil
695 "Non-nil means export source code using the listings package.
697 This package will fontify source code, possibly even with color.
698 If you want to use this, you also need to make LaTeX use the
699 listings package, and if you want to have color, the color
700 package. Just add these to `org-latex-packages-alist', for
701 example using customize, or with something like:
703 \(require 'ox-latex)
704 \(add-to-list 'org-latex-packages-alist '(\"\" \"listings\"))
705 \(add-to-list 'org-latex-packages-alist '(\"\" \"color\"))
707 Alternatively,
709 \(setq org-latex-listings 'minted)
711 causes source code to be exported using the minted package as
712 opposed to listings. If you want to use minted, you need to add
713 the minted package to `org-latex-packages-alist', for example
714 using customize, or with
716 \(require 'ox-latex)
717 \(add-to-list 'org-latex-packages-alist '(\"\" \"minted\"))
719 In addition, it is necessary to install pygments
720 \(http://pygments.org), and to configure the variable
721 `org-latex-pdf-process' so that the -shell-escape option is
722 passed to pdflatex.
724 The minted choice has possible repercussions on the preview of
725 latex fragments (see `org-preview-latex-fragment'). If you run
726 into previewing problems, please consult
728 http://orgmode.org/worg/org-tutorials/org-latex-preview.html"
729 :group 'org-export-latex
730 :type '(choice
731 (const :tag "Use listings" t)
732 (const :tag "Use minted" minted)
733 (const :tag "Export verbatim" nil))
734 :safe (lambda (s) (memq s '(t nil minted))))
736 (defcustom org-latex-listings-langs
737 '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
738 (c "C") (cc "C++")
739 (fortran "fortran")
740 (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
741 (html "HTML") (xml "XML")
742 (tex "TeX") (latex "[LaTeX]TeX")
743 (shell-script "bash")
744 (gnuplot "Gnuplot")
745 (ocaml "Caml") (caml "Caml")
746 (sql "SQL") (sqlite "sql"))
747 "Alist mapping languages to their listing language counterpart.
748 The key is a symbol, the major mode symbol without the \"-mode\".
749 The value is the string that should be inserted as the language
750 parameter for the listings package. If the mode name and the
751 listings name are the same, the language does not need an entry
752 in this list - but it does not hurt if it is present."
753 :group 'org-export-latex
754 :type '(repeat
755 (list
756 (symbol :tag "Major mode ")
757 (string :tag "Listings language"))))
759 (defcustom org-latex-listings-options nil
760 "Association list of options for the latex listings package.
762 These options are supplied as a comma-separated list to the
763 \\lstset command. Each element of the association list should be
764 a list containing two strings: the name of the option, and the
765 value. For example,
767 (setq org-latex-listings-options
768 '((\"basicstyle\" \"\\\\small\")
769 (\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\")))
771 will typeset the code in a small size font with underlined, bold
772 black keywords.
774 Note that the same options will be applied to blocks of all
775 languages. If you need block-specific options, you may use the
776 following syntax:
778 #+ATTR_LATEX: :options key1=value1,key2=value2
779 #+BEGIN_SRC <LANG>
781 #+END_SRC"
782 :group 'org-export-latex
783 :type '(repeat
784 (list
785 (string :tag "Listings option name ")
786 (string :tag "Listings option value"))))
788 (defcustom org-latex-minted-langs
789 '((emacs-lisp "common-lisp")
790 (cc "c++")
791 (cperl "perl")
792 (shell-script "bash")
793 (caml "ocaml"))
794 "Alist mapping languages to their minted language counterpart.
795 The key is a symbol, the major mode symbol without the \"-mode\".
796 The value is the string that should be inserted as the language
797 parameter for the minted package. If the mode name and the
798 listings name are the same, the language does not need an entry
799 in this list - but it does not hurt if it is present.
801 Note that minted uses all lower case for language identifiers,
802 and that the full list of language identifiers can be obtained
803 with:
805 pygmentize -L lexers"
806 :group 'org-export-latex
807 :type '(repeat
808 (list
809 (symbol :tag "Major mode ")
810 (string :tag "Minted language"))))
812 (defcustom org-latex-minted-options nil
813 "Association list of options for the latex minted package.
815 These options are supplied within square brackets in
816 \\begin{minted} environments. Each element of the alist should
817 be a list containing two strings: the name of the option, and the
818 value. For example,
820 \(setq org-latex-minted-options
821 '\((\"bgcolor\" \"bg\") \(\"frame\" \"lines\")))
823 will result in src blocks being exported with
825 \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
827 as the start of the minted environment. Note that the same
828 options will be applied to blocks of all languages. If you need
829 block-specific options, you may use the following syntax:
831 #+ATTR_LATEX: :options key1=value1,key2=value2
832 #+BEGIN_SRC <LANG>
834 #+END_SRC"
835 :group 'org-export-latex
836 :type '(repeat
837 (list
838 (string :tag "Minted option name ")
839 (string :tag "Minted option value"))))
841 (defvar org-latex-custom-lang-environments nil
842 "Alist mapping languages to language-specific LaTeX environments.
844 It is used during export of src blocks by the listings and minted
845 latex packages. For example,
847 \(setq org-latex-custom-lang-environments
848 '\(\(python \"pythoncode\"\)\)\)
850 would have the effect that if org encounters begin_src python
851 during latex export it will output
853 \\begin{pythoncode}
854 <src block body>
855 \\end{pythoncode}")
858 ;;;; Compilation
860 (defcustom org-latex-pdf-process
861 '("pdflatex -interaction nonstopmode -output-directory %o %f"
862 "pdflatex -interaction nonstopmode -output-directory %o %f"
863 "pdflatex -interaction nonstopmode -output-directory %o %f")
864 "Commands to process a LaTeX file to a PDF file.
865 This is a list of strings, each of them will be given to the
866 shell as a command. %f in the command will be replaced by the
867 full file name, %b by the file base name (i.e. without directory
868 and extension parts) and %o by the base directory of the file.
870 The reason why this is a list is that it usually takes several
871 runs of `pdflatex', maybe mixed with a call to `bibtex'. Org
872 does not have a clever mechanism to detect which of these
873 commands have to be run to get to a stable result, and it also
874 does not do any error checking.
876 By default, Org uses 3 runs of `pdflatex' to do the processing.
877 If you have texi2dvi on your system and if that does not cause
878 the infamous egrep/locale bug:
880 http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
882 then `texi2dvi' is the superior choice as it automates the LaTeX
883 build process by calling the \"correct\" combinations of
884 auxiliary programs. Org does offer `texi2dvi' as one of the
885 customize options. Alternatively, `rubber' and `latexmk' also
886 provide similar functionality. The latter supports `biber' out
887 of the box.
889 Alternatively, this may be a Lisp function that does the
890 processing, so you could use this to apply the machinery of
891 AUCTeX or the Emacs LaTeX mode. This function should accept the
892 file name as its single argument."
893 :group 'org-export-pdf
894 :type '(choice
895 (repeat :tag "Shell command sequence"
896 (string :tag "Shell command"))
897 (const :tag "2 runs of pdflatex"
898 ("pdflatex -interaction nonstopmode -output-directory %o %f"
899 "pdflatex -interaction nonstopmode -output-directory %o %f"))
900 (const :tag "3 runs of pdflatex"
901 ("pdflatex -interaction nonstopmode -output-directory %o %f"
902 "pdflatex -interaction nonstopmode -output-directory %o %f"
903 "pdflatex -interaction nonstopmode -output-directory %o %f"))
904 (const :tag "pdflatex,bibtex,pdflatex,pdflatex"
905 ("pdflatex -interaction nonstopmode -output-directory %o %f"
906 "bibtex %b"
907 "pdflatex -interaction nonstopmode -output-directory %o %f"
908 "pdflatex -interaction nonstopmode -output-directory %o %f"))
909 (const :tag "2 runs of xelatex"
910 ("xelatex -interaction nonstopmode -output-directory %o %f"
911 "xelatex -interaction nonstopmode -output-directory %o %f"))
912 (const :tag "3 runs of xelatex"
913 ("xelatex -interaction nonstopmode -output-directory %o %f"
914 "xelatex -interaction nonstopmode -output-directory %o %f"
915 "xelatex -interaction nonstopmode -output-directory %o %f"))
916 (const :tag "xelatex,bibtex,xelatex,xelatex"
917 ("xelatex -interaction nonstopmode -output-directory %o %f"
918 "bibtex %b"
919 "xelatex -interaction nonstopmode -output-directory %o %f"
920 "xelatex -interaction nonstopmode -output-directory %o %f"))
921 (const :tag "texi2dvi"
922 ("texi2dvi -p -b -V %f"))
923 (const :tag "rubber"
924 ("rubber -d --into %o %f"))
925 (const :tag "latexmk"
926 ("latexmk -g -pdf %f"))
927 (function)))
929 (defcustom org-latex-logfiles-extensions
930 '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
931 "The list of file extensions to consider as LaTeX logfiles.
932 The logfiles will be remove if `org-latex-remove-logfiles' is
933 non-nil."
934 :group 'org-export-latex
935 :type '(repeat (string :tag "Extension")))
937 (defcustom org-latex-remove-logfiles t
938 "Non-nil means remove the logfiles produced by PDF production.
939 By default, logfiles are files with these extensions: .aux, .idx,
940 .log, .out, .toc, .nav, .snm and .vrb. To define the set of
941 logfiles to remove, set `org-latex-logfiles-extensions'."
942 :group 'org-export-latex
943 :type 'boolean)
945 (defcustom org-latex-known-warnings
946 '(("Reference.*?undefined" . "[undefined reference]")
947 ("Runaway argument" . "[runaway argument]")
948 ("Underfull \\hbox" . "[underfull hbox]")
949 ("Overfull \\hbox" . "[overfull hbox]")
950 ("Citation.*?undefined" . "[undefined citation]")
951 ("Undefined control sequence" . "[undefined control sequence]"))
952 "Alist of regular expressions and associated messages for the user.
953 The regular expressions are used to find possible warnings in the
954 log of a latex-run. These warnings will be reported after
955 calling `org-latex-compile'."
956 :group 'org-export-latex
957 :version "24.5"
958 :package-version '(Org . "8.3")
959 :type '(repeat
960 (cons
961 (string :tag "Regexp")
962 (string :tag "Message"))))
966 ;;; Internal Functions
968 (defun org-latex--caption/label-string (element info)
969 "Return caption and label LaTeX string for ELEMENT.
971 INFO is a plist holding contextual information. If there's no
972 caption nor label, return the empty string.
974 For non-floats, see `org-latex--wrap-label'."
975 (let* ((label (org-element-property :name element))
976 (label-str (if (not (org-string-nw-p label)) ""
977 (format "\\label{%s}"
978 (org-export-solidify-link-text label))))
979 (main (org-export-get-caption element))
980 (short (org-export-get-caption element t))
981 (caption-from-attr-latex (org-export-read-attribute :attr_latex element :caption)))
982 (cond
983 ((org-string-nw-p caption-from-attr-latex)
984 (concat caption-from-attr-latex "\n"))
985 ((and (not main) (equal label-str "")) "")
986 ((not main) (concat label-str "\n"))
987 ;; Option caption format with short name.
988 (short (format "\\caption[%s]{%s%s}\n"
989 (org-export-data short info)
990 label-str
991 (org-export-data main info)))
992 ;; Standard caption format.
993 (t (format "\\caption{%s%s}\n" label-str (org-export-data main info))))))
995 (defun org-latex-guess-inputenc (header)
996 "Set the coding system in inputenc to what the buffer is.
998 HEADER is the LaTeX header string. This function only applies
999 when specified inputenc option is \"AUTO\".
1001 Return the new header, as a string."
1002 (let* ((cs (or (ignore-errors
1003 (latexenc-coding-system-to-inputenc
1004 (or org-export-coding-system buffer-file-coding-system)))
1005 "utf8")))
1006 (if (not cs) header
1007 ;; First translate if that is requested.
1008 (setq cs (or (cdr (assoc cs org-latex-inputenc-alist)) cs))
1009 ;; Then find the \usepackage statement and replace the option.
1010 (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
1011 cs header t nil 1))))
1013 (defun org-latex-guess-babel-language (header info)
1014 "Set Babel's language according to LANGUAGE keyword.
1016 HEADER is the LaTeX header string. INFO is the plist used as
1017 a communication channel.
1019 Insertion of guessed language only happens when Babel package has
1020 explicitly been loaded. Then it is added to the rest of
1021 package's options.
1023 The argument to Babel may be \"AUTO\" which is then replaced with
1024 the language of the document or `org-export-default-language'
1025 unless language in question is already loaded.
1027 Return the new header."
1028 (let ((language-code (plist-get info :language)))
1029 ;; If no language is set or Babel package is not loaded, return
1030 ;; HEADER as-is.
1031 (if (or (not (stringp language-code))
1032 (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
1033 header
1034 (let ((options (save-match-data
1035 (org-split-string (match-string 1 header) ",[ \t]*")))
1036 (language (cdr (assoc language-code
1037 org-latex-babel-language-alist))))
1038 ;; If LANGUAGE is already loaded, return header without AUTO.
1039 ;; Otherwise, replace AUTO with language or append language if
1040 ;; AUTO is not present.
1041 (replace-match
1042 (mapconcat (lambda (option) (if (equal "AUTO" option) language option))
1043 (cond ((member language options) (delete "AUTO" options))
1044 ((member "AUTO" options) options)
1045 (t (append options (list language))))
1046 ", ")
1047 t nil header 1)))))
1049 (defun org-latex--find-verb-separator (s)
1050 "Return a character not used in string S.
1051 This is used to choose a separator for constructs like \\verb."
1052 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1053 (loop for c across ll
1054 when (not (string-match (regexp-quote (char-to-string c)) s))
1055 return (char-to-string c))))
1057 (defun org-latex--make-option-string (options)
1058 "Return a comma separated string of keywords and values.
1059 OPTIONS is an alist where the key is the options keyword as
1060 a string, and the value a list containing the keyword value, or
1061 nil."
1062 (mapconcat (lambda (pair)
1063 (concat (first pair)
1064 (when (> (length (second pair)) 0)
1065 (concat "=" (second pair)))))
1066 options
1067 ","))
1069 (defun org-latex--wrap-label (element output)
1070 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1071 This function shouldn't be used for floats. See
1072 `org-latex--caption/label-string'."
1073 (let ((label (org-element-property :name element)))
1074 (if (not (and (org-string-nw-p output) (org-string-nw-p label))) output
1075 (concat (format "\\label{%s}\n" (org-export-solidify-link-text label))
1076 output))))
1078 (defun org-latex--text-markup (text markup)
1079 "Format TEXT depending on MARKUP text markup.
1080 See `org-latex-text-markup-alist' for details."
1081 (let ((fmt (cdr (assq markup org-latex-text-markup-alist))))
1082 (cond
1083 ;; No format string: Return raw text.
1084 ((not fmt) text)
1085 ;; Handle the `verb' special case: Find an appropriate separator
1086 ;; and use "\\verb" command.
1087 ((eq 'verb fmt)
1088 (let ((separator (org-latex--find-verb-separator text)))
1089 (concat "\\verb" separator
1090 (replace-regexp-in-string "\n" " " text)
1091 separator)))
1092 ;; Handle the `protectedtexttt' special case: Protect some
1093 ;; special chars and use "\texttt{%s}" format string.
1094 ((eq 'protectedtexttt fmt)
1095 (let ((start 0)
1096 (trans '(("\\" . "\\textbackslash{}")
1097 ("~" . "\\textasciitilde{}")
1098 ("^" . "\\textasciicircum{}")))
1099 (rtn "")
1100 char)
1101 (while (string-match "[\\{}$%&_#~^]" text)
1102 (setq char (match-string 0 text))
1103 (if (> (match-beginning 0) 0)
1104 (setq rtn (concat rtn (substring text 0 (match-beginning 0)))))
1105 (setq text (substring text (1+ (match-beginning 0))))
1106 (setq char (or (cdr (assoc char trans)) (concat "\\" char))
1107 rtn (concat rtn char)))
1108 (setq text (concat rtn text)
1109 fmt "\\texttt{%s}")
1110 (while (string-match "--" text)
1111 (setq text (replace-match "-{}-" t t text)))
1112 (format fmt text)))
1113 ;; Else use format string.
1114 (t (format fmt text)))))
1116 (defun org-latex--delayed-footnotes-definitions (element info)
1117 "Return footnotes definitions in ELEMENT as a string.
1119 INFO is a plist used as a communication channel.
1121 Footnotes definitions are returned within \"\\footnotetxt{}\"
1122 commands.
1124 This function is used within constructs that don't support
1125 \"\\footnote{}\" command (i.e. an item's tag). In that case,
1126 \"\\footnotemark\" is used within the construct and the function
1127 just outside of it."
1128 (mapconcat
1129 (lambda (ref)
1130 (format
1131 "\\footnotetext[%s]{%s}"
1132 (org-export-get-footnote-number ref info)
1133 (org-trim
1134 (org-export-data
1135 (org-export-get-footnote-definition ref info) info))))
1136 ;; Find every footnote reference in ELEMENT.
1137 (let* (all-refs
1138 search-refs ; For byte-compiler.
1139 (search-refs
1140 (function
1141 (lambda (data)
1142 ;; Return a list of all footnote references never seen
1143 ;; before in DATA.
1144 (org-element-map data 'footnote-reference
1145 (lambda (ref)
1146 (when (org-export-footnote-first-reference-p ref info)
1147 (push ref all-refs)
1148 (when (eq (org-element-property :type ref) 'standard)
1149 (funcall search-refs
1150 (org-export-get-footnote-definition ref info)))))
1151 info)
1152 (reverse all-refs)))))
1153 (funcall search-refs element))
1154 ""))
1156 (defun org-latex--translate (s info)
1157 "Translate string S according to specified language.
1158 INFO is a plist used as a communication channel."
1159 (org-export-translate s :latex info))
1163 ;;; Template
1165 (defun org-latex-template (contents info)
1166 "Return complete document string after LaTeX conversion.
1167 CONTENTS is the transcoded contents string. INFO is a plist
1168 holding export options."
1169 (let ((title (org-export-data (plist-get info :title) info)))
1170 (concat
1171 ;; Time-stamp.
1172 (and (plist-get info :time-stamp-file)
1173 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
1174 ;; Document class and packages.
1175 (let* ((class (plist-get info :latex-class))
1176 (class-options (plist-get info :latex-class-options))
1177 (header (nth 1 (assoc class org-latex-classes)))
1178 (document-class-string
1179 (and (stringp header)
1180 (if (not class-options) header
1181 (replace-regexp-in-string
1182 "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
1183 class-options header t nil 1)))))
1184 (if (not document-class-string)
1185 (user-error "Unknown LaTeX class `%s'" class)
1186 (org-latex-guess-babel-language
1187 (org-latex-guess-inputenc
1188 (org-element-normalize-string
1189 (org-splice-latex-header
1190 document-class-string
1191 org-latex-default-packages-alist
1192 org-latex-packages-alist nil
1193 (concat (org-element-normalize-string
1194 (plist-get info :latex-header))
1195 (plist-get info :latex-header-extra)))))
1196 info)))
1197 ;; Possibly limit depth for headline numbering.
1198 (let ((sec-num (plist-get info :section-numbers)))
1199 (when (integerp sec-num)
1200 (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
1201 ;; Author.
1202 (let ((author (and (plist-get info :with-author)
1203 (let ((auth (plist-get info :author)))
1204 (and auth (org-export-data auth info)))))
1205 (email (and (plist-get info :with-email)
1206 (org-export-data (plist-get info :email) info))))
1207 (cond ((and author email (not (string= "" email)))
1208 (format "\\author{%s\\thanks{%s}}\n" author email))
1209 ((or author email) (format "\\author{%s}\n" (or author email)))))
1210 ;; Date.
1211 (let ((date (and (plist-get info :with-date) (org-export-get-date info))))
1212 (format "\\date{%s}\n" (org-export-data date info)))
1213 ;; Title
1214 (format "\\title{%s}\n" title)
1215 ;; Hyperref options.
1216 (format-spec (plist-get info :latex-hyperref)
1217 (format-spec-make
1218 ?k (or (plist-get info :keywords) "")
1219 ?d (or (plist-get info :description)"")
1220 ?c (if (plist-get info :with-creator)
1221 (plist-get info :creator)
1222 "")))
1223 ;; Document start.
1224 "\\begin{document}\n\n"
1225 ;; Title command.
1226 (org-element-normalize-string
1227 (cond ((string= "" title) nil)
1228 ((not (stringp org-latex-title-command)) nil)
1229 ((string-match "\\(?:[^%]\\|^\\)%s"
1230 org-latex-title-command)
1231 (format org-latex-title-command title))
1232 (t org-latex-title-command)))
1233 ;; Table of contents.
1234 (let ((depth (plist-get info :with-toc)))
1235 (when depth
1236 (concat (when (wholenump depth)
1237 (format "\\setcounter{tocdepth}{%d}\n" depth))
1238 org-latex-toc-command)))
1239 ;; Document's body.
1240 contents
1241 ;; Creator.
1242 (let ((creator-info (plist-get info :with-creator)))
1243 (cond
1244 ((not creator-info) "")
1245 ((eq creator-info 'comment)
1246 (format "%% %s\n" (plist-get info :creator)))
1247 (t (concat (plist-get info :creator) "\n"))))
1248 ;; Document end.
1249 "\\end{document}")))
1253 ;;; Transcode Functions
1255 ;;;; Bold
1257 (defun org-latex-bold (bold contents info)
1258 "Transcode BOLD from Org to LaTeX.
1259 CONTENTS is the text with bold markup. INFO is a plist holding
1260 contextual information."
1261 (org-latex--text-markup contents 'bold))
1264 ;;;; Center Block
1266 (defun org-latex-center-block (center-block contents info)
1267 "Transcode a CENTER-BLOCK element from Org to LaTeX.
1268 CONTENTS holds the contents of the center block. INFO is a plist
1269 holding contextual information."
1270 (org-latex--wrap-label
1271 center-block
1272 (format "\\begin{center}\n%s\\end{center}" contents)))
1275 ;;;; Clock
1277 (defun org-latex-clock (clock contents info)
1278 "Transcode a CLOCK element from Org to LaTeX.
1279 CONTENTS is nil. INFO is a plist holding contextual
1280 information."
1281 (concat
1282 "\\noindent"
1283 (format "\\textbf{%s} " org-clock-string)
1284 (format org-latex-inactive-timestamp-format
1285 (concat (org-translate-time
1286 (org-element-property :raw-value
1287 (org-element-property :value clock)))
1288 (let ((time (org-element-property :duration clock)))
1289 (and time (format " (%s)" time)))))
1290 "\\\\"))
1293 ;;;; Code
1295 (defun org-latex-code (code contents info)
1296 "Transcode a CODE object from Org to LaTeX.
1297 CONTENTS is nil. INFO is a plist used as a communication
1298 channel."
1299 (org-latex--text-markup (org-element-property :value code) 'code))
1302 ;;;; Drawer
1304 (defun org-latex-drawer (drawer contents info)
1305 "Transcode a DRAWER element from Org to LaTeX.
1306 CONTENTS holds the contents of the block. INFO is a plist
1307 holding contextual information."
1308 (let* ((name (org-element-property :drawer-name drawer))
1309 (output (funcall org-latex-format-drawer-function
1310 name contents)))
1311 (org-latex--wrap-label drawer output)))
1314 ;;;; Dynamic Block
1316 (defun org-latex-dynamic-block (dynamic-block contents info)
1317 "Transcode a DYNAMIC-BLOCK element from Org to LaTeX.
1318 CONTENTS holds the contents of the block. INFO is a plist
1319 holding contextual information. See `org-export-data'."
1320 (org-latex--wrap-label dynamic-block contents))
1323 ;;;; Entity
1325 (defun org-latex-entity (entity contents info)
1326 "Transcode an ENTITY object from Org to LaTeX.
1327 CONTENTS are the definition itself. INFO is a plist holding
1328 contextual information."
1329 (org-element-property :latex entity))
1332 ;;;; Example Block
1334 (defun org-latex-example-block (example-block contents info)
1335 "Transcode an EXAMPLE-BLOCK element from Org to LaTeX.
1336 CONTENTS is nil. INFO is a plist holding contextual
1337 information."
1338 (when (org-string-nw-p (org-element-property :value example-block))
1339 (org-latex--wrap-label
1340 example-block
1341 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1342 (org-export-format-code-default example-block info)))))
1345 ;;;; Export Block
1347 (defun org-latex-export-block (export-block contents info)
1348 "Transcode a EXPORT-BLOCK element from Org to LaTeX.
1349 CONTENTS is nil. INFO is a plist holding contextual information."
1350 (when (member (org-element-property :type export-block) '("LATEX" "TEX"))
1351 (org-remove-indentation (org-element-property :value export-block))))
1354 ;;;; Export Snippet
1356 (defun org-latex-export-snippet (export-snippet contents info)
1357 "Transcode a EXPORT-SNIPPET object from Org to LaTeX.
1358 CONTENTS is nil. INFO is a plist holding contextual information."
1359 (when (eq (org-export-snippet-backend export-snippet) 'latex)
1360 (org-element-property :value export-snippet)))
1363 ;;;; Fixed Width
1365 (defun org-latex-fixed-width (fixed-width contents info)
1366 "Transcode a FIXED-WIDTH element from Org to LaTeX.
1367 CONTENTS is nil. INFO is a plist holding contextual information."
1368 (org-latex--wrap-label
1369 fixed-width
1370 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1371 (org-remove-indentation
1372 (org-element-property :value fixed-width)))))
1375 ;;;; Footnote Reference
1377 (defun org-latex-footnote-reference (footnote-reference contents info)
1378 "Transcode a FOOTNOTE-REFERENCE element from Org to LaTeX.
1379 CONTENTS is nil. INFO is a plist holding contextual information."
1380 (concat
1381 ;; Insert separator between two footnotes in a row.
1382 (let ((prev (org-export-get-previous-element footnote-reference info)))
1383 (when (eq (org-element-type prev) 'footnote-reference)
1384 org-latex-footnote-separator))
1385 (cond
1386 ;; Use \footnotemark if the footnote has already been defined.
1387 ((not (org-export-footnote-first-reference-p footnote-reference info))
1388 (format "\\footnotemark[%s]{}"
1389 (org-export-get-footnote-number footnote-reference info)))
1390 ;; Use \footnotemark if reference is within another footnote
1391 ;; reference, footnote definition or table cell.
1392 ((loop for parent in (org-export-get-genealogy footnote-reference)
1393 thereis (memq (org-element-type parent)
1394 '(footnote-reference footnote-definition table-cell)))
1395 "\\footnotemark")
1396 ;; Otherwise, define it with \footnote command.
1398 (let ((def (org-export-get-footnote-definition footnote-reference info)))
1399 (concat
1400 (format "\\footnote{%s}" (org-trim (org-export-data def info)))
1401 ;; Retrieve all footnote references within the footnote and
1402 ;; add their definition after it, since LaTeX doesn't support
1403 ;; them inside.
1404 (org-latex--delayed-footnotes-definitions def info)))))))
1407 ;;;; Headline
1409 (defun org-latex-headline (headline contents info)
1410 "Transcode a HEADLINE element from Org to LaTeX.
1411 CONTENTS holds the contents of the headline. INFO is a plist
1412 holding contextual information."
1413 (unless (org-element-property :footnote-section-p headline)
1414 (let* ((class (plist-get info :latex-class))
1415 (level (org-export-get-relative-level headline info))
1416 (numberedp (org-export-numbered-headline-p headline info))
1417 (class-sectioning (assoc class org-latex-classes))
1418 ;; Section formatting will set two placeholders: one for
1419 ;; the title and the other for the contents.
1420 (section-fmt
1421 (let ((sec (if (functionp (nth 2 class-sectioning))
1422 (funcall (nth 2 class-sectioning) level numberedp)
1423 (nth (1+ level) class-sectioning))))
1424 (cond
1425 ;; No section available for that LEVEL.
1426 ((not sec) nil)
1427 ;; Section format directly returned by a function. Add
1428 ;; placeholder for contents.
1429 ((stringp sec) (concat sec "\n%s"))
1430 ;; (numbered-section . unnumbered-section)
1431 ((not (consp (cdr sec)))
1432 (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
1433 ;; (numbered-open numbered-close)
1434 ((= (length sec) 2)
1435 (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
1436 ;; (num-in num-out no-num-in no-num-out)
1437 ((= (length sec) 4)
1438 (if numberedp (concat (car sec) "\n%s" (nth 1 sec))
1439 (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
1440 ;; Create a temporary export back-end that hard-codes
1441 ;; "\underline" within "\section" and alike.
1442 (section-back-end
1443 (org-export-create-backend
1444 :parent 'latex
1445 :transcoders
1446 '((underline . (lambda (o c i) (format "\\underline{%s}" c))))))
1447 (text
1448 (org-export-data-with-backend
1449 (org-element-property :title headline) section-back-end info))
1450 (todo
1451 (and (plist-get info :with-todo-keywords)
1452 (let ((todo (org-element-property :todo-keyword headline)))
1453 (and todo (org-export-data todo info)))))
1454 (todo-type (and todo (org-element-property :todo-type headline)))
1455 (tags (and (plist-get info :with-tags)
1456 (org-export-get-tags headline info)))
1457 (priority (and (plist-get info :with-priority)
1458 (org-element-property :priority headline)))
1459 ;; Create the headline text along with a no-tag version.
1460 ;; The latter is required to remove tags from toc.
1461 (full-text (funcall org-latex-format-headline-function
1462 todo todo-type priority text tags))
1463 ;; Associate \label to the headline for internal links.
1464 (headline-label
1465 (let ((custom-label
1466 (and (plist-get info :latex-custom-id-labels)
1467 (org-element-property :CUSTOM_ID headline))))
1468 (if custom-label (format "\\label{%s}\n" custom-label)
1469 (format "\\label{sec-%s}\n"
1470 (mapconcat
1471 #'number-to-string
1472 (org-export-get-headline-number headline info)
1473 "-")))))
1474 (pre-blanks
1475 (make-string (org-element-property :pre-blank headline) 10)))
1476 (if (or (not section-fmt) (org-export-low-level-p headline info))
1477 ;; This is a deep sub-tree: export it as a list item. Also
1478 ;; export as items headlines for which no section format has
1479 ;; been found.
1480 (let ((low-level-body
1481 (concat
1482 ;; If headline is the first sibling, start a list.
1483 (when (org-export-first-sibling-p headline info)
1484 (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
1485 ;; Itemize headline
1486 "\\item"
1487 (and full-text (org-string-match-p "\\`[ \t]*\\[" full-text)
1488 "\\relax")
1489 " " full-text "\n"
1490 headline-label
1491 pre-blanks
1492 contents)))
1493 ;; If headline is not the last sibling simply return
1494 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before
1495 ;; any blank line.
1496 (if (not (org-export-last-sibling-p headline info)) low-level-body
1497 (replace-regexp-in-string
1498 "[ \t\n]*\\'"
1499 (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
1500 low-level-body)))
1501 ;; This is a standard headline. Export it as a section. Add
1502 ;; an alternative heading when possible, and when this is not
1503 ;; identical to the usual heading.
1504 (let ((opt-title
1505 (funcall org-latex-format-headline-function
1506 todo todo-type priority
1507 (org-export-data-with-backend
1508 (org-export-get-alt-title headline info)
1509 section-back-end info)
1510 (and (eq (plist-get info :with-tags) t) tags))))
1511 (if (and numberedp opt-title
1512 (not (equal opt-title full-text))
1513 (string-match "\\`\\\\\\(.*?[^*]\\){" section-fmt))
1514 (format (replace-match "\\1[%s]" nil nil section-fmt 1)
1515 ;; Replace square brackets with parenthesis
1516 ;; since square brackets are not supported in
1517 ;; optional arguments.
1518 (replace-regexp-in-string
1519 "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title))
1520 full-text
1521 (concat headline-label pre-blanks contents))
1522 ;; Impossible to add an alternative heading. Fallback to
1523 ;; regular sectioning format string.
1524 (format section-fmt full-text
1525 (concat headline-label pre-blanks contents))))))))
1527 (defun org-latex-format-headline-default-function
1528 (todo todo-type priority text tags)
1529 "Default format function for a headline.
1530 See `org-latex-format-headline-function' for details."
1531 (concat
1532 (and todo (format "{\\bfseries\\sffamily %s} " todo))
1533 (and priority (format "\\framebox{\\#%c} " priority))
1534 text
1535 (and tags
1536 (format "\\hfill{}\\textsc{%s}" (mapconcat 'identity tags ":")))))
1539 ;;;; Horizontal Rule
1541 (defun org-latex-horizontal-rule (horizontal-rule contents info)
1542 "Transcode an HORIZONTAL-RULE object from Org to LaTeX.
1543 CONTENTS is nil. INFO is a plist holding contextual information."
1544 (let ((attr (org-export-read-attribute :attr_latex horizontal-rule))
1545 (prev (org-export-get-previous-element horizontal-rule info)))
1546 (concat
1547 ;; Make sure the rule doesn't start at the end of the current
1548 ;; line by separating it with a blank line from previous element.
1549 (when (and prev
1550 (let ((prev-blank (org-element-property :post-blank prev)))
1551 (or (not prev-blank) (zerop prev-blank))))
1552 "\n")
1553 (org-latex--wrap-label
1554 horizontal-rule
1555 (format "\\rule{%s}{%s}"
1556 (or (plist-get attr :width) "\\linewidth")
1557 (or (plist-get attr :thickness) "0.5pt"))))))
1560 ;;;; Inline Src Block
1562 (defun org-latex-inline-src-block (inline-src-block contents info)
1563 "Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
1564 CONTENTS holds the contents of the item. INFO is a plist holding
1565 contextual information."
1566 (let* ((code (org-element-property :value inline-src-block))
1567 (separator (org-latex--find-verb-separator code)))
1568 (cond
1569 ;; Do not use a special package: transcode it verbatim.
1570 ((not org-latex-listings)
1571 (concat "\\verb" separator code separator))
1572 ;; Use minted package.
1573 ((eq org-latex-listings 'minted)
1574 (let* ((org-lang (org-element-property :language inline-src-block))
1575 (mint-lang (or (cadr (assq (intern org-lang)
1576 org-latex-minted-langs))
1577 (downcase org-lang)))
1578 (options (org-latex--make-option-string
1579 org-latex-minted-options)))
1580 (concat (format "\\mint%s{%s}"
1581 (if (string= options "") "" (format "[%s]" options))
1582 mint-lang)
1583 separator code separator)))
1584 ;; Use listings package.
1586 ;; Maybe translate language's name.
1587 (let* ((org-lang (org-element-property :language inline-src-block))
1588 (lst-lang (or (cadr (assq (intern org-lang)
1589 org-latex-listings-langs))
1590 org-lang))
1591 (options (org-latex--make-option-string
1592 (append org-latex-listings-options
1593 `(("language" ,lst-lang))))))
1594 (concat (format "\\lstinline[%s]" options)
1595 separator code separator))))))
1598 ;;;; Inlinetask
1600 (defun org-latex-inlinetask (inlinetask contents info)
1601 "Transcode an INLINETASK element from Org to LaTeX.
1602 CONTENTS holds the contents of the block. INFO is a plist
1603 holding contextual information."
1604 (let ((title (org-export-data (org-element-property :title inlinetask) info))
1605 (todo (and (plist-get info :with-todo-keywords)
1606 (let ((todo (org-element-property :todo-keyword inlinetask)))
1607 (and todo (org-export-data todo info)))))
1608 (todo-type (org-element-property :todo-type inlinetask))
1609 (tags (and (plist-get info :with-tags)
1610 (org-export-get-tags inlinetask info)))
1611 (priority (and (plist-get info :with-priority)
1612 (org-element-property :priority inlinetask))))
1613 ;; If `org-latex-format-inlinetask-function' is provided, call it
1614 ;; with appropriate arguments.
1615 (if (not (eq org-latex-format-inlinetask-function 'ignore))
1616 (funcall org-latex-format-inlinetask-function
1617 todo todo-type priority title tags contents)
1618 ;; Otherwise, use a default template.
1619 (org-latex--wrap-label
1620 inlinetask
1621 (let ((full-title
1622 (concat
1623 (when todo (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
1624 (when priority (format "\\framebox{\\#%c} " priority))
1625 title
1626 (when tags (format "\\hfill{}\\textsc{:%s:}"
1627 (mapconcat 'identity tags ":"))))))
1628 (format (concat "\\begin{center}\n"
1629 "\\fbox{\n"
1630 "\\begin{minipage}[c]{.6\\textwidth}\n"
1631 "%s\n\n"
1632 "\\rule[.8em]{\\textwidth}{2pt}\n\n"
1633 "%s"
1634 "\\end{minipage}\n"
1635 "}\n"
1636 "\\end{center}")
1637 full-title contents))))))
1640 ;;;; Italic
1642 (defun org-latex-italic (italic contents info)
1643 "Transcode ITALIC from Org to LaTeX.
1644 CONTENTS is the text with italic markup. INFO is a plist holding
1645 contextual information."
1646 (org-latex--text-markup contents 'italic))
1649 ;;;; Item
1651 (defun org-latex-item (item contents info)
1652 "Transcode an ITEM element from Org to LaTeX.
1653 CONTENTS holds the contents of the item. INFO is a plist holding
1654 contextual information."
1655 (let* ((counter
1656 (let ((count (org-element-property :counter item))
1657 (level
1658 ;; Determine level of current item to determine the
1659 ;; correct LaTeX counter to use (enumi, enumii...).
1660 (let ((parent item) (level 0))
1661 (while (memq (org-element-type
1662 (setq parent (org-export-get-parent parent)))
1663 '(plain-list item))
1664 (when (and (eq (org-element-type parent) 'plain-list)
1665 (eq (org-element-property :type parent)
1666 'ordered))
1667 (incf level)))
1668 level)))
1669 (and count
1670 (< level 5)
1671 (format "\\setcounter{enum%s}{%s}\n"
1672 (nth (1- level) '("i" "ii" "iii" "iv"))
1673 (1- count)))))
1674 (checkbox (case (org-element-property :checkbox item)
1675 (on "$\\boxtimes$ ")
1676 (off "$\\square$ ")
1677 (trans "$\\boxminus$ ")))
1678 (tag (let ((tag (org-element-property :tag item)))
1679 ;; Check-boxes must belong to the tag.
1680 (and tag (format "[{%s}] "
1681 (concat checkbox
1682 (org-export-data tag info)))))))
1683 (concat counter
1684 "\\item"
1685 (cond
1686 (tag)
1687 (checkbox (concat " " checkbox))
1688 ;; Without a tag or a check-box, if CONTENTS starts with
1689 ;; an opening square bracket, add "\relax" to "\item",
1690 ;; unless the brackets comes from an initial export
1691 ;; snippet (i.e. it is inserted willingly by the user).
1692 ((and contents
1693 (org-string-match-p "\\`[ \t]*\\[" contents)
1694 (not (let ((e (car (org-element-contents item))))
1695 (and (eq (org-element-type e) 'paragraph)
1696 (let ((o (car (org-element-contents e))))
1697 (and (eq (org-element-type o) 'export-snippet)
1698 (eq (org-export-snippet-backend o)
1699 'latex)))))))
1700 "\\relax ")
1701 (t " "))
1702 (and contents (org-trim contents))
1703 ;; If there are footnotes references in tag, be sure to
1704 ;; add their definition at the end of the item. This
1705 ;; workaround is necessary since "\footnote{}" command is
1706 ;; not supported in tags.
1707 (and tag
1708 (org-latex--delayed-footnotes-definitions
1709 (org-element-property :tag item) info)))))
1712 ;;;; Keyword
1714 (defun org-latex-keyword (keyword contents info)
1715 "Transcode a KEYWORD element from Org to LaTeX.
1716 CONTENTS is nil. INFO is a plist holding contextual information."
1717 (let ((key (org-element-property :key keyword))
1718 (value (org-element-property :value keyword)))
1719 (cond
1720 ((string= key "LATEX") value)
1721 ((string= key "INDEX") (format "\\index{%s}" value))
1722 ((string= key "TOC")
1723 (let ((value (downcase value)))
1724 (cond
1725 ((string-match "\\<headlines\\>" value)
1726 (let ((depth (or (and (string-match "[0-9]+" value)
1727 (string-to-number (match-string 0 value)))
1728 (plist-get info :with-toc))))
1729 (concat
1730 (when (wholenump depth)
1731 (format "\\setcounter{tocdepth}{%s}\n" depth))
1732 "\\tableofcontents")))
1733 ((string= "tables" value) "\\listoftables")
1734 ((string= "listings" value)
1735 (cond
1736 ((eq org-latex-listings 'minted) "\\listoflistings")
1737 (org-latex-listings "\\lstlistoflistings")
1738 ;; At the moment, src blocks with a caption are wrapped
1739 ;; into a figure environment.
1740 (t "\\listoffigures")))))))))
1743 ;;;; Latex Environment
1745 (defun org-latex-latex-environment (latex-environment contents info)
1746 "Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
1747 CONTENTS is nil. INFO is a plist holding contextual information."
1748 (when (plist-get info :with-latex)
1749 (let ((label (org-element-property :name latex-environment))
1750 (value (org-remove-indentation
1751 (org-element-property :value latex-environment))))
1752 (if (not (org-string-nw-p label)) value
1753 ;; Environment is labeled: label must be within the environment
1754 ;; (otherwise, a reference pointing to that element will count
1755 ;; the section instead).
1756 (with-temp-buffer
1757 (insert value)
1758 (goto-char (point-min))
1759 (forward-line)
1760 (insert
1761 (format "\\label{%s}\n" (org-export-solidify-link-text label)))
1762 (buffer-string))))))
1765 ;;;; Latex Fragment
1767 (defun org-latex-latex-fragment (latex-fragment contents info)
1768 "Transcode a LATEX-FRAGMENT object from Org to LaTeX.
1769 CONTENTS is nil. INFO is a plist holding contextual information."
1770 (let ((value (org-element-property :value latex-fragment)))
1771 ;; Trim math markers since the fragment is enclosed within
1772 ;; a latex-math-block object anyway.
1773 (cond ((string-match "\\`\\(\\$\\{1,2\\}\\)\\([^\000]*\\)\\1\\'" value)
1774 (match-string 2 value))
1775 ((string-match "\\`\\\\(\\([^\000]*\\)\\\\)\\'" value)
1776 (match-string 1 value))
1777 (t value))))
1780 ;;;; Line Break
1782 (defun org-latex-line-break (line-break contents info)
1783 "Transcode a LINE-BREAK object from Org to LaTeX.
1784 CONTENTS is nil. INFO is a plist holding contextual information."
1785 "\\\\\n")
1788 ;;;; Link
1790 (defun org-latex--inline-image (link info)
1791 "Return LaTeX code for an inline image.
1792 LINK is the link pointing to the inline image. INFO is a plist
1793 used as a communication channel."
1794 (let* ((parent (org-export-get-parent-element link))
1795 (path (let ((raw-path (org-element-property :path link)))
1796 (if (not (file-name-absolute-p raw-path)) raw-path
1797 (expand-file-name raw-path))))
1798 (filetype (file-name-extension path))
1799 (caption (org-latex--caption/label-string parent info))
1800 ;; Retrieve latex attributes from the element around.
1801 (attr (org-export-read-attribute :attr_latex parent))
1802 (float (let ((float (plist-get attr :float)))
1803 (cond ((and (not float) (plist-member attr :float)) nil)
1804 ((string= float "wrap") 'wrap)
1805 ((string= float "sideways") 'sideways)
1806 ((string= float "multicolumn") 'multicolumn)
1807 ((or float
1808 (org-element-property :caption parent)
1809 (org-string-nw-p (plist-get attr :caption)))
1810 'figure))))
1811 (placement
1812 (let ((place (plist-get attr :placement)))
1813 (cond (place (format "%s" place))
1814 ((eq float 'wrap) "{l}{0.5\\textwidth}")
1815 ((eq float 'figure)
1816 (format "[%s]" org-latex-default-figure-position))
1817 (t ""))))
1818 (comment-include (if (plist-get attr :comment-include) "%" ""))
1819 ;; It is possible to specify width and height in the
1820 ;; ATTR_LATEX line, and also via default variables.
1821 (width (cond ((plist-get attr :width))
1822 ((plist-get attr :height) "")
1823 ((eq float 'wrap) "0.48\\textwidth")
1824 (t org-latex-image-default-width)))
1825 (height (cond ((plist-get attr :height))
1826 ((or (plist-get attr :width)
1827 (memq float '(figure wrap))) "")
1828 (t org-latex-image-default-height)))
1829 (options (let ((opt (or (plist-get attr :options)
1830 org-latex-image-default-option)))
1831 (if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt)) opt
1832 (match-string 1 opt))))
1833 image-code)
1834 (if (member filetype '("tikz" "pgf"))
1835 ;; For tikz images:
1836 ;; - use \input to read in image file.
1837 ;; - if options are present, wrap in a tikzpicture environment.
1838 ;; - if width or height are present, use \resizebox to change
1839 ;; the image size.
1840 (progn
1841 (setq image-code (format "\\input{%s}" path))
1842 (when (org-string-nw-p options)
1843 (setq image-code
1844 (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
1845 options
1846 image-code)))
1847 (when (or (org-string-nw-p width) (org-string-nw-p height))
1848 (setq image-code (format "\\resizebox{%s}{%s}{%s}"
1849 (if (org-string-nw-p width) width "!")
1850 (if (org-string-nw-p height) height "!")
1851 image-code))))
1852 ;; For other images:
1853 ;; - add width and height to options.
1854 ;; - include the image with \includegraphics.
1855 (when (org-string-nw-p width)
1856 (setq options (concat options ",width=" width)))
1857 (when (org-string-nw-p height)
1858 (setq options (concat options ",height=" height)))
1859 (setq image-code
1860 (format "\\includegraphics%s{%s}"
1861 (cond ((not (org-string-nw-p options)) "")
1862 ((= (aref options 0) ?,)
1863 (format "[%s]"(substring options 1)))
1864 (t (format "[%s]" options)))
1865 path))
1866 (when (equal filetype "svg")
1867 (setq image-code (replace-regexp-in-string "^\\\\includegraphics"
1868 "\\includesvg"
1869 image-code
1870 nil t))
1871 (setq image-code (replace-regexp-in-string "\\.svg}"
1873 image-code
1874 nil t))))
1875 ;; Return proper string, depending on FLOAT.
1876 (case float
1877 (wrap (format "\\begin{wrapfigure}%s
1878 \\centering
1879 %s%s
1880 %s\\end{wrapfigure}" placement comment-include image-code caption))
1881 (sideways (format "\\begin{sidewaysfigure}
1882 \\centering
1883 %s%s
1884 %s\\end{sidewaysfigure}" comment-include image-code caption))
1885 (multicolumn (format "\\begin{figure*}%s
1886 \\centering
1887 %s%s
1888 %s\\end{figure*}" placement comment-include image-code caption))
1889 (figure (format "\\begin{figure}%s
1890 \\centering
1891 %s%s
1892 %s\\end{figure}" placement comment-include image-code caption))
1893 (otherwise image-code))))
1895 (defun org-latex-link (link desc info)
1896 "Transcode a LINK object from Org to LaTeX.
1898 DESC is the description part of the link, or the empty string.
1899 INFO is a plist holding contextual information. See
1900 `org-export-data'."
1901 (let* ((type (org-element-property :type link))
1902 (raw-path (replace-regexp-in-string
1903 "%" "\\%" (org-element-property :path link) nil t))
1904 ;; Ensure DESC really exists, or set it to nil.
1905 (desc (and (not (string= desc "")) desc))
1906 (imagep (org-export-inline-image-p
1907 link org-latex-inline-image-rules))
1908 (path (cond
1909 ((member type '("http" "https" "ftp" "mailto"))
1910 (concat type ":" raw-path))
1911 ((and (string= type "file") (file-name-absolute-p raw-path))
1912 (concat "file:" raw-path))
1913 (t raw-path)))
1914 protocol)
1915 (cond
1916 ;; Image file.
1917 (imagep (org-latex--inline-image link info))
1918 ;; Radio link: Transcode target's contents and use them as link's
1919 ;; description.
1920 ((string= type "radio")
1921 (let ((destination (org-export-resolve-radio-link link info)))
1922 (when destination
1923 (format "\\hyperref[%s]{%s}"
1924 (org-export-solidify-link-text
1925 (org-element-property :value destination))
1926 desc))))
1927 ;; Links pointing to a headline: Find destination and build
1928 ;; appropriate referencing command.
1929 ((member type '("custom-id" "fuzzy" "id"))
1930 (let ((destination (if (string= type "fuzzy")
1931 (org-export-resolve-fuzzy-link link info)
1932 (org-export-resolve-id-link link info))))
1933 (case (org-element-type destination)
1934 ;; Id link points to an external file.
1935 (plain-text
1936 (if desc (format "\\href{%s}{%s}" destination desc)
1937 (format "\\url{%s}" destination)))
1938 ;; Fuzzy link points nowhere.
1939 ('nil
1940 (format org-latex-link-with-unknown-path-format
1941 (or desc
1942 (org-export-data
1943 (org-element-property :raw-link link) info))))
1944 ;; LINK points to a headline. If headlines are numbered
1945 ;; and the link has no description, display headline's
1946 ;; number. Otherwise, display description or headline's
1947 ;; title.
1948 (headline
1949 (let* ((custom-label
1950 (and (plist-get info :latex-custom-id-labels)
1951 (org-element-property :CUSTOM_ID destination)))
1952 (label
1954 custom-label
1955 (format "sec-%s"
1956 (mapconcat
1957 #'number-to-string
1958 (org-export-get-headline-number destination info)
1959 "-")))))
1960 (if (and (plist-get info :section-numbers) (not desc))
1961 (format "\\ref{%s}" label)
1962 (format "\\hyperref[%s]{%s}" label
1963 (or desc
1964 (org-export-data
1965 (org-element-property :title destination) info))))))
1966 ;; Fuzzy link points to a target. Do as above.
1967 (otherwise
1968 (let ((path (org-export-solidify-link-text path)))
1969 (if (not desc) (format "\\ref{%s}" path)
1970 (format "\\hyperref[%s]{%s}" path desc)))))))
1971 ;; Coderef: replace link with the reference name or the
1972 ;; equivalent line number.
1973 ((string= type "coderef")
1974 (format (org-export-get-coderef-format path desc)
1975 (org-export-resolve-coderef path info)))
1976 ;; Link type is handled by a special function.
1977 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
1978 (funcall protocol (org-link-unescape path) desc 'latex))
1979 ;; External link with a description part.
1980 ((and path desc) (format "\\href{%s}{%s}" path desc))
1981 ;; External link without a description part.
1982 (path (format "\\url{%s}" path))
1983 ;; No path, only description. Try to do something useful.
1984 (t (format org-latex-link-with-unknown-path-format desc)))))
1987 ;;;; Node Property
1989 (defun org-latex-node-property (node-property contents info)
1990 "Transcode a NODE-PROPERTY element from Org to LaTeX.
1991 CONTENTS is nil. INFO is a plist holding contextual
1992 information."
1993 (format "%s:%s"
1994 (org-element-property :key node-property)
1995 (let ((value (org-element-property :value node-property)))
1996 (if value (concat " " value) ""))))
1999 ;;;; Paragraph
2001 (defun org-latex-paragraph (paragraph contents info)
2002 "Transcode a PARAGRAPH element from Org to LaTeX.
2003 CONTENTS is the contents of the paragraph, as a string. INFO is
2004 the plist used as a communication channel."
2005 contents)
2008 ;;;; Plain List
2010 (defun org-latex-plain-list (plain-list contents info)
2011 "Transcode a PLAIN-LIST element from Org to LaTeX.
2012 CONTENTS is the contents of the list. INFO is a plist holding
2013 contextual information."
2014 (let* ((type (org-element-property :type plain-list))
2015 (attr (org-export-read-attribute :attr_latex plain-list))
2016 (latex-type (let ((env (plist-get attr :environment)))
2017 (cond (env (format "%s" env))
2018 ((eq type 'ordered) "enumerate")
2019 ((eq type 'descriptive) "description")
2020 (t "itemize")))))
2021 (org-latex--wrap-label
2022 plain-list
2023 (format "\\begin{%s}%s\n%s\\end{%s}"
2024 latex-type
2025 (or (plist-get attr :options) "")
2026 contents
2027 latex-type))))
2030 ;;;; Plain Text
2032 (defun org-latex-plain-text (text info)
2033 "Transcode a TEXT string from Org to LaTeX.
2034 TEXT is the string to transcode. INFO is a plist holding
2035 contextual information."
2036 (let ((specialp (plist-get info :with-special-strings))
2037 (output text))
2038 ;; Protect %, #, &, $, _, { and }.
2039 (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}_]\\)" output)
2040 (setq output
2041 (replace-match
2042 (format "\\%s" (match-string 2 output)) nil t output 2)))
2043 ;; Protect ^.
2044 (setq output
2045 (replace-regexp-in-string
2046 "\\([^\\]\\|^\\)\\(\\^\\)" "\\\\^{}" output nil nil 2))
2047 ;; Protect \. If special strings are used, be careful not to
2048 ;; protect "\" in "\-" constructs.
2049 (let ((symbols (if specialp "-%$#&{}^_\\" "%$#&{}^_\\")))
2050 (setq output
2051 (replace-regexp-in-string
2052 (format "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%s]\\|$\\)" symbols)
2053 "$\\backslash$" output nil t 1)))
2054 ;; Protect ~.
2055 (setq output
2056 (replace-regexp-in-string
2057 "\\([^\\]\\|^\\)\\(~\\)" "\\textasciitilde{}" output nil t 2))
2058 ;; Activate smart quotes. Be sure to provide original TEXT string
2059 ;; since OUTPUT may have been modified.
2060 (when (plist-get info :with-smart-quotes)
2061 (setq output (org-export-activate-smart-quotes output :latex info text)))
2062 ;; LaTeX into \LaTeX{} and TeX into \TeX{}.
2063 (let ((case-fold-search nil)
2064 (start 0))
2065 (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" output start)
2066 (setq output (replace-match
2067 (format "\\%s{}" (match-string 1 output)) nil t output)
2068 start (match-end 0))))
2069 ;; Convert special strings.
2070 (when specialp
2071 (setq output
2072 (replace-regexp-in-string "\\.\\.\\." "\\ldots{}" output nil t)))
2073 ;; Handle break preservation if required.
2074 (when (plist-get info :preserve-breaks)
2075 (setq output (replace-regexp-in-string
2076 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" output)))
2077 ;; Return value.
2078 output))
2081 ;;;; Planning
2083 (defun org-latex-planning (planning contents info)
2084 "Transcode a PLANNING element from Org to LaTeX.
2085 CONTENTS is nil. INFO is a plist holding contextual
2086 information."
2087 (concat
2088 "\\noindent"
2089 (mapconcat
2090 'identity
2091 (delq nil
2092 (list
2093 (let ((closed (org-element-property :closed planning)))
2094 (when closed
2095 (concat
2096 (format "\\textbf{%s} " org-closed-string)
2097 (format org-latex-inactive-timestamp-format
2098 (org-translate-time
2099 (org-element-property :raw-value closed))))))
2100 (let ((deadline (org-element-property :deadline planning)))
2101 (when deadline
2102 (concat
2103 (format "\\textbf{%s} " org-deadline-string)
2104 (format org-latex-active-timestamp-format
2105 (org-translate-time
2106 (org-element-property :raw-value deadline))))))
2107 (let ((scheduled (org-element-property :scheduled planning)))
2108 (when scheduled
2109 (concat
2110 (format "\\textbf{%s} " org-scheduled-string)
2111 (format org-latex-active-timestamp-format
2112 (org-translate-time
2113 (org-element-property :raw-value scheduled))))))))
2114 " ")
2115 "\\\\"))
2118 ;;;; Property Drawer
2120 (defun org-latex-property-drawer (property-drawer contents info)
2121 "Transcode a PROPERTY-DRAWER element from Org to LaTeX.
2122 CONTENTS holds the contents of the drawer. INFO is a plist
2123 holding contextual information."
2124 (and (org-string-nw-p contents)
2125 (format "\\begin{verbatim}\n%s\\end{verbatim}" contents)))
2128 ;;;; Pseudo Object: LaTeX Math Block
2130 (defun org-latex--wrap-latex-math-block (data info)
2131 "Merge contiguous math objects in a pseudo-object container.
2132 DATA is a parse tree or a secondary string. INFO is a plist
2133 containing export options. Modify DATA by side-effect and return it."
2134 (let ((valid-object-p
2135 (function
2136 ;; Non-nil when OBJ can be added to the latex math block.
2137 (lambda (obj)
2138 (case (org-element-type obj)
2139 (entity (org-element-property :latex-math-p obj))
2140 (latex-fragment
2141 (let ((value (org-element-property :value obj)))
2142 (or (org-string-match-p "\\`\\\\([^\000]*\\\\)\\'" value)
2143 (org-string-match-p "\\`\\$[^\000]*\\$\\'" value))))
2144 ((subscript superscript) t))))))
2145 (org-element-map data '(entity latex-fragment subscript superscript)
2146 (lambda (object)
2147 ;; Skip objects already wrapped.
2148 (when (and (not (eq (org-element-type
2149 (org-element-property :parent object))
2150 'latex-math-block))
2151 (funcall valid-object-p object))
2152 (let ((math-block (list 'latex-math-block nil))
2153 (next-elements (org-export-get-next-element object info t))
2154 (last object))
2155 ;; Wrap MATH-BLOCK around OBJECT in DATA.
2156 (org-element-insert-before math-block object)
2157 (org-element-extract-element object)
2158 (org-element-adopt-elements math-block object)
2159 (when (zerop (or (org-element-property :post-blank object) 0))
2160 ;; MATH-BLOCK swallows consecutive math objects.
2161 (catch 'exit
2162 (dolist (next next-elements)
2163 (if (not (funcall valid-object-p next)) (throw 'exit nil)
2164 (org-element-extract-element next)
2165 (org-element-adopt-elements math-block next)
2166 ;; Eschew the case: \beta$x$ -> \(\betax\).
2167 (unless (memq (org-element-type next)
2168 '(subscript superscript))
2169 (org-element-put-property last :post-blank 1))
2170 (setq last next)
2171 (when (> (or (org-element-property :post-blank next) 0) 0)
2172 (throw 'exit nil))))))
2173 (org-element-put-property
2174 math-block :post-blank (org-element-property :post-blank last)))))
2175 info nil '(subscript superscript latex-math-block) t)
2176 ;; Return updated DATA.
2177 data))
2179 (defun org-latex-math-block-tree-filter (tree backend info)
2180 (org-latex--wrap-latex-math-block tree info))
2182 (defun org-latex-math-block-options-filter (info backend)
2183 (dolist (prop '(:author :date :title) info)
2184 (plist-put info prop
2185 (org-latex--wrap-latex-math-block (plist-get info prop) info))))
2187 (defun org-latex-math-block (math-block contents info)
2188 "Transcode a MATH-BLOCK object from Org to LaTeX.
2189 CONTENTS is a string. INFO is a plist used as a communication
2190 channel."
2191 (when (org-string-nw-p contents)
2192 (format "\\(%s\\)" (org-trim contents))))
2194 ;;;; Quote Block
2196 (defun org-latex-quote-block (quote-block contents info)
2197 "Transcode a QUOTE-BLOCK element from Org to LaTeX.
2198 CONTENTS holds the contents of the block. INFO is a plist
2199 holding contextual information."
2200 (org-latex--wrap-label
2201 quote-block
2202 (format "\\begin{quote}\n%s\\end{quote}" contents)))
2205 ;;;; Radio Target
2207 (defun org-latex-radio-target (radio-target text info)
2208 "Transcode a RADIO-TARGET object from Org to LaTeX.
2209 TEXT is the text of the target. INFO is a plist holding
2210 contextual information."
2211 (format "\\label{%s}%s"
2212 (org-export-solidify-link-text
2213 (org-element-property :value radio-target))
2214 text))
2217 ;;;; Section
2219 (defun org-latex-section (section contents info)
2220 "Transcode a SECTION element from Org to LaTeX.
2221 CONTENTS holds the contents of the section. INFO is a plist
2222 holding contextual information."
2223 contents)
2226 ;;;; Special Block
2228 (defun org-latex-special-block (special-block contents info)
2229 "Transcode a SPECIAL-BLOCK element from Org to LaTeX.
2230 CONTENTS holds the contents of the block. INFO is a plist
2231 holding contextual information."
2232 (let ((type (downcase (org-element-property :type special-block)))
2233 (opt (org-export-read-attribute :attr_latex special-block :options)))
2234 (concat (format "\\begin{%s}%s\n" type (or opt ""))
2235 ;; Insert any label or caption within the block
2236 ;; (otherwise, a reference pointing to that element will
2237 ;; count the section instead).
2238 (org-latex--caption/label-string special-block info)
2239 contents
2240 (format "\\end{%s}" type))))
2243 ;;;; Src Block
2245 (defun org-latex-src-block (src-block contents info)
2246 "Transcode a SRC-BLOCK element from Org to LaTeX.
2247 CONTENTS holds the contents of the item. INFO is a plist holding
2248 contextual information."
2249 (when (org-string-nw-p (org-element-property :value src-block))
2250 (let* ((lang (org-element-property :language src-block))
2251 (caption (org-element-property :caption src-block))
2252 (label (org-element-property :name src-block))
2253 (custom-env (and lang
2254 (cadr (assq (intern lang)
2255 org-latex-custom-lang-environments))))
2256 (num-start (case (org-element-property :number-lines src-block)
2257 (continued (org-export-get-loc src-block info))
2258 (new 0)))
2259 (retain-labels (org-element-property :retain-labels src-block))
2260 (attributes (org-export-read-attribute :attr_latex src-block))
2261 (float (plist-get attributes :float)))
2262 (cond
2263 ;; Case 1. No source fontification.
2264 ((not org-latex-listings)
2265 (let* ((caption-str (org-latex--caption/label-string src-block info))
2266 (float-env
2267 (cond ((and (not float) (plist-member attributes :float)) "%s")
2268 ((string= "multicolumn" float)
2269 (format "\\begin{figure*}[%s]\n%%s%s\n\\end{figure*}"
2270 org-latex-default-figure-position
2271 caption-str))
2272 ((or caption float)
2273 (format "\\begin{figure}[H]\n%%s%s\n\\end{figure}"
2274 caption-str))
2275 (t "%s"))))
2276 (format
2277 float-env
2278 (concat (format "\\begin{verbatim}\n%s\\end{verbatim}"
2279 (org-export-format-code-default src-block info))))))
2280 ;; Case 2. Custom environment.
2281 (custom-env (format "\\begin{%s}\n%s\\end{%s}\n"
2282 custom-env
2283 (org-export-format-code-default src-block info)
2284 custom-env))
2285 ;; Case 3. Use minted package.
2286 ((eq org-latex-listings 'minted)
2287 (let* ((caption-str (org-latex--caption/label-string src-block info))
2288 (float-env
2289 (cond ((and (not float) (plist-member attributes :float)) "%s")
2290 ((string= "multicolumn" float)
2291 (format "\\begin{listing*}\n%%s\n%s\\end{listing*}"
2292 caption-str))
2293 ((or caption float)
2294 (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
2295 caption-str))
2296 (t "%s")))
2297 (body
2298 (format
2299 "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
2300 ;; Options.
2301 (concat
2302 (org-latex--make-option-string
2303 (if (or (not num-start)
2304 (assoc "linenos" org-latex-minted-options))
2305 org-latex-minted-options
2306 (append
2307 `(("linenos")
2308 ("firstnumber" ,(number-to-string (1+ num-start))))
2309 org-latex-minted-options)))
2310 (let ((local-options (plist-get attributes :options)))
2311 (and local-options (concat "," local-options))))
2312 ;; Language.
2313 (or (cadr (assq (intern lang) org-latex-minted-langs))
2314 (downcase lang))
2315 ;; Source code.
2316 (let* ((code-info (org-export-unravel-code src-block))
2317 (max-width
2318 (apply 'max
2319 (mapcar 'length
2320 (org-split-string (car code-info)
2321 "\n")))))
2322 (org-export-format-code
2323 (car code-info)
2324 (lambda (loc num ref)
2325 (concat
2327 (when ref
2328 ;; Ensure references are flushed to the right,
2329 ;; separated with 6 spaces from the widest line
2330 ;; of code.
2331 (concat (make-string (+ (- max-width (length loc)) 6)
2332 ?\s)
2333 (format "(%s)" ref)))))
2334 nil (and retain-labels (cdr code-info)))))))
2335 ;; Return value.
2336 (format float-env body)))
2337 ;; Case 4. Use listings package.
2339 (let ((lst-lang
2340 (or (cadr (assq (intern lang) org-latex-listings-langs)) lang))
2341 (caption-str
2342 (when caption
2343 (let ((main (org-export-get-caption src-block))
2344 (secondary (org-export-get-caption src-block t)))
2345 (if (not secondary)
2346 (format "{%s}" (org-export-data main info))
2347 (format "{[%s]%s}"
2348 (org-export-data secondary info)
2349 (org-export-data main info)))))))
2350 (concat
2351 ;; Options.
2352 (format
2353 "\\lstset{%s}\n"
2354 (concat
2355 (org-latex--make-option-string
2356 (append
2357 org-latex-listings-options
2358 (cond
2359 ((and (not float) (plist-member attributes :float)) nil)
2360 ((string= "multicolumn" float) '(("float" "*")))
2361 ((and float (not (assoc "float" org-latex-listings-options)))
2362 `(("float" ,org-latex-default-figure-position))))
2363 `(("language" ,lst-lang))
2364 (if label `(("label" ,label)) '(("label" " ")))
2365 (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
2366 (cond ((assoc "numbers" org-latex-listings-options) nil)
2367 ((not num-start) '(("numbers" "none")))
2368 ((zerop num-start) '(("numbers" "left")))
2369 (t `(("numbers" "left")
2370 ("firstnumber"
2371 ,(number-to-string (1+ num-start))))))))
2372 (let ((local-options (plist-get attributes :options)))
2373 (and local-options (concat "," local-options)))))
2374 ;; Source code.
2375 (format
2376 "\\begin{lstlisting}\n%s\\end{lstlisting}"
2377 (let* ((code-info (org-export-unravel-code src-block))
2378 (max-width
2379 (apply 'max
2380 (mapcar 'length
2381 (org-split-string (car code-info) "\n")))))
2382 (org-export-format-code
2383 (car code-info)
2384 (lambda (loc num ref)
2385 (concat
2387 (when ref
2388 ;; Ensure references are flushed to the right,
2389 ;; separated with 6 spaces from the widest line of
2390 ;; code
2391 (concat (make-string (+ (- max-width (length loc)) 6) ? )
2392 (format "(%s)" ref)))))
2393 nil (and retain-labels (cdr code-info))))))))))))
2396 ;;;; Statistics Cookie
2398 (defun org-latex-statistics-cookie (statistics-cookie contents info)
2399 "Transcode a STATISTICS-COOKIE object from Org to LaTeX.
2400 CONTENTS is nil. INFO is a plist holding contextual information."
2401 (replace-regexp-in-string
2402 "%" "\\%" (org-element-property :value statistics-cookie) nil t))
2405 ;;;; Strike-Through
2407 (defun org-latex-strike-through (strike-through contents info)
2408 "Transcode STRIKE-THROUGH from Org to LaTeX.
2409 CONTENTS is the text with strike-through markup. INFO is a plist
2410 holding contextual information."
2411 (org-latex--text-markup contents 'strike-through))
2414 ;;;; Subscript
2416 (defun org-latex--script-size (object info)
2417 "Transcode a subscript or superscript object.
2418 OBJECT is an Org object. INFO is a plist used as a communication
2419 channel."
2420 (let ((type (org-element-type object))
2421 (output ""))
2422 (org-element-map (org-element-contents object)
2423 (cons 'plain-text org-element-all-objects)
2424 (lambda (obj)
2425 (case (org-element-type obj)
2426 ((entity latex-fragment)
2427 (let ((data (org-trim (org-export-data obj info))))
2428 (string-match
2429 "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
2430 data)
2431 (setq output
2432 (concat output
2433 (match-string 1 data)
2434 (let ((blank (org-element-property :post-blank obj)))
2435 (and blank (> blank 0) "\\ "))))))
2436 (plain-text
2437 (setq output
2438 (format "%s\\text{%s}" output (org-export-data obj info))))
2439 (otherwise
2440 (setq output
2441 (concat output
2442 (org-export-data obj info)
2443 (let ((blank (org-element-property :post-blank obj)))
2444 (and blank (> blank 0) "\\ ")))))))
2445 info nil org-element-recursive-objects)
2446 ;; Result. Do not wrap into curly brackets if OUTPUT is a single
2447 ;; character.
2448 (concat (if (eq (org-element-type object) 'subscript) "_" "^")
2449 (and (> (length output) 1) "{")
2450 output
2451 (and (> (length output) 1) "}"))))
2453 (defun org-latex-subscript (subscript contents info)
2454 "Transcode a SUBSCRIPT object from Org to LaTeX.
2455 CONTENTS is the contents of the object. INFO is a plist holding
2456 contextual information."
2457 (org-latex--script-size subscript info))
2460 ;;;; Superscript
2462 (defun org-latex-superscript (superscript contents info)
2463 "Transcode a SUPERSCRIPT object from Org to LaTeX.
2464 CONTENTS is the contents of the object. INFO is a plist holding
2465 contextual information."
2466 (org-latex--script-size superscript info))
2469 ;;;; Table
2471 ;; `org-latex-table' is the entry point for table transcoding. It
2472 ;; takes care of tables with a "verbatim" mode. Otherwise, it
2473 ;; delegates the job to either `org-latex--table.el-table',
2474 ;; `org-latex--org-table' or `org-latex--math-table' functions,
2475 ;; depending of the type of the table and the mode requested.
2477 ;; `org-latex--align-string' is a subroutine used to build alignment
2478 ;; string for Org tables.
2480 (defun org-latex-table (table contents info)
2481 "Transcode a TABLE element from Org to LaTeX.
2482 CONTENTS is the contents of the table. INFO is a plist holding
2483 contextual information."
2484 (if (eq (org-element-property :type table) 'table.el)
2485 ;; "table.el" table. Convert it using appropriate tools.
2486 (org-latex--table.el-table table info)
2487 (let ((type (or (org-export-read-attribute :attr_latex table :mode)
2488 org-latex-default-table-mode)))
2489 (cond
2490 ;; Case 1: Verbatim table.
2491 ((string= type "verbatim")
2492 (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
2493 ;; Re-create table, without affiliated keywords.
2494 (org-trim (org-element-interpret-data
2495 `(table nil ,@(org-element-contents table))
2496 org-latex-pseudo-objects))))
2497 ;; Case 2: Matrix.
2498 ((or (string= type "math") (string= type "inline-math"))
2499 (org-latex--math-table table info))
2500 ;; Case 3: Standard table.
2501 (t (concat (org-latex--org-table table contents info)
2502 ;; When there are footnote references within the
2503 ;; table, insert their definition just after it.
2504 (org-latex--delayed-footnotes-definitions table info)))))))
2506 (defun org-latex--align-string (table info)
2507 "Return an appropriate LaTeX alignment string.
2508 TABLE is the considered table. INFO is a plist used as
2509 a communication channel."
2510 (or (org-export-read-attribute :attr_latex table :align)
2511 (let (align)
2512 ;; Extract column groups and alignment from first (non-rule)
2513 ;; row.
2514 (org-element-map
2515 (org-element-map table 'table-row
2516 (lambda (row)
2517 (and (eq (org-element-property :type row) 'standard) row))
2518 info 'first-match)
2519 'table-cell
2520 (lambda (cell)
2521 (let ((borders (org-export-table-cell-borders cell info)))
2522 ;; Check left border for the first cell only.
2523 (when (and (memq 'left borders) (not align))
2524 (push "|" align))
2525 (push (case (org-export-table-cell-alignment cell info)
2526 (left "l")
2527 (right "r")
2528 (center "c"))
2529 align)
2530 (when (memq 'right borders) (push "|" align))))
2531 info)
2532 (apply 'concat (nreverse align)))))
2534 (defun org-latex--org-table (table contents info)
2535 "Return appropriate LaTeX code for an Org table.
2537 TABLE is the table type element to transcode. CONTENTS is its
2538 contents, as a string. INFO is a plist used as a communication
2539 channel.
2541 This function assumes TABLE has `org' as its `:type' property and
2542 `table' as its `:mode' attribute."
2543 (let* ((caption (org-latex--caption/label-string table info))
2544 (attr (org-export-read-attribute :attr_latex table))
2545 ;; Determine alignment string.
2546 (alignment (org-latex--align-string table info))
2547 ;; Determine environment for the table: longtable, tabular...
2548 (table-env (or (plist-get attr :environment)
2549 org-latex-default-table-environment))
2550 ;; If table is a float, determine environment: table, table*
2551 ;; or sidewaystable.
2552 (float-env (unless (member table-env '("longtable" "longtabu"))
2553 (let ((float (plist-get attr :float)))
2554 (cond
2555 ((and (not float) (plist-member attr :float)) nil)
2556 ((or (string= float "sidewaystable")
2557 (string= float "sideways")) "sidewaystable")
2558 ((string= float "multicolumn") "table*")
2559 ((or float
2560 (org-element-property :caption table)
2561 (org-string-nw-p (plist-get attr :caption)))
2562 "table")))))
2563 ;; Extract others display options.
2564 (fontsize (let ((font (plist-get attr :font)))
2565 (and font (concat font "\n"))))
2566 (width (plist-get attr :width))
2567 (spreadp (plist-get attr :spread))
2568 (placement (or (plist-get attr :placement)
2569 (format "[%s]" org-latex-default-figure-position)))
2570 (centerp (if (plist-member attr :center) (plist-get attr :center)
2571 org-latex-tables-centered)))
2572 ;; Prepare the final format string for the table.
2573 (cond
2574 ;; Longtable.
2575 ((equal "longtable" table-env)
2576 (concat (and fontsize (concat "{" fontsize))
2577 (format "\\begin{longtable}{%s}\n" alignment)
2578 (and org-latex-table-caption-above
2579 (org-string-nw-p caption)
2580 (concat caption "\\\\\n"))
2581 contents
2582 (and (not org-latex-table-caption-above)
2583 (org-string-nw-p caption)
2584 (concat caption "\\\\\n"))
2585 "\\end{longtable}\n"
2586 (and fontsize "}")))
2587 ;; Longtabu
2588 ((equal "longtabu" table-env)
2589 (concat (and fontsize (concat "{" fontsize))
2590 (format "\\begin{longtabu}%s{%s}\n"
2591 (if width
2592 (format " %s %s "
2593 (if spreadp "spread" "to") width) "")
2594 alignment)
2595 (and org-latex-table-caption-above
2596 (org-string-nw-p caption)
2597 (concat caption "\\\\\n"))
2598 contents
2599 (and (not org-latex-table-caption-above)
2600 (org-string-nw-p caption)
2601 (concat caption "\\\\\n"))
2602 "\\end{longtabu}\n"
2603 (and fontsize "}")))
2604 ;; Others.
2605 (t (concat (cond
2606 (float-env
2607 (concat (format "\\begin{%s}%s\n" float-env placement)
2608 (if org-latex-table-caption-above caption "")
2609 (when centerp "\\centering\n")
2610 fontsize))
2611 (centerp (concat "\\begin{center}\n" fontsize))
2612 (fontsize (concat "{" fontsize)))
2613 (cond ((equal "tabu" table-env)
2614 (format "\\begin{tabu}%s{%s}\n%s\\end{tabu}"
2615 (if width (format
2616 (if spreadp " spread %s " " to %s ")
2617 width) "")
2618 alignment
2619 contents))
2620 (t (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
2621 table-env
2622 (if width (format "{%s}" width) "")
2623 alignment
2624 contents
2625 table-env)))
2626 (cond
2627 (float-env
2628 (concat (if org-latex-table-caption-above "" caption)
2629 (format "\n\\end{%s}" float-env)))
2630 (centerp "\n\\end{center}")
2631 (fontsize "}")))))))
2633 (defun org-latex--table.el-table (table info)
2634 "Return appropriate LaTeX code for a table.el table.
2636 TABLE is the table type element to transcode. INFO is a plist
2637 used as a communication channel.
2639 This function assumes TABLE has `table.el' as its `:type'
2640 property."
2641 (require 'table)
2642 ;; Ensure "*org-export-table*" buffer is empty.
2643 (with-current-buffer (get-buffer-create "*org-export-table*")
2644 (erase-buffer))
2645 (let ((output (with-temp-buffer
2646 (insert (org-element-property :value table))
2647 (goto-char 1)
2648 (re-search-forward "^[ \t]*|[^|]" nil t)
2649 (table-generate-source 'latex "*org-export-table*")
2650 (with-current-buffer "*org-export-table*"
2651 (org-trim (buffer-string))))))
2652 (kill-buffer (get-buffer "*org-export-table*"))
2653 ;; Remove left out comments.
2654 (while (string-match "^%.*\n" output)
2655 (setq output (replace-match "" t t output)))
2656 (let ((attr (org-export-read-attribute :attr_latex table)))
2657 (when (plist-get attr :rmlines)
2658 ;; When the "rmlines" attribute is provided, remove all hlines
2659 ;; but the the one separating heading from the table body.
2660 (let ((n 0) (pos 0))
2661 (while (and (< (length output) pos)
2662 (setq pos (string-match "^\\\\hline\n?" output pos)))
2663 (incf n)
2664 (unless (= n 2) (setq output (replace-match "" nil nil output))))))
2665 (let ((centerp (if (plist-member attr :center) (plist-get attr :center)
2666 org-latex-tables-centered)))
2667 (if (not centerp) output
2668 (format "\\begin{center}\n%s\n\\end{center}" output))))))
2670 (defun org-latex--math-table (table info)
2671 "Return appropriate LaTeX code for a matrix.
2673 TABLE is the table type element to transcode. INFO is a plist
2674 used as a communication channel.
2676 This function assumes TABLE has `org' as its `:type' property and
2677 `inline-math' or `math' as its `:mode' attribute.."
2678 (let* ((caption (org-latex--caption/label-string table info))
2679 (attr (org-export-read-attribute :attr_latex table))
2680 (inlinep (equal (plist-get attr :mode) "inline-math"))
2681 (env (or (plist-get attr :environment)
2682 org-latex-default-table-environment))
2683 (contents
2684 (mapconcat
2685 (lambda (row)
2686 ;; Ignore horizontal rules.
2687 (when (eq (org-element-property :type row) 'standard)
2688 ;; Return each cell unmodified.
2689 (concat
2690 (mapconcat
2691 (lambda (cell)
2692 (substring
2693 (org-element-interpret-data cell org-latex-pseudo-objects)
2694 0 -1))
2695 (org-element-map row 'table-cell 'identity info) "&")
2696 (or (cdr (assoc env org-latex-table-matrix-macros)) "\\\\")
2697 "\n")))
2698 (org-element-map table 'table-row 'identity info) ""))
2699 ;; Variables related to math clusters (contiguous math tables
2700 ;; of the same type).
2701 (mode (org-export-read-attribute :attr_latex table :mode))
2702 (prev (org-export-get-previous-element table info))
2703 (next (org-export-get-next-element table info))
2704 (same-mode-p
2705 (lambda (table)
2706 ;; Non-nil when TABLE has the same mode as current table.
2707 (string= (or (org-export-read-attribute :attr_latex table :mode)
2708 org-latex-default-table-mode)
2709 mode))))
2710 (concat
2711 ;; Opening string. If TABLE is in the middle of a table cluster,
2712 ;; do not insert any.
2713 (cond ((and prev
2714 (eq (org-element-type prev) 'table)
2715 (memq (org-element-property :post-blank prev) '(0 nil))
2716 (funcall same-mode-p prev))
2717 nil)
2718 (inlinep "\\(")
2719 ((org-string-nw-p caption) (concat "\\begin{equation}\n" caption))
2720 (t "\\["))
2721 ;; Prefix.
2722 (or (plist-get attr :math-prefix) "")
2723 ;; Environment. Also treat special cases.
2724 (cond ((equal env "array")
2725 (let ((align (org-latex--align-string table info)))
2726 (format "\\begin{array}{%s}\n%s\\end{array}" align contents)))
2727 ((assoc env org-latex-table-matrix-macros)
2728 (format "\\%s%s{\n%s}"
2730 (or (plist-get attr :math-arguments) "")
2731 contents))
2732 (t (format "\\begin{%s}\n%s\\end{%s}" env contents env)))
2733 ;; Suffix.
2734 (or (plist-get attr :math-suffix) "")
2735 ;; Closing string. If TABLE is in the middle of a table cluster,
2736 ;; do not insert any. If it closes such a cluster, be sure to
2737 ;; close the cluster with a string matching the opening string.
2738 (cond ((and next
2739 (eq (org-element-type next) 'table)
2740 (memq (org-element-property :post-blank table) '(0 nil))
2741 (funcall same-mode-p next))
2742 nil)
2743 (inlinep "\\)")
2744 ;; Find cluster beginning to know which environment to use.
2745 ((let ((cluster-beg table) prev)
2746 (while (and (setq prev (org-export-get-previous-element
2747 cluster-beg info))
2748 (memq (org-element-property :post-blank prev)
2749 '(0 nil))
2750 (funcall same-mode-p prev))
2751 (setq cluster-beg prev))
2752 (and (or (org-element-property :caption cluster-beg)
2753 (org-element-property :name cluster-beg))
2754 "\n\\end{equation}")))
2755 (t "\\]")))))
2758 ;;;; Table Cell
2760 (defun org-latex-table-cell (table-cell contents info)
2761 "Transcode a TABLE-CELL element from Org to LaTeX.
2762 CONTENTS is the cell contents. INFO is a plist used as
2763 a communication channel."
2764 (concat (if (and contents
2765 org-latex-table-scientific-notation
2766 (string-match orgtbl-exp-regexp contents))
2767 ;; Use appropriate format string for scientific
2768 ;; notation.
2769 (format org-latex-table-scientific-notation
2770 (match-string 1 contents)
2771 (match-string 2 contents))
2772 contents)
2773 (when (org-export-get-next-element table-cell info) " & ")))
2776 ;;;; Table Row
2778 (defun org-latex-table-row (table-row contents info)
2779 "Transcode a TABLE-ROW element from Org to LaTeX.
2780 CONTENTS is the contents of the row. INFO is a plist used as
2781 a communication channel."
2782 ;; Rules are ignored since table separators are deduced from
2783 ;; borders of the current row.
2784 (when (eq (org-element-property :type table-row) 'standard)
2785 (let* ((attr (org-export-read-attribute :attr_latex
2786 (org-export-get-parent table-row)))
2787 (longtablep (member (or (plist-get attr :environment)
2788 org-latex-default-table-environment)
2789 '("longtable" "longtabu")))
2790 (booktabsp (if (plist-member attr :booktabs)
2791 (plist-get attr :booktabs)
2792 org-latex-tables-booktabs))
2793 ;; TABLE-ROW's borders are extracted from its first cell.
2794 (borders (org-export-table-cell-borders
2795 (car (org-element-contents table-row)) info)))
2796 (concat
2797 ;; When BOOKTABS are activated enforce top-rule even when no
2798 ;; hline was specifically marked.
2799 (cond ((and booktabsp (memq 'top borders)) "\\toprule\n")
2800 ((and (memq 'top borders) (memq 'above borders)) "\\hline\n"))
2801 contents "\\\\\n"
2802 (cond
2803 ;; Special case for long tables. Define header and footers.
2804 ((and longtablep (org-export-table-row-ends-header-p table-row info))
2805 (format "%s
2806 \\endfirsthead
2807 \\multicolumn{%d}{l}{%s} \\\\
2809 %s \\\\\n
2811 \\endhead
2812 %s\\multicolumn{%d}{r}{%s} \\\\
2813 \\endfoot
2814 \\endlastfoot"
2815 (if booktabsp "\\midrule" "\\hline")
2816 (cdr (org-export-table-dimensions
2817 (org-export-get-parent-table table-row) info))
2818 (org-latex--translate "Continued from previous page" info)
2819 (cond ((and booktabsp (memq 'top borders)) "\\toprule\n")
2820 ((and (memq 'top borders)
2821 (memq 'above borders)) "\\hline\n")
2822 (t ""))
2823 contents
2824 (if booktabsp "\\midrule" "\\hline")
2825 (if booktabsp "\\midrule" "\\hline")
2826 ;; Number of columns.
2827 (cdr (org-export-table-dimensions
2828 (org-export-get-parent-table table-row) info))
2829 (org-latex--translate "Continued on next page" info)))
2830 ;; When BOOKTABS are activated enforce bottom rule even when
2831 ;; no hline was specifically marked.
2832 ((and booktabsp (memq 'bottom borders)) "\\bottomrule")
2833 ((and (memq 'bottom borders) (memq 'below borders)) "\\hline")
2834 ((memq 'below borders) (if booktabsp "\\midrule" "\\hline")))))))
2837 ;;;; Target
2839 (defun org-latex-target (target contents info)
2840 "Transcode a TARGET object from Org to LaTeX.
2841 CONTENTS is nil. INFO is a plist holding contextual
2842 information."
2843 (format "\\label{%s}"
2844 (org-export-solidify-link-text (org-element-property :value target))))
2847 ;;;; Timestamp
2849 (defun org-latex-timestamp (timestamp contents info)
2850 "Transcode a TIMESTAMP object from Org to LaTeX.
2851 CONTENTS is nil. INFO is a plist holding contextual
2852 information."
2853 (let ((value (org-latex-plain-text
2854 (org-timestamp-translate timestamp) info)))
2855 (case (org-element-property :type timestamp)
2856 ((active active-range) (format org-latex-active-timestamp-format value))
2857 ((inactive inactive-range)
2858 (format org-latex-inactive-timestamp-format value))
2859 (otherwise (format org-latex-diary-timestamp-format value)))))
2862 ;;;; Underline
2864 (defun org-latex-underline (underline contents info)
2865 "Transcode UNDERLINE from Org to LaTeX.
2866 CONTENTS is the text with underline markup. INFO is a plist
2867 holding contextual information."
2868 (org-latex--text-markup contents 'underline))
2871 ;;;; Verbatim
2873 (defun org-latex-verbatim (verbatim contents info)
2874 "Transcode a VERBATIM object from Org to LaTeX.
2875 CONTENTS is nil. INFO is a plist used as a communication
2876 channel."
2877 (org-latex--text-markup (org-element-property :value verbatim) 'verbatim))
2880 ;;;; Verse Block
2882 (defun org-latex-verse-block (verse-block contents info)
2883 "Transcode a VERSE-BLOCK element from Org to LaTeX.
2884 CONTENTS is verse block contents. INFO is a plist holding
2885 contextual information."
2886 (org-latex--wrap-label
2887 verse-block
2888 ;; In a verse environment, add a line break to each newline
2889 ;; character and change each white space at beginning of a line
2890 ;; into a space of 1 em. Also change each blank line with
2891 ;; a vertical space of 1 em.
2892 (progn
2893 (setq contents (replace-regexp-in-string
2894 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
2895 (replace-regexp-in-string
2896 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" contents)))
2897 (while (string-match "^[ \t]+" contents)
2898 (let ((new-str (format "\\hspace*{%dem}"
2899 (length (match-string 0 contents)))))
2900 (setq contents (replace-match new-str nil t contents))))
2901 (format "\\begin{verse}\n%s\\end{verse}" contents))))
2905 ;;; End-user functions
2907 ;;;###autoload
2908 (defun org-latex-export-as-latex
2909 (&optional async subtreep visible-only body-only ext-plist)
2910 "Export current buffer as a LaTeX buffer.
2912 If narrowing is active in the current buffer, only export its
2913 narrowed part.
2915 If a region is active, export that region.
2917 A non-nil optional argument ASYNC means the process should happen
2918 asynchronously. The resulting buffer should be accessible
2919 through the `org-export-stack' interface.
2921 When optional argument SUBTREEP is non-nil, export the sub-tree
2922 at point, extracting information from the headline properties
2923 first.
2925 When optional argument VISIBLE-ONLY is non-nil, don't export
2926 contents of hidden elements.
2928 When optional argument BODY-ONLY is non-nil, only write code
2929 between \"\\begin{document}\" and \"\\end{document}\".
2931 EXT-PLIST, when provided, is a property list with external
2932 parameters overriding Org default settings, but still inferior to
2933 file-local settings.
2935 Export is done in a buffer named \"*Org LATEX Export*\", which
2936 will be displayed when `org-export-show-temporary-export-buffer'
2937 is non-nil."
2938 (interactive)
2939 (org-export-to-buffer 'latex "*Org LATEX Export*"
2940 async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
2942 ;;;###autoload
2943 (defun org-latex-convert-region-to-latex ()
2944 "Assume the current region has org-mode syntax, and convert it to LaTeX.
2945 This can be used in any buffer. For example, you can write an
2946 itemized list in org-mode syntax in an LaTeX buffer and use this
2947 command to convert it."
2948 (interactive)
2949 (org-export-replace-region-by 'latex))
2951 ;;;###autoload
2952 (defun org-latex-export-to-latex
2953 (&optional async subtreep visible-only body-only ext-plist)
2954 "Export current buffer to a LaTeX file.
2956 If narrowing is active in the current buffer, only export its
2957 narrowed part.
2959 If a region is active, export that region.
2961 A non-nil optional argument ASYNC means the process should happen
2962 asynchronously. The resulting file should be accessible through
2963 the `org-export-stack' interface.
2965 When optional argument SUBTREEP is non-nil, export the sub-tree
2966 at point, extracting information from the headline properties
2967 first.
2969 When optional argument VISIBLE-ONLY is non-nil, don't export
2970 contents of hidden elements.
2972 When optional argument BODY-ONLY is non-nil, only write code
2973 between \"\\begin{document}\" and \"\\end{document}\".
2975 EXT-PLIST, when provided, is a property list with external
2976 parameters overriding Org default settings, but still inferior to
2977 file-local settings."
2978 (interactive)
2979 (let ((outfile (org-export-output-file-name ".tex" subtreep)))
2980 (org-export-to-file 'latex outfile
2981 async subtreep visible-only body-only ext-plist)))
2983 ;;;###autoload
2984 (defun org-latex-export-to-pdf
2985 (&optional async subtreep visible-only body-only ext-plist)
2986 "Export current buffer to LaTeX then process through to PDF.
2988 If narrowing is active in the current buffer, only export its
2989 narrowed part.
2991 If a region is active, export that region.
2993 A non-nil optional argument ASYNC means the process should happen
2994 asynchronously. The resulting file should be accessible through
2995 the `org-export-stack' interface.
2997 When optional argument SUBTREEP is non-nil, export the sub-tree
2998 at point, extracting information from the headline properties
2999 first.
3001 When optional argument VISIBLE-ONLY is non-nil, don't export
3002 contents of hidden elements.
3004 When optional argument BODY-ONLY is non-nil, only write code
3005 between \"\\begin{document}\" and \"\\end{document}\".
3007 EXT-PLIST, when provided, is a property list with external
3008 parameters overriding Org default settings, but still inferior to
3009 file-local settings.
3011 Return PDF file's name."
3012 (interactive)
3013 (let ((outfile (org-export-output-file-name ".tex" subtreep)))
3014 (org-export-to-file 'latex outfile
3015 async subtreep visible-only body-only ext-plist
3016 (lambda (file) (org-latex-compile file)))))
3018 (defun org-latex-compile (texfile &optional snippet)
3019 "Compile a TeX file.
3021 TEXFILE is the name of the file being compiled. Processing is
3022 done through the command specified in `org-latex-pdf-process'.
3024 When optional argument SNIPPET is non-nil, TEXFILE is a temporary
3025 file used to preview a LaTeX snippet. In this case, do not
3026 create a log buffer and do not bother removing log files.
3028 Return PDF file name or an error if it couldn't be produced."
3029 (let* ((base-name (file-name-sans-extension (file-name-nondirectory texfile)))
3030 (full-name (file-truename texfile))
3031 (out-dir (file-name-directory texfile))
3032 ;; Properly set working directory for compilation.
3033 (default-directory (if (file-name-absolute-p texfile)
3034 (file-name-directory full-name)
3035 default-directory))
3036 (time (current-time))
3037 warnings)
3038 (unless snippet (message (format "Processing LaTeX file %s..." texfile)))
3039 (save-window-excursion
3040 (cond
3041 ;; A function is provided: Apply it.
3042 ((functionp org-latex-pdf-process)
3043 (funcall org-latex-pdf-process (shell-quote-argument texfile)))
3044 ;; A list is provided: Replace %b, %f and %o with appropriate
3045 ;; values in each command before applying it. Output is
3046 ;; redirected to "*Org PDF LaTeX Output*" buffer.
3047 ((consp org-latex-pdf-process)
3048 (let ((outbuf (and (not snippet)
3049 (get-buffer-create "*Org PDF LaTeX Output*"))))
3050 (mapc
3051 (lambda (command)
3052 (shell-command
3053 (replace-regexp-in-string
3054 "%b" (shell-quote-argument base-name)
3055 (replace-regexp-in-string
3056 "%f" (shell-quote-argument full-name)
3057 (replace-regexp-in-string
3058 "%o" (shell-quote-argument out-dir) command t t) t t) t t)
3059 outbuf))
3060 org-latex-pdf-process)
3061 ;; Collect standard errors from output buffer.
3062 (setq warnings (and (not snippet)
3063 (org-latex--collect-warnings outbuf)))))
3064 (t (error "No valid command to process to PDF")))
3065 (let ((pdffile (concat out-dir base-name ".pdf")))
3066 ;; Check for process failure. Provide collected errors if
3067 ;; possible.
3068 (if (or (not (file-exists-p pdffile))
3069 (time-less-p (nth 5 (file-attributes pdffile)) time))
3070 (error (format "PDF file %s wasn't produced" pdffile))
3071 ;; Else remove log files, when specified, and signal end of
3072 ;; process to user, along with any error encountered.
3073 (when (and (not snippet) org-latex-remove-logfiles)
3074 (dolist (file (directory-files
3075 out-dir t
3076 (concat (regexp-quote base-name)
3077 "\\(?:\\.[0-9]+\\)?"
3078 "\\."
3079 (regexp-opt org-latex-logfiles-extensions))))
3080 (delete-file file)))
3081 (message (concat "PDF file produced"
3082 (cond
3083 ((eq warnings 'error) " with errors.")
3084 (warnings (concat " with warnings: " warnings))
3085 (t ".")))))
3086 ;; Return output file name.
3087 pdffile))))
3089 (defun org-latex--collect-warnings (buffer)
3090 "Collect some warnings from \"pdflatex\" command output.
3091 BUFFER is the buffer containing output. Return collected
3092 warnings types as a string, `error' if a LaTeX error was
3093 encountered or nil if there was none."
3094 (with-current-buffer buffer
3095 (save-excursion
3096 (goto-char (point-max))
3097 (when (re-search-backward "^[ \t]*This is .*?TeX.*?Version" nil t)
3098 (if (re-search-forward "^!" nil t) 'error
3099 (let ((case-fold-search t)
3100 (warnings ""))
3101 (dolist (warning org-latex-known-warnings)
3102 (save-excursion
3103 (when (save-excursion (re-search-forward (car warning) nil t))
3104 (setq warnings (concat warnings " " (cdr warning))))))
3105 (and (org-string-nw-p warnings) (org-trim warnings))))))))
3107 ;;;###autoload
3108 (defun org-latex-publish-to-latex (plist filename pub-dir)
3109 "Publish an Org file to LaTeX.
3111 FILENAME is the filename of the Org file to be published. PLIST
3112 is the property list for the given project. PUB-DIR is the
3113 publishing directory.
3115 Return output file name."
3116 (org-publish-org-to 'latex filename ".tex" plist pub-dir))
3118 ;;;###autoload
3119 (defun org-latex-publish-to-pdf (plist filename pub-dir)
3120 "Publish an Org file to PDF (via LaTeX).
3122 FILENAME is the filename of the Org file to be published. PLIST
3123 is the property list for the given project. PUB-DIR is the
3124 publishing directory.
3126 Return output file name."
3127 ;; Unlike to `org-latex-publish-to-latex', PDF file is generated
3128 ;; in working directory and then moved to publishing directory.
3129 (org-publish-attachment
3130 plist
3131 (org-latex-compile
3132 (org-publish-org-to
3133 'latex filename ".tex" plist (file-name-directory filename)))
3134 pub-dir))
3137 (provide 'ox-latex)
3139 ;; Local variables:
3140 ;; generated-autoload-file: "org-loaddefs.el"
3141 ;; End:
3143 ;;; ox-latex.el ends here