Radio targets cannot beging or end with whitespace
[org-mode.git] / lisp / ox-latex.el
blobd65c975cda6fe29e6ba39088f6d3cb6a3aaf488f
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-errors
946 '(("Reference.*?undefined" . "[undefined reference]")
947 ("Citation.*?undefined" . "[undefined citation]")
948 ("Undefined control sequence" . "[undefined control sequence]")
949 ("^! LaTeX.*?Error" . "[LaTeX error]")
950 ("^! Package.*?Error" . "[package error]")
951 ("Runaway argument" . "Runaway argument"))
952 "Alist of regular expressions and associated messages for the user.
953 The regular expressions are used to find possible errors in the
954 log of a latex-run."
955 :group 'org-export-latex
956 :version "24.4"
957 :package-version '(Org . "8.0")
958 :type '(repeat
959 (cons
960 (string :tag "Regexp")
961 (string :tag "Message"))))
965 ;;; Internal Functions
967 (defun org-latex--caption/label-string (element info)
968 "Return caption and label LaTeX string for ELEMENT.
970 INFO is a plist holding contextual information. If there's no
971 caption nor label, return the empty string.
973 For non-floats, see `org-latex--wrap-label'."
974 (let* ((label (org-element-property :name element))
975 (label-str (if (not (org-string-nw-p label)) ""
976 (format "\\label{%s}"
977 (org-export-solidify-link-text label))))
978 (main (org-export-get-caption element))
979 (short (org-export-get-caption element t))
980 (caption-from-attr-latex (org-export-read-attribute :attr_latex element :caption)))
981 (cond
982 ((org-string-nw-p caption-from-attr-latex)
983 (concat caption-from-attr-latex "\n"))
984 ((and (not main) (equal label-str "")) "")
985 ((not main) (concat label-str "\n"))
986 ;; Option caption format with short name.
987 (short (format "\\caption[%s]{%s%s}\n"
988 (org-export-data short info)
989 label-str
990 (org-export-data main info)))
991 ;; Standard caption format.
992 (t (format "\\caption{%s%s}\n" label-str (org-export-data main info))))))
994 (defun org-latex-guess-inputenc (header)
995 "Set the coding system in inputenc to what the buffer is.
997 HEADER is the LaTeX header string. This function only applies
998 when specified inputenc option is \"AUTO\".
1000 Return the new header, as a string."
1001 (let* ((cs (or (ignore-errors
1002 (latexenc-coding-system-to-inputenc
1003 (or org-export-coding-system buffer-file-coding-system)))
1004 "utf8")))
1005 (if (not cs) header
1006 ;; First translate if that is requested.
1007 (setq cs (or (cdr (assoc cs org-latex-inputenc-alist)) cs))
1008 ;; Then find the \usepackage statement and replace the option.
1009 (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
1010 cs header t nil 1))))
1012 (defun org-latex-guess-babel-language (header info)
1013 "Set Babel's language according to LANGUAGE keyword.
1015 HEADER is the LaTeX header string. INFO is the plist used as
1016 a communication channel.
1018 Insertion of guessed language only happens when Babel package has
1019 explicitly been loaded. Then it is added to the rest of
1020 package's options.
1022 The argument to Babel may be \"AUTO\" which is then replaced with
1023 the language of the document or `org-export-default-language'
1024 unless language in question is already loaded.
1026 Return the new header."
1027 (let ((language-code (plist-get info :language)))
1028 ;; If no language is set or Babel package is not loaded, return
1029 ;; HEADER as-is.
1030 (if (or (not (stringp language-code))
1031 (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
1032 header
1033 (let ((options (save-match-data
1034 (org-split-string (match-string 1 header) ",[ \t]*")))
1035 (language (cdr (assoc language-code
1036 org-latex-babel-language-alist))))
1037 ;; If LANGUAGE is already loaded, return header without AUTO.
1038 ;; Otherwise, replace AUTO with language or append language if
1039 ;; AUTO is not present.
1040 (replace-match
1041 (mapconcat (lambda (option) (if (equal "AUTO" option) language option))
1042 (cond ((member language options) (delete "AUTO" options))
1043 ((member "AUTO" options) options)
1044 (t (append options (list language))))
1045 ", ")
1046 t nil header 1)))))
1048 (defun org-latex--find-verb-separator (s)
1049 "Return a character not used in string S.
1050 This is used to choose a separator for constructs like \\verb."
1051 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1052 (loop for c across ll
1053 when (not (string-match (regexp-quote (char-to-string c)) s))
1054 return (char-to-string c))))
1056 (defun org-latex--make-option-string (options)
1057 "Return a comma separated string of keywords and values.
1058 OPTIONS is an alist where the key is the options keyword as
1059 a string, and the value a list containing the keyword value, or
1060 nil."
1061 (mapconcat (lambda (pair)
1062 (concat (first pair)
1063 (when (> (length (second pair)) 0)
1064 (concat "=" (second pair)))))
1065 options
1066 ","))
1068 (defun org-latex--wrap-label (element output)
1069 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1070 This function shouldn't be used for floats. See
1071 `org-latex--caption/label-string'."
1072 (let ((label (org-element-property :name element)))
1073 (if (not (and (org-string-nw-p output) (org-string-nw-p label))) output
1074 (concat (format "\\label{%s}\n" (org-export-solidify-link-text label))
1075 output))))
1077 (defun org-latex--text-markup (text markup)
1078 "Format TEXT depending on MARKUP text markup.
1079 See `org-latex-text-markup-alist' for details."
1080 (let ((fmt (cdr (assq markup org-latex-text-markup-alist))))
1081 (cond
1082 ;; No format string: Return raw text.
1083 ((not fmt) text)
1084 ;; Handle the `verb' special case: Find an appropriate separator
1085 ;; and use "\\verb" command.
1086 ((eq 'verb fmt)
1087 (let ((separator (org-latex--find-verb-separator text)))
1088 (concat "\\verb" separator
1089 (replace-regexp-in-string "\n" " " text)
1090 separator)))
1091 ;; Handle the `protectedtexttt' special case: Protect some
1092 ;; special chars and use "\texttt{%s}" format string.
1093 ((eq 'protectedtexttt fmt)
1094 (let ((start 0)
1095 (trans '(("\\" . "\\textbackslash{}")
1096 ("~" . "\\textasciitilde{}")
1097 ("^" . "\\textasciicircum{}")))
1098 (rtn "")
1099 char)
1100 (while (string-match "[\\{}$%&_#~^]" text)
1101 (setq char (match-string 0 text))
1102 (if (> (match-beginning 0) 0)
1103 (setq rtn (concat rtn (substring text 0 (match-beginning 0)))))
1104 (setq text (substring text (1+ (match-beginning 0))))
1105 (setq char (or (cdr (assoc char trans)) (concat "\\" char))
1106 rtn (concat rtn char)))
1107 (setq text (concat rtn text)
1108 fmt "\\texttt{%s}")
1109 (while (string-match "--" text)
1110 (setq text (replace-match "-{}-" t t text)))
1111 (format fmt text)))
1112 ;; Else use format string.
1113 (t (format fmt text)))))
1115 (defun org-latex--delayed-footnotes-definitions (element info)
1116 "Return footnotes definitions in ELEMENT as a string.
1118 INFO is a plist used as a communication channel.
1120 Footnotes definitions are returned within \"\\footnotetxt{}\"
1121 commands.
1123 This function is used within constructs that don't support
1124 \"\\footnote{}\" command (i.e. an item's tag). In that case,
1125 \"\\footnotemark\" is used within the construct and the function
1126 just outside of it."
1127 (mapconcat
1128 (lambda (ref)
1129 (format
1130 "\\footnotetext[%s]{%s}"
1131 (org-export-get-footnote-number ref info)
1132 (org-trim
1133 (org-export-data
1134 (org-export-get-footnote-definition ref info) info))))
1135 ;; Find every footnote reference in ELEMENT.
1136 (let* (all-refs
1137 search-refs ; For byte-compiler.
1138 (search-refs
1139 (function
1140 (lambda (data)
1141 ;; Return a list of all footnote references never seen
1142 ;; before in DATA.
1143 (org-element-map data 'footnote-reference
1144 (lambda (ref)
1145 (when (org-export-footnote-first-reference-p ref info)
1146 (push ref all-refs)
1147 (when (eq (org-element-property :type ref) 'standard)
1148 (funcall search-refs
1149 (org-export-get-footnote-definition ref info)))))
1150 info)
1151 (reverse all-refs)))))
1152 (funcall search-refs element))
1153 ""))
1155 (defun org-latex--translate (s info)
1156 "Translate string S according to specified language.
1157 INFO is a plist used as a communication channel."
1158 (org-export-translate s :latex info))
1162 ;;; Template
1164 (defun org-latex-template (contents info)
1165 "Return complete document string after LaTeX conversion.
1166 CONTENTS is the transcoded contents string. INFO is a plist
1167 holding export options."
1168 (let ((title (org-export-data (plist-get info :title) info)))
1169 (concat
1170 ;; Time-stamp.
1171 (and (plist-get info :time-stamp-file)
1172 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
1173 ;; Document class and packages.
1174 (let* ((class (plist-get info :latex-class))
1175 (class-options (plist-get info :latex-class-options))
1176 (header (nth 1 (assoc class org-latex-classes)))
1177 (document-class-string
1178 (and (stringp header)
1179 (if (not class-options) header
1180 (replace-regexp-in-string
1181 "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
1182 class-options header t nil 1)))))
1183 (if (not document-class-string)
1184 (user-error "Unknown LaTeX class `%s'" class)
1185 (org-latex-guess-babel-language
1186 (org-latex-guess-inputenc
1187 (org-element-normalize-string
1188 (org-splice-latex-header
1189 document-class-string
1190 org-latex-default-packages-alist
1191 org-latex-packages-alist nil
1192 (concat (org-element-normalize-string
1193 (plist-get info :latex-header))
1194 (plist-get info :latex-header-extra)))))
1195 info)))
1196 ;; Possibly limit depth for headline numbering.
1197 (let ((sec-num (plist-get info :section-numbers)))
1198 (when (integerp sec-num)
1199 (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
1200 ;; Author.
1201 (let ((author (and (plist-get info :with-author)
1202 (let ((auth (plist-get info :author)))
1203 (and auth (org-export-data auth info)))))
1204 (email (and (plist-get info :with-email)
1205 (org-export-data (plist-get info :email) info))))
1206 (cond ((and author email (not (string= "" email)))
1207 (format "\\author{%s\\thanks{%s}}\n" author email))
1208 ((or author email) (format "\\author{%s}\n" (or author email)))))
1209 ;; Date.
1210 (let ((date (and (plist-get info :with-date) (org-export-get-date info))))
1211 (format "\\date{%s}\n" (org-export-data date info)))
1212 ;; Title
1213 (format "\\title{%s}\n" title)
1214 ;; Hyperref options.
1215 (format-spec (plist-get info :latex-hyperref)
1216 (format-spec-make
1217 ?k (or (plist-get info :keywords) "")
1218 ?d (or (plist-get info :description)"")
1219 ?c (if (plist-get info :with-creator)
1220 (plist-get info :creator)
1221 "")))
1222 ;; Document start.
1223 "\\begin{document}\n\n"
1224 ;; Title command.
1225 (org-element-normalize-string
1226 (cond ((string= "" title) nil)
1227 ((not (stringp org-latex-title-command)) nil)
1228 ((string-match "\\(?:[^%]\\|^\\)%s"
1229 org-latex-title-command)
1230 (format org-latex-title-command title))
1231 (t org-latex-title-command)))
1232 ;; Table of contents.
1233 (let ((depth (plist-get info :with-toc)))
1234 (when depth
1235 (concat (when (wholenump depth)
1236 (format "\\setcounter{tocdepth}{%d}\n" depth))
1237 org-latex-toc-command)))
1238 ;; Document's body.
1239 contents
1240 ;; Creator.
1241 (let ((creator-info (plist-get info :with-creator)))
1242 (cond
1243 ((not creator-info) "")
1244 ((eq creator-info 'comment)
1245 (format "%% %s\n" (plist-get info :creator)))
1246 (t (concat (plist-get info :creator) "\n"))))
1247 ;; Document end.
1248 "\\end{document}")))
1252 ;;; Transcode Functions
1254 ;;;; Bold
1256 (defun org-latex-bold (bold contents info)
1257 "Transcode BOLD from Org to LaTeX.
1258 CONTENTS is the text with bold markup. INFO is a plist holding
1259 contextual information."
1260 (org-latex--text-markup contents 'bold))
1263 ;;;; Center Block
1265 (defun org-latex-center-block (center-block contents info)
1266 "Transcode a CENTER-BLOCK element from Org to LaTeX.
1267 CONTENTS holds the contents of the center block. INFO is a plist
1268 holding contextual information."
1269 (org-latex--wrap-label
1270 center-block
1271 (format "\\begin{center}\n%s\\end{center}" contents)))
1274 ;;;; Clock
1276 (defun org-latex-clock (clock contents info)
1277 "Transcode a CLOCK element from Org to LaTeX.
1278 CONTENTS is nil. INFO is a plist holding contextual
1279 information."
1280 (concat
1281 "\\noindent"
1282 (format "\\textbf{%s} " org-clock-string)
1283 (format org-latex-inactive-timestamp-format
1284 (concat (org-translate-time
1285 (org-element-property :raw-value
1286 (org-element-property :value clock)))
1287 (let ((time (org-element-property :duration clock)))
1288 (and time (format " (%s)" time)))))
1289 "\\\\"))
1292 ;;;; Code
1294 (defun org-latex-code (code contents info)
1295 "Transcode a CODE object from Org to LaTeX.
1296 CONTENTS is nil. INFO is a plist used as a communication
1297 channel."
1298 (org-latex--text-markup (org-element-property :value code) 'code))
1301 ;;;; Drawer
1303 (defun org-latex-drawer (drawer contents info)
1304 "Transcode a DRAWER element from Org to LaTeX.
1305 CONTENTS holds the contents of the block. INFO is a plist
1306 holding contextual information."
1307 (let* ((name (org-element-property :drawer-name drawer))
1308 (output (funcall org-latex-format-drawer-function
1309 name contents)))
1310 (org-latex--wrap-label drawer output)))
1313 ;;;; Dynamic Block
1315 (defun org-latex-dynamic-block (dynamic-block contents info)
1316 "Transcode a DYNAMIC-BLOCK element from Org to LaTeX.
1317 CONTENTS holds the contents of the block. INFO is a plist
1318 holding contextual information. See `org-export-data'."
1319 (org-latex--wrap-label dynamic-block contents))
1322 ;;;; Entity
1324 (defun org-latex-entity (entity contents info)
1325 "Transcode an ENTITY object from Org to LaTeX.
1326 CONTENTS are the definition itself. INFO is a plist holding
1327 contextual information."
1328 (org-element-property :latex entity))
1331 ;;;; Example Block
1333 (defun org-latex-example-block (example-block contents info)
1334 "Transcode an EXAMPLE-BLOCK element from Org to LaTeX.
1335 CONTENTS is nil. INFO is a plist holding contextual
1336 information."
1337 (when (org-string-nw-p (org-element-property :value example-block))
1338 (org-latex--wrap-label
1339 example-block
1340 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1341 (org-export-format-code-default example-block info)))))
1344 ;;;; Export Block
1346 (defun org-latex-export-block (export-block contents info)
1347 "Transcode a EXPORT-BLOCK element from Org to LaTeX.
1348 CONTENTS is nil. INFO is a plist holding contextual information."
1349 (when (member (org-element-property :type export-block) '("LATEX" "TEX"))
1350 (org-remove-indentation (org-element-property :value export-block))))
1353 ;;;; Export Snippet
1355 (defun org-latex-export-snippet (export-snippet contents info)
1356 "Transcode a EXPORT-SNIPPET object from Org to LaTeX.
1357 CONTENTS is nil. INFO is a plist holding contextual information."
1358 (when (eq (org-export-snippet-backend export-snippet) 'latex)
1359 (org-element-property :value export-snippet)))
1362 ;;;; Fixed Width
1364 (defun org-latex-fixed-width (fixed-width contents info)
1365 "Transcode a FIXED-WIDTH element from Org to LaTeX.
1366 CONTENTS is nil. INFO is a plist holding contextual information."
1367 (org-latex--wrap-label
1368 fixed-width
1369 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1370 (org-remove-indentation
1371 (org-element-property :value fixed-width)))))
1374 ;;;; Footnote Reference
1376 (defun org-latex-footnote-reference (footnote-reference contents info)
1377 "Transcode a FOOTNOTE-REFERENCE element from Org to LaTeX.
1378 CONTENTS is nil. INFO is a plist holding contextual information."
1379 (concat
1380 ;; Insert separator between two footnotes in a row.
1381 (let ((prev (org-export-get-previous-element footnote-reference info)))
1382 (when (eq (org-element-type prev) 'footnote-reference)
1383 org-latex-footnote-separator))
1384 (cond
1385 ;; Use \footnotemark if the footnote has already been defined.
1386 ((not (org-export-footnote-first-reference-p footnote-reference info))
1387 (format "\\footnotemark[%s]{}"
1388 (org-export-get-footnote-number footnote-reference info)))
1389 ;; Use \footnotemark if reference is within another footnote
1390 ;; reference, footnote definition or table cell.
1391 ((loop for parent in (org-export-get-genealogy footnote-reference)
1392 thereis (memq (org-element-type parent)
1393 '(footnote-reference footnote-definition table-cell)))
1394 "\\footnotemark")
1395 ;; Otherwise, define it with \footnote command.
1397 (let ((def (org-export-get-footnote-definition footnote-reference info)))
1398 (concat
1399 (format "\\footnote{%s}" (org-trim (org-export-data def info)))
1400 ;; Retrieve all footnote references within the footnote and
1401 ;; add their definition after it, since LaTeX doesn't support
1402 ;; them inside.
1403 (org-latex--delayed-footnotes-definitions def info)))))))
1406 ;;;; Headline
1408 (defun org-latex-headline (headline contents info)
1409 "Transcode a HEADLINE element from Org to LaTeX.
1410 CONTENTS holds the contents of the headline. INFO is a plist
1411 holding contextual information."
1412 (unless (org-element-property :footnote-section-p headline)
1413 (let* ((class (plist-get info :latex-class))
1414 (level (org-export-get-relative-level headline info))
1415 (numberedp (org-export-numbered-headline-p headline info))
1416 (class-sectioning (assoc class org-latex-classes))
1417 ;; Section formatting will set two placeholders: one for
1418 ;; the title and the other for the contents.
1419 (section-fmt
1420 (let ((sec (if (functionp (nth 2 class-sectioning))
1421 (funcall (nth 2 class-sectioning) level numberedp)
1422 (nth (1+ level) class-sectioning))))
1423 (cond
1424 ;; No section available for that LEVEL.
1425 ((not sec) nil)
1426 ;; Section format directly returned by a function. Add
1427 ;; placeholder for contents.
1428 ((stringp sec) (concat sec "\n%s"))
1429 ;; (numbered-section . unnumbered-section)
1430 ((not (consp (cdr sec)))
1431 (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
1432 ;; (numbered-open numbered-close)
1433 ((= (length sec) 2)
1434 (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
1435 ;; (num-in num-out no-num-in no-num-out)
1436 ((= (length sec) 4)
1437 (if numberedp (concat (car sec) "\n%s" (nth 1 sec))
1438 (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
1439 ;; Create a temporary export back-end that hard-codes
1440 ;; "\underline" within "\section" and alike.
1441 (section-back-end
1442 (org-export-create-backend
1443 :parent 'latex
1444 :transcoders
1445 '((underline . (lambda (o c i) (format "\\underline{%s}" c))))))
1446 (text
1447 (org-export-data-with-backend
1448 (org-element-property :title headline) section-back-end info))
1449 (todo
1450 (and (plist-get info :with-todo-keywords)
1451 (let ((todo (org-element-property :todo-keyword headline)))
1452 (and todo (org-export-data todo info)))))
1453 (todo-type (and todo (org-element-property :todo-type headline)))
1454 (tags (and (plist-get info :with-tags)
1455 (org-export-get-tags headline info)))
1456 (priority (and (plist-get info :with-priority)
1457 (org-element-property :priority headline)))
1458 ;; Create the headline text along with a no-tag version.
1459 ;; The latter is required to remove tags from toc.
1460 (full-text (funcall org-latex-format-headline-function
1461 todo todo-type priority text tags))
1462 ;; Associate \label to the headline for internal links.
1463 (headline-label
1464 (let ((custom-label
1465 (and (plist-get info :latex-custom-id-labels)
1466 (org-element-property :CUSTOM_ID headline))))
1467 (if custom-label (format "\\label{%s}\n" custom-label)
1468 (format "\\label{sec-%s}\n"
1469 (mapconcat
1470 #'number-to-string
1471 (org-export-get-headline-number headline info)
1472 "-")))))
1473 (pre-blanks
1474 (make-string (org-element-property :pre-blank headline) 10)))
1475 (if (or (not section-fmt) (org-export-low-level-p headline info))
1476 ;; This is a deep sub-tree: export it as a list item. Also
1477 ;; export as items headlines for which no section format has
1478 ;; been found.
1479 (let ((low-level-body
1480 (concat
1481 ;; If headline is the first sibling, start a list.
1482 (when (org-export-first-sibling-p headline info)
1483 (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
1484 ;; Itemize headline
1485 "\\item"
1486 (and full-text (org-string-match-p "\\`[ \t]*\\[" full-text)
1487 "\\relax")
1488 " " full-text "\n"
1489 headline-label
1490 pre-blanks
1491 contents)))
1492 ;; If headline is not the last sibling simply return
1493 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before
1494 ;; any blank line.
1495 (if (not (org-export-last-sibling-p headline info)) low-level-body
1496 (replace-regexp-in-string
1497 "[ \t\n]*\\'"
1498 (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
1499 low-level-body)))
1500 ;; This is a standard headline. Export it as a section. Add
1501 ;; an alternative heading when possible, and when this is not
1502 ;; identical to the usual heading.
1503 (let ((opt-title
1504 (funcall org-latex-format-headline-function
1505 todo todo-type priority
1506 (org-export-data-with-backend
1507 (org-export-get-alt-title headline info)
1508 section-back-end info)
1509 (and (eq (plist-get info :with-tags) t) tags))))
1510 (if (and numberedp opt-title
1511 (not (equal opt-title full-text))
1512 (string-match "\\`\\\\\\(.*?[^*]\\){" section-fmt))
1513 (format (replace-match "\\1[%s]" nil nil section-fmt 1)
1514 ;; Replace square brackets with parenthesis
1515 ;; since square brackets are not supported in
1516 ;; optional arguments.
1517 (replace-regexp-in-string
1518 "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title))
1519 full-text
1520 (concat headline-label pre-blanks contents))
1521 ;; Impossible to add an alternative heading. Fallback to
1522 ;; regular sectioning format string.
1523 (format section-fmt full-text
1524 (concat headline-label pre-blanks contents))))))))
1526 (defun org-latex-format-headline-default-function
1527 (todo todo-type priority text tags)
1528 "Default format function for a headline.
1529 See `org-latex-format-headline-function' for details."
1530 (concat
1531 (and todo (format "{\\bfseries\\sffamily %s} " todo))
1532 (and priority (format "\\framebox{\\#%c} " priority))
1533 text
1534 (and tags
1535 (format "\\hfill{}\\textsc{%s}" (mapconcat 'identity tags ":")))))
1538 ;;;; Horizontal Rule
1540 (defun org-latex-horizontal-rule (horizontal-rule contents info)
1541 "Transcode an HORIZONTAL-RULE object from Org to LaTeX.
1542 CONTENTS is nil. INFO is a plist holding contextual information."
1543 (let ((attr (org-export-read-attribute :attr_latex horizontal-rule))
1544 (prev (org-export-get-previous-element horizontal-rule info)))
1545 (concat
1546 ;; Make sure the rule doesn't start at the end of the current
1547 ;; line by separating it with a blank line from previous element.
1548 (when (and prev
1549 (let ((prev-blank (org-element-property :post-blank prev)))
1550 (or (not prev-blank) (zerop prev-blank))))
1551 "\n")
1552 (org-latex--wrap-label
1553 horizontal-rule
1554 (format "\\rule{%s}{%s}"
1555 (or (plist-get attr :width) "\\linewidth")
1556 (or (plist-get attr :thickness) "0.5pt"))))))
1559 ;;;; Inline Src Block
1561 (defun org-latex-inline-src-block (inline-src-block contents info)
1562 "Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
1563 CONTENTS holds the contents of the item. INFO is a plist holding
1564 contextual information."
1565 (let* ((code (org-element-property :value inline-src-block))
1566 (separator (org-latex--find-verb-separator code)))
1567 (cond
1568 ;; Do not use a special package: transcode it verbatim.
1569 ((not org-latex-listings)
1570 (concat "\\verb" separator code separator))
1571 ;; Use minted package.
1572 ((eq org-latex-listings 'minted)
1573 (let* ((org-lang (org-element-property :language inline-src-block))
1574 (mint-lang (or (cadr (assq (intern org-lang)
1575 org-latex-minted-langs))
1576 org-lang))
1577 (options (org-latex--make-option-string
1578 org-latex-minted-options)))
1579 (concat (format "\\mint%s{%s}"
1580 (if (string= options "") "" (format "[%s]" options))
1581 mint-lang)
1582 separator code separator)))
1583 ;; Use listings package.
1585 ;; Maybe translate language's name.
1586 (let* ((org-lang (org-element-property :language inline-src-block))
1587 (lst-lang (or (cadr (assq (intern org-lang)
1588 org-latex-listings-langs))
1589 org-lang))
1590 (options (org-latex--make-option-string
1591 (append org-latex-listings-options
1592 `(("language" ,lst-lang))))))
1593 (concat (format "\\lstinline[%s]" options)
1594 separator code separator))))))
1597 ;;;; Inlinetask
1599 (defun org-latex-inlinetask (inlinetask contents info)
1600 "Transcode an INLINETASK element from Org to LaTeX.
1601 CONTENTS holds the contents of the block. INFO is a plist
1602 holding contextual information."
1603 (let ((title (org-export-data (org-element-property :title inlinetask) info))
1604 (todo (and (plist-get info :with-todo-keywords)
1605 (let ((todo (org-element-property :todo-keyword inlinetask)))
1606 (and todo (org-export-data todo info)))))
1607 (todo-type (org-element-property :todo-type inlinetask))
1608 (tags (and (plist-get info :with-tags)
1609 (org-export-get-tags inlinetask info)))
1610 (priority (and (plist-get info :with-priority)
1611 (org-element-property :priority inlinetask))))
1612 ;; If `org-latex-format-inlinetask-function' is provided, call it
1613 ;; with appropriate arguments.
1614 (if (not (eq org-latex-format-inlinetask-function 'ignore))
1615 (funcall org-latex-format-inlinetask-function
1616 todo todo-type priority title tags contents)
1617 ;; Otherwise, use a default template.
1618 (org-latex--wrap-label
1619 inlinetask
1620 (let ((full-title
1621 (concat
1622 (when todo (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
1623 (when priority (format "\\framebox{\\#%c} " priority))
1624 title
1625 (when tags (format "\\hfill{}\\textsc{:%s:}"
1626 (mapconcat 'identity tags ":"))))))
1627 (format (concat "\\begin{center}\n"
1628 "\\fbox{\n"
1629 "\\begin{minipage}[c]{.6\\textwidth}\n"
1630 "%s\n\n"
1631 "\\rule[.8em]{\\textwidth}{2pt}\n\n"
1632 "%s"
1633 "\\end{minipage}\n"
1634 "}\n"
1635 "\\end{center}")
1636 full-title contents))))))
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 "multicolumn") 'multicolumn)
1805 ((or float
1806 (org-element-property :caption parent)
1807 (org-string-nw-p (plist-get attr :caption)))
1808 'figure))))
1809 (placement
1810 (let ((place (plist-get attr :placement)))
1811 (cond (place (format "%s" place))
1812 ((eq float 'wrap) "{l}{0.5\\textwidth}")
1813 ((eq float 'figure)
1814 (format "[%s]" org-latex-default-figure-position))
1815 (t ""))))
1816 (comment-include (if (plist-get attr :comment-include) "%" ""))
1817 ;; It is possible to specify width and height in the
1818 ;; ATTR_LATEX line, and also via default variables.
1819 (width (cond ((plist-get attr :width))
1820 ((plist-get attr :height) "")
1821 ((eq float 'wrap) "0.48\\textwidth")
1822 (t org-latex-image-default-width)))
1823 (height (cond ((plist-get attr :height))
1824 ((or (plist-get attr :width)
1825 (memq float '(figure wrap))) "")
1826 (t org-latex-image-default-height)))
1827 (options (let ((opt (or (plist-get attr :options)
1828 org-latex-image-default-option)))
1829 (if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt)) opt
1830 (match-string 1 opt))))
1831 image-code)
1832 (if (member filetype '("tikz" "pgf"))
1833 ;; For tikz images:
1834 ;; - use \input to read in image file.
1835 ;; - if options are present, wrap in a tikzpicture environment.
1836 ;; - if width or height are present, use \resizebox to change
1837 ;; the image size.
1838 (progn
1839 (setq image-code (format "\\input{%s}" path))
1840 (when (org-string-nw-p options)
1841 (setq image-code
1842 (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
1843 options
1844 image-code)))
1845 (when (or (org-string-nw-p width) (org-string-nw-p height))
1846 (setq image-code (format "\\resizebox{%s}{%s}{%s}"
1847 (if (org-string-nw-p width) width "!")
1848 (if (org-string-nw-p height) height "!")
1849 image-code))))
1850 ;; For other images:
1851 ;; - add width and height to options.
1852 ;; - include the image with \includegraphics.
1853 (when (org-string-nw-p width)
1854 (setq options (concat options ",width=" width)))
1855 (when (org-string-nw-p height)
1856 (setq options (concat options ",height=" height)))
1857 (setq image-code
1858 (format "\\includegraphics%s{%s}"
1859 (cond ((not (org-string-nw-p options)) "")
1860 ((= (aref options 0) ?,)
1861 (format "[%s]"(substring options 1)))
1862 (t (format "[%s]" options)))
1863 path))
1864 (when (equal filetype "svg")
1865 (setq image-code (replace-regexp-in-string "^\\\\includegraphics"
1866 "\\includesvg"
1867 image-code
1868 nil t))
1869 (setq image-code (replace-regexp-in-string "\\.svg}"
1871 image-code
1872 nil t))))
1873 ;; Return proper string, depending on FLOAT.
1874 (case float
1875 (wrap (format "\\begin{wrapfigure}%s
1876 \\centering
1877 %s%s
1878 %s\\end{wrapfigure}" placement comment-include image-code caption))
1879 (multicolumn (format "\\begin{figure*}%s
1880 \\centering
1881 %s%s
1882 %s\\end{figure*}" placement comment-include image-code caption))
1883 (figure (format "\\begin{figure}%s
1884 \\centering
1885 %s%s
1886 %s\\end{figure}" placement comment-include image-code caption))
1887 (otherwise image-code))))
1889 (defun org-latex-link (link desc info)
1890 "Transcode a LINK object from Org to LaTeX.
1892 DESC is the description part of the link, or the empty string.
1893 INFO is a plist holding contextual information. See
1894 `org-export-data'."
1895 (let* ((type (org-element-property :type link))
1896 (raw-path (replace-regexp-in-string
1897 "%" "\\%" (org-element-property :path link) nil t))
1898 ;; Ensure DESC really exists, or set it to nil.
1899 (desc (and (not (string= desc "")) desc))
1900 (imagep (org-export-inline-image-p
1901 link org-latex-inline-image-rules))
1902 (path (cond
1903 ((member type '("http" "https" "ftp" "mailto"))
1904 (concat type ":" raw-path))
1905 ((string= type "file")
1906 (if (not (file-name-absolute-p raw-path)) raw-path
1907 (concat "file://" (expand-file-name raw-path))))
1908 (t raw-path)))
1909 protocol)
1910 (cond
1911 ;; Image file.
1912 (imagep (org-latex--inline-image link info))
1913 ;; Radio link: Transcode target's contents and use them as link's
1914 ;; description.
1915 ((string= type "radio")
1916 (let ((destination (org-export-resolve-radio-link link info)))
1917 (when destination
1918 (format "\\hyperref[%s]{%s}"
1919 (org-export-solidify-link-text
1920 (org-element-property :value destination))
1921 desc))))
1922 ;; Links pointing to a headline: Find destination and build
1923 ;; appropriate referencing command.
1924 ((member type '("custom-id" "fuzzy" "id"))
1925 (let ((destination (if (string= type "fuzzy")
1926 (org-export-resolve-fuzzy-link link info)
1927 (org-export-resolve-id-link link info))))
1928 (case (org-element-type destination)
1929 ;; Id link points to an external file.
1930 (plain-text
1931 (if desc (format "\\href{%s}{%s}" destination desc)
1932 (format "\\url{%s}" destination)))
1933 ;; Fuzzy link points nowhere.
1934 ('nil
1935 (format org-latex-link-with-unknown-path-format
1936 (or desc
1937 (org-export-data
1938 (org-element-property :raw-link link) info))))
1939 ;; LINK points to a headline. If headlines are numbered
1940 ;; and the link has no description, display headline's
1941 ;; number. Otherwise, display description or headline's
1942 ;; title.
1943 (headline
1944 (let* ((custom-label
1945 (and (plist-get info :latex-custom-id-labels)
1946 (org-element-property :CUSTOM_ID destination)))
1947 (label
1949 custom-label
1950 (format "sec-%s"
1951 (mapconcat
1952 #'number-to-string
1953 (org-export-get-headline-number destination info)
1954 "-")))))
1955 (if (and (plist-get info :section-numbers) (not desc))
1956 (format "\\ref{%s}" label)
1957 (format "\\hyperref[%s]{%s}" label
1958 (or desc
1959 (org-export-data
1960 (org-element-property :title destination) info))))))
1961 ;; Fuzzy link points to a target. Do as above.
1962 (otherwise
1963 (let ((path (org-export-solidify-link-text path)))
1964 (if (not desc) (format "\\ref{%s}" path)
1965 (format "\\hyperref[%s]{%s}" path desc)))))))
1966 ;; Coderef: replace link with the reference name or the
1967 ;; equivalent line number.
1968 ((string= type "coderef")
1969 (format (org-export-get-coderef-format path desc)
1970 (org-export-resolve-coderef path info)))
1971 ;; Link type is handled by a special function.
1972 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
1973 (funcall protocol (org-link-unescape path) desc 'latex))
1974 ;; External link with a description part.
1975 ((and path desc) (format "\\href{%s}{%s}" path desc))
1976 ;; External link without a description part.
1977 (path (format "\\url{%s}" path))
1978 ;; No path, only description. Try to do something useful.
1979 (t (format org-latex-link-with-unknown-path-format desc)))))
1982 ;;;; Node Property
1984 (defun org-latex-node-property (node-property contents info)
1985 "Transcode a NODE-PROPERTY element from Org to LaTeX.
1986 CONTENTS is nil. INFO is a plist holding contextual
1987 information."
1988 (format "%s:%s"
1989 (org-element-property :key node-property)
1990 (let ((value (org-element-property :value node-property)))
1991 (if value (concat " " value) ""))))
1994 ;;;; Paragraph
1996 (defun org-latex-paragraph (paragraph contents info)
1997 "Transcode a PARAGRAPH element from Org to LaTeX.
1998 CONTENTS is the contents of the paragraph, as a string. INFO is
1999 the plist used as a communication channel."
2000 contents)
2003 ;;;; Plain List
2005 (defun org-latex-plain-list (plain-list contents info)
2006 "Transcode a PLAIN-LIST element from Org to LaTeX.
2007 CONTENTS is the contents of the list. INFO is a plist holding
2008 contextual information."
2009 (let* ((type (org-element-property :type plain-list))
2010 (attr (org-export-read-attribute :attr_latex plain-list))
2011 (latex-type (let ((env (plist-get attr :environment)))
2012 (cond (env (format "%s" env))
2013 ((eq type 'ordered) "enumerate")
2014 ((eq type 'descriptive) "description")
2015 (t "itemize")))))
2016 (org-latex--wrap-label
2017 plain-list
2018 (format "\\begin{%s}%s\n%s\\end{%s}"
2019 latex-type
2020 (or (plist-get attr :options) "")
2021 contents
2022 latex-type))))
2025 ;;;; Plain Text
2027 (defun org-latex-plain-text (text info)
2028 "Transcode a TEXT string from Org to LaTeX.
2029 TEXT is the string to transcode. INFO is a plist holding
2030 contextual information."
2031 (let ((specialp (plist-get info :with-special-strings))
2032 (output text))
2033 ;; Protect %, #, &, $, _, { and }.
2034 (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}_]\\)" output)
2035 (setq output
2036 (replace-match
2037 (format "\\%s" (match-string 2 output)) nil t output 2)))
2038 ;; Protect ^.
2039 (setq output
2040 (replace-regexp-in-string
2041 "\\([^\\]\\|^\\)\\(\\^\\)" "\\\\^{}" output nil nil 2))
2042 ;; Protect \. If special strings are used, be careful not to
2043 ;; protect "\" in "\-" constructs.
2044 (let ((symbols (if specialp "-%$#&{}^_\\" "%$#&{}^_\\")))
2045 (setq output
2046 (replace-regexp-in-string
2047 (format "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%s]\\|$\\)" symbols)
2048 "$\\backslash$" output nil t 1)))
2049 ;; Protect ~.
2050 (setq output
2051 (replace-regexp-in-string
2052 "\\([^\\]\\|^\\)\\(~\\)" "\\textasciitilde{}" output nil t 2))
2053 ;; Activate smart quotes. Be sure to provide original TEXT string
2054 ;; since OUTPUT may have been modified.
2055 (when (plist-get info :with-smart-quotes)
2056 (setq output (org-export-activate-smart-quotes output :latex info text)))
2057 ;; LaTeX into \LaTeX{} and TeX into \TeX{}.
2058 (let ((case-fold-search nil)
2059 (start 0))
2060 (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" output start)
2061 (setq output (replace-match
2062 (format "\\%s{}" (match-string 1 output)) nil t output)
2063 start (match-end 0))))
2064 ;; Convert special strings.
2065 (when specialp
2066 (setq output
2067 (replace-regexp-in-string "\\.\\.\\." "\\ldots{}" output nil t)))
2068 ;; Handle break preservation if required.
2069 (when (plist-get info :preserve-breaks)
2070 (setq output (replace-regexp-in-string
2071 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" output)))
2072 ;; Return value.
2073 output))
2076 ;;;; Planning
2078 (defun org-latex-planning (planning contents info)
2079 "Transcode a PLANNING element from Org to LaTeX.
2080 CONTENTS is nil. INFO is a plist holding contextual
2081 information."
2082 (concat
2083 "\\noindent"
2084 (mapconcat
2085 'identity
2086 (delq nil
2087 (list
2088 (let ((closed (org-element-property :closed planning)))
2089 (when closed
2090 (concat
2091 (format "\\textbf{%s} " org-closed-string)
2092 (format org-latex-inactive-timestamp-format
2093 (org-translate-time
2094 (org-element-property :raw-value closed))))))
2095 (let ((deadline (org-element-property :deadline planning)))
2096 (when deadline
2097 (concat
2098 (format "\\textbf{%s} " org-deadline-string)
2099 (format org-latex-active-timestamp-format
2100 (org-translate-time
2101 (org-element-property :raw-value deadline))))))
2102 (let ((scheduled (org-element-property :scheduled planning)))
2103 (when scheduled
2104 (concat
2105 (format "\\textbf{%s} " org-scheduled-string)
2106 (format org-latex-active-timestamp-format
2107 (org-translate-time
2108 (org-element-property :raw-value scheduled))))))))
2109 " ")
2110 "\\\\"))
2113 ;;;; Property Drawer
2115 (defun org-latex-property-drawer (property-drawer contents info)
2116 "Transcode a PROPERTY-DRAWER element from Org to LaTeX.
2117 CONTENTS holds the contents of the drawer. INFO is a plist
2118 holding contextual information."
2119 (and (org-string-nw-p contents)
2120 (format "\\begin{verbatim}\n%s\\end{verbatim}" contents)))
2123 ;;;; Pseudo Object: LaTeX Math Block
2125 (defun org-latex--wrap-latex-math-block (data info)
2126 "Merge contiguous math objects in a pseudo-object container.
2127 DATA is a parse tree or a secondary string. INFO is a plist
2128 containing export options. Modify DATA by side-effect and return it."
2129 (let ((valid-object-p
2130 (function
2131 ;; Non-nil when OBJ can be added to the latex math block.
2132 (lambda (obj)
2133 (case (org-element-type obj)
2134 (entity (org-element-property :latex-math-p obj))
2135 (latex-fragment
2136 (let ((value (org-element-property :value obj)))
2137 (or (org-string-match-p "\\`\\\\([^\000]*\\\\)\\'" value)
2138 (org-string-match-p "\\`\\$[^\000]*\\$\\'" value))))
2139 ((subscript superscript) t))))))
2140 (org-element-map data '(entity latex-fragment subscript superscript)
2141 (lambda (object)
2142 ;; Skip objects already wrapped.
2143 (when (and (not (eq (org-element-type
2144 (org-element-property :parent object))
2145 'latex-math-block))
2146 (funcall valid-object-p object))
2147 (let ((math-block (list 'latex-math-block nil))
2148 (next-elements (org-export-get-next-element object info t))
2149 (last object))
2150 ;; Wrap MATH-BLOCK around OBJECT in DATA.
2151 (org-element-insert-before math-block object)
2152 (org-element-extract-element object)
2153 (org-element-adopt-elements math-block object)
2154 (when (zerop (or (org-element-property :post-blank object) 0))
2155 ;; MATH-BLOCK swallows consecutive math objects.
2156 (catch 'exit
2157 (dolist (next next-elements)
2158 (if (not (funcall valid-object-p next)) (throw 'exit nil)
2159 (org-element-extract-element next)
2160 (org-element-adopt-elements math-block next)
2161 ;; Eschew the case: \beta$x$ -> \(\betax\).
2162 (unless (memq (org-element-type next)
2163 '(subscript superscript))
2164 (org-element-put-property last :post-blank 1))
2165 (setq last next)
2166 (when (> (or (org-element-property :post-blank next) 0) 0)
2167 (throw 'exit nil))))))
2168 (org-element-put-property
2169 math-block :post-blank (org-element-property :post-blank last)))))
2170 info nil '(subscript superscript latex-math-block) t)
2171 ;; Return updated DATA.
2172 data))
2174 (defun org-latex-math-block-tree-filter (tree backend info)
2175 (org-latex--wrap-latex-math-block tree info))
2177 (defun org-latex-math-block-options-filter (info backend)
2178 (dolist (prop '(:author :date :title) info)
2179 (plist-put info prop
2180 (org-latex--wrap-latex-math-block (plist-get info prop) info))))
2182 (defun org-latex-math-block (math-block contents info)
2183 "Transcode a MATH-BLOCK object from Org to LaTeX.
2184 CONTENTS is a string. INFO is a plist used as a communication
2185 channel."
2186 (when (org-string-nw-p contents)
2187 (format "\\(%s\\)" (org-trim contents))))
2189 ;;;; Quote Block
2191 (defun org-latex-quote-block (quote-block contents info)
2192 "Transcode a QUOTE-BLOCK element from Org to LaTeX.
2193 CONTENTS holds the contents of the block. INFO is a plist
2194 holding contextual information."
2195 (org-latex--wrap-label
2196 quote-block
2197 (format "\\begin{quote}\n%s\\end{quote}" contents)))
2200 ;;;; Radio Target
2202 (defun org-latex-radio-target (radio-target text info)
2203 "Transcode a RADIO-TARGET object from Org to LaTeX.
2204 TEXT is the text of the target. INFO is a plist holding
2205 contextual information."
2206 (format "\\label{%s}%s"
2207 (org-export-solidify-link-text
2208 (org-element-property :value radio-target))
2209 text))
2212 ;;;; Section
2214 (defun org-latex-section (section contents info)
2215 "Transcode a SECTION element from Org to LaTeX.
2216 CONTENTS holds the contents of the section. INFO is a plist
2217 holding contextual information."
2218 contents)
2221 ;;;; Special Block
2223 (defun org-latex-special-block (special-block contents info)
2224 "Transcode a SPECIAL-BLOCK element from Org to LaTeX.
2225 CONTENTS holds the contents of the block. INFO is a plist
2226 holding contextual information."
2227 (let ((type (downcase (org-element-property :type special-block)))
2228 (opt (org-export-read-attribute :attr_latex special-block :options)))
2229 (concat (format "\\begin{%s}%s\n" type (or opt ""))
2230 ;; Insert any label or caption within the block
2231 ;; (otherwise, a reference pointing to that element will
2232 ;; count the section instead).
2233 (org-latex--caption/label-string special-block info)
2234 contents
2235 (format "\\end{%s}" type))))
2238 ;;;; Src Block
2240 (defun org-latex-src-block (src-block contents info)
2241 "Transcode a SRC-BLOCK element from Org to LaTeX.
2242 CONTENTS holds the contents of the item. INFO is a plist holding
2243 contextual information."
2244 (when (org-string-nw-p (org-element-property :value src-block))
2245 (let* ((lang (org-element-property :language src-block))
2246 (caption (org-element-property :caption src-block))
2247 (label (org-element-property :name src-block))
2248 (custom-env (and lang
2249 (cadr (assq (intern lang)
2250 org-latex-custom-lang-environments))))
2251 (num-start (case (org-element-property :number-lines src-block)
2252 (continued (org-export-get-loc src-block info))
2253 (new 0)))
2254 (retain-labels (org-element-property :retain-labels src-block))
2255 (attributes (org-export-read-attribute :attr_latex src-block))
2256 (float (plist-get attributes :float)))
2257 (cond
2258 ;; Case 1. No source fontification.
2259 ((not org-latex-listings)
2260 (let* ((caption-str (org-latex--caption/label-string src-block info))
2261 (float-env
2262 (cond ((and (not float) (plist-member attributes :float)) "%s")
2263 ((string= "multicolumn" float)
2264 (format "\\begin{figure*}[%s]\n%%s%s\n\\end{figure*}"
2265 org-latex-default-figure-position
2266 caption-str))
2267 ((or caption float)
2268 (format "\\begin{figure}[H]\n%%s%s\n\\end{figure}"
2269 caption-str))
2270 (t "%s"))))
2271 (format
2272 float-env
2273 (concat (format "\\begin{verbatim}\n%s\\end{verbatim}"
2274 (org-export-format-code-default src-block info))))))
2275 ;; Case 2. Custom environment.
2276 (custom-env (format "\\begin{%s}\n%s\\end{%s}\n"
2277 custom-env
2278 (org-export-format-code-default src-block info)
2279 custom-env))
2280 ;; Case 3. Use minted package.
2281 ((eq org-latex-listings 'minted)
2282 (let* ((caption-str (org-latex--caption/label-string src-block info))
2283 (float-env
2284 (cond ((and (not float) (plist-member attributes :float)) "%s")
2285 ((string= "multicolumn" float)
2286 (format "\\begin{listing*}\n%%s\n%s\\end{listing*}"
2287 caption-str))
2288 ((or caption float)
2289 (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
2290 caption-str))
2291 (t "%s")))
2292 (body
2293 (format
2294 "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
2295 ;; Options.
2296 (concat
2297 (org-latex--make-option-string
2298 (if (or (not num-start)
2299 (assoc "linenos" org-latex-minted-options))
2300 org-latex-minted-options
2301 (append
2302 `(("linenos")
2303 ("firstnumber" ,(number-to-string (1+ num-start))))
2304 org-latex-minted-options)))
2305 (let ((local-options (plist-get attributes :options)))
2306 (and local-options (concat "," local-options))))
2307 ;; Language.
2308 (or (cadr (assq (intern lang) org-latex-minted-langs)) lang)
2309 ;; Source code.
2310 (let* ((code-info (org-export-unravel-code src-block))
2311 (max-width
2312 (apply 'max
2313 (mapcar 'length
2314 (org-split-string (car code-info)
2315 "\n")))))
2316 (org-export-format-code
2317 (car code-info)
2318 (lambda (loc num ref)
2319 (concat
2321 (when ref
2322 ;; Ensure references are flushed to the right,
2323 ;; separated with 6 spaces from the widest line
2324 ;; of code.
2325 (concat (make-string (+ (- max-width (length loc)) 6)
2326 ?\s)
2327 (format "(%s)" ref)))))
2328 nil (and retain-labels (cdr code-info)))))))
2329 ;; Return value.
2330 (format float-env body)))
2331 ;; Case 4. Use listings package.
2333 (let ((lst-lang
2334 (or (cadr (assq (intern lang) org-latex-listings-langs)) lang))
2335 (caption-str
2336 (when caption
2337 (let ((main (org-export-get-caption src-block))
2338 (secondary (org-export-get-caption src-block t)))
2339 (if (not secondary)
2340 (format "{%s}" (org-export-data main info))
2341 (format "{[%s]%s}"
2342 (org-export-data secondary info)
2343 (org-export-data main info)))))))
2344 (concat
2345 ;; Options.
2346 (format
2347 "\\lstset{%s}\n"
2348 (concat
2349 (org-latex--make-option-string
2350 (append
2351 org-latex-listings-options
2352 (cond
2353 ((and (not float) (plist-member attributes :float)) nil)
2354 ((string= "multicolumn" float) '(("float" "*")))
2355 ((and float (not (assoc "float" org-latex-listings-options)))
2356 `(("float" ,org-latex-default-figure-position))))
2357 `(("language" ,lst-lang))
2358 (when label `(("label" ,label)))
2359 (when caption-str `(("caption" ,caption-str)))
2360 (cond ((assoc "numbers" org-latex-listings-options) nil)
2361 ((not num-start) '(("numbers" "none")))
2362 ((zerop num-start) '(("numbers" "left")))
2363 (t `(("numbers" "left")
2364 ("firstnumber"
2365 ,(number-to-string (1+ num-start))))))))
2366 (let ((local-options (plist-get attributes :options)))
2367 (and local-options (concat "," local-options)))))
2368 ;; Source code.
2369 (format
2370 "\\begin{lstlisting}\n%s\\end{lstlisting}"
2371 (let* ((code-info (org-export-unravel-code src-block))
2372 (max-width
2373 (apply 'max
2374 (mapcar 'length
2375 (org-split-string (car code-info) "\n")))))
2376 (org-export-format-code
2377 (car code-info)
2378 (lambda (loc num ref)
2379 (concat
2381 (when ref
2382 ;; Ensure references are flushed to the right,
2383 ;; separated with 6 spaces from the widest line of
2384 ;; code
2385 (concat (make-string (+ (- max-width (length loc)) 6) ? )
2386 (format "(%s)" ref)))))
2387 nil (and retain-labels (cdr code-info))))))))))))
2390 ;;;; Statistics Cookie
2392 (defun org-latex-statistics-cookie (statistics-cookie contents info)
2393 "Transcode a STATISTICS-COOKIE object from Org to LaTeX.
2394 CONTENTS is nil. INFO is a plist holding contextual information."
2395 (replace-regexp-in-string
2396 "%" "\\%" (org-element-property :value statistics-cookie) nil t))
2399 ;;;; Strike-Through
2401 (defun org-latex-strike-through (strike-through contents info)
2402 "Transcode STRIKE-THROUGH from Org to LaTeX.
2403 CONTENTS is the text with strike-through markup. INFO is a plist
2404 holding contextual information."
2405 (org-latex--text-markup contents 'strike-through))
2408 ;;;; Subscript
2410 (defun org-latex--script-size (object info)
2411 "Transcode a subscript or superscript object.
2412 OBJECT is an Org object. INFO is a plist used as a communication
2413 channel."
2414 (let ((type (org-element-type object))
2415 (output ""))
2416 (org-element-map (org-element-contents object)
2417 (cons 'plain-text org-element-all-objects)
2418 (lambda (obj)
2419 (case (org-element-type obj)
2420 ((entity latex-fragment)
2421 (let ((data (org-trim (org-export-data obj info))))
2422 (string-match
2423 "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
2424 data)
2425 (setq output
2426 (concat output
2427 (match-string 1 data)
2428 (let ((blank (org-element-property :post-blank obj)))
2429 (and blank (> blank 0) "\\ "))))))
2430 (plain-text
2431 (setq output
2432 (format "%s\\text{%s}" output (org-export-data obj info))))
2433 (otherwise
2434 (setq output
2435 (concat output
2436 (org-export-data obj info)
2437 (let ((blank (org-element-property :post-blank obj)))
2438 (and blank (> blank 0) "\\ ")))))))
2439 info nil org-element-recursive-objects)
2440 ;; Result. Do not wrap into curly brackets if OUTPUT is a single
2441 ;; character.
2442 (concat (if (eq (org-element-type object) 'subscript) "_" "^")
2443 (and (> (length output) 1) "{")
2444 output
2445 (and (> (length output) 1) "}"))))
2447 (defun org-latex-subscript (subscript contents info)
2448 "Transcode a SUBSCRIPT object from Org to LaTeX.
2449 CONTENTS is the contents of the object. INFO is a plist holding
2450 contextual information."
2451 (org-latex--script-size subscript info))
2454 ;;;; Superscript
2456 (defun org-latex-superscript (superscript contents info)
2457 "Transcode a SUPERSCRIPT object from Org to LaTeX.
2458 CONTENTS is the contents of the object. INFO is a plist holding
2459 contextual information."
2460 (org-latex--script-size superscript info))
2463 ;;;; Table
2465 ;; `org-latex-table' is the entry point for table transcoding. It
2466 ;; takes care of tables with a "verbatim" mode. Otherwise, it
2467 ;; delegates the job to either `org-latex--table.el-table',
2468 ;; `org-latex--org-table' or `org-latex--math-table' functions,
2469 ;; depending of the type of the table and the mode requested.
2471 ;; `org-latex--align-string' is a subroutine used to build alignment
2472 ;; string for Org tables.
2474 (defun org-latex-table (table contents info)
2475 "Transcode a TABLE element from Org to LaTeX.
2476 CONTENTS is the contents of the table. INFO is a plist holding
2477 contextual information."
2478 (if (eq (org-element-property :type table) 'table.el)
2479 ;; "table.el" table. Convert it using appropriate tools.
2480 (org-latex--table.el-table table info)
2481 (let ((type (or (org-export-read-attribute :attr_latex table :mode)
2482 org-latex-default-table-mode)))
2483 (cond
2484 ;; Case 1: Verbatim table.
2485 ((string= type "verbatim")
2486 (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
2487 ;; Re-create table, without affiliated keywords.
2488 (org-trim (org-element-interpret-data
2489 `(table nil ,@(org-element-contents table))
2490 org-latex-pseudo-objects))))
2491 ;; Case 2: Matrix.
2492 ((or (string= type "math") (string= type "inline-math"))
2493 (org-latex--math-table table info))
2494 ;; Case 3: Standard table.
2495 (t (concat (org-latex--org-table table contents info)
2496 ;; When there are footnote references within the
2497 ;; table, insert their definition just after it.
2498 (org-latex--delayed-footnotes-definitions table info)))))))
2500 (defun org-latex--align-string (table info)
2501 "Return an appropriate LaTeX alignment string.
2502 TABLE is the considered table. INFO is a plist used as
2503 a communication channel."
2504 (or (org-export-read-attribute :attr_latex table :align)
2505 (let (align)
2506 ;; Extract column groups and alignment from first (non-rule)
2507 ;; row.
2508 (org-element-map
2509 (org-element-map table 'table-row
2510 (lambda (row)
2511 (and (eq (org-element-property :type row) 'standard) row))
2512 info 'first-match)
2513 'table-cell
2514 (lambda (cell)
2515 (let ((borders (org-export-table-cell-borders cell info)))
2516 ;; Check left border for the first cell only.
2517 (when (and (memq 'left borders) (not align))
2518 (push "|" align))
2519 (push (case (org-export-table-cell-alignment cell info)
2520 (left "l")
2521 (right "r")
2522 (center "c"))
2523 align)
2524 (when (memq 'right borders) (push "|" align))))
2525 info)
2526 (apply 'concat (nreverse align)))))
2528 (defun org-latex--org-table (table contents info)
2529 "Return appropriate LaTeX code for an Org table.
2531 TABLE is the table type element to transcode. CONTENTS is its
2532 contents, as a string. INFO is a plist used as a communication
2533 channel.
2535 This function assumes TABLE has `org' as its `:type' property and
2536 `table' as its `:mode' attribute."
2537 (let* ((caption (org-latex--caption/label-string table info))
2538 (attr (org-export-read-attribute :attr_latex table))
2539 ;; Determine alignment string.
2540 (alignment (org-latex--align-string table info))
2541 ;; Determine environment for the table: longtable, tabular...
2542 (table-env (or (plist-get attr :environment)
2543 org-latex-default-table-environment))
2544 ;; If table is a float, determine environment: table, table*
2545 ;; or sidewaystable.
2546 (float-env (unless (member table-env '("longtable" "longtabu"))
2547 (let ((float (plist-get attr :float)))
2548 (cond
2549 ((and (not float) (plist-member attr :float)) nil)
2550 ((string= float "sidewaystable") "sidewaystable")
2551 ((string= float "multicolumn") "table*")
2552 ((or float
2553 (org-element-property :caption table)
2554 (org-string-nw-p (plist-get attr :caption)))
2555 "table")))))
2556 ;; Extract others display options.
2557 (fontsize (let ((font (plist-get attr :font)))
2558 (and font (concat font "\n"))))
2559 (width (plist-get attr :width))
2560 (spreadp (plist-get attr :spread))
2561 (placement (or (plist-get attr :placement)
2562 (format "[%s]" org-latex-default-figure-position)))
2563 (centerp (if (plist-member attr :center) (plist-get attr :center)
2564 org-latex-tables-centered)))
2565 ;; Prepare the final format string for the table.
2566 (cond
2567 ;; Longtable.
2568 ((equal "longtable" table-env)
2569 (concat (and fontsize (concat "{" fontsize))
2570 (format "\\begin{longtable}{%s}\n" alignment)
2571 (and org-latex-table-caption-above
2572 (org-string-nw-p caption)
2573 (concat caption "\\\\\n"))
2574 contents
2575 (and (not org-latex-table-caption-above)
2576 (org-string-nw-p caption)
2577 (concat caption "\\\\\n"))
2578 "\\end{longtable}\n"
2579 (and fontsize "}")))
2580 ;; Longtabu
2581 ((equal "longtabu" table-env)
2582 (concat (and fontsize (concat "{" fontsize))
2583 (format "\\begin{longtabu}%s{%s}\n"
2584 (if width
2585 (format " %s %s "
2586 (if spreadp "spread" "to") width) "")
2587 alignment)
2588 (and org-latex-table-caption-above
2589 (org-string-nw-p caption)
2590 (concat caption "\\\\\n"))
2591 contents
2592 (and (not org-latex-table-caption-above)
2593 (org-string-nw-p caption)
2594 (concat caption "\\\\\n"))
2595 "\\end{longtabu}\n"
2596 (and fontsize "}")))
2597 ;; Others.
2598 (t (concat (cond
2599 (float-env
2600 (concat (format "\\begin{%s}%s\n" float-env placement)
2601 (if org-latex-table-caption-above caption "")
2602 (when centerp "\\centering\n")
2603 fontsize))
2604 (centerp (concat "\\begin{center}\n" fontsize))
2605 (fontsize (concat "{" fontsize)))
2606 (cond ((equal "tabu" table-env)
2607 (format "\\begin{tabu}%s{%s}\n%s\\end{tabu}"
2608 (if width (format
2609 (if spreadp " spread %s " " to %s ")
2610 width) "")
2611 alignment
2612 contents))
2613 (t (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
2614 table-env
2615 (if width (format "{%s}" width) "")
2616 alignment
2617 contents
2618 table-env)))
2619 (cond
2620 (float-env
2621 (concat (if org-latex-table-caption-above "" caption)
2622 (format "\n\\end{%s}" float-env)))
2623 (centerp "\n\\end{center}")
2624 (fontsize "}")))))))
2626 (defun org-latex--table.el-table (table info)
2627 "Return appropriate LaTeX code for a table.el table.
2629 TABLE is the table type element to transcode. INFO is a plist
2630 used as a communication channel.
2632 This function assumes TABLE has `table.el' as its `:type'
2633 property."
2634 (require 'table)
2635 ;; Ensure "*org-export-table*" buffer is empty.
2636 (with-current-buffer (get-buffer-create "*org-export-table*")
2637 (erase-buffer))
2638 (let ((output (with-temp-buffer
2639 (insert (org-element-property :value table))
2640 (goto-char 1)
2641 (re-search-forward "^[ \t]*|[^|]" nil t)
2642 (table-generate-source 'latex "*org-export-table*")
2643 (with-current-buffer "*org-export-table*"
2644 (org-trim (buffer-string))))))
2645 (kill-buffer (get-buffer "*org-export-table*"))
2646 ;; Remove left out comments.
2647 (while (string-match "^%.*\n" output)
2648 (setq output (replace-match "" t t output)))
2649 (let ((attr (org-export-read-attribute :attr_latex table)))
2650 (when (plist-get attr :rmlines)
2651 ;; When the "rmlines" attribute is provided, remove all hlines
2652 ;; but the the one separating heading from the table body.
2653 (let ((n 0) (pos 0))
2654 (while (and (< (length output) pos)
2655 (setq pos (string-match "^\\\\hline\n?" output pos)))
2656 (incf n)
2657 (unless (= n 2) (setq output (replace-match "" nil nil output))))))
2658 (let ((centerp (if (plist-member attr :center) (plist-get attr :center)
2659 org-latex-tables-centered)))
2660 (if (not centerp) output
2661 (format "\\begin{center}\n%s\n\\end{center}" output))))))
2663 (defun org-latex--math-table (table info)
2664 "Return appropriate LaTeX code for a matrix.
2666 TABLE is the table type element to transcode. INFO is a plist
2667 used as a communication channel.
2669 This function assumes TABLE has `org' as its `:type' property and
2670 `inline-math' or `math' as its `:mode' attribute.."
2671 (let* ((caption (org-latex--caption/label-string table info))
2672 (attr (org-export-read-attribute :attr_latex table))
2673 (inlinep (equal (plist-get attr :mode) "inline-math"))
2674 (env (or (plist-get attr :environment)
2675 org-latex-default-table-environment))
2676 (contents
2677 (mapconcat
2678 (lambda (row)
2679 ;; Ignore horizontal rules.
2680 (when (eq (org-element-property :type row) 'standard)
2681 ;; Return each cell unmodified.
2682 (concat
2683 (mapconcat
2684 (lambda (cell)
2685 (substring
2686 (org-element-interpret-data cell org-latex-pseudo-objects)
2687 0 -1))
2688 (org-element-map row 'table-cell 'identity info) "&")
2689 (or (cdr (assoc env org-latex-table-matrix-macros)) "\\\\")
2690 "\n")))
2691 (org-element-map table 'table-row 'identity info) ""))
2692 ;; Variables related to math clusters (contiguous math tables
2693 ;; of the same type).
2694 (mode (org-export-read-attribute :attr_latex table :mode))
2695 (prev (org-export-get-previous-element table info))
2696 (next (org-export-get-next-element table info))
2697 (same-mode-p
2698 (lambda (table)
2699 ;; Non-nil when TABLE has the same mode as current table.
2700 (string= (or (org-export-read-attribute :attr_latex table :mode)
2701 org-latex-default-table-mode)
2702 mode))))
2703 (concat
2704 ;; Opening string. If TABLE is in the middle of a table cluster,
2705 ;; do not insert any.
2706 (cond ((and prev
2707 (eq (org-element-type prev) 'table)
2708 (memq (org-element-property :post-blank prev) '(0 nil))
2709 (funcall same-mode-p prev))
2710 nil)
2711 (inlinep "\\(")
2712 ((org-string-nw-p caption) (concat "\\begin{equation}\n" caption))
2713 (t "\\["))
2714 ;; Prefix.
2715 (or (plist-get attr :math-prefix) "")
2716 ;; Environment. Also treat special cases.
2717 (cond ((equal env "array")
2718 (let ((align (org-latex--align-string table info)))
2719 (format "\\begin{array}{%s}\n%s\\end{array}" align contents)))
2720 ((assoc env org-latex-table-matrix-macros)
2721 (format "\\%s%s{\n%s}"
2723 (or (plist-get attr :math-arguments) "")
2724 contents))
2725 (t (format "\\begin{%s}\n%s\\end{%s}" env contents env)))
2726 ;; Suffix.
2727 (or (plist-get attr :math-suffix) "")
2728 ;; Closing string. If TABLE is in the middle of a table cluster,
2729 ;; do not insert any. If it closes such a cluster, be sure to
2730 ;; close the cluster with a string matching the opening string.
2731 (cond ((and next
2732 (eq (org-element-type next) 'table)
2733 (memq (org-element-property :post-blank table) '(0 nil))
2734 (funcall same-mode-p next))
2735 nil)
2736 (inlinep "\\)")
2737 ;; Find cluster beginning to know which environment to use.
2738 ((let ((cluster-beg table) prev)
2739 (while (and (setq prev (org-export-get-previous-element
2740 cluster-beg info))
2741 (memq (org-element-property :post-blank prev)
2742 '(0 nil))
2743 (funcall same-mode-p prev))
2744 (setq cluster-beg prev))
2745 (and (or (org-element-property :caption cluster-beg)
2746 (org-element-property :name cluster-beg))
2747 "\n\\end{equation}")))
2748 (t "\\]")))))
2751 ;;;; Table Cell
2753 (defun org-latex-table-cell (table-cell contents info)
2754 "Transcode a TABLE-CELL element from Org to LaTeX.
2755 CONTENTS is the cell contents. INFO is a plist used as
2756 a communication channel."
2757 (concat (if (and contents
2758 org-latex-table-scientific-notation
2759 (string-match orgtbl-exp-regexp contents))
2760 ;; Use appropriate format string for scientific
2761 ;; notation.
2762 (format org-latex-table-scientific-notation
2763 (match-string 1 contents)
2764 (match-string 2 contents))
2765 contents)
2766 (when (org-export-get-next-element table-cell info) " & ")))
2769 ;;;; Table Row
2771 (defun org-latex-table-row (table-row contents info)
2772 "Transcode a TABLE-ROW element from Org to LaTeX.
2773 CONTENTS is the contents of the row. INFO is a plist used as
2774 a communication channel."
2775 ;; Rules are ignored since table separators are deduced from
2776 ;; borders of the current row.
2777 (when (eq (org-element-property :type table-row) 'standard)
2778 (let* ((attr (org-export-read-attribute :attr_latex
2779 (org-export-get-parent table-row)))
2780 (longtablep (member (or (plist-get attr :environment)
2781 org-latex-default-table-environment)
2782 '("longtable" "longtabu")))
2783 (booktabsp (if (plist-member attr :booktabs)
2784 (plist-get attr :booktabs)
2785 org-latex-tables-booktabs))
2786 ;; TABLE-ROW's borders are extracted from its first cell.
2787 (borders (org-export-table-cell-borders
2788 (car (org-element-contents table-row)) info)))
2789 (concat
2790 ;; When BOOKTABS are activated enforce top-rule even when no
2791 ;; hline was specifically marked.
2792 (cond ((and booktabsp (memq 'top borders)) "\\toprule\n")
2793 ((and (memq 'top borders) (memq 'above borders)) "\\hline\n"))
2794 contents "\\\\\n"
2795 (cond
2796 ;; Special case for long tables. Define header and footers.
2797 ((and longtablep (org-export-table-row-ends-header-p table-row info))
2798 (format "%s
2799 \\endfirsthead
2800 \\multicolumn{%d}{l}{%s} \\\\
2802 %s \\\\\n
2804 \\endhead
2805 %s\\multicolumn{%d}{r}{%s} \\\\
2806 \\endfoot
2807 \\endlastfoot"
2808 (if booktabsp "\\midrule" "\\hline")
2809 (cdr (org-export-table-dimensions
2810 (org-export-get-parent-table table-row) info))
2811 (org-latex--translate "Continued from previous page" info)
2812 (cond ((and booktabsp (memq 'top borders)) "\\toprule\n")
2813 ((and (memq 'top borders)
2814 (memq 'above borders)) "\\hline\n")
2815 (t ""))
2816 contents
2817 (if booktabsp "\\midrule" "\\hline")
2818 (if booktabsp "\\midrule" "\\hline")
2819 ;; Number of columns.
2820 (cdr (org-export-table-dimensions
2821 (org-export-get-parent-table table-row) info))
2822 (org-latex--translate "Continued on next page" info)))
2823 ;; When BOOKTABS are activated enforce bottom rule even when
2824 ;; no hline was specifically marked.
2825 ((and booktabsp (memq 'bottom borders)) "\\bottomrule")
2826 ((and (memq 'bottom borders) (memq 'below borders)) "\\hline")
2827 ((memq 'below borders) (if booktabsp "\\midrule" "\\hline")))))))
2830 ;;;; Target
2832 (defun org-latex-target (target contents info)
2833 "Transcode a TARGET object from Org to LaTeX.
2834 CONTENTS is nil. INFO is a plist holding contextual
2835 information."
2836 (format "\\label{%s}"
2837 (org-export-solidify-link-text (org-element-property :value target))))
2840 ;;;; Timestamp
2842 (defun org-latex-timestamp (timestamp contents info)
2843 "Transcode a TIMESTAMP object from Org to LaTeX.
2844 CONTENTS is nil. INFO is a plist holding contextual
2845 information."
2846 (let ((value (org-latex-plain-text
2847 (org-timestamp-translate timestamp) info)))
2848 (case (org-element-property :type timestamp)
2849 ((active active-range) (format org-latex-active-timestamp-format value))
2850 ((inactive inactive-range)
2851 (format org-latex-inactive-timestamp-format value))
2852 (otherwise (format org-latex-diary-timestamp-format value)))))
2855 ;;;; Underline
2857 (defun org-latex-underline (underline contents info)
2858 "Transcode UNDERLINE from Org to LaTeX.
2859 CONTENTS is the text with underline markup. INFO is a plist
2860 holding contextual information."
2861 (org-latex--text-markup contents 'underline))
2864 ;;;; Verbatim
2866 (defun org-latex-verbatim (verbatim contents info)
2867 "Transcode a VERBATIM object from Org to LaTeX.
2868 CONTENTS is nil. INFO is a plist used as a communication
2869 channel."
2870 (org-latex--text-markup (org-element-property :value verbatim) 'verbatim))
2873 ;;;; Verse Block
2875 (defun org-latex-verse-block (verse-block contents info)
2876 "Transcode a VERSE-BLOCK element from Org to LaTeX.
2877 CONTENTS is verse block contents. INFO is a plist holding
2878 contextual information."
2879 (org-latex--wrap-label
2880 verse-block
2881 ;; In a verse environment, add a line break to each newline
2882 ;; character and change each white space at beginning of a line
2883 ;; into a space of 1 em. Also change each blank line with
2884 ;; a vertical space of 1 em.
2885 (progn
2886 (setq contents (replace-regexp-in-string
2887 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
2888 (replace-regexp-in-string
2889 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" contents)))
2890 (while (string-match "^[ \t]+" contents)
2891 (let ((new-str (format "\\hspace*{%dem}"
2892 (length (match-string 0 contents)))))
2893 (setq contents (replace-match new-str nil t contents))))
2894 (format "\\begin{verse}\n%s\\end{verse}" contents))))
2898 ;;; End-user functions
2900 ;;;###autoload
2901 (defun org-latex-export-as-latex
2902 (&optional async subtreep visible-only body-only ext-plist)
2903 "Export current buffer as a LaTeX buffer.
2905 If narrowing is active in the current buffer, only export its
2906 narrowed part.
2908 If a region is active, export that region.
2910 A non-nil optional argument ASYNC means the process should happen
2911 asynchronously. The resulting buffer should be accessible
2912 through the `org-export-stack' interface.
2914 When optional argument SUBTREEP is non-nil, export the sub-tree
2915 at point, extracting information from the headline properties
2916 first.
2918 When optional argument VISIBLE-ONLY is non-nil, don't export
2919 contents of hidden elements.
2921 When optional argument BODY-ONLY is non-nil, only write code
2922 between \"\\begin{document}\" and \"\\end{document}\".
2924 EXT-PLIST, when provided, is a property list with external
2925 parameters overriding Org default settings, but still inferior to
2926 file-local settings.
2928 Export is done in a buffer named \"*Org LATEX Export*\", which
2929 will be displayed when `org-export-show-temporary-export-buffer'
2930 is non-nil."
2931 (interactive)
2932 (org-export-to-buffer 'latex "*Org LATEX Export*"
2933 async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
2935 ;;;###autoload
2936 (defun org-latex-convert-region-to-latex ()
2937 "Assume the current region has org-mode syntax, and convert it to LaTeX.
2938 This can be used in any buffer. For example, you can write an
2939 itemized list in org-mode syntax in an LaTeX buffer and use this
2940 command to convert it."
2941 (interactive)
2942 (org-export-replace-region-by 'latex))
2944 ;;;###autoload
2945 (defun org-latex-export-to-latex
2946 (&optional async subtreep visible-only body-only ext-plist)
2947 "Export current buffer to a LaTeX file.
2949 If narrowing is active in the current buffer, only export its
2950 narrowed part.
2952 If a region is active, export that region.
2954 A non-nil optional argument ASYNC means the process should happen
2955 asynchronously. The resulting file should be accessible through
2956 the `org-export-stack' interface.
2958 When optional argument SUBTREEP is non-nil, export the sub-tree
2959 at point, extracting information from the headline properties
2960 first.
2962 When optional argument VISIBLE-ONLY is non-nil, don't export
2963 contents of hidden elements.
2965 When optional argument BODY-ONLY is non-nil, only write code
2966 between \"\\begin{document}\" and \"\\end{document}\".
2968 EXT-PLIST, when provided, is a property list with external
2969 parameters overriding Org default settings, but still inferior to
2970 file-local settings."
2971 (interactive)
2972 (let ((outfile (org-export-output-file-name ".tex" subtreep)))
2973 (org-export-to-file 'latex outfile
2974 async subtreep visible-only body-only ext-plist)))
2976 ;;;###autoload
2977 (defun org-latex-export-to-pdf
2978 (&optional async subtreep visible-only body-only ext-plist)
2979 "Export current buffer to LaTeX then process through to PDF.
2981 If narrowing is active in the current buffer, only export its
2982 narrowed part.
2984 If a region is active, export that region.
2986 A non-nil optional argument ASYNC means the process should happen
2987 asynchronously. The resulting file should be accessible through
2988 the `org-export-stack' interface.
2990 When optional argument SUBTREEP is non-nil, export the sub-tree
2991 at point, extracting information from the headline properties
2992 first.
2994 When optional argument VISIBLE-ONLY is non-nil, don't export
2995 contents of hidden elements.
2997 When optional argument BODY-ONLY is non-nil, only write code
2998 between \"\\begin{document}\" and \"\\end{document}\".
3000 EXT-PLIST, when provided, is a property list with external
3001 parameters overriding Org default settings, but still inferior to
3002 file-local settings.
3004 Return PDF file's name."
3005 (interactive)
3006 (let ((outfile (org-export-output-file-name ".tex" subtreep)))
3007 (org-export-to-file 'latex outfile
3008 async subtreep visible-only body-only ext-plist
3009 (lambda (file) (org-latex-compile file)))))
3011 (defun org-latex-compile (texfile &optional snippet)
3012 "Compile a TeX file.
3014 TEXFILE is the name of the file being compiled. Processing is
3015 done through the command specified in `org-latex-pdf-process'.
3017 When optional argument SNIPPET is non-nil, TEXFILE is a temporary
3018 file used to preview a LaTeX snippet. In this case, do not
3019 create a log buffer and do not bother removing log files.
3021 Return PDF file name or an error if it couldn't be produced."
3022 (let* ((base-name (file-name-sans-extension (file-name-nondirectory texfile)))
3023 (full-name (file-truename texfile))
3024 (out-dir (file-name-directory texfile))
3025 ;; Properly set working directory for compilation.
3026 (default-directory (if (file-name-absolute-p texfile)
3027 (file-name-directory full-name)
3028 default-directory))
3029 errors)
3030 (unless snippet (message (format "Processing LaTeX file %s..." texfile)))
3031 (save-window-excursion
3032 (cond
3033 ;; A function is provided: Apply it.
3034 ((functionp org-latex-pdf-process)
3035 (funcall org-latex-pdf-process (shell-quote-argument texfile)))
3036 ;; A list is provided: Replace %b, %f and %o with appropriate
3037 ;; values in each command before applying it. Output is
3038 ;; redirected to "*Org PDF LaTeX Output*" buffer.
3039 ((consp org-latex-pdf-process)
3040 (let ((outbuf (and (not snippet)
3041 (get-buffer-create "*Org PDF LaTeX Output*"))))
3042 (mapc
3043 (lambda (command)
3044 (shell-command
3045 (replace-regexp-in-string
3046 "%b" (shell-quote-argument base-name)
3047 (replace-regexp-in-string
3048 "%f" (shell-quote-argument full-name)
3049 (replace-regexp-in-string
3050 "%o" (shell-quote-argument out-dir) command t t) t t) t t)
3051 outbuf))
3052 org-latex-pdf-process)
3053 ;; Collect standard errors from output buffer.
3054 (setq errors (and (not snippet) (org-latex--collect-errors outbuf)))))
3055 (t (error "No valid command to process to PDF")))
3056 (let ((pdffile (concat out-dir base-name ".pdf")))
3057 ;; Check for process failure. Provide collected errors if
3058 ;; possible.
3059 (if (not (file-exists-p pdffile))
3060 (error (concat (format "PDF file %s wasn't produced" pdffile)
3061 (when errors (concat ": " errors))))
3062 ;; Else remove log files, when specified, and signal end of
3063 ;; process to user, along with any error encountered.
3064 (when (and (not snippet) org-latex-remove-logfiles)
3065 (dolist (file (directory-files
3066 out-dir t
3067 (concat (regexp-quote base-name)
3068 "\\(?:\\.[0-9]+\\)?"
3069 "\\."
3070 (regexp-opt org-latex-logfiles-extensions))))
3071 (delete-file file)))
3072 (message (concat "Process completed"
3073 (if (not errors) "."
3074 (concat " with errors: " errors)))))
3075 ;; Return output file name.
3076 pdffile))))
3078 (defun org-latex--collect-errors (buffer)
3079 "Collect some kind of errors from \"pdflatex\" command output.
3081 BUFFER is the buffer containing output.
3083 Return collected error types as a string, or nil if there was
3084 none."
3085 (with-current-buffer buffer
3086 (save-excursion
3087 (goto-char (point-max))
3088 (when (re-search-backward "^[ \t]*This is .*?TeX.*?Version" nil t)
3089 (let ((case-fold-search t)
3090 (errors ""))
3091 (dolist (latex-error org-latex-known-errors)
3092 (when (save-excursion (re-search-forward (car latex-error) nil t))
3093 (setq errors (concat errors " " (cdr latex-error)))))
3094 (and (org-string-nw-p errors) (org-trim errors)))))))
3096 ;;;###autoload
3097 (defun org-latex-publish-to-latex (plist filename pub-dir)
3098 "Publish an Org file to LaTeX.
3100 FILENAME is the filename of the Org file to be published. PLIST
3101 is the property list for the given project. PUB-DIR is the
3102 publishing directory.
3104 Return output file name."
3105 (org-publish-org-to 'latex filename ".tex" plist pub-dir))
3107 ;;;###autoload
3108 (defun org-latex-publish-to-pdf (plist filename pub-dir)
3109 "Publish an Org file to PDF (via LaTeX).
3111 FILENAME is the filename of the Org file to be published. PLIST
3112 is the property list for the given project. PUB-DIR is the
3113 publishing directory.
3115 Return output file name."
3116 ;; Unlike to `org-latex-publish-to-latex', PDF file is generated
3117 ;; in working directory and then moved to publishing directory.
3118 (org-publish-attachment
3119 plist
3120 (org-latex-compile
3121 (org-publish-org-to
3122 'latex filename ".tex" plist (file-name-directory filename)))
3123 pub-dir))
3126 (provide 'ox-latex)
3128 ;; Local variables:
3129 ;; generated-autoload-file: "org-loaddefs.el"
3130 ;; End:
3132 ;;; ox-latex.el ends here