Simplify comments matching functions
[org-mode/org-kjn.git] / lisp / ox-latex.el
blob5435a73b66fb78bcd81c7a66a8dde39fc1e4d3f3
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 (concat "\\begin{center}\n"
1629 "\\fbox{\n"
1630 "\\begin{minipage}[c]{.6\\textwidth}\n"
1631 full-title "\n\n"
1632 (and (org-string-nw-p contents)
1633 (concat "\\rule[.8em]{\\textwidth}{2pt}\n\n" contents))
1634 "\\end{minipage}\n"
1635 "}\n"
1636 "\\end{center}"))))))
1639 ;;;; Italic
1641 (defun org-latex-italic (italic contents info)
1642 "Transcode ITALIC from Org to LaTeX.
1643 CONTENTS is the text with italic markup. INFO is a plist holding
1644 contextual information."
1645 (org-latex--text-markup contents 'italic))
1648 ;;;; Item
1650 (defun org-latex-item (item contents info)
1651 "Transcode an ITEM element from Org to LaTeX.
1652 CONTENTS holds the contents of the item. INFO is a plist holding
1653 contextual information."
1654 (let* ((counter
1655 (let ((count (org-element-property :counter item))
1656 (level
1657 ;; Determine level of current item to determine the
1658 ;; correct LaTeX counter to use (enumi, enumii...).
1659 (let ((parent item) (level 0))
1660 (while (memq (org-element-type
1661 (setq parent (org-export-get-parent parent)))
1662 '(plain-list item))
1663 (when (and (eq (org-element-type parent) 'plain-list)
1664 (eq (org-element-property :type parent)
1665 'ordered))
1666 (incf level)))
1667 level)))
1668 (and count
1669 (< level 5)
1670 (format "\\setcounter{enum%s}{%s}\n"
1671 (nth (1- level) '("i" "ii" "iii" "iv"))
1672 (1- count)))))
1673 (checkbox (case (org-element-property :checkbox item)
1674 (on "$\\boxtimes$ ")
1675 (off "$\\square$ ")
1676 (trans "$\\boxminus$ ")))
1677 (tag (let ((tag (org-element-property :tag item)))
1678 ;; Check-boxes must belong to the tag.
1679 (and tag (format "[{%s}] "
1680 (concat checkbox
1681 (org-export-data tag info)))))))
1682 (concat counter
1683 "\\item"
1684 (cond
1685 (tag)
1686 (checkbox (concat " " checkbox))
1687 ;; Without a tag or a check-box, if CONTENTS starts with
1688 ;; an opening square bracket, add "\relax" to "\item",
1689 ;; unless the brackets comes from an initial export
1690 ;; snippet (i.e. it is inserted willingly by the user).
1691 ((and contents
1692 (org-string-match-p "\\`[ \t]*\\[" contents)
1693 (not (let ((e (car (org-element-contents item))))
1694 (and (eq (org-element-type e) 'paragraph)
1695 (let ((o (car (org-element-contents e))))
1696 (and (eq (org-element-type o) 'export-snippet)
1697 (eq (org-export-snippet-backend o)
1698 'latex)))))))
1699 "\\relax ")
1700 (t " "))
1701 (and contents (org-trim contents))
1702 ;; If there are footnotes references in tag, be sure to
1703 ;; add their definition at the end of the item. This
1704 ;; workaround is necessary since "\footnote{}" command is
1705 ;; not supported in tags.
1706 (and tag
1707 (org-latex--delayed-footnotes-definitions
1708 (org-element-property :tag item) info)))))
1711 ;;;; Keyword
1713 (defun org-latex-keyword (keyword contents info)
1714 "Transcode a KEYWORD element from Org to LaTeX.
1715 CONTENTS is nil. INFO is a plist holding contextual information."
1716 (let ((key (org-element-property :key keyword))
1717 (value (org-element-property :value keyword)))
1718 (cond
1719 ((string= key "LATEX") value)
1720 ((string= key "INDEX") (format "\\index{%s}" value))
1721 ((string= key "TOC")
1722 (let ((value (downcase value)))
1723 (cond
1724 ((string-match "\\<headlines\\>" value)
1725 (let ((depth (or (and (string-match "[0-9]+" value)
1726 (string-to-number (match-string 0 value)))
1727 (plist-get info :with-toc))))
1728 (concat
1729 (when (wholenump depth)
1730 (format "\\setcounter{tocdepth}{%s}\n" depth))
1731 "\\tableofcontents")))
1732 ((string= "tables" value) "\\listoftables")
1733 ((string= "listings" value)
1734 (cond
1735 ((eq org-latex-listings 'minted) "\\listoflistings")
1736 (org-latex-listings "\\lstlistoflistings")
1737 ;; At the moment, src blocks with a caption are wrapped
1738 ;; into a figure environment.
1739 (t "\\listoffigures")))))))))
1742 ;;;; Latex Environment
1744 (defun org-latex-latex-environment (latex-environment contents info)
1745 "Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
1746 CONTENTS is nil. INFO is a plist holding contextual information."
1747 (when (plist-get info :with-latex)
1748 (let ((label (org-element-property :name latex-environment))
1749 (value (org-remove-indentation
1750 (org-element-property :value latex-environment))))
1751 (if (not (org-string-nw-p label)) value
1752 ;; Environment is labeled: label must be within the environment
1753 ;; (otherwise, a reference pointing to that element will count
1754 ;; the section instead).
1755 (with-temp-buffer
1756 (insert value)
1757 (goto-char (point-min))
1758 (forward-line)
1759 (insert
1760 (format "\\label{%s}\n" (org-export-solidify-link-text label)))
1761 (buffer-string))))))
1764 ;;;; Latex Fragment
1766 (defun org-latex-latex-fragment (latex-fragment contents info)
1767 "Transcode a LATEX-FRAGMENT object from Org to LaTeX.
1768 CONTENTS is nil. INFO is a plist holding contextual information."
1769 (let ((value (org-element-property :value latex-fragment)))
1770 ;; Trim math markers since the fragment is enclosed within
1771 ;; a latex-math-block object anyway.
1772 (cond ((string-match "\\`\\(\\$\\{1,2\\}\\)\\([^\000]*\\)\\1\\'" value)
1773 (match-string 2 value))
1774 ((string-match "\\`\\\\(\\([^\000]*\\)\\\\)\\'" value)
1775 (match-string 1 value))
1776 (t value))))
1779 ;;;; Line Break
1781 (defun org-latex-line-break (line-break contents info)
1782 "Transcode a LINE-BREAK object from Org to LaTeX.
1783 CONTENTS is nil. INFO is a plist holding contextual information."
1784 "\\\\\n")
1787 ;;;; Link
1789 (defun org-latex--inline-image (link info)
1790 "Return LaTeX code for an inline image.
1791 LINK is the link pointing to the inline image. INFO is a plist
1792 used as a communication channel."
1793 (let* ((parent (org-export-get-parent-element link))
1794 (path (let ((raw-path (org-element-property :path link)))
1795 (if (not (file-name-absolute-p raw-path)) raw-path
1796 (expand-file-name raw-path))))
1797 (filetype (file-name-extension path))
1798 (caption (org-latex--caption/label-string parent info))
1799 ;; Retrieve latex attributes from the element around.
1800 (attr (org-export-read-attribute :attr_latex parent))
1801 (float (let ((float (plist-get attr :float)))
1802 (cond ((and (not float) (plist-member attr :float)) nil)
1803 ((string= float "wrap") 'wrap)
1804 ((string= float "sideways") 'sideways)
1805 ((string= float "multicolumn") 'multicolumn)
1806 ((or float
1807 (org-element-property :caption parent)
1808 (org-string-nw-p (plist-get attr :caption)))
1809 'figure))))
1810 (placement
1811 (let ((place (plist-get attr :placement)))
1812 (cond (place (format "%s" place))
1813 ((eq float 'wrap) "{l}{0.5\\textwidth}")
1814 ((eq float 'figure)
1815 (format "[%s]" org-latex-default-figure-position))
1816 (t ""))))
1817 (comment-include (if (plist-get attr :comment-include) "%" ""))
1818 ;; It is possible to specify width and height in the
1819 ;; ATTR_LATEX line, and also via default variables.
1820 (width (cond ((plist-get attr :width))
1821 ((plist-get attr :height) "")
1822 ((eq float 'wrap) "0.48\\textwidth")
1823 (t org-latex-image-default-width)))
1824 (height (cond ((plist-get attr :height))
1825 ((or (plist-get attr :width)
1826 (memq float '(figure wrap))) "")
1827 (t org-latex-image-default-height)))
1828 (options (let ((opt (or (plist-get attr :options)
1829 org-latex-image-default-option)))
1830 (if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt)) opt
1831 (match-string 1 opt))))
1832 image-code)
1833 (if (member filetype '("tikz" "pgf"))
1834 ;; For tikz images:
1835 ;; - use \input to read in image file.
1836 ;; - if options are present, wrap in a tikzpicture environment.
1837 ;; - if width or height are present, use \resizebox to change
1838 ;; the image size.
1839 (progn
1840 (setq image-code (format "\\input{%s}" path))
1841 (when (org-string-nw-p options)
1842 (setq image-code
1843 (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
1844 options
1845 image-code)))
1846 (when (or (org-string-nw-p width) (org-string-nw-p height))
1847 (setq image-code (format "\\resizebox{%s}{%s}{%s}"
1848 (if (org-string-nw-p width) width "!")
1849 (if (org-string-nw-p height) height "!")
1850 image-code))))
1851 ;; For other images:
1852 ;; - add width and height to options.
1853 ;; - include the image with \includegraphics.
1854 (when (org-string-nw-p width)
1855 (setq options (concat options ",width=" width)))
1856 (when (org-string-nw-p height)
1857 (setq options (concat options ",height=" height)))
1858 (setq image-code
1859 (format "\\includegraphics%s{%s}"
1860 (cond ((not (org-string-nw-p options)) "")
1861 ((= (aref options 0) ?,)
1862 (format "[%s]"(substring options 1)))
1863 (t (format "[%s]" options)))
1864 path))
1865 (when (equal filetype "svg")
1866 (setq image-code (replace-regexp-in-string "^\\\\includegraphics"
1867 "\\includesvg"
1868 image-code
1869 nil t))
1870 (setq image-code (replace-regexp-in-string "\\.svg}"
1872 image-code
1873 nil t))))
1874 ;; Return proper string, depending on FLOAT.
1875 (case float
1876 (wrap (format "\\begin{wrapfigure}%s
1877 \\centering
1878 %s%s
1879 %s\\end{wrapfigure}" placement comment-include image-code caption))
1880 (sideways (format "\\begin{sidewaysfigure}
1881 \\centering
1882 %s%s
1883 %s\\end{sidewaysfigure}" comment-include image-code caption))
1884 (multicolumn (format "\\begin{figure*}%s
1885 \\centering
1886 %s%s
1887 %s\\end{figure*}" placement comment-include image-code caption))
1888 (figure (format "\\begin{figure}%s
1889 \\centering
1890 %s%s
1891 %s\\end{figure}" placement comment-include image-code caption))
1892 (otherwise image-code))))
1894 (defun org-latex-link (link desc info)
1895 "Transcode a LINK object from Org to LaTeX.
1897 DESC is the description part of the link, or the empty string.
1898 INFO is a plist holding contextual information. See
1899 `org-export-data'."
1900 (let* ((type (org-element-property :type link))
1901 (raw-path (replace-regexp-in-string
1902 "%" "\\%" (org-element-property :path link) nil t))
1903 ;; Ensure DESC really exists, or set it to nil.
1904 (desc (and (not (string= desc "")) desc))
1905 (imagep (org-export-inline-image-p
1906 link org-latex-inline-image-rules))
1907 (path (cond
1908 ((member type '("http" "https" "ftp" "mailto"))
1909 (concat type ":" raw-path))
1910 ((and (string= type "file") (file-name-absolute-p raw-path))
1911 (concat "file:" raw-path))
1912 (t raw-path)))
1913 protocol)
1914 (cond
1915 ;; Image file.
1916 (imagep (org-latex--inline-image link info))
1917 ;; Radio link: Transcode target's contents and use them as link's
1918 ;; description.
1919 ((string= type "radio")
1920 (let ((destination (org-export-resolve-radio-link link info)))
1921 (when destination
1922 (format "\\hyperref[%s]{%s}"
1923 (org-export-solidify-link-text
1924 (org-element-property :value destination))
1925 desc))))
1926 ;; Links pointing to a headline: Find destination and build
1927 ;; appropriate referencing command.
1928 ((member type '("custom-id" "fuzzy" "id"))
1929 (let ((destination (if (string= type "fuzzy")
1930 (org-export-resolve-fuzzy-link link info)
1931 (org-export-resolve-id-link link info))))
1932 (case (org-element-type destination)
1933 ;; Id link points to an external file.
1934 (plain-text
1935 (if desc (format "\\href{%s}{%s}" destination desc)
1936 (format "\\url{%s}" destination)))
1937 ;; Fuzzy link points nowhere.
1938 ('nil
1939 (format org-latex-link-with-unknown-path-format
1940 (or desc
1941 (org-export-data
1942 (org-element-property :raw-link link) info))))
1943 ;; LINK points to a headline. If headlines are numbered
1944 ;; and the link has no description, display headline's
1945 ;; number. Otherwise, display description or headline's
1946 ;; title.
1947 (headline
1948 (let* ((custom-label
1949 (and (plist-get info :latex-custom-id-labels)
1950 (org-element-property :CUSTOM_ID destination)))
1951 (label
1953 custom-label
1954 (format "sec-%s"
1955 (mapconcat
1956 #'number-to-string
1957 (org-export-get-headline-number destination info)
1958 "-")))))
1959 (if (and (plist-get info :section-numbers) (not desc))
1960 (format "\\ref{%s}" label)
1961 (format "\\hyperref[%s]{%s}" label
1962 (or desc
1963 (org-export-data
1964 (org-element-property :title destination) info))))))
1965 ;; Fuzzy link points to a target. Do as above.
1966 (otherwise
1967 (let ((path (org-export-solidify-link-text path)))
1968 (if (not desc) (format "\\ref{%s}" path)
1969 (format "\\hyperref[%s]{%s}" path desc)))))))
1970 ;; Coderef: replace link with the reference name or the
1971 ;; equivalent line number.
1972 ((string= type "coderef")
1973 (format (org-export-get-coderef-format path desc)
1974 (org-export-resolve-coderef path info)))
1975 ;; Link type is handled by a special function.
1976 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
1977 (funcall protocol (org-link-unescape path) desc 'latex))
1978 ;; External link with a description part.
1979 ((and path desc) (format "\\href{%s}{%s}" path desc))
1980 ;; External link without a description part.
1981 (path (format "\\url{%s}" path))
1982 ;; No path, only description. Try to do something useful.
1983 (t (format org-latex-link-with-unknown-path-format desc)))))
1986 ;;;; Node Property
1988 (defun org-latex-node-property (node-property contents info)
1989 "Transcode a NODE-PROPERTY element from Org to LaTeX.
1990 CONTENTS is nil. INFO is a plist holding contextual
1991 information."
1992 (format "%s:%s"
1993 (org-element-property :key node-property)
1994 (let ((value (org-element-property :value node-property)))
1995 (if value (concat " " value) ""))))
1998 ;;;; Paragraph
2000 (defun org-latex-paragraph (paragraph contents info)
2001 "Transcode a PARAGRAPH element from Org to LaTeX.
2002 CONTENTS is the contents of the paragraph, as a string. INFO is
2003 the plist used as a communication channel."
2004 contents)
2007 ;;;; Plain List
2009 (defun org-latex-plain-list (plain-list contents info)
2010 "Transcode a PLAIN-LIST element from Org to LaTeX.
2011 CONTENTS is the contents of the list. INFO is a plist holding
2012 contextual information."
2013 (let* ((type (org-element-property :type plain-list))
2014 (attr (org-export-read-attribute :attr_latex plain-list))
2015 (latex-type (let ((env (plist-get attr :environment)))
2016 (cond (env (format "%s" env))
2017 ((eq type 'ordered) "enumerate")
2018 ((eq type 'descriptive) "description")
2019 (t "itemize")))))
2020 (org-latex--wrap-label
2021 plain-list
2022 (format "\\begin{%s}%s\n%s\\end{%s}"
2023 latex-type
2024 (or (plist-get attr :options) "")
2025 contents
2026 latex-type))))
2029 ;;;; Plain Text
2031 (defun org-latex-plain-text (text info)
2032 "Transcode a TEXT string from Org to LaTeX.
2033 TEXT is the string to transcode. INFO is a plist holding
2034 contextual information."
2035 (let ((specialp (plist-get info :with-special-strings))
2036 (output text))
2037 ;; Protect %, #, &, $, _, { and }.
2038 (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}_]\\)" output)
2039 (setq output
2040 (replace-match
2041 (format "\\%s" (match-string 2 output)) nil t output 2)))
2042 ;; Protect ^.
2043 (setq output
2044 (replace-regexp-in-string
2045 "\\([^\\]\\|^\\)\\(\\^\\)" "\\\\^{}" output nil nil 2))
2046 ;; Protect \. If special strings are used, be careful not to
2047 ;; protect "\" in "\-" constructs.
2048 (let ((symbols (if specialp "-%$#&{}^_\\" "%$#&{}^_\\")))
2049 (setq output
2050 (replace-regexp-in-string
2051 (format "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%s]\\|$\\)" symbols)
2052 "$\\backslash$" output nil t 1)))
2053 ;; Protect ~.
2054 (setq output
2055 (replace-regexp-in-string
2056 "\\([^\\]\\|^\\)\\(~\\)" "\\textasciitilde{}" output nil t 2))
2057 ;; Activate smart quotes. Be sure to provide original TEXT string
2058 ;; since OUTPUT may have been modified.
2059 (when (plist-get info :with-smart-quotes)
2060 (setq output (org-export-activate-smart-quotes output :latex info text)))
2061 ;; LaTeX into \LaTeX{} and TeX into \TeX{}.
2062 (let ((case-fold-search nil)
2063 (start 0))
2064 (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" output start)
2065 (setq output (replace-match
2066 (format "\\%s{}" (match-string 1 output)) nil t output)
2067 start (match-end 0))))
2068 ;; Convert special strings.
2069 (when specialp
2070 (setq output
2071 (replace-regexp-in-string "\\.\\.\\." "\\ldots{}" output nil t)))
2072 ;; Handle break preservation if required.
2073 (when (plist-get info :preserve-breaks)
2074 (setq output (replace-regexp-in-string
2075 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" output)))
2076 ;; Return value.
2077 output))
2080 ;;;; Planning
2082 (defun org-latex-planning (planning contents info)
2083 "Transcode a PLANNING element from Org to LaTeX.
2084 CONTENTS is nil. INFO is a plist holding contextual
2085 information."
2086 (concat
2087 "\\noindent"
2088 (mapconcat
2089 'identity
2090 (delq nil
2091 (list
2092 (let ((closed (org-element-property :closed planning)))
2093 (when closed
2094 (concat
2095 (format "\\textbf{%s} " org-closed-string)
2096 (format org-latex-inactive-timestamp-format
2097 (org-translate-time
2098 (org-element-property :raw-value closed))))))
2099 (let ((deadline (org-element-property :deadline planning)))
2100 (when deadline
2101 (concat
2102 (format "\\textbf{%s} " org-deadline-string)
2103 (format org-latex-active-timestamp-format
2104 (org-translate-time
2105 (org-element-property :raw-value deadline))))))
2106 (let ((scheduled (org-element-property :scheduled planning)))
2107 (when scheduled
2108 (concat
2109 (format "\\textbf{%s} " org-scheduled-string)
2110 (format org-latex-active-timestamp-format
2111 (org-translate-time
2112 (org-element-property :raw-value scheduled))))))))
2113 " ")
2114 "\\\\"))
2117 ;;;; Property Drawer
2119 (defun org-latex-property-drawer (property-drawer contents info)
2120 "Transcode a PROPERTY-DRAWER element from Org to LaTeX.
2121 CONTENTS holds the contents of the drawer. INFO is a plist
2122 holding contextual information."
2123 (and (org-string-nw-p contents)
2124 (format "\\begin{verbatim}\n%s\\end{verbatim}" contents)))
2127 ;;;; Pseudo Object: LaTeX Math Block
2129 (defun org-latex--wrap-latex-math-block (data info)
2130 "Merge contiguous math objects in a pseudo-object container.
2131 DATA is a parse tree or a secondary string. INFO is a plist
2132 containing export options. Modify DATA by side-effect and return it."
2133 (let ((valid-object-p
2134 (function
2135 ;; Non-nil when OBJ can be added to the latex math block.
2136 (lambda (obj)
2137 (case (org-element-type obj)
2138 (entity (org-element-property :latex-math-p obj))
2139 (latex-fragment
2140 (let ((value (org-element-property :value obj)))
2141 (or (org-string-match-p "\\`\\\\([^\000]*\\\\)\\'" value)
2142 (org-string-match-p "\\`\\$[^\000]*\\$\\'" value))))
2143 ((subscript superscript) t))))))
2144 (org-element-map data '(entity latex-fragment subscript superscript)
2145 (lambda (object)
2146 ;; Skip objects already wrapped.
2147 (when (and (not (eq (org-element-type
2148 (org-element-property :parent object))
2149 'latex-math-block))
2150 (funcall valid-object-p object))
2151 (let ((math-block (list 'latex-math-block nil))
2152 (next-elements (org-export-get-next-element object info t))
2153 (last object))
2154 ;; Wrap MATH-BLOCK around OBJECT in DATA.
2155 (org-element-insert-before math-block object)
2156 (org-element-extract-element object)
2157 (org-element-adopt-elements math-block object)
2158 (when (zerop (or (org-element-property :post-blank object) 0))
2159 ;; MATH-BLOCK swallows consecutive math objects.
2160 (catch 'exit
2161 (dolist (next next-elements)
2162 (if (not (funcall valid-object-p next)) (throw 'exit nil)
2163 (org-element-extract-element next)
2164 (org-element-adopt-elements math-block next)
2165 ;; Eschew the case: \beta$x$ -> \(\betax\).
2166 (unless (memq (org-element-type next)
2167 '(subscript superscript))
2168 (org-element-put-property last :post-blank 1))
2169 (setq last next)
2170 (when (> (or (org-element-property :post-blank next) 0) 0)
2171 (throw 'exit nil))))))
2172 (org-element-put-property
2173 math-block :post-blank (org-element-property :post-blank last)))))
2174 info nil '(subscript superscript latex-math-block) t)
2175 ;; Return updated DATA.
2176 data))
2178 (defun org-latex-math-block-tree-filter (tree backend info)
2179 (org-latex--wrap-latex-math-block tree info))
2181 (defun org-latex-math-block-options-filter (info backend)
2182 (dolist (prop '(:author :date :title) info)
2183 (plist-put info prop
2184 (org-latex--wrap-latex-math-block (plist-get info prop) info))))
2186 (defun org-latex-math-block (math-block contents info)
2187 "Transcode a MATH-BLOCK object from Org to LaTeX.
2188 CONTENTS is a string. INFO is a plist used as a communication
2189 channel."
2190 (when (org-string-nw-p contents)
2191 (format "\\(%s\\)" (org-trim contents))))
2193 ;;;; Quote Block
2195 (defun org-latex-quote-block (quote-block contents info)
2196 "Transcode a QUOTE-BLOCK element from Org to LaTeX.
2197 CONTENTS holds the contents of the block. INFO is a plist
2198 holding contextual information."
2199 (org-latex--wrap-label
2200 quote-block
2201 (format "\\begin{quote}\n%s\\end{quote}" contents)))
2204 ;;;; Radio Target
2206 (defun org-latex-radio-target (radio-target text info)
2207 "Transcode a RADIO-TARGET object from Org to LaTeX.
2208 TEXT is the text of the target. INFO is a plist holding
2209 contextual information."
2210 (format "\\label{%s}%s"
2211 (org-export-solidify-link-text
2212 (org-element-property :value radio-target))
2213 text))
2216 ;;;; Section
2218 (defun org-latex-section (section contents info)
2219 "Transcode a SECTION element from Org to LaTeX.
2220 CONTENTS holds the contents of the section. INFO is a plist
2221 holding contextual information."
2222 contents)
2225 ;;;; Special Block
2227 (defun org-latex-special-block (special-block contents info)
2228 "Transcode a SPECIAL-BLOCK element from Org to LaTeX.
2229 CONTENTS holds the contents of the block. INFO is a plist
2230 holding contextual information."
2231 (let ((type (downcase (org-element-property :type special-block)))
2232 (opt (org-export-read-attribute :attr_latex special-block :options)))
2233 (concat (format "\\begin{%s}%s\n" type (or opt ""))
2234 ;; Insert any label or caption within the block
2235 ;; (otherwise, a reference pointing to that element will
2236 ;; count the section instead).
2237 (org-latex--caption/label-string special-block info)
2238 contents
2239 (format "\\end{%s}" type))))
2242 ;;;; Src Block
2244 (defun org-latex-src-block (src-block contents info)
2245 "Transcode a SRC-BLOCK element from Org to LaTeX.
2246 CONTENTS holds the contents of the item. INFO is a plist holding
2247 contextual information."
2248 (when (org-string-nw-p (org-element-property :value src-block))
2249 (let* ((lang (org-element-property :language src-block))
2250 (caption (org-element-property :caption src-block))
2251 (label (org-element-property :name src-block))
2252 (custom-env (and lang
2253 (cadr (assq (intern lang)
2254 org-latex-custom-lang-environments))))
2255 (num-start (case (org-element-property :number-lines src-block)
2256 (continued (org-export-get-loc src-block info))
2257 (new 0)))
2258 (retain-labels (org-element-property :retain-labels src-block))
2259 (attributes (org-export-read-attribute :attr_latex src-block))
2260 (float (plist-get attributes :float)))
2261 (cond
2262 ;; Case 1. No source fontification.
2263 ((not org-latex-listings)
2264 (let* ((caption-str (org-latex--caption/label-string src-block info))
2265 (float-env
2266 (cond ((and (not float) (plist-member attributes :float)) "%s")
2267 ((string= "multicolumn" float)
2268 (format "\\begin{figure*}[%s]\n%%s%s\n\\end{figure*}"
2269 org-latex-default-figure-position
2270 caption-str))
2271 ((or caption float)
2272 (format "\\begin{figure}[H]\n%%s%s\n\\end{figure}"
2273 caption-str))
2274 (t "%s"))))
2275 (format
2276 float-env
2277 (concat (format "\\begin{verbatim}\n%s\\end{verbatim}"
2278 (org-export-format-code-default src-block info))))))
2279 ;; Case 2. Custom environment.
2280 (custom-env (format "\\begin{%s}\n%s\\end{%s}\n"
2281 custom-env
2282 (org-export-format-code-default src-block info)
2283 custom-env))
2284 ;; Case 3. Use minted package.
2285 ((eq org-latex-listings 'minted)
2286 (let* ((caption-str (org-latex--caption/label-string src-block info))
2287 (float-env
2288 (cond ((and (not float) (plist-member attributes :float)) "%s")
2289 ((string= "multicolumn" float)
2290 (format "\\begin{listing*}\n%%s\n%s\\end{listing*}"
2291 caption-str))
2292 ((or caption float)
2293 (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
2294 caption-str))
2295 (t "%s")))
2296 (body
2297 (format
2298 "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
2299 ;; Options.
2300 (concat
2301 (org-latex--make-option-string
2302 (if (or (not num-start)
2303 (assoc "linenos" org-latex-minted-options))
2304 org-latex-minted-options
2305 (append
2306 `(("linenos")
2307 ("firstnumber" ,(number-to-string (1+ num-start))))
2308 org-latex-minted-options)))
2309 (let ((local-options (plist-get attributes :options)))
2310 (and local-options (concat "," local-options))))
2311 ;; Language.
2312 (or (cadr (assq (intern lang) org-latex-minted-langs))
2313 (downcase lang))
2314 ;; Source code.
2315 (let* ((code-info (org-export-unravel-code src-block))
2316 (max-width
2317 (apply 'max
2318 (mapcar 'length
2319 (org-split-string (car code-info)
2320 "\n")))))
2321 (org-export-format-code
2322 (car code-info)
2323 (lambda (loc num ref)
2324 (concat
2326 (when ref
2327 ;; Ensure references are flushed to the right,
2328 ;; separated with 6 spaces from the widest line
2329 ;; of code.
2330 (concat (make-string (+ (- max-width (length loc)) 6)
2331 ?\s)
2332 (format "(%s)" ref)))))
2333 nil (and retain-labels (cdr code-info)))))))
2334 ;; Return value.
2335 (format float-env body)))
2336 ;; Case 4. Use listings package.
2338 (let ((lst-lang
2339 (or (cadr (assq (intern lang) org-latex-listings-langs)) lang))
2340 (caption-str
2341 (when caption
2342 (let ((main (org-export-get-caption src-block))
2343 (secondary (org-export-get-caption src-block t)))
2344 (if (not secondary)
2345 (format "{%s}" (org-export-data main info))
2346 (format "{[%s]%s}"
2347 (org-export-data secondary info)
2348 (org-export-data main info)))))))
2349 (concat
2350 ;; Options.
2351 (format
2352 "\\lstset{%s}\n"
2353 (concat
2354 (org-latex--make-option-string
2355 (append
2356 org-latex-listings-options
2357 (cond
2358 ((and (not float) (plist-member attributes :float)) nil)
2359 ((string= "multicolumn" float) '(("float" "*")))
2360 ((and float (not (assoc "float" org-latex-listings-options)))
2361 `(("float" ,org-latex-default-figure-position))))
2362 `(("language" ,lst-lang))
2363 (if label `(("label" ,label)) '(("label" " ")))
2364 (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
2365 (cond ((assoc "numbers" org-latex-listings-options) nil)
2366 ((not num-start) '(("numbers" "none")))
2367 ((zerop num-start) '(("numbers" "left")))
2368 (t `(("numbers" "left")
2369 ("firstnumber"
2370 ,(number-to-string (1+ num-start))))))))
2371 (let ((local-options (plist-get attributes :options)))
2372 (and local-options (concat "," local-options)))))
2373 ;; Source code.
2374 (format
2375 "\\begin{lstlisting}\n%s\\end{lstlisting}"
2376 (let* ((code-info (org-export-unravel-code src-block))
2377 (max-width
2378 (apply 'max
2379 (mapcar 'length
2380 (org-split-string (car code-info) "\n")))))
2381 (org-export-format-code
2382 (car code-info)
2383 (lambda (loc num ref)
2384 (concat
2386 (when ref
2387 ;; Ensure references are flushed to the right,
2388 ;; separated with 6 spaces from the widest line of
2389 ;; code
2390 (concat (make-string (+ (- max-width (length loc)) 6) ? )
2391 (format "(%s)" ref)))))
2392 nil (and retain-labels (cdr code-info))))))))))))
2395 ;;;; Statistics Cookie
2397 (defun org-latex-statistics-cookie (statistics-cookie contents info)
2398 "Transcode a STATISTICS-COOKIE object from Org to LaTeX.
2399 CONTENTS is nil. INFO is a plist holding contextual information."
2400 (replace-regexp-in-string
2401 "%" "\\%" (org-element-property :value statistics-cookie) nil t))
2404 ;;;; Strike-Through
2406 (defun org-latex-strike-through (strike-through contents info)
2407 "Transcode STRIKE-THROUGH from Org to LaTeX.
2408 CONTENTS is the text with strike-through markup. INFO is a plist
2409 holding contextual information."
2410 (org-latex--text-markup contents 'strike-through))
2413 ;;;; Subscript
2415 (defun org-latex--script-size (object info)
2416 "Transcode a subscript or superscript object.
2417 OBJECT is an Org object. INFO is a plist used as a communication
2418 channel."
2419 (let ((type (org-element-type object))
2420 (output ""))
2421 (org-element-map (org-element-contents object)
2422 (cons 'plain-text org-element-all-objects)
2423 (lambda (obj)
2424 (case (org-element-type obj)
2425 ((entity latex-fragment)
2426 (let ((data (org-trim (org-export-data obj info))))
2427 (string-match
2428 "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
2429 data)
2430 (setq output
2431 (concat output
2432 (match-string 1 data)
2433 (let ((blank (org-element-property :post-blank obj)))
2434 (and blank (> blank 0) "\\ "))))))
2435 (plain-text
2436 (setq output
2437 (format "%s\\text{%s}" output (org-export-data obj info))))
2438 (otherwise
2439 (setq output
2440 (concat output
2441 (org-export-data obj info)
2442 (let ((blank (org-element-property :post-blank obj)))
2443 (and blank (> blank 0) "\\ ")))))))
2444 info nil org-element-recursive-objects)
2445 ;; Result. Do not wrap into curly brackets if OUTPUT is a single
2446 ;; character.
2447 (concat (if (eq (org-element-type object) 'subscript) "_" "^")
2448 (and (> (length output) 1) "{")
2449 output
2450 (and (> (length output) 1) "}"))))
2452 (defun org-latex-subscript (subscript contents info)
2453 "Transcode a SUBSCRIPT object from Org to LaTeX.
2454 CONTENTS is the contents of the object. INFO is a plist holding
2455 contextual information."
2456 (org-latex--script-size subscript info))
2459 ;;;; Superscript
2461 (defun org-latex-superscript (superscript contents info)
2462 "Transcode a SUPERSCRIPT object from Org to LaTeX.
2463 CONTENTS is the contents of the object. INFO is a plist holding
2464 contextual information."
2465 (org-latex--script-size superscript info))
2468 ;;;; Table
2470 ;; `org-latex-table' is the entry point for table transcoding. It
2471 ;; takes care of tables with a "verbatim" mode. Otherwise, it
2472 ;; delegates the job to either `org-latex--table.el-table',
2473 ;; `org-latex--org-table' or `org-latex--math-table' functions,
2474 ;; depending of the type of the table and the mode requested.
2476 ;; `org-latex--align-string' is a subroutine used to build alignment
2477 ;; string for Org tables.
2479 (defun org-latex-table (table contents info)
2480 "Transcode a TABLE element from Org to LaTeX.
2481 CONTENTS is the contents of the table. INFO is a plist holding
2482 contextual information."
2483 (if (eq (org-element-property :type table) 'table.el)
2484 ;; "table.el" table. Convert it using appropriate tools.
2485 (org-latex--table.el-table table info)
2486 (let ((type (or (org-export-read-attribute :attr_latex table :mode)
2487 org-latex-default-table-mode)))
2488 (cond
2489 ;; Case 1: Verbatim table.
2490 ((string= type "verbatim")
2491 (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
2492 ;; Re-create table, without affiliated keywords.
2493 (org-trim (org-element-interpret-data
2494 `(table nil ,@(org-element-contents table))
2495 org-latex-pseudo-objects))))
2496 ;; Case 2: Matrix.
2497 ((or (string= type "math") (string= type "inline-math"))
2498 (org-latex--math-table table info))
2499 ;; Case 3: Standard table.
2500 (t (concat (org-latex--org-table table contents info)
2501 ;; When there are footnote references within the
2502 ;; table, insert their definition just after it.
2503 (org-latex--delayed-footnotes-definitions table info)))))))
2505 (defun org-latex--align-string (table info)
2506 "Return an appropriate LaTeX alignment string.
2507 TABLE is the considered table. INFO is a plist used as
2508 a communication channel."
2509 (or (org-export-read-attribute :attr_latex table :align)
2510 (let (align)
2511 ;; Extract column groups and alignment from first (non-rule)
2512 ;; row.
2513 (org-element-map
2514 (org-element-map table 'table-row
2515 (lambda (row)
2516 (and (eq (org-element-property :type row) 'standard) row))
2517 info 'first-match)
2518 'table-cell
2519 (lambda (cell)
2520 (let ((borders (org-export-table-cell-borders cell info)))
2521 ;; Check left border for the first cell only.
2522 (when (and (memq 'left borders) (not align))
2523 (push "|" align))
2524 (push (case (org-export-table-cell-alignment cell info)
2525 (left "l")
2526 (right "r")
2527 (center "c"))
2528 align)
2529 (when (memq 'right borders) (push "|" align))))
2530 info)
2531 (apply 'concat (nreverse align)))))
2533 (defun org-latex--org-table (table contents info)
2534 "Return appropriate LaTeX code for an Org table.
2536 TABLE is the table type element to transcode. CONTENTS is its
2537 contents, as a string. INFO is a plist used as a communication
2538 channel.
2540 This function assumes TABLE has `org' as its `:type' property and
2541 `table' as its `:mode' attribute."
2542 (let* ((caption (org-latex--caption/label-string table info))
2543 (attr (org-export-read-attribute :attr_latex table))
2544 ;; Determine alignment string.
2545 (alignment (org-latex--align-string table info))
2546 ;; Determine environment for the table: longtable, tabular...
2547 (table-env (or (plist-get attr :environment)
2548 org-latex-default-table-environment))
2549 ;; If table is a float, determine environment: table, table*
2550 ;; or sidewaystable.
2551 (float-env (unless (member table-env '("longtable" "longtabu"))
2552 (let ((float (plist-get attr :float)))
2553 (cond
2554 ((and (not float) (plist-member attr :float)) nil)
2555 ((or (string= float "sidewaystable")
2556 (string= float "sideways")) "sidewaystable")
2557 ((string= float "multicolumn") "table*")
2558 ((or float
2559 (org-element-property :caption table)
2560 (org-string-nw-p (plist-get attr :caption)))
2561 "table")))))
2562 ;; Extract others display options.
2563 (fontsize (let ((font (plist-get attr :font)))
2564 (and font (concat font "\n"))))
2565 (width (plist-get attr :width))
2566 (spreadp (plist-get attr :spread))
2567 (placement (or (plist-get attr :placement)
2568 (format "[%s]" org-latex-default-figure-position)))
2569 (centerp (if (plist-member attr :center) (plist-get attr :center)
2570 org-latex-tables-centered)))
2571 ;; Prepare the final format string for the table.
2572 (cond
2573 ;; Longtable.
2574 ((equal "longtable" table-env)
2575 (concat (and fontsize (concat "{" fontsize))
2576 (format "\\begin{longtable}{%s}\n" alignment)
2577 (and org-latex-table-caption-above
2578 (org-string-nw-p caption)
2579 (concat caption "\\\\\n"))
2580 contents
2581 (and (not org-latex-table-caption-above)
2582 (org-string-nw-p caption)
2583 (concat caption "\\\\\n"))
2584 "\\end{longtable}\n"
2585 (and fontsize "}")))
2586 ;; Longtabu
2587 ((equal "longtabu" table-env)
2588 (concat (and fontsize (concat "{" fontsize))
2589 (format "\\begin{longtabu}%s{%s}\n"
2590 (if width
2591 (format " %s %s "
2592 (if spreadp "spread" "to") width) "")
2593 alignment)
2594 (and org-latex-table-caption-above
2595 (org-string-nw-p caption)
2596 (concat caption "\\\\\n"))
2597 contents
2598 (and (not org-latex-table-caption-above)
2599 (org-string-nw-p caption)
2600 (concat caption "\\\\\n"))
2601 "\\end{longtabu}\n"
2602 (and fontsize "}")))
2603 ;; Others.
2604 (t (concat (cond
2605 (float-env
2606 (concat (format "\\begin{%s}%s\n" float-env placement)
2607 (if org-latex-table-caption-above caption "")
2608 (when centerp "\\centering\n")
2609 fontsize))
2610 (centerp (concat "\\begin{center}\n" fontsize))
2611 (fontsize (concat "{" fontsize)))
2612 (cond ((equal "tabu" table-env)
2613 (format "\\begin{tabu}%s{%s}\n%s\\end{tabu}"
2614 (if width (format
2615 (if spreadp " spread %s " " to %s ")
2616 width) "")
2617 alignment
2618 contents))
2619 (t (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
2620 table-env
2621 (if width (format "{%s}" width) "")
2622 alignment
2623 contents
2624 table-env)))
2625 (cond
2626 (float-env
2627 (concat (if org-latex-table-caption-above "" caption)
2628 (format "\n\\end{%s}" float-env)))
2629 (centerp "\n\\end{center}")
2630 (fontsize "}")))))))
2632 (defun org-latex--table.el-table (table info)
2633 "Return appropriate LaTeX code for a table.el table.
2635 TABLE is the table type element to transcode. INFO is a plist
2636 used as a communication channel.
2638 This function assumes TABLE has `table.el' as its `:type'
2639 property."
2640 (require 'table)
2641 ;; Ensure "*org-export-table*" buffer is empty.
2642 (with-current-buffer (get-buffer-create "*org-export-table*")
2643 (erase-buffer))
2644 (let ((output (with-temp-buffer
2645 (insert (org-element-property :value table))
2646 (goto-char 1)
2647 (re-search-forward "^[ \t]*|[^|]" nil t)
2648 (table-generate-source 'latex "*org-export-table*")
2649 (with-current-buffer "*org-export-table*"
2650 (org-trim (buffer-string))))))
2651 (kill-buffer (get-buffer "*org-export-table*"))
2652 ;; Remove left out comments.
2653 (while (string-match "^%.*\n" output)
2654 (setq output (replace-match "" t t output)))
2655 (let ((attr (org-export-read-attribute :attr_latex table)))
2656 (when (plist-get attr :rmlines)
2657 ;; When the "rmlines" attribute is provided, remove all hlines
2658 ;; but the the one separating heading from the table body.
2659 (let ((n 0) (pos 0))
2660 (while (and (< (length output) pos)
2661 (setq pos (string-match "^\\\\hline\n?" output pos)))
2662 (incf n)
2663 (unless (= n 2) (setq output (replace-match "" nil nil output))))))
2664 (let ((centerp (if (plist-member attr :center) (plist-get attr :center)
2665 org-latex-tables-centered)))
2666 (if (not centerp) output
2667 (format "\\begin{center}\n%s\n\\end{center}" output))))))
2669 (defun org-latex--math-table (table info)
2670 "Return appropriate LaTeX code for a matrix.
2672 TABLE is the table type element to transcode. INFO is a plist
2673 used as a communication channel.
2675 This function assumes TABLE has `org' as its `:type' property and
2676 `inline-math' or `math' as its `:mode' attribute.."
2677 (let* ((caption (org-latex--caption/label-string table info))
2678 (attr (org-export-read-attribute :attr_latex table))
2679 (inlinep (equal (plist-get attr :mode) "inline-math"))
2680 (env (or (plist-get attr :environment)
2681 org-latex-default-table-environment))
2682 (contents
2683 (mapconcat
2684 (lambda (row)
2685 ;; Ignore horizontal rules.
2686 (when (eq (org-element-property :type row) 'standard)
2687 ;; Return each cell unmodified.
2688 (concat
2689 (mapconcat
2690 (lambda (cell)
2691 (substring
2692 (org-element-interpret-data cell org-latex-pseudo-objects)
2693 0 -1))
2694 (org-element-map row 'table-cell 'identity info) "&")
2695 (or (cdr (assoc env org-latex-table-matrix-macros)) "\\\\")
2696 "\n")))
2697 (org-element-map table 'table-row 'identity info) ""))
2698 ;; Variables related to math clusters (contiguous math tables
2699 ;; of the same type).
2700 (mode (org-export-read-attribute :attr_latex table :mode))
2701 (prev (org-export-get-previous-element table info))
2702 (next (org-export-get-next-element table info))
2703 (same-mode-p
2704 (lambda (table)
2705 ;; Non-nil when TABLE has the same mode as current table.
2706 (string= (or (org-export-read-attribute :attr_latex table :mode)
2707 org-latex-default-table-mode)
2708 mode))))
2709 (concat
2710 ;; Opening string. If TABLE is in the middle of a table cluster,
2711 ;; do not insert any.
2712 (cond ((and prev
2713 (eq (org-element-type prev) 'table)
2714 (memq (org-element-property :post-blank prev) '(0 nil))
2715 (funcall same-mode-p prev))
2716 nil)
2717 (inlinep "\\(")
2718 ((org-string-nw-p caption) (concat "\\begin{equation}\n" caption))
2719 (t "\\["))
2720 ;; Prefix.
2721 (or (plist-get attr :math-prefix) "")
2722 ;; Environment. Also treat special cases.
2723 (cond ((equal env "array")
2724 (let ((align (org-latex--align-string table info)))
2725 (format "\\begin{array}{%s}\n%s\\end{array}" align contents)))
2726 ((assoc env org-latex-table-matrix-macros)
2727 (format "\\%s%s{\n%s}"
2729 (or (plist-get attr :math-arguments) "")
2730 contents))
2731 (t (format "\\begin{%s}\n%s\\end{%s}" env contents env)))
2732 ;; Suffix.
2733 (or (plist-get attr :math-suffix) "")
2734 ;; Closing string. If TABLE is in the middle of a table cluster,
2735 ;; do not insert any. If it closes such a cluster, be sure to
2736 ;; close the cluster with a string matching the opening string.
2737 (cond ((and next
2738 (eq (org-element-type next) 'table)
2739 (memq (org-element-property :post-blank table) '(0 nil))
2740 (funcall same-mode-p next))
2741 nil)
2742 (inlinep "\\)")
2743 ;; Find cluster beginning to know which environment to use.
2744 ((let ((cluster-beg table) prev)
2745 (while (and (setq prev (org-export-get-previous-element
2746 cluster-beg info))
2747 (memq (org-element-property :post-blank prev)
2748 '(0 nil))
2749 (funcall same-mode-p prev))
2750 (setq cluster-beg prev))
2751 (and (or (org-element-property :caption cluster-beg)
2752 (org-element-property :name cluster-beg))
2753 "\n\\end{equation}")))
2754 (t "\\]")))))
2757 ;;;; Table Cell
2759 (defun org-latex-table-cell (table-cell contents info)
2760 "Transcode a TABLE-CELL element from Org to LaTeX.
2761 CONTENTS is the cell contents. INFO is a plist used as
2762 a communication channel."
2763 (concat (if (and contents
2764 org-latex-table-scientific-notation
2765 (string-match orgtbl-exp-regexp contents))
2766 ;; Use appropriate format string for scientific
2767 ;; notation.
2768 (format org-latex-table-scientific-notation
2769 (match-string 1 contents)
2770 (match-string 2 contents))
2771 contents)
2772 (when (org-export-get-next-element table-cell info) " & ")))
2775 ;;;; Table Row
2777 (defun org-latex-table-row (table-row contents info)
2778 "Transcode a TABLE-ROW element from Org to LaTeX.
2779 CONTENTS is the contents of the row. INFO is a plist used as
2780 a communication channel."
2781 ;; Rules are ignored since table separators are deduced from
2782 ;; borders of the current row.
2783 (when (eq (org-element-property :type table-row) 'standard)
2784 (let* ((attr (org-export-read-attribute :attr_latex
2785 (org-export-get-parent table-row)))
2786 (longtablep (member (or (plist-get attr :environment)
2787 org-latex-default-table-environment)
2788 '("longtable" "longtabu")))
2789 (booktabsp (if (plist-member attr :booktabs)
2790 (plist-get attr :booktabs)
2791 org-latex-tables-booktabs))
2792 ;; TABLE-ROW's borders are extracted from its first cell.
2793 (borders (org-export-table-cell-borders
2794 (car (org-element-contents table-row)) info)))
2795 (concat
2796 ;; When BOOKTABS are activated enforce top-rule even when no
2797 ;; hline was specifically marked.
2798 (cond ((and booktabsp (memq 'top borders)) "\\toprule\n")
2799 ((and (memq 'top borders) (memq 'above borders)) "\\hline\n"))
2800 contents "\\\\\n"
2801 (cond
2802 ;; Special case for long tables. Define header and footers.
2803 ((and longtablep (org-export-table-row-ends-header-p table-row info))
2804 (format "%s
2805 \\endfirsthead
2806 \\multicolumn{%d}{l}{%s} \\\\
2808 %s \\\\\n
2810 \\endhead
2811 %s\\multicolumn{%d}{r}{%s} \\\\
2812 \\endfoot
2813 \\endlastfoot"
2814 (if booktabsp "\\midrule" "\\hline")
2815 (cdr (org-export-table-dimensions
2816 (org-export-get-parent-table table-row) info))
2817 (org-latex--translate "Continued from previous page" info)
2818 (cond ((and booktabsp (memq 'top borders)) "\\toprule\n")
2819 ((and (memq 'top borders)
2820 (memq 'above borders)) "\\hline\n")
2821 (t ""))
2822 contents
2823 (if booktabsp "\\midrule" "\\hline")
2824 (if booktabsp "\\midrule" "\\hline")
2825 ;; Number of columns.
2826 (cdr (org-export-table-dimensions
2827 (org-export-get-parent-table table-row) info))
2828 (org-latex--translate "Continued on next page" info)))
2829 ;; When BOOKTABS are activated enforce bottom rule even when
2830 ;; no hline was specifically marked.
2831 ((and booktabsp (memq 'bottom borders)) "\\bottomrule")
2832 ((and (memq 'bottom borders) (memq 'below borders)) "\\hline")
2833 ((memq 'below borders) (if booktabsp "\\midrule" "\\hline")))))))
2836 ;;;; Target
2838 (defun org-latex-target (target contents info)
2839 "Transcode a TARGET object from Org to LaTeX.
2840 CONTENTS is nil. INFO is a plist holding contextual
2841 information."
2842 (format "\\label{%s}"
2843 (org-export-solidify-link-text (org-element-property :value target))))
2846 ;;;; Timestamp
2848 (defun org-latex-timestamp (timestamp contents info)
2849 "Transcode a TIMESTAMP object from Org to LaTeX.
2850 CONTENTS is nil. INFO is a plist holding contextual
2851 information."
2852 (let ((value (org-latex-plain-text
2853 (org-timestamp-translate timestamp) info)))
2854 (case (org-element-property :type timestamp)
2855 ((active active-range) (format org-latex-active-timestamp-format value))
2856 ((inactive inactive-range)
2857 (format org-latex-inactive-timestamp-format value))
2858 (otherwise (format org-latex-diary-timestamp-format value)))))
2861 ;;;; Underline
2863 (defun org-latex-underline (underline contents info)
2864 "Transcode UNDERLINE from Org to LaTeX.
2865 CONTENTS is the text with underline markup. INFO is a plist
2866 holding contextual information."
2867 (org-latex--text-markup contents 'underline))
2870 ;;;; Verbatim
2872 (defun org-latex-verbatim (verbatim contents info)
2873 "Transcode a VERBATIM object from Org to LaTeX.
2874 CONTENTS is nil. INFO is a plist used as a communication
2875 channel."
2876 (org-latex--text-markup (org-element-property :value verbatim) 'verbatim))
2879 ;;;; Verse Block
2881 (defun org-latex-verse-block (verse-block contents info)
2882 "Transcode a VERSE-BLOCK element from Org to LaTeX.
2883 CONTENTS is verse block contents. INFO is a plist holding
2884 contextual information."
2885 (org-latex--wrap-label
2886 verse-block
2887 ;; In a verse environment, add a line break to each newline
2888 ;; character and change each white space at beginning of a line
2889 ;; into a space of 1 em. Also change each blank line with
2890 ;; a vertical space of 1 em.
2891 (progn
2892 (setq contents (replace-regexp-in-string
2893 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
2894 (replace-regexp-in-string
2895 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" contents)))
2896 (while (string-match "^[ \t]+" contents)
2897 (let ((new-str (format "\\hspace*{%dem}"
2898 (length (match-string 0 contents)))))
2899 (setq contents (replace-match new-str nil t contents))))
2900 (format "\\begin{verse}\n%s\\end{verse}" contents))))
2904 ;;; End-user functions
2906 ;;;###autoload
2907 (defun org-latex-export-as-latex
2908 (&optional async subtreep visible-only body-only ext-plist)
2909 "Export current buffer as a LaTeX buffer.
2911 If narrowing is active in the current buffer, only export its
2912 narrowed part.
2914 If a region is active, export that region.
2916 A non-nil optional argument ASYNC means the process should happen
2917 asynchronously. The resulting buffer should be accessible
2918 through the `org-export-stack' interface.
2920 When optional argument SUBTREEP is non-nil, export the sub-tree
2921 at point, extracting information from the headline properties
2922 first.
2924 When optional argument VISIBLE-ONLY is non-nil, don't export
2925 contents of hidden elements.
2927 When optional argument BODY-ONLY is non-nil, only write code
2928 between \"\\begin{document}\" and \"\\end{document}\".
2930 EXT-PLIST, when provided, is a property list with external
2931 parameters overriding Org default settings, but still inferior to
2932 file-local settings.
2934 Export is done in a buffer named \"*Org LATEX Export*\", which
2935 will be displayed when `org-export-show-temporary-export-buffer'
2936 is non-nil."
2937 (interactive)
2938 (org-export-to-buffer 'latex "*Org LATEX Export*"
2939 async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
2941 ;;;###autoload
2942 (defun org-latex-convert-region-to-latex ()
2943 "Assume the current region has org-mode syntax, and convert it to LaTeX.
2944 This can be used in any buffer. For example, you can write an
2945 itemized list in org-mode syntax in an LaTeX buffer and use this
2946 command to convert it."
2947 (interactive)
2948 (org-export-replace-region-by 'latex))
2950 ;;;###autoload
2951 (defun org-latex-export-to-latex
2952 (&optional async subtreep visible-only body-only ext-plist)
2953 "Export current buffer to a LaTeX file.
2955 If narrowing is active in the current buffer, only export its
2956 narrowed part.
2958 If a region is active, export that region.
2960 A non-nil optional argument ASYNC means the process should happen
2961 asynchronously. The resulting file should be accessible through
2962 the `org-export-stack' interface.
2964 When optional argument SUBTREEP is non-nil, export the sub-tree
2965 at point, extracting information from the headline properties
2966 first.
2968 When optional argument VISIBLE-ONLY is non-nil, don't export
2969 contents of hidden elements.
2971 When optional argument BODY-ONLY is non-nil, only write code
2972 between \"\\begin{document}\" and \"\\end{document}\".
2974 EXT-PLIST, when provided, is a property list with external
2975 parameters overriding Org default settings, but still inferior to
2976 file-local settings."
2977 (interactive)
2978 (let ((outfile (org-export-output-file-name ".tex" subtreep)))
2979 (org-export-to-file 'latex outfile
2980 async subtreep visible-only body-only ext-plist)))
2982 ;;;###autoload
2983 (defun org-latex-export-to-pdf
2984 (&optional async subtreep visible-only body-only ext-plist)
2985 "Export current buffer to LaTeX then process through to PDF.
2987 If narrowing is active in the current buffer, only export its
2988 narrowed part.
2990 If a region is active, export that region.
2992 A non-nil optional argument ASYNC means the process should happen
2993 asynchronously. The resulting file should be accessible through
2994 the `org-export-stack' interface.
2996 When optional argument SUBTREEP is non-nil, export the sub-tree
2997 at point, extracting information from the headline properties
2998 first.
3000 When optional argument VISIBLE-ONLY is non-nil, don't export
3001 contents of hidden elements.
3003 When optional argument BODY-ONLY is non-nil, only write code
3004 between \"\\begin{document}\" and \"\\end{document}\".
3006 EXT-PLIST, when provided, is a property list with external
3007 parameters overriding Org default settings, but still inferior to
3008 file-local settings.
3010 Return PDF file's name."
3011 (interactive)
3012 (let ((outfile (org-export-output-file-name ".tex" subtreep)))
3013 (org-export-to-file 'latex outfile
3014 async subtreep visible-only body-only ext-plist
3015 (lambda (file) (org-latex-compile file)))))
3017 (defun org-latex-compile (texfile &optional snippet)
3018 "Compile a TeX file.
3020 TEXFILE is the name of the file being compiled. Processing is
3021 done through the command specified in `org-latex-pdf-process'.
3023 When optional argument SNIPPET is non-nil, TEXFILE is a temporary
3024 file used to preview a LaTeX snippet. In this case, do not
3025 create a log buffer and do not bother removing log files.
3027 Return PDF file name or an error if it couldn't be produced."
3028 (let* ((base-name (file-name-sans-extension (file-name-nondirectory texfile)))
3029 (full-name (file-truename texfile))
3030 (out-dir (file-name-directory texfile))
3031 ;; Properly set working directory for compilation.
3032 (default-directory (if (file-name-absolute-p texfile)
3033 (file-name-directory full-name)
3034 default-directory))
3035 (time (current-time))
3036 warnings)
3037 (unless snippet (message (format "Processing LaTeX file %s..." texfile)))
3038 (save-window-excursion
3039 (cond
3040 ;; A function is provided: Apply it.
3041 ((functionp org-latex-pdf-process)
3042 (funcall org-latex-pdf-process (shell-quote-argument texfile)))
3043 ;; A list is provided: Replace %b, %f and %o with appropriate
3044 ;; values in each command before applying it. Output is
3045 ;; redirected to "*Org PDF LaTeX Output*" buffer.
3046 ((consp org-latex-pdf-process)
3047 (let ((outbuf (and (not snippet)
3048 (get-buffer-create "*Org PDF LaTeX Output*"))))
3049 (mapc
3050 (lambda (command)
3051 (shell-command
3052 (replace-regexp-in-string
3053 "%b" (shell-quote-argument base-name)
3054 (replace-regexp-in-string
3055 "%f" (shell-quote-argument full-name)
3056 (replace-regexp-in-string
3057 "%o" (shell-quote-argument out-dir) command t t) t t) t t)
3058 outbuf))
3059 org-latex-pdf-process)
3060 ;; Collect standard errors from output buffer.
3061 (setq warnings (and (not snippet)
3062 (org-latex--collect-warnings outbuf)))))
3063 (t (error "No valid command to process to PDF")))
3064 (let ((pdffile (concat out-dir base-name ".pdf")))
3065 ;; Check for process failure. Provide collected errors if
3066 ;; possible.
3067 (if (or (not (file-exists-p pdffile))
3068 (time-less-p (nth 5 (file-attributes pdffile)) time))
3069 (error (format "PDF file %s wasn't produced" pdffile))
3070 ;; Else remove log files, when specified, and signal end of
3071 ;; process to user, along with any error encountered.
3072 (when (and (not snippet) org-latex-remove-logfiles)
3073 (dolist (file (directory-files
3074 out-dir t
3075 (concat (regexp-quote base-name)
3076 "\\(?:\\.[0-9]+\\)?"
3077 "\\."
3078 (regexp-opt org-latex-logfiles-extensions))))
3079 (delete-file file)))
3080 (message (concat "PDF file produced"
3081 (cond
3082 ((eq warnings 'error) " with errors.")
3083 (warnings (concat " with warnings: " warnings))
3084 (t ".")))))
3085 ;; Return output file name.
3086 pdffile))))
3088 (defun org-latex--collect-warnings (buffer)
3089 "Collect some warnings from \"pdflatex\" command output.
3090 BUFFER is the buffer containing output. Return collected
3091 warnings types as a string, `error' if a LaTeX error was
3092 encountered or nil if there was none."
3093 (with-current-buffer buffer
3094 (save-excursion
3095 (goto-char (point-max))
3096 (when (re-search-backward "^[ \t]*This is .*?TeX.*?Version" nil t)
3097 (if (re-search-forward "^!" nil t) 'error
3098 (let ((case-fold-search t)
3099 (warnings ""))
3100 (dolist (warning org-latex-known-warnings)
3101 (save-excursion
3102 (when (save-excursion (re-search-forward (car warning) nil t))
3103 (setq warnings (concat warnings " " (cdr warning))))))
3104 (and (org-string-nw-p warnings) (org-trim warnings))))))))
3106 ;;;###autoload
3107 (defun org-latex-publish-to-latex (plist filename pub-dir)
3108 "Publish an Org file to LaTeX.
3110 FILENAME is the filename of the Org file to be published. PLIST
3111 is the property list for the given project. PUB-DIR is the
3112 publishing directory.
3114 Return output file name."
3115 (org-publish-org-to 'latex filename ".tex" plist pub-dir))
3117 ;;;###autoload
3118 (defun org-latex-publish-to-pdf (plist filename pub-dir)
3119 "Publish an Org file to PDF (via LaTeX).
3121 FILENAME is the filename of the Org file to be published. PLIST
3122 is the property list for the given project. PUB-DIR is the
3123 publishing directory.
3125 Return output file name."
3126 ;; Unlike to `org-latex-publish-to-latex', PDF file is generated
3127 ;; in working directory and then moved to publishing directory.
3128 (org-publish-attachment
3129 plist
3130 (org-latex-compile
3131 (org-publish-org-to
3132 'latex filename ".tex" plist (file-name-directory filename)))
3133 pub-dir))
3136 (provide 'ox-latex)
3138 ;; Local variables:
3139 ;; generated-autoload-file: "org-loaddefs.el"
3140 ;; End:
3142 ;;; ox-latex.el ends here