Improve `org-fix-tags-on-the-fly'
[org-mode/org-tableheadings.git] / lisp / ox-latex.el
blobc67f217e9c89a5cacc7f01d62af591c74736007d
1 ;;; ox-latex.el --- LaTeX Back-End for Org Export Engine -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2011-2018 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 <https://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; See Org manual for details.
27 ;;; Code:
29 (require 'cl-lib)
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 (drawer . org-latex-drawer)
47 (dynamic-block . org-latex-dynamic-block)
48 (entity . org-latex-entity)
49 (example-block . org-latex-example-block)
50 (export-block . org-latex-export-block)
51 (export-snippet . org-latex-export-snippet)
52 (fixed-width . org-latex-fixed-width)
53 (footnote-definition . org-latex-footnote-definition)
54 (footnote-reference . org-latex-footnote-reference)
55 (headline . org-latex-headline)
56 (horizontal-rule . org-latex-horizontal-rule)
57 (inline-src-block . org-latex-inline-src-block)
58 (inlinetask . org-latex-inlinetask)
59 (italic . org-latex-italic)
60 (item . org-latex-item)
61 (keyword . org-latex-keyword)
62 (latex-environment . org-latex-latex-environment)
63 (latex-fragment . org-latex-latex-fragment)
64 (line-break . org-latex-line-break)
65 (link . org-latex-link)
66 (node-property . org-latex-node-property)
67 (paragraph . org-latex-paragraph)
68 (plain-list . org-latex-plain-list)
69 (plain-text . org-latex-plain-text)
70 (planning . org-latex-planning)
71 (property-drawer . org-latex-property-drawer)
72 (quote-block . org-latex-quote-block)
73 (radio-target . org-latex-radio-target)
74 (section . org-latex-section)
75 (special-block . org-latex-special-block)
76 (src-block . org-latex-src-block)
77 (statistics-cookie . org-latex-statistics-cookie)
78 (strike-through . org-latex-strike-through)
79 (subscript . org-latex-subscript)
80 (superscript . org-latex-superscript)
81 (table . org-latex-table)
82 (table-cell . org-latex-table-cell)
83 (table-row . org-latex-table-row)
84 (target . org-latex-target)
85 (template . org-latex-template)
86 (timestamp . org-latex-timestamp)
87 (underline . org-latex-underline)
88 (verbatim . org-latex-verbatim)
89 (verse-block . org-latex-verse-block)
90 ;; Pseudo objects and elements.
91 (latex-math-block . org-latex-math-block)
92 (latex-matrices . org-latex-matrices))
93 :menu-entry
94 '(?l "Export to LaTeX"
95 ((?L "As LaTeX buffer" org-latex-export-as-latex)
96 (?l "As LaTeX file" org-latex-export-to-latex)
97 (?p "As PDF file" org-latex-export-to-pdf)
98 (?o "As PDF file and open"
99 (lambda (a s v b)
100 (if a (org-latex-export-to-pdf t s v b)
101 (org-open-file (org-latex-export-to-pdf nil s v b)))))))
102 :filters-alist '((:filter-options . org-latex-math-block-options-filter)
103 (:filter-paragraph . org-latex-clean-invalid-line-breaks)
104 (:filter-parse-tree org-latex-math-block-tree-filter
105 org-latex-matrices-tree-filter
106 org-latex-image-link-filter)
107 (:filter-verse-block . org-latex-clean-invalid-line-breaks))
108 :options-alist
109 '((:latex-class "LATEX_CLASS" nil org-latex-default-class t)
110 (:latex-class-options "LATEX_CLASS_OPTIONS" nil nil t)
111 (:latex-header "LATEX_HEADER" nil nil newline)
112 (:latex-header-extra "LATEX_HEADER_EXTRA" nil nil newline)
113 (:description "DESCRIPTION" nil nil parse)
114 (:keywords "KEYWORDS" nil nil parse)
115 (:subtitle "SUBTITLE" nil nil parse)
116 ;; Other variables.
117 (:latex-active-timestamp-format nil nil org-latex-active-timestamp-format)
118 (:latex-caption-above nil nil org-latex-caption-above)
119 (:latex-classes nil nil org-latex-classes)
120 (:latex-default-figure-position nil nil org-latex-default-figure-position)
121 (:latex-default-table-environment nil nil org-latex-default-table-environment)
122 (:latex-default-table-mode nil nil org-latex-default-table-mode)
123 (:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format)
124 (:latex-footnote-defined-format nil nil org-latex-footnote-defined-format)
125 (:latex-footnote-separator nil nil org-latex-footnote-separator)
126 (:latex-format-drawer-function nil nil org-latex-format-drawer-function)
127 (:latex-format-headline-function nil nil org-latex-format-headline-function)
128 (:latex-format-inlinetask-function nil nil org-latex-format-inlinetask-function)
129 (:latex-hyperref-template nil nil org-latex-hyperref-template t)
130 (:latex-image-default-height nil nil org-latex-image-default-height)
131 (:latex-image-default-option nil nil org-latex-image-default-option)
132 (:latex-image-default-width nil nil org-latex-image-default-width)
133 (:latex-images-centered nil nil org-latex-images-centered)
134 (:latex-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format)
135 (:latex-inline-image-rules nil nil org-latex-inline-image-rules)
136 (:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format)
137 (:latex-listings nil nil org-latex-listings)
138 (:latex-listings-langs nil nil org-latex-listings-langs)
139 (:latex-listings-options nil nil org-latex-listings-options)
140 (:latex-minted-langs nil nil org-latex-minted-langs)
141 (:latex-minted-options nil nil org-latex-minted-options)
142 (:latex-prefer-user-labels nil nil org-latex-prefer-user-labels)
143 (:latex-subtitle-format nil nil org-latex-subtitle-format)
144 (:latex-subtitle-separate nil nil org-latex-subtitle-separate)
145 (:latex-table-scientific-notation nil nil org-latex-table-scientific-notation)
146 (:latex-tables-booktabs nil nil org-latex-tables-booktabs)
147 (:latex-tables-centered nil nil org-latex-tables-centered)
148 (:latex-text-markup-alist nil nil org-latex-text-markup-alist)
149 (:latex-title-command nil nil org-latex-title-command)
150 (:latex-toc-command nil nil org-latex-toc-command)
151 (:latex-compiler "LATEX_COMPILER" nil org-latex-compiler)
152 ;; Redefine regular options.
153 (:date "DATE" nil "\\today" parse)))
157 ;;; Internal Variables
159 (defconst org-latex-babel-language-alist
160 '(("af" . "afrikaans")
161 ("bg" . "bulgarian")
162 ("bt-br" . "brazilian")
163 ("ca" . "catalan")
164 ("cs" . "czech")
165 ("cy" . "welsh")
166 ("da" . "danish")
167 ("de" . "germanb")
168 ("de-at" . "naustrian")
169 ("de-de" . "ngerman")
170 ("el" . "greek")
171 ("en" . "english")
172 ("en-au" . "australian")
173 ("en-ca" . "canadian")
174 ("en-gb" . "british")
175 ("en-ie" . "irish")
176 ("en-nz" . "newzealand")
177 ("en-us" . "american")
178 ("es" . "spanish")
179 ("et" . "estonian")
180 ("eu" . "basque")
181 ("fi" . "finnish")
182 ("fr" . "frenchb")
183 ("fr-ca" . "canadien")
184 ("gl" . "galician")
185 ("hr" . "croatian")
186 ("hu" . "hungarian")
187 ("id" . "indonesian")
188 ("is" . "icelandic")
189 ("it" . "italian")
190 ("la" . "latin")
191 ("ms" . "malay")
192 ("nl" . "dutch")
193 ("nb" . "norsk")
194 ("nn" . "nynorsk")
195 ("no" . "norsk")
196 ("pl" . "polish")
197 ("pt" . "portuguese")
198 ("ro" . "romanian")
199 ("ru" . "russian")
200 ("sa" . "sanskrit")
201 ("sb" . "uppersorbian")
202 ("sk" . "slovak")
203 ("sl" . "slovene")
204 ("sq" . "albanian")
205 ("sr" . "serbian")
206 ("sv" . "swedish")
207 ("ta" . "tamil")
208 ("tr" . "turkish")
209 ("uk" . "ukrainian"))
210 "Alist between language code and corresponding Babel option.")
212 (defconst org-latex-polyglossia-language-alist
213 '(("am" "amharic")
214 ("ast" "asturian")
215 ("ar" "arabic")
216 ("bo" "tibetan")
217 ("bn" "bengali")
218 ("bg" "bulgarian")
219 ("br" "breton")
220 ("bt-br" "brazilian")
221 ("ca" "catalan")
222 ("cop" "coptic")
223 ("cs" "czech")
224 ("cy" "welsh")
225 ("da" "danish")
226 ("de" "german" "german")
227 ("de-at" "german" "austrian")
228 ("de-de" "german" "german")
229 ("dv" "divehi")
230 ("el" "greek")
231 ("en" "english" "usmax")
232 ("en-au" "english" "australian")
233 ("en-gb" "english" "uk")
234 ("en-nz" "english" "newzealand")
235 ("en-us" "english" "usmax")
236 ("eo" "esperanto")
237 ("es" "spanish")
238 ("et" "estonian")
239 ("eu" "basque")
240 ("fa" "farsi")
241 ("fi" "finnish")
242 ("fr" "french")
243 ("fu" "friulan")
244 ("ga" "irish")
245 ("gd" "scottish")
246 ("gl" "galician")
247 ("he" "hebrew")
248 ("hi" "hindi")
249 ("hr" "croatian")
250 ("hu" "magyar")
251 ("hy" "armenian")
252 ("id" "bahasai")
253 ("ia" "interlingua")
254 ("is" "icelandic")
255 ("it" "italian")
256 ("kn" "kannada")
257 ("la" "latin" "modern")
258 ("la-modern" "latin" "modern")
259 ("la-classic" "latin" "classic")
260 ("la-medieval" "latin" "medieval")
261 ("lo" "lao")
262 ("lt" "lithuanian")
263 ("lv" "latvian")
264 ("mr" "maranthi")
265 ("ml" "malayalam")
266 ("nl" "dutch")
267 ("nb" "norsk")
268 ("nn" "nynorsk")
269 ("nko" "nko")
270 ("no" "norsk")
271 ("oc" "occitan")
272 ("pl" "polish")
273 ("pms" "piedmontese")
274 ("pt" "portuges")
275 ("rm" "romansh")
276 ("ro" "romanian")
277 ("ru" "russian")
278 ("sa" "sanskrit")
279 ("hsb" "usorbian")
280 ("dsb" "lsorbian")
281 ("sk" "slovak")
282 ("sl" "slovenian")
283 ("se" "samin")
284 ("sq" "albanian")
285 ("sr" "serbian")
286 ("sv" "swedish")
287 ("syr" "syriac")
288 ("ta" "tamil")
289 ("te" "telugu")
290 ("th" "thai")
291 ("tk" "turkmen")
292 ("tr" "turkish")
293 ("uk" "ukrainian")
294 ("ur" "urdu")
295 ("vi" "vietnamese"))
296 "Alist between language code and corresponding Polyglossia option")
300 (defconst org-latex-table-matrix-macros '(("bordermatrix" . "\\cr")
301 ("qbordermatrix" . "\\cr")
302 ("kbordermatrix" . "\\\\"))
303 "Alist between matrix macros and their row ending.")
305 (defconst org-latex-math-environments-re
306 (format
307 "\\`[ \t]*\\\\begin{%s\\*?}"
308 (regexp-opt
309 '("equation" "eqnarray" "math" "displaymath"
310 "align" "gather" "multline" "flalign" "alignat"
311 "xalignat" "xxalignat"
312 "subequations"
313 ;; breqn
314 "dmath" "dseries" "dgroup" "darray"
315 ;; empheq
316 "empheq")))
317 "Regexp of LaTeX math environments.")
320 ;;; User Configurable Variables
322 (defgroup org-export-latex nil
323 "Options for exporting Org mode files to LaTeX."
324 :tag "Org Export LaTeX"
325 :group 'org-export)
327 ;;;; Generic
329 (defcustom org-latex-caption-above '(table)
330 "When non-nil, place caption string at the beginning of elements.
331 Otherwise, place it near the end. When value is a list of
332 symbols, put caption above selected elements only. Allowed
333 symbols are: `image', `table', `src-block' and `special-block'."
334 :group 'org-export-latex
335 :version "26.1"
336 :package-version '(Org . "8.3")
337 :type '(choice
338 (const :tag "For all elements" t)
339 (const :tag "For no element" nil)
340 (set :tag "For the following elements only" :greedy t
341 (const :tag "Images" image)
342 (const :tag "Tables" table)
343 (const :tag "Source code" src-block)
344 (const :tag "Special blocks" special-block))))
346 (defcustom org-latex-prefer-user-labels nil
347 "Use user-provided labels instead of internal ones when non-nil.
349 When this variable is non-nil, Org will use the value of
350 CUSTOM_ID property, NAME keyword or Org target as the key for the
351 \\label commands generated.
353 By default, Org generates its own internal labels during LaTeX
354 export. This process ensures that the \\label keys are unique
355 and valid, but it means the keys are not available in advance of
356 the export process.
358 Setting this variable gives you control over how Org generates
359 labels during LaTeX export, so that you may know their keys in
360 advance. One reason to do this is that it allows you to refer to
361 various elements using a single label both in Org's link syntax
362 and in embedded LaTeX code.
364 For example, when this variable is non-nil, a headline like this:
366 ** Some section
367 :PROPERTIES:
368 :CUSTOM_ID: sec:foo
369 :END:
370 This is section [[#sec:foo]].
371 #+BEGIN_EXPORT latex
372 And this is still section \\ref{sec:foo}.
373 #+END_EXPORT
375 will be exported to LaTeX as:
377 \\subsection{Some section}
378 \\label{sec:foo}
379 This is section \\ref{sec:foo}.
380 And this is still section \\ref{sec:foo}.
382 Note, however, that setting this variable introduces a limitation
383 on the possible values for CUSTOM_ID and NAME. When this
384 variable is non-nil, Org passes their value to \\label unchanged.
385 You are responsible for ensuring that the value is a valid LaTeX
386 \\label key, and that no other \\label commands with the same key
387 appear elsewhere in your document. (Keys may contain letters,
388 numbers, and the following punctuation: '_' '.' '-' ':'.) There
389 are no such limitations on CUSTOM_ID and NAME when this variable
390 is nil.
392 For headlines that do not define the CUSTOM_ID property or
393 elements without a NAME, Org will continue to use its default
394 labeling scheme to generate labels and resolve links into proper
395 references."
396 :group 'org-export-latex
397 :type 'boolean
398 :version "26.1"
399 :package-version '(Org . "8.3"))
401 ;;;; Preamble
403 (defcustom org-latex-default-class "article"
404 "The default LaTeX class."
405 :group 'org-export-latex
406 :type '(string :tag "LaTeX class"))
408 (defcustom org-latex-classes
409 '(("article"
410 "\\documentclass[11pt]{article}"
411 ("\\section{%s}" . "\\section*{%s}")
412 ("\\subsection{%s}" . "\\subsection*{%s}")
413 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
414 ("\\paragraph{%s}" . "\\paragraph*{%s}")
415 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
416 ("report"
417 "\\documentclass[11pt]{report}"
418 ("\\part{%s}" . "\\part*{%s}")
419 ("\\chapter{%s}" . "\\chapter*{%s}")
420 ("\\section{%s}" . "\\section*{%s}")
421 ("\\subsection{%s}" . "\\subsection*{%s}")
422 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
423 ("book"
424 "\\documentclass[11pt]{book}"
425 ("\\part{%s}" . "\\part*{%s}")
426 ("\\chapter{%s}" . "\\chapter*{%s}")
427 ("\\section{%s}" . "\\section*{%s}")
428 ("\\subsection{%s}" . "\\subsection*{%s}")
429 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
430 "Alist of LaTeX classes and associated header and structure.
431 If #+LATEX_CLASS is set in the buffer, use its value and the
432 associated information. Here is the structure of each cell:
434 (class-name
435 header-string
436 (numbered-section . unnumbered-section)
437 ...)
439 The header string
440 -----------------
442 The HEADER-STRING is the header that will be inserted into the
443 LaTeX file. It should contain the \\documentclass macro, and
444 anything else that is needed for this setup. To this header, the
445 following commands will be added:
447 - Calls to \\usepackage for all packages mentioned in the
448 variables `org-latex-default-packages-alist' and
449 `org-latex-packages-alist'. Thus, your header definitions
450 should avoid to also request these packages.
452 - Lines specified via \"#+LATEX_HEADER:\" and
453 \"#+LATEX_HEADER_EXTRA:\" keywords.
455 If you need more control about the sequence in which the header
456 is built up, or if you want to exclude one of these building
457 blocks for a particular class, you can use the following
458 macro-like placeholders.
460 [DEFAULT-PACKAGES] \\usepackage statements for default packages
461 [NO-DEFAULT-PACKAGES] do not include any of the default packages
462 [PACKAGES] \\usepackage statements for packages
463 [NO-PACKAGES] do not include the packages
464 [EXTRA] the stuff from #+LATEX_HEADER(_EXTRA)
465 [NO-EXTRA] do not include #+LATEX_HEADER(_EXTRA) stuff
467 So a header like
469 \\documentclass{article}
470 [NO-DEFAULT-PACKAGES]
471 [EXTRA]
472 \\providecommand{\\alert}[1]{\\textbf{#1}}
473 [PACKAGES]
475 will omit the default packages, and will include the
476 #+LATEX_HEADER and #+LATEX_HEADER_EXTRA lines, then have a call
477 to \\providecommand, and then place \\usepackage commands based
478 on the content of `org-latex-packages-alist'.
480 If your header, `org-latex-default-packages-alist' or
481 `org-latex-packages-alist' inserts \"\\usepackage[AUTO]{inputenc}\",
482 AUTO will automatically be replaced with a coding system derived
483 from `buffer-file-coding-system'. See also the variable
484 `org-latex-inputenc-alist' for a way to influence this mechanism.
486 Likewise, if your header contains \"\\usepackage[AUTO]{babel}\"
487 or \"\\usepackage[AUTO]{polyglossia}\", AUTO will be replaced
488 with the language related to the language code specified by
489 `org-export-default-language'. Note that constructions such as
490 \"\\usepackage[french,AUTO,english]{babel}\" are permitted. For
491 Polyglossia the language will be set via the macros
492 \"\\setmainlanguage\" and \"\\setotherlanguage\". See also
493 `org-latex-guess-babel-language' and
494 `org-latex-guess-polyglossia-language'.
496 The sectioning structure
497 ------------------------
499 The sectioning structure of the class is given by the elements
500 following the header string. For each sectioning level, a number
501 of strings is specified. A %s formatter is mandatory in each
502 section string and will be replaced by the title of the section.
504 Instead of a cons cell (numbered . unnumbered), you can also
505 provide a list of 2 or 4 elements,
507 (numbered-open numbered-close)
511 (numbered-open numbered-close unnumbered-open unnumbered-close)
513 providing opening and closing strings for a LaTeX environment
514 that should represent the document section. The opening clause
515 should have a %s to represent the section title.
517 Instead of a list of sectioning commands, you can also specify
518 a function name. That function will be called with two
519 parameters, the (reduced) level of the headline, and a predicate
520 non-nil when the headline should be numbered. It must return
521 a format string in which the section title will be added."
522 :group 'org-export-latex
523 :type '(repeat
524 (list (string :tag "LaTeX class")
525 (string :tag "LaTeX header")
526 (repeat :tag "Levels" :inline t
527 (choice
528 (cons :tag "Heading"
529 (string :tag " numbered")
530 (string :tag "unnumbered"))
531 (list :tag "Environment"
532 (string :tag "Opening (numbered)")
533 (string :tag "Closing (numbered)")
534 (string :tag "Opening (unnumbered)")
535 (string :tag "Closing (unnumbered)"))
536 (function :tag "Hook computing sectioning"))))))
538 (defcustom org-latex-inputenc-alist nil
539 "Alist of inputenc coding system names, and what should really be used.
540 For example, adding an entry
542 (\"utf8\" . \"utf8x\")
544 will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
545 are written as utf8 files."
546 :group 'org-export-latex
547 :type '(repeat
548 (cons
549 (string :tag "Derived from buffer")
550 (string :tag "Use this instead"))))
552 (defcustom org-latex-title-command "\\maketitle"
553 "The command used to insert the title just after \\begin{document}.
555 This format string may contain these elements:
557 %a for AUTHOR keyword
558 %t for TITLE keyword
559 %s for SUBTITLE keyword
560 %k for KEYWORDS line
561 %d for DESCRIPTION line
562 %c for CREATOR line
563 %l for Language keyword
564 %L for capitalized language keyword
565 %D for DATE keyword
567 If you need to use a \"%\" character, you need to escape it
568 like that: \"%%\".
570 Setting :latex-title-command in publishing projects will take
571 precedence over this variable."
572 :group 'org-export-latex
573 :type '(string :tag "Format string"))
575 (defcustom org-latex-subtitle-format "\\\\\\medskip\n\\large %s"
576 "Format string used for transcoded subtitle.
577 The format string should have at most one \"%s\"-expression,
578 which is replaced with the subtitle."
579 :group 'org-export-latex
580 :version "26.1"
581 :package-version '(Org . "8.3")
582 :type '(string :tag "Format string"))
584 (defcustom org-latex-subtitle-separate nil
585 "Non-nil means the subtitle is not typeset as part of title."
586 :group 'org-export-latex
587 :version "26.1"
588 :package-version '(Org . "8.3")
589 :type 'boolean)
591 (defcustom org-latex-toc-command "\\tableofcontents\n\n"
592 "LaTeX command to set the table of contents, list of figures, etc.
593 This command only applies to the table of contents generated with
594 the toc:nil option, not to those generated with #+TOC keyword."
595 :group 'org-export-latex
596 :type 'string)
598 (defcustom org-latex-hyperref-template
599 "\\hypersetup{\n pdfauthor={%a},\n pdftitle={%t},\n pdfkeywords={%k},
600 pdfsubject={%d},\n pdfcreator={%c}, \n pdflang={%L}}\n"
601 "Template for hyperref package options.
603 This format string may contain these elements:
605 %a for AUTHOR keyword
606 %t for TITLE keyword
607 %s for SUBTITLE keyword
608 %k for KEYWORDS line
609 %d for DESCRIPTION line
610 %c for CREATOR line
611 %l for Language keyword
612 %L for capitalized language keyword
613 %D for DATE keyword
615 If you need to use a \"%\" character, you need to escape it
616 like that: \"%%\".
618 As a special case, a nil value prevents template from being
619 inserted.
621 Setting :latex-hyperref-template in publishing projects will take
622 precedence over this variable."
623 :group 'org-export-latex
624 :version "26.1"
625 :package-version '(Org . "8.3")
626 :type '(choice (const :tag "No template" nil)
627 (string :tag "Format string")))
629 ;;;; Headline
631 (defcustom org-latex-format-headline-function
632 'org-latex-format-headline-default-function
633 "Function for formatting the headline's text.
635 This function will be called with six arguments:
636 TODO the todo keyword (string or nil)
637 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
638 PRIORITY the priority of the headline (integer or nil)
639 TEXT the main headline text (string)
640 TAGS the tags (list of strings or nil)
641 INFO the export options (plist)
643 The function result will be used in the section format string."
644 :group 'org-export-latex
645 :version "24.4"
646 :package-version '(Org . "8.0")
647 :type 'function)
650 ;;;; Footnotes
652 (defcustom org-latex-footnote-separator "\\textsuperscript{,}\\,"
653 "Text used to separate footnotes."
654 :group 'org-export-latex
655 :type 'string)
657 (defcustom org-latex-footnote-defined-format "\\textsuperscript{\\ref{%s}}"
658 "Format string used to format reference to footnote already defined.
659 %s will be replaced by the label of the referred footnote."
660 :group 'org-export-latex
661 :type '(choice
662 (const :tag "Use plain superscript (default)" "\\textsuperscript{\\ref{%s}}")
663 (const :tag "Use Memoir/KOMA-Script footref" "\\footref{%s}")
664 (string :tag "Other format string"))
665 :version "26.1"
666 :package-version '(Org . "9.0"))
668 ;;;; Timestamps
670 (defcustom org-latex-active-timestamp-format "\\textit{%s}"
671 "A printf format string to be applied to active timestamps."
672 :group 'org-export-latex
673 :type 'string)
675 (defcustom org-latex-inactive-timestamp-format "\\textit{%s}"
676 "A printf format string to be applied to inactive timestamps."
677 :group 'org-export-latex
678 :type 'string)
680 (defcustom org-latex-diary-timestamp-format "\\textit{%s}"
681 "A printf format string to be applied to diary timestamps."
682 :group 'org-export-latex
683 :type 'string)
686 ;;;; Links
688 (defcustom org-latex-images-centered t
689 "When non-nil, images are centered."
690 :group 'org-export-latex
691 :version "26.1"
692 :package-version '(Org . "9.0")
693 :type 'boolean
694 :safe #'booleanp)
696 (defcustom org-latex-image-default-option ""
697 "Default option for images."
698 :group 'org-export-latex
699 :version "24.4"
700 :package-version '(Org . "8.0")
701 :type 'string)
703 (defcustom org-latex-image-default-width ".9\\linewidth"
704 "Default width for images.
705 This value will not be used if a height is provided."
706 :group 'org-export-latex
707 :version "24.4"
708 :package-version '(Org . "8.0")
709 :type 'string)
711 (defcustom org-latex-image-default-height ""
712 "Default height for images.
713 This value will not be used if a width is provided, or if the
714 image is wrapped within a \"figure\" or \"wrapfigure\"
715 environment."
716 :group 'org-export-latex
717 :version "24.4"
718 :package-version '(Org . "8.0")
719 :type 'string)
721 (defcustom org-latex-default-figure-position "htbp"
722 "Default position for LaTeX figures."
723 :group 'org-export-latex
724 :type 'string
725 :version "26.1"
726 :package-version '(Org . "9.0")
727 :safe #'stringp)
729 (defcustom org-latex-inline-image-rules
730 `(("file" . ,(regexp-opt
731 '("pdf" "jpeg" "jpg" "png" "ps" "eps" "tikz" "pgf" "svg"))))
732 "Rules characterizing image files that can be inlined into LaTeX.
734 A rule consists in an association whose key is the type of link
735 to consider, and value is a regexp that will be matched against
736 link's path.
738 Note that, by default, the image extension *actually* allowed
739 depend on the way the LaTeX file is processed. When used with
740 pdflatex, pdf, jpg and png images are OK. When processing
741 through dvi to Postscript, only ps and eps are allowed. The
742 default we use here encompasses both."
743 :group 'org-export-latex
744 :version "24.4"
745 :package-version '(Org . "8.0")
746 :type '(alist :key-type (string :tag "Type")
747 :value-type (regexp :tag "Path")))
749 (defcustom org-latex-link-with-unknown-path-format "\\texttt{%s}"
750 "Format string for links with unknown path type."
751 :group 'org-export-latex
752 :type 'string)
755 ;;;; Tables
757 (defcustom org-latex-default-table-environment "tabular"
758 "Default environment used to build tables."
759 :group 'org-export-latex
760 :version "24.4"
761 :package-version '(Org . "8.0")
762 :type 'string)
764 (defcustom org-latex-default-table-mode 'table
765 "Default mode for tables.
767 Value can be a symbol among:
769 `table' Regular LaTeX table.
771 `math' In this mode, every cell is considered as being in math
772 mode and the complete table will be wrapped within a math
773 environment. It is particularly useful to write matrices.
775 `inline-math' This mode is almost the same as `math', but the
776 math environment will be inlined.
778 `verbatim' The table is exported as it appears in the Org
779 buffer, within a verbatim environment.
781 This value can be overridden locally with, i.e. \":mode math\" in
782 LaTeX attributes.
784 When modifying this variable, it may be useful to change
785 `org-latex-default-table-environment' accordingly."
786 :group 'org-export-latex
787 :version "24.4"
788 :package-version '(Org . "8.0")
789 :type '(choice (const :tag "Table" table)
790 (const :tag "Matrix" math)
791 (const :tag "Inline matrix" inline-math)
792 (const :tag "Verbatim" verbatim))
793 :safe (lambda (s) (memq s '(table math inline-math verbatim))))
795 (defcustom org-latex-tables-centered t
796 "When non-nil, tables are exported in a center environment."
797 :group 'org-export-latex
798 :type 'boolean
799 :safe #'booleanp)
801 (defcustom org-latex-tables-booktabs nil
802 "When non-nil, display tables in a formal \"booktabs\" style.
803 This option assumes that the \"booktabs\" package is properly
804 loaded in the header of the document. This value can be ignored
805 locally with \":booktabs t\" and \":booktabs nil\" LaTeX
806 attributes."
807 :group 'org-export-latex
808 :version "24.4"
809 :package-version '(Org . "8.0")
810 :type 'boolean
811 :safe #'booleanp)
813 (defcustom org-latex-table-scientific-notation nil
814 "Format string to display numbers in scientific notation.
816 The format should have \"%s\" twice, for mantissa and exponent
817 \(i.e., \"%s\\\\times10^{%s}\").
819 When nil, no transformation is made."
820 :group 'org-export-latex
821 :version "24.4"
822 :package-version '(Org . "8.0")
823 :type '(choice
824 (string :tag "Format string")
825 (const :tag "No formatting" nil)))
827 ;;;; Text markup
829 (defcustom org-latex-text-markup-alist '((bold . "\\textbf{%s}")
830 (code . protectedtexttt)
831 (italic . "\\emph{%s}")
832 (strike-through . "\\sout{%s}")
833 (underline . "\\uline{%s}")
834 (verbatim . protectedtexttt))
835 "Alist of LaTeX expressions to convert text markup.
837 The key must be a symbol among `bold', `code', `italic',
838 `strike-through', `underline' and `verbatim'. The value is
839 a formatting string to wrap fontified text with.
841 Value can also be set to the following symbols: `verb' and
842 `protectedtexttt'. For the former, Org will use \"\\verb\" to
843 create a format string and select a delimiter character that
844 isn't in the string. For the latter, Org will use \"\\texttt\"
845 to typeset and try to protect special characters.
847 If no association can be found for a given markup, text will be
848 returned as-is."
849 :group 'org-export-latex
850 :version "26.1"
851 :package-version '(Org . "8.3")
852 :type 'alist
853 :options '(bold code italic strike-through underline verbatim))
856 ;;;; Drawers
858 (defcustom org-latex-format-drawer-function (lambda (_ contents) contents)
859 "Function called to format a drawer in LaTeX code.
861 The function must accept two parameters:
862 NAME the drawer name, like \"LOGBOOK\"
863 CONTENTS the contents of the drawer.
865 The function should return the string to be exported.
867 The default function simply returns the value of CONTENTS."
868 :group 'org-export-latex
869 :version "26.1"
870 :package-version '(Org . "8.3")
871 :type 'function)
874 ;;;; Inlinetasks
876 (defcustom org-latex-format-inlinetask-function
877 'org-latex-format-inlinetask-default-function
878 "Function called to format an inlinetask in LaTeX code.
880 The function must accept seven parameters:
881 TODO the todo keyword (string or nil)
882 TODO-TYPE the todo type (symbol: `todo', `done', nil)
883 PRIORITY the inlinetask priority (integer or nil)
884 NAME the inlinetask name (string)
885 TAGS the inlinetask tags (list of strings or nil)
886 CONTENTS the contents of the inlinetask (string or nil)
887 INFO the export options (plist)
889 The function should return the string to be exported."
890 :group 'org-export-latex
891 :type 'function
892 :version "26.1"
893 :package-version '(Org . "8.3"))
896 ;; Src blocks
898 (defcustom org-latex-listings nil
899 "Non-nil means export source code using the listings package.
901 This package will fontify source code, possibly even with color.
902 If you want to use this, you also need to make LaTeX use the
903 listings package, and if you want to have color, the color
904 package. Just add these to `org-latex-packages-alist', for
905 example using customize, or with something like:
907 (require \\='ox-latex)
908 (add-to-list \\='org-latex-packages-alist \\='(\"\" \"listings\"))
909 (add-to-list \\='org-latex-packages-alist \\='(\"\" \"color\"))
911 Alternatively,
913 (setq org-latex-listings \\='minted)
915 causes source code to be exported using the minted package as
916 opposed to listings. If you want to use minted, you need to add
917 the minted package to `org-latex-packages-alist', for example
918 using customize, or with
920 (require \\='ox-latex)
921 (add-to-list \\='org-latex-packages-alist \\='(\"newfloat\" \"minted\"))
923 In addition, it is necessary to install pygments
924 \(URL `http://pygments.org>'), and to configure the variable
925 `org-latex-pdf-process' so that the -shell-escape option is
926 passed to pdflatex.
928 The minted choice has possible repercussions on the preview of
929 latex fragments (see `org-preview-latex-fragment'). If you run
930 into previewing problems, please consult
931 URL `https://orgmode.org/worg/org-tutorials/org-latex-preview.html'."
932 :group 'org-export-latex
933 :type '(choice
934 (const :tag "Use listings" t)
935 (const :tag "Use minted" minted)
936 (const :tag "Export verbatim" nil))
937 :safe (lambda (s) (memq s '(t nil minted))))
939 (defcustom org-latex-listings-langs
940 '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
941 (c "C") (cc "C++")
942 (fortran "fortran")
943 (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
944 (html "HTML") (xml "XML")
945 (tex "TeX") (latex "[LaTeX]TeX")
946 (shell-script "bash")
947 (gnuplot "Gnuplot")
948 (ocaml "Caml") (caml "Caml")
949 (sql "SQL") (sqlite "sql")
950 (makefile "make")
951 (R "r"))
952 "Alist mapping languages to their listing language counterpart.
953 The key is a symbol, the major mode symbol without the \"-mode\".
954 The value is the string that should be inserted as the language
955 parameter for the listings package. If the mode name and the
956 listings name are the same, the language does not need an entry
957 in this list - but it does not hurt if it is present."
958 :group 'org-export-latex
959 :version "26.1"
960 :package-version '(Org . "8.3")
961 :type '(repeat
962 (list
963 (symbol :tag "Major mode ")
964 (string :tag "Listings language"))))
966 (defcustom org-latex-listings-options nil
967 "Association list of options for the latex listings package.
969 These options are supplied as a comma-separated list to the
970 \\lstset command. Each element of the association list should be
971 a list containing two strings: the name of the option, and the
972 value. For example,
974 (setq org-latex-listings-options
975 \\='((\"basicstyle\" \"\\\\small\")
976 (\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\")))
978 will typeset the code in a small size font with underlined, bold
979 black keywords.
981 Note that the same options will be applied to blocks of all
982 languages. If you need block-specific options, you may use the
983 following syntax:
985 #+ATTR_LATEX: :options key1=value1,key2=value2
986 #+BEGIN_SRC <LANG>
988 #+END_SRC"
989 :group 'org-export-latex
990 :type '(repeat
991 (list
992 (string :tag "Listings option name ")
993 (string :tag "Listings option value"))))
995 (defcustom org-latex-minted-langs
996 '((emacs-lisp "common-lisp")
997 (cc "c++")
998 (cperl "perl")
999 (shell-script "bash")
1000 (caml "ocaml"))
1001 "Alist mapping languages to their minted language counterpart.
1002 The key is a symbol, the major mode symbol without the \"-mode\".
1003 The value is the string that should be inserted as the language
1004 parameter for the minted package. If the mode name and the
1005 listings name are the same, the language does not need an entry
1006 in this list - but it does not hurt if it is present.
1008 Note that minted uses all lower case for language identifiers,
1009 and that the full list of language identifiers can be obtained
1010 with:
1012 pygmentize -L lexers"
1013 :group 'org-export-latex
1014 :type '(repeat
1015 (list
1016 (symbol :tag "Major mode ")
1017 (string :tag "Minted language"))))
1019 (defcustom org-latex-minted-options nil
1020 "Association list of options for the latex minted package.
1022 These options are supplied within square brackets in
1023 \\begin{minted} environments. Each element of the alist should
1024 be a list containing two strings: the name of the option, and the
1025 value. For example,
1027 (setq org-latex-minted-options
1028 \\='((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
1030 will result in src blocks being exported with
1032 \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
1034 as the start of the minted environment. Note that the same
1035 options will be applied to blocks of all languages. If you need
1036 block-specific options, you may use the following syntax:
1038 #+ATTR_LATEX: :options key1=value1,key2=value2
1039 #+BEGIN_SRC <LANG>
1041 #+END_SRC"
1042 :group 'org-export-latex
1043 :type '(repeat
1044 (list
1045 (string :tag "Minted option name ")
1046 (string :tag "Minted option value"))))
1048 (defcustom org-latex-custom-lang-environments nil
1049 "Alist mapping languages to language-specific LaTeX environments.
1051 It is used during export of src blocks by the listings and minted
1052 latex packages. The environment may be a simple string, composed of
1053 only letters and numbers. In this case, the string is directly the
1054 name of the latex environment to use. The environment may also be
1055 a format string. In this case the format string will be directly
1056 exported. This format string may contain these elements:
1058 %s for the formatted source
1059 %c for the caption
1060 %f for the float attribute
1061 %l for an appropriate label
1062 %o for the LaTeX attributes
1064 For example,
1066 (setq org-latex-custom-lang-environments
1067 \\='((python \"pythoncode\")
1068 (ocaml \"\\\\begin{listing}
1069 \\\\begin{minted}[%o]{ocaml}
1070 %s\\\\end{minted}
1071 \\\\caption{%c}
1072 \\\\label{%l}\")))
1074 would have the effect that if Org encounters a Python source block
1075 during LaTeX export it will produce
1077 \\begin{pythoncode}
1078 <src block body>
1079 \\end{pythoncode}
1081 and if Org encounters an Ocaml source block during LaTeX export it
1082 will produce
1084 \\begin{listing}
1085 \\begin{minted}[<attr_latex options>]{ocaml}
1086 <src block body>
1087 \\end{minted}
1088 \\caption{<caption>}
1089 \\label{<label>}
1090 \\end{listing}"
1091 :group 'org-export-latex
1092 :type '(repeat
1093 (list
1094 (symbol :tag "Language name ")
1095 (string :tag "Environment name or format string")))
1096 :version "26.1"
1097 :package-version '(Org . "9.0"))
1100 ;;;; Compilation
1102 (defcustom org-latex-compiler-file-string "%% Intended LaTeX compiler: %s\n"
1103 "LaTeX compiler format-string.
1104 See also `org-latex-compiler'."
1105 :group 'org-export-latex
1106 :type '(choice
1107 (const :tag "Comment" "%% Intended LaTeX compiler: %s\n")
1108 (const :tag "latex-mode file variable" "%% -*- latex-run-command: %s -*-\n")
1109 (const :tag "AUCTeX file variable" "%% -*- LaTeX-command: %s -*-\n")
1110 (string :tag "custom format" "%% %s"))
1111 :version "26.1"
1112 :package-version '(Org . "9.0"))
1114 (defcustom org-latex-compiler "pdflatex"
1115 "LaTeX compiler to use.
1117 Must be an element in `org-latex-compilers' or the empty quote.
1118 Can also be set in buffers via #+LATEX_COMPILER. See also
1119 `org-latex-compiler-file-string'."
1120 :group 'org-export-latex
1121 :type '(choice
1122 (const :tag "pdfLaTeX" "pdflatex")
1123 (const :tag "XeLaTeX" "xelatex")
1124 (const :tag "LuaLaTeX" "lualatex")
1125 (const :tag "Unset" ""))
1126 :version "26.1"
1127 :package-version '(Org . "9.0"))
1129 (defconst org-latex-compilers '("pdflatex" "xelatex" "lualatex")
1130 "Known LaTeX compilers.
1131 See also `org-latex-compiler'.")
1133 (defcustom org-latex-bib-compiler "bibtex"
1134 "Command to process a LaTeX file's bibliography.
1136 The shorthand %bib in `org-latex-pdf-process' is replaced with
1137 this value.
1139 A better approach is to use a compiler suit such as `latexmk'."
1140 :group 'org-export-latex
1141 :type '(choice (const :tag "BibTeX" "bibtex")
1142 (const :tag "Biber" "biber")
1143 (string :tag "Other process"))
1144 :version "26.1"
1145 :package-version '(Org . "9.0"))
1147 (defcustom org-latex-pdf-process
1148 '("%latex -interaction nonstopmode -output-directory %o %f"
1149 "%latex -interaction nonstopmode -output-directory %o %f"
1150 "%latex -interaction nonstopmode -output-directory %o %f")
1151 "Commands to process a LaTeX file to a PDF file.
1153 This is a list of strings, each of them will be given to the
1154 shell as a command. %f in the command will be replaced by the
1155 relative file name, %F by the absolute file name, %b by the file
1156 base name (i.e. without directory and extension parts), %o by the
1157 base directory of the file, %O by the absolute file name of the
1158 output file, %latex is the LaTeX compiler (see
1159 `org-latex-compiler'), and %bib is the BibTeX-like compiler (see
1160 `org-latex-bib-compiler').
1162 The reason why this is a list is that it usually takes several
1163 runs of `pdflatex', maybe mixed with a call to `bibtex'. Org
1164 does not have a clever mechanism to detect which of these
1165 commands have to be run to get to a stable result, and it also
1166 does not do any error checking.
1168 Consider a smart LaTeX compiler such as `texi2dvi' or `latexmk',
1169 which calls the \"correct\" combinations of auxiliary programs.
1171 Alternatively, this may be a Lisp function that does the
1172 processing, so you could use this to apply the machinery of
1173 AUCTeX or the Emacs LaTeX mode. This function should accept the
1174 file name as its single argument."
1175 :group 'org-export-pdf
1176 :type '(choice
1177 (repeat :tag "Shell command sequence"
1178 (string :tag "Shell command"))
1179 (const :tag "2 runs of latex"
1180 ("%latex -interaction nonstopmode -output-directory %o %f"
1181 "%latex -interaction nonstopmode -output-directory %o %f"))
1182 (const :tag "3 runs of latex"
1183 ("%latex -interaction nonstopmode -output-directory %o %f"
1184 "%latex -interaction nonstopmode -output-directory %o %f"
1185 "%latex -interaction nonstopmode -output-directory %o %f"))
1186 (const :tag "latex,bibtex,latex,latex"
1187 ("%latex -interaction nonstopmode -output-directory %o %f"
1188 "%bib %b"
1189 "%latex -interaction nonstopmode -output-directory %o %f"
1190 "%latex -interaction nonstopmode -output-directory %o %f"))
1191 (const :tag "texi2dvi"
1192 ("cd %o; LATEX=\"%latex\" texi2dvi -p -b -V %b.tex"))
1193 (const :tag "latexmk"
1194 ("latexmk -g -pdf -pdflatex=\"%latex\" -outdir=%o %f"))
1195 (function)))
1197 (defcustom org-latex-logfiles-extensions
1198 '("aux" "bcf" "blg" "fdb_latexmk" "fls" "figlist" "idx" "log" "nav" "out"
1199 "ptc" "run.xml" "snm" "toc" "vrb" "xdv")
1200 "The list of file extensions to consider as LaTeX logfiles.
1201 The logfiles will be removed if `org-latex-remove-logfiles' is
1202 non-nil."
1203 :group 'org-export-latex
1204 :version "26.1"
1205 :package-version '(Org . "8.3")
1206 :type '(repeat (string :tag "Extension")))
1208 (defcustom org-latex-remove-logfiles t
1209 "Non-nil means remove the logfiles produced by PDF production.
1210 By default, logfiles are files with these extensions: .aux, .idx,
1211 .log, .out, .toc, .nav, .snm and .vrb. To define the set of
1212 logfiles to remove, set `org-latex-logfiles-extensions'."
1213 :group 'org-export-latex
1214 :type 'boolean)
1216 (defcustom org-latex-known-warnings
1217 '(("Reference.*?undefined" . "[undefined reference]")
1218 ("Runaway argument" . "[runaway argument]")
1219 ("Underfull \\hbox" . "[underfull hbox]")
1220 ("Overfull \\hbox" . "[overfull hbox]")
1221 ("Citation.*?undefined" . "[undefined citation]")
1222 ("Undefined control sequence" . "[undefined control sequence]"))
1223 "Alist of regular expressions and associated messages for the user.
1224 The regular expressions are used to find possible warnings in the
1225 log of a latex-run. These warnings will be reported after
1226 calling `org-latex-compile'."
1227 :group 'org-export-latex
1228 :version "26.1"
1229 :package-version '(Org . "8.3")
1230 :type '(repeat
1231 (cons
1232 (string :tag "Regexp")
1233 (string :tag "Message"))))
1237 ;;; Internal Functions
1239 (defun org-latex--caption-above-p (element info)
1240 "Non nil when caption is expected to be located above ELEMENT.
1241 INFO is a plist holding contextual information."
1242 (let ((above (plist-get info :latex-caption-above)))
1243 (if (symbolp above) above
1244 (let ((type (org-element-type element)))
1245 (memq (if (eq type 'link) 'image type) above)))))
1247 (defun org-latex--label (datum info &optional force full)
1248 "Return an appropriate label for DATUM.
1249 DATUM is an element or a `target' type object. INFO is the
1250 current export state, as a plist.
1252 Return nil if element DATUM has no NAME or VALUE affiliated
1253 keyword or no CUSTOM_ID property, unless FORCE is non-nil. In
1254 this case always return a unique label.
1256 Eventually, if FULL is non-nil, wrap label within \"\\label{}\"."
1257 (let* ((type (org-element-type datum))
1258 (user-label
1259 (org-element-property
1260 (cl-case type
1261 ((headline inlinetask) :CUSTOM_ID)
1262 (target :value)
1263 (otherwise :name))
1264 datum))
1265 (label
1266 (and (or user-label force)
1267 (if (and user-label (plist-get info :latex-prefer-user-labels))
1268 user-label
1269 (concat (cl-case type
1270 (headline "sec:")
1271 (table "tab:")
1272 (latex-environment
1273 (and (string-match-p
1274 org-latex-math-environments-re
1275 (org-element-property :value datum))
1276 "eq:"))
1277 (paragraph
1278 (and (org-element-property :caption datum)
1279 "fig:")))
1280 (org-export-get-reference datum info))))))
1281 (cond ((not full) label)
1282 (label (format "\\label{%s}%s"
1283 label
1284 (if (eq type 'target) "" "\n")))
1285 (t ""))))
1287 (defun org-latex--caption/label-string (element info)
1288 "Return caption and label LaTeX string for ELEMENT.
1290 INFO is a plist holding contextual information. If there's no
1291 caption nor label, return the empty string.
1293 For non-floats, see `org-latex--wrap-label'."
1294 (let* ((label (org-latex--label element info nil t))
1295 (main (org-export-get-caption element))
1296 (attr (org-export-read-attribute :attr_latex element))
1297 (type (org-element-type element))
1298 (nonfloat (or (and (plist-member attr :float)
1299 (not (plist-get attr :float))
1300 main)
1301 (and (eq type 'src-block)
1302 (not (plist-get attr :float))
1303 (null (plist-get info :latex-listings)))))
1304 (short (org-export-get-caption element t))
1305 (caption-from-attr-latex (plist-get attr :caption)))
1306 (cond
1307 ((org-string-nw-p caption-from-attr-latex)
1308 (concat caption-from-attr-latex "\n"))
1309 ((and (not main) (equal label "")) "")
1310 ((not main) label)
1311 ;; Option caption format with short name.
1313 (format (if nonfloat "\\captionof{%s}%s{%s%s}\n"
1314 "\\caption%s%s{%s%s}\n")
1315 (let ((type* (if (eq type 'latex-environment)
1316 (org-latex--environment-type element)
1317 type)))
1318 (if nonfloat
1319 (cl-case type*
1320 (paragraph "figure")
1321 (image "figure")
1322 (special-block "figure")
1323 (src-block (if (plist-get info :latex-listings)
1324 "listing"
1325 "figure"))
1326 (t (symbol-name type*)))
1327 ""))
1328 (if short (format "[%s]" (org-export-data short info)) "")
1329 label
1330 (org-export-data main info))))))
1332 (defun org-latex-guess-inputenc (header)
1333 "Set the coding system in inputenc to what the buffer is.
1335 HEADER is the LaTeX header string. This function only applies
1336 when specified inputenc option is \"AUTO\".
1338 Return the new header, as a string."
1339 (let* ((cs (or (ignore-errors
1340 (latexenc-coding-system-to-inputenc
1341 (or org-export-coding-system buffer-file-coding-system)))
1342 "utf8")))
1343 (if (not cs) header
1344 ;; First translate if that is requested.
1345 (setq cs (or (cdr (assoc cs org-latex-inputenc-alist)) cs))
1346 ;; Then find the \usepackage statement and replace the option.
1347 (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
1348 cs header t nil 1))))
1350 (defun org-latex-guess-babel-language (header info)
1351 "Set Babel's language according to LANGUAGE keyword.
1353 HEADER is the LaTeX header string. INFO is the plist used as
1354 a communication channel.
1356 Insertion of guessed language only happens when Babel package has
1357 explicitly been loaded. Then it is added to the rest of
1358 package's options.
1360 The argument to Babel may be \"AUTO\" which is then replaced with
1361 the language of the document or `org-export-default-language'
1362 unless language in question is already loaded.
1364 Return the new header."
1365 (let ((language-code (plist-get info :language)))
1366 ;; If no language is set or Babel package is not loaded, return
1367 ;; HEADER as-is.
1368 (if (or (not (stringp language-code))
1369 (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
1370 header
1371 (let ((options (save-match-data
1372 (org-split-string (match-string 1 header) ",[ \t]*")))
1373 (language (cdr (assoc-string language-code
1374 org-latex-babel-language-alist t))))
1375 ;; If LANGUAGE is already loaded, return header without AUTO.
1376 ;; Otherwise, replace AUTO with language or append language if
1377 ;; AUTO is not present.
1378 (replace-match
1379 (mapconcat (lambda (option) (if (equal "AUTO" option) language option))
1380 (cond ((member language options) (delete "AUTO" options))
1381 ((member "AUTO" options) options)
1382 (t (append options (list language))))
1383 ", ")
1384 t nil header 1)))))
1386 (defun org-latex-guess-polyglossia-language (header info)
1387 "Set the Polyglossia language according to the LANGUAGE keyword.
1389 HEADER is the LaTeX header string. INFO is the plist used as
1390 a communication channel.
1392 Insertion of guessed language only happens when the Polyglossia
1393 package has been explicitly loaded.
1395 The argument to Polyglossia may be \"AUTO\" which is then
1396 replaced with the language of the document or
1397 `org-export-default-language'. Note, the language is really set
1398 using \setdefaultlanguage and not as an option to the package.
1400 Return the new header."
1401 (let ((language (plist-get info :language)))
1402 ;; If no language is set or Polyglossia is not loaded, return
1403 ;; HEADER as-is.
1404 (if (or (not (stringp language))
1405 (not (string-match
1406 "\\\\usepackage\\(?:\\[\\([^]]+?\\)\\]\\){polyglossia}\n"
1407 header)))
1408 header
1409 (let* ((options (org-string-nw-p (match-string 1 header)))
1410 (languages (and options
1411 ;; Reverse as the last loaded language is
1412 ;; the main language.
1413 (nreverse
1414 (delete-dups
1415 (save-match-data
1416 (org-split-string
1417 (replace-regexp-in-string
1418 "AUTO" language options t)
1419 ",[ \t]*"))))))
1420 (main-language-set
1421 (string-match-p "\\\\setmainlanguage{.*?}" header)))
1422 (replace-match
1423 (concat "\\usepackage{polyglossia}\n"
1424 (mapconcat
1425 (lambda (l)
1426 (let ((l (or (assoc l org-latex-polyglossia-language-alist)
1427 l)))
1428 (format (if main-language-set "\\setotherlanguage%s{%s}\n"
1429 (setq main-language-set t)
1430 "\\setmainlanguage%s{%s}\n")
1431 (if (and (consp l) (= (length l) 3))
1432 (format "[variant=%s]" (nth 2 l))
1434 (nth 1 l))))
1435 languages
1436 ""))
1437 t t header 0)))))
1439 (defun org-latex--remove-packages (pkg-alist info)
1440 "Remove packages based on the current LaTeX compiler.
1442 If the fourth argument of an element is set in pkg-alist, and it
1443 is not a member of the LaTeX compiler of the document, the packages
1444 is removed. See also `org-latex-compiler'.
1446 Return modified pkg-alist."
1447 (let ((compiler (or (plist-get info :latex-compiler) "")))
1448 (if (member-ignore-case compiler org-latex-compilers)
1449 (delq nil
1450 (mapcar
1451 (lambda (pkg)
1452 (unless (and
1453 (listp pkg)
1454 (let ((third (nth 3 pkg)))
1455 (and third
1456 (not (member-ignore-case
1457 compiler
1458 (if (listp third) third (list third)))))))
1459 pkg))
1460 pkg-alist))
1461 pkg-alist)))
1463 (defun org-latex--find-verb-separator (s)
1464 "Return a character not used in string S.
1465 This is used to choose a separator for constructs like \\verb."
1466 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1467 (cl-loop for c across ll
1468 when (not (string-match (regexp-quote (char-to-string c)) s))
1469 return (char-to-string c))))
1471 (defun org-latex--make-option-string (options)
1472 "Return a comma separated string of keywords and values.
1473 OPTIONS is an alist where the key is the options keyword as
1474 a string, and the value a list containing the keyword value, or
1475 nil."
1476 (mapconcat (lambda (pair)
1477 (pcase-let ((`(,keyword ,value) pair))
1478 (concat keyword
1479 (and (> (length value) 0)
1480 (concat "=" value)))))
1481 options
1482 ","))
1484 (defun org-latex--wrap-label (element output info)
1485 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1486 INFO is the current export state, as a plist. This function
1487 should not be used for floats. See
1488 `org-latex--caption/label-string'."
1489 (if (not (and (org-string-nw-p output) (org-element-property :name element)))
1490 output
1491 (concat (format "\\phantomsection\n\\label{%s}\n"
1492 (org-latex--label element info))
1493 output)))
1495 (defun org-latex--protect-text (text)
1496 "Protect special characters in string TEXT and return it."
1497 (replace-regexp-in-string "[\\{}$%&_#~^]" "\\\\\\&" text))
1499 (defun org-latex--text-markup (text markup info)
1500 "Format TEXT depending on MARKUP text markup.
1501 INFO is a plist used as a communication channel. See
1502 `org-latex-text-markup-alist' for details."
1503 (let ((fmt (cdr (assq markup (plist-get info :latex-text-markup-alist)))))
1504 (cl-case fmt
1505 ;; No format string: Return raw text.
1506 ((nil) text)
1507 ;; Handle the `verb' special case: Find an appropriate separator
1508 ;; and use "\\verb" command.
1509 (verb
1510 (let ((separator (org-latex--find-verb-separator text)))
1511 (concat "\\verb"
1512 separator
1513 (replace-regexp-in-string "\n" " " text)
1514 separator)))
1515 ;; Handle the `protectedtexttt' special case: Protect some
1516 ;; special chars and use "\texttt{%s}" format string.
1517 (protectedtexttt
1518 (format "\\texttt{%s}"
1519 (replace-regexp-in-string
1520 "--\\|[\\{}$%&_#~^]"
1521 (lambda (m)
1522 (cond ((equal m "--") "-{}-")
1523 ((equal m "\\") "\\textbackslash{}")
1524 ((equal m "~") "\\textasciitilde{}")
1525 ((equal m "^") "\\textasciicircum{}")
1526 (t (org-latex--protect-text m))))
1527 text nil t)))
1528 ;; Else use format string.
1529 (t (format fmt text)))))
1531 (defun org-latex--delayed-footnotes-definitions (element info)
1532 "Return footnotes definitions in ELEMENT as a string.
1534 INFO is a plist used as a communication channel.
1536 Footnotes definitions are returned within \"\\footnotetext{}\"
1537 commands.
1539 This function is used within constructs that don't support
1540 \"\\footnote{}\" command (e.g., an item tag). In that case,
1541 \"\\footnotemark\" is used within the construct and the function
1542 just outside of it."
1543 (mapconcat
1544 (lambda (ref)
1545 (let ((def (org-export-get-footnote-definition ref info)))
1546 (format "\\footnotetext[%d]{%s%s}"
1547 (org-export-get-footnote-number ref info)
1548 (org-trim (org-latex--label def info t t))
1549 (org-trim (org-export-data def info)))))
1550 ;; Find every footnote reference in ELEMENT.
1551 (letrec ((all-refs nil)
1552 (search-refs
1553 (lambda (data)
1554 ;; Return a list of all footnote references never seen
1555 ;; before in DATA.
1556 (org-element-map data 'footnote-reference
1557 (lambda (ref)
1558 (when (org-export-footnote-first-reference-p ref info)
1559 (push ref all-refs)
1560 (when (eq (org-element-property :type ref) 'standard)
1561 (funcall search-refs
1562 (org-export-get-footnote-definition ref info)))))
1563 info)
1564 (reverse all-refs))))
1565 (funcall search-refs element))
1566 ""))
1568 (defun org-latex--translate (s info)
1569 "Translate string S according to specified language.
1570 INFO is a plist used as a communication channel."
1571 (org-export-translate s :latex info))
1573 (defun org-latex--format-spec (info)
1574 "Create a format-spec for document meta-data.
1575 INFO is a plist used as a communication channel."
1576 (let ((language (let ((lang (plist-get info :language)))
1577 (or (cdr (assoc-string lang org-latex-babel-language-alist t))
1578 (nth 1 (assoc-string lang org-latex-polyglossia-language-alist t))
1579 lang))))
1580 `((?a . ,(org-export-data (plist-get info :author) info))
1581 (?t . ,(org-export-data (plist-get info :title) info))
1582 (?k . ,(org-export-data (org-latex--wrap-latex-math-block
1583 (plist-get info :keywords) info)
1584 info))
1585 (?d . ,(org-export-data (org-latex--wrap-latex-math-block
1586 (plist-get info :description) info)
1587 info))
1588 (?c . ,(plist-get info :creator))
1589 (?l . ,language)
1590 (?L . ,(capitalize language))
1591 (?D . ,(org-export-get-date info)))))
1593 (defun org-latex--insert-compiler (info)
1594 "Insert LaTeX_compiler info into the document.
1595 INFO is a plist used as a communication channel."
1596 (let ((compiler (plist-get info :latex-compiler)))
1597 (and (org-string-nw-p org-latex-compiler-file-string)
1598 (member (or compiler "") org-latex-compilers)
1599 (format org-latex-compiler-file-string compiler))))
1602 ;;; Filters
1604 (defun org-latex-matrices-tree-filter (tree _backend info)
1605 (org-latex--wrap-latex-matrices tree info))
1607 (defun org-latex-math-block-tree-filter (tree _backend info)
1608 (org-latex--wrap-latex-math-block tree info))
1610 (defun org-latex-math-block-options-filter (info _backend)
1611 (dolist (prop '(:author :date :title) info)
1612 (plist-put info prop
1613 (org-latex--wrap-latex-math-block (plist-get info prop) info))))
1615 (defun org-latex-clean-invalid-line-breaks (data _backend _info)
1616 (replace-regexp-in-string
1617 "\\(\\end{[A-Za-z0-9*]+}\\|^\\)[ \t]*\\\\\\\\[ \t]*$" "\\1"
1618 data))
1621 ;;; Template
1623 ;;;###autoload
1624 (defun org-latex-make-preamble (info &optional template snippet?)
1625 "Return a formatted LaTeX preamble.
1626 INFO is a plist used as a communication channel. Optional
1627 argument TEMPLATE, when non-nil, is the header template string,
1628 as expected by `org-splice-latex-header'. When SNIPPET? is
1629 non-nil, only includes packages relevant to image generation, as
1630 specified in `org-latex-default-packages-alist' or
1631 `org-latex-packages-alist'."
1632 (let* ((class (plist-get info :latex-class))
1633 (class-template
1634 (or template
1635 (let* ((class-options (plist-get info :latex-class-options))
1636 (header (nth 1 (assoc class (plist-get info :latex-classes)))))
1637 (and (stringp header)
1638 (if (not class-options) header
1639 (replace-regexp-in-string
1640 "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
1641 class-options header t nil 1))))
1642 (user-error "Unknown LaTeX class `%s'" class))))
1643 (org-latex-guess-polyglossia-language
1644 (org-latex-guess-babel-language
1645 (org-latex-guess-inputenc
1646 (org-element-normalize-string
1647 (org-splice-latex-header
1648 class-template
1649 (org-latex--remove-packages org-latex-default-packages-alist info)
1650 (org-latex--remove-packages org-latex-packages-alist info)
1651 snippet?
1652 (mapconcat #'org-element-normalize-string
1653 (list (plist-get info :latex-header)
1654 (and (not snippet?)
1655 (plist-get info :latex-header-extra)))
1656 ""))))
1657 info)
1658 info)))
1660 (defun org-latex-template (contents info)
1661 "Return complete document string after LaTeX conversion.
1662 CONTENTS is the transcoded contents string. INFO is a plist
1663 holding export options."
1664 (let ((title (org-export-data (plist-get info :title) info))
1665 (spec (org-latex--format-spec info)))
1666 (concat
1667 ;; Time-stamp.
1668 (and (plist-get info :time-stamp-file)
1669 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
1670 ;; LaTeX compiler.
1671 (org-latex--insert-compiler info)
1672 ;; Document class and packages.
1673 (org-latex-make-preamble info)
1674 ;; Possibly limit depth for headline numbering.
1675 (let ((sec-num (plist-get info :section-numbers)))
1676 (when (integerp sec-num)
1677 (format "\\setcounter{secnumdepth}{%d}\n" sec-num)))
1678 ;; Author.
1679 (let ((author (and (plist-get info :with-author)
1680 (let ((auth (plist-get info :author)))
1681 (and auth (org-export-data auth info)))))
1682 (email (and (plist-get info :with-email)
1683 (org-export-data (plist-get info :email) info))))
1684 (cond ((and author email (not (string= "" email)))
1685 (format "\\author{%s\\thanks{%s}}\n" author email))
1686 ((or author email) (format "\\author{%s}\n" (or author email)))))
1687 ;; Date.
1688 (let ((date (and (plist-get info :with-date) (org-export-get-date info))))
1689 (format "\\date{%s}\n" (org-export-data date info)))
1690 ;; Title and subtitle.
1691 (let* ((subtitle (plist-get info :subtitle))
1692 (formatted-subtitle
1693 (when subtitle
1694 (format (plist-get info :latex-subtitle-format)
1695 (org-export-data subtitle info))))
1696 (separate (plist-get info :latex-subtitle-separate)))
1697 (concat
1698 (format "\\title{%s%s}\n" title
1699 (if separate "" (or formatted-subtitle "")))
1700 (when (and separate subtitle)
1701 (concat formatted-subtitle "\n"))))
1702 ;; Hyperref options.
1703 (let ((template (plist-get info :latex-hyperref-template)))
1704 (and (stringp template)
1705 (format-spec template spec)))
1706 ;; Document start.
1707 "\\begin{document}\n\n"
1708 ;; Title command.
1709 (let* ((title-command (plist-get info :latex-title-command))
1710 (command (and (stringp title-command)
1711 (format-spec title-command spec))))
1712 (org-element-normalize-string
1713 (cond ((not (plist-get info :with-title)) nil)
1714 ((string= "" title) nil)
1715 ((not (stringp command)) nil)
1716 ((string-match "\\(?:[^%]\\|^\\)%s" command)
1717 (format command title))
1718 (t command))))
1719 ;; Table of contents.
1720 (let ((depth (plist-get info :with-toc)))
1721 (when depth
1722 (concat (when (integerp depth)
1723 (format "\\setcounter{tocdepth}{%d}\n" depth))
1724 (plist-get info :latex-toc-command))))
1725 ;; Document's body.
1726 contents
1727 ;; Creator.
1728 (and (plist-get info :with-creator)
1729 (concat (plist-get info :creator) "\n"))
1730 ;; Document end.
1731 "\\end{document}")))
1735 ;;; Transcode Functions
1737 ;;;; Bold
1739 (defun org-latex-bold (_bold contents info)
1740 "Transcode BOLD from Org to LaTeX.
1741 CONTENTS is the text with bold markup. INFO is a plist holding
1742 contextual information."
1743 (org-latex--text-markup contents 'bold info))
1746 ;;;; Center Block
1748 (defun org-latex-center-block (center-block contents info)
1749 "Transcode a CENTER-BLOCK element from Org to LaTeX.
1750 CONTENTS holds the contents of the center block. INFO is a plist
1751 holding contextual information."
1752 (org-latex--wrap-label
1753 center-block (format "\\begin{center}\n%s\\end{center}" contents) info))
1756 ;;;; Clock
1758 (defun org-latex-clock (clock _contents info)
1759 "Transcode a CLOCK element from Org to LaTeX.
1760 CONTENTS is nil. INFO is a plist holding contextual
1761 information."
1762 (concat
1763 "\\noindent"
1764 (format "\\textbf{%s} " org-clock-string)
1765 (format (plist-get info :latex-inactive-timestamp-format)
1766 (concat (org-timestamp-translate (org-element-property :value clock))
1767 (let ((time (org-element-property :duration clock)))
1768 (and time (format " (%s)" time)))))
1769 "\\\\"))
1772 ;;;; Code
1774 (defun org-latex-code (code _contents info)
1775 "Transcode a CODE object from Org to LaTeX.
1776 CONTENTS is nil. INFO is a plist used as a communication
1777 channel."
1778 (org-latex--text-markup (org-element-property :value code) 'code info))
1781 ;;;; Drawer
1783 (defun org-latex-drawer (drawer contents info)
1784 "Transcode a DRAWER element from Org to LaTeX.
1785 CONTENTS holds the contents of the block. INFO is a plist
1786 holding contextual information."
1787 (let* ((name (org-element-property :drawer-name drawer))
1788 (output (funcall (plist-get info :latex-format-drawer-function)
1789 name contents)))
1790 (org-latex--wrap-label drawer output info)))
1793 ;;;; Dynamic Block
1795 (defun org-latex-dynamic-block (dynamic-block contents info)
1796 "Transcode a DYNAMIC-BLOCK element from Org to LaTeX.
1797 CONTENTS holds the contents of the block. INFO is a plist
1798 holding contextual information. See `org-export-data'."
1799 (org-latex--wrap-label dynamic-block contents info))
1802 ;;;; Entity
1804 (defun org-latex-entity (entity _contents _info)
1805 "Transcode an ENTITY object from Org to LaTeX.
1806 CONTENTS are the definition itself. INFO is a plist holding
1807 contextual information."
1808 (org-element-property :latex entity))
1811 ;;;; Example Block
1813 (defun org-latex-example-block (example-block _contents info)
1814 "Transcode an EXAMPLE-BLOCK element from Org to LaTeX.
1815 CONTENTS is nil. INFO is a plist holding contextual
1816 information."
1817 (when (org-string-nw-p (org-element-property :value example-block))
1818 (let ((environment (or (org-export-read-attribute
1819 :attr_latex example-block :environment)
1820 "verbatim")))
1821 (org-latex--wrap-label
1822 example-block
1823 (format "\\begin{%s}\n%s\\end{%s}"
1824 environment
1825 (org-export-format-code-default example-block info)
1826 environment)
1827 info))))
1830 ;;;; Export Block
1832 (defun org-latex-export-block (export-block _contents _info)
1833 "Transcode a EXPORT-BLOCK element from Org to LaTeX.
1834 CONTENTS is nil. INFO is a plist holding contextual information."
1835 (when (member (org-element-property :type export-block) '("LATEX" "TEX"))
1836 (org-remove-indentation (org-element-property :value export-block))))
1839 ;;;; Export Snippet
1841 (defun org-latex-export-snippet (export-snippet _contents _info)
1842 "Transcode a EXPORT-SNIPPET object from Org to LaTeX.
1843 CONTENTS is nil. INFO is a plist holding contextual information."
1844 (when (eq (org-export-snippet-backend export-snippet) 'latex)
1845 (org-element-property :value export-snippet)))
1848 ;;;; Fixed Width
1850 (defun org-latex-fixed-width (fixed-width _contents info)
1851 "Transcode a FIXED-WIDTH element from Org to LaTeX.
1852 CONTENTS is nil. INFO is a plist holding contextual information."
1853 (org-latex--wrap-label
1854 fixed-width
1855 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1856 (org-remove-indentation
1857 (org-element-property :value fixed-width)))
1858 info))
1861 ;;;; Footnote Reference
1863 (defun org-latex-footnote-reference (footnote-reference _contents info)
1864 "Transcode a FOOTNOTE-REFERENCE element from Org to LaTeX.
1865 CONTENTS is nil. INFO is a plist holding contextual information."
1866 (let ((label (org-element-property :label footnote-reference)))
1867 (concat
1868 ;; Insert separator between two footnotes in a row.
1869 (let ((prev (org-export-get-previous-element footnote-reference info)))
1870 (when (eq (org-element-type prev) 'footnote-reference)
1871 (plist-get info :latex-footnote-separator)))
1872 (cond
1873 ;; Use `:latex-footnote-defined-format' if the footnote has
1874 ;; already been defined.
1875 ((not (org-export-footnote-first-reference-p footnote-reference info))
1876 (format (plist-get info :latex-footnote-defined-format)
1877 (org-latex--label
1878 (org-export-get-footnote-definition footnote-reference info)
1879 info t)))
1880 ;; Use \footnotemark if reference is within another footnote
1881 ;; reference, footnote definition or table cell.
1882 ((org-element-lineage footnote-reference
1883 '(footnote-reference footnote-definition table-cell))
1884 "\\footnotemark")
1885 ;; Otherwise, define it with \footnote command.
1887 (let ((def (org-export-get-footnote-definition footnote-reference info)))
1888 (concat
1889 (format "\\footnote{%s%s}" (org-trim (org-export-data def info))
1890 ;; Only insert a \label if there exist another
1891 ;; reference to def.
1892 (cond ((not label) "")
1893 ((org-element-map (plist-get info :parse-tree) 'footnote-reference
1894 (lambda (f)
1895 (and (not (eq f footnote-reference))
1896 (equal (org-element-property :label f) label)
1897 (org-trim (org-latex--label def info t t))))
1898 info t))
1899 (t "")))
1900 ;; Retrieve all footnote references within the footnote and
1901 ;; add their definition after it, since LaTeX doesn't support
1902 ;; them inside.
1903 (org-latex--delayed-footnotes-definitions def info))))))))
1906 ;;;; Headline
1908 (defun org-latex-headline (headline contents info)
1909 "Transcode a HEADLINE element from Org to LaTeX.
1910 CONTENTS holds the contents of the headline. INFO is a plist
1911 holding contextual information."
1912 (unless (org-element-property :footnote-section-p headline)
1913 (let* ((class (plist-get info :latex-class))
1914 (level (org-export-get-relative-level headline info))
1915 (numberedp (org-export-numbered-headline-p headline info))
1916 (class-sectioning (assoc class (plist-get info :latex-classes)))
1917 ;; Section formatting will set two placeholders: one for
1918 ;; the title and the other for the contents.
1919 (section-fmt
1920 (let ((sec (if (functionp (nth 2 class-sectioning))
1921 (funcall (nth 2 class-sectioning) level numberedp)
1922 (nth (1+ level) class-sectioning))))
1923 (cond
1924 ;; No section available for that LEVEL.
1925 ((not sec) nil)
1926 ;; Section format directly returned by a function. Add
1927 ;; placeholder for contents.
1928 ((stringp sec) (concat sec "\n%s"))
1929 ;; (numbered-section . unnumbered-section)
1930 ((not (consp (cdr sec)))
1931 (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
1932 ;; (numbered-open numbered-close)
1933 ((= (length sec) 2)
1934 (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
1935 ;; (num-in num-out no-num-in no-num-out)
1936 ((= (length sec) 4)
1937 (if numberedp (concat (car sec) "\n%s" (nth 1 sec))
1938 (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
1939 ;; Create a temporary export back-end that hard-codes
1940 ;; "\underline" within "\section" and alike.
1941 (section-back-end
1942 (org-export-create-backend
1943 :parent 'latex
1944 :transcoders
1945 '((underline . (lambda (o c i) (format "\\underline{%s}" c))))))
1946 (text
1947 (org-export-data-with-backend
1948 (org-element-property :title headline) section-back-end info))
1949 (todo
1950 (and (plist-get info :with-todo-keywords)
1951 (let ((todo (org-element-property :todo-keyword headline)))
1952 (and todo (org-export-data todo info)))))
1953 (todo-type (and todo (org-element-property :todo-type headline)))
1954 (tags (and (plist-get info :with-tags)
1955 (org-export-get-tags headline info)))
1956 (priority (and (plist-get info :with-priority)
1957 (org-element-property :priority headline)))
1958 ;; Create the headline text along with a no-tag version.
1959 ;; The latter is required to remove tags from toc.
1960 (full-text (funcall (plist-get info :latex-format-headline-function)
1961 todo todo-type priority text tags info))
1962 ;; Associate \label to the headline for internal links.
1963 (headline-label (org-latex--label headline info t t))
1964 (pre-blanks
1965 (make-string (org-element-property :pre-blank headline) ?\n)))
1966 (if (or (not section-fmt) (org-export-low-level-p headline info))
1967 ;; This is a deep sub-tree: export it as a list item. Also
1968 ;; export as items headlines for which no section format has
1969 ;; been found.
1970 (let ((low-level-body
1971 (concat
1972 ;; If headline is the first sibling, start a list.
1973 (when (org-export-first-sibling-p headline info)
1974 (format "\\begin{%s}\n" (if numberedp 'enumerate 'itemize)))
1975 ;; Itemize headline
1976 "\\item"
1977 (and full-text
1978 (string-match-p "\\`[ \t]*\\[" full-text)
1979 "\\relax")
1980 " " full-text "\n"
1981 headline-label
1982 pre-blanks
1983 contents)))
1984 ;; If headline is not the last sibling simply return
1985 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before
1986 ;; any blank line.
1987 (if (not (org-export-last-sibling-p headline info)) low-level-body
1988 (replace-regexp-in-string
1989 "[ \t\n]*\\'"
1990 (format "\n\\\\end{%s}" (if numberedp 'enumerate 'itemize))
1991 low-level-body)))
1992 ;; This is a standard headline. Export it as a section. Add
1993 ;; an alternative heading when possible, and when this is not
1994 ;; identical to the usual heading.
1995 (let ((opt-title
1996 (funcall (plist-get info :latex-format-headline-function)
1997 todo todo-type priority
1998 (org-export-data-with-backend
1999 (org-export-get-alt-title headline info)
2000 section-back-end info)
2001 (and (eq (plist-get info :with-tags) t) tags)
2002 info))
2003 ;; Maybe end local TOC (see `org-latex-keyword').
2004 (contents
2005 (concat
2006 contents
2007 (let ((case-fold-search t)
2008 (section
2009 (let ((first (car (org-element-contents headline))))
2010 (and (eq (org-element-type first) 'section) first))))
2011 (org-element-map section 'keyword
2012 (lambda (k)
2013 (and (equal (org-element-property :key k) "TOC")
2014 (let ((v (org-element-property :value k)))
2015 (and (string-match-p "\\<headlines\\>" v)
2016 (string-match-p "\\<local\\>" v)
2017 (format "\\stopcontents[level-%d]" level)))))
2018 info t)))))
2019 (if (and opt-title
2020 (not (equal opt-title full-text))
2021 (string-match "\\`\\\\\\(.+?\\){" section-fmt))
2022 (format (replace-match "\\1[%s]" nil nil section-fmt 1)
2023 ;; Replace square brackets with parenthesis
2024 ;; since square brackets are not supported in
2025 ;; optional arguments.
2026 (replace-regexp-in-string
2027 "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title))
2028 full-text
2029 (concat headline-label pre-blanks contents))
2030 ;; Impossible to add an alternative heading. Fallback to
2031 ;; regular sectioning format string.
2032 (format section-fmt full-text
2033 (concat headline-label pre-blanks contents))))))))
2035 (defun org-latex-format-headline-default-function
2036 (todo _todo-type priority text tags _info)
2037 "Default format function for a headline.
2038 See `org-latex-format-headline-function' for details."
2039 (concat
2040 (and todo (format "{\\bfseries\\sffamily %s} " todo))
2041 (and priority (format "\\framebox{\\#%c} " priority))
2042 text
2043 (and tags
2044 (format "\\hfill{}\\textsc{%s}"
2045 (mapconcat #'org-latex--protect-text tags ":")))))
2048 ;;;; Horizontal Rule
2050 (defun org-latex-horizontal-rule (horizontal-rule _contents info)
2051 "Transcode an HORIZONTAL-RULE object from Org to LaTeX.
2052 CONTENTS is nil. INFO is a plist holding contextual information."
2053 (let ((attr (org-export-read-attribute :attr_latex horizontal-rule))
2054 (prev (org-export-get-previous-element horizontal-rule info)))
2055 (concat
2056 ;; Make sure the rule doesn't start at the end of the current
2057 ;; line by separating it with a blank line from previous element.
2058 (when (and prev
2059 (let ((prev-blank (org-element-property :post-blank prev)))
2060 (or (not prev-blank) (zerop prev-blank))))
2061 "\n")
2062 (org-latex--wrap-label
2063 horizontal-rule
2064 (format "\\noindent\\rule{%s}{%s}"
2065 (or (plist-get attr :width) "\\textwidth")
2066 (or (plist-get attr :thickness) "0.5pt"))
2067 info))))
2070 ;;;; Inline Src Block
2072 (defun org-latex-inline-src-block (inline-src-block _contents info)
2073 "Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
2074 CONTENTS holds the contents of the item. INFO is a plist holding
2075 contextual information."
2076 (let* ((code (org-element-property :value inline-src-block))
2077 (separator (org-latex--find-verb-separator code)))
2078 (cl-case (plist-get info :latex-listings)
2079 ;; Do not use a special package: transcode it verbatim.
2080 ((nil) (format "\\texttt{%s}" (org-latex--text-markup code 'code info)))
2081 ;; Use minted package.
2082 (minted
2083 (let* ((org-lang (org-element-property :language inline-src-block))
2084 (mint-lang (or (cadr (assq (intern org-lang)
2085 (plist-get info :latex-minted-langs)))
2086 (downcase org-lang)))
2087 (options (org-latex--make-option-string
2088 (plist-get info :latex-minted-options))))
2089 (format "\\mintinline%s{%s}{%s}"
2090 (if (string= options "") "" (format "[%s]" options))
2091 mint-lang
2092 code)))
2093 ;; Use listings package.
2094 (otherwise
2095 ;; Maybe translate language's name.
2096 (let* ((org-lang (org-element-property :language inline-src-block))
2097 (lst-lang (or (cadr (assq (intern org-lang)
2098 (plist-get info :latex-listings-langs)))
2099 org-lang))
2100 (options (org-latex--make-option-string
2101 (append (plist-get info :latex-listings-options)
2102 `(("language" ,lst-lang))))))
2103 (concat (format "\\lstinline[%s]" options)
2104 separator code separator))))))
2107 ;;;; Inlinetask
2109 (defun org-latex-inlinetask (inlinetask contents info)
2110 "Transcode an INLINETASK element from Org to LaTeX.
2111 CONTENTS holds the contents of the block. INFO is a plist
2112 holding contextual information."
2113 (let ((title (org-export-data (org-element-property :title inlinetask) info))
2114 (todo (and (plist-get info :with-todo-keywords)
2115 (let ((todo (org-element-property :todo-keyword inlinetask)))
2116 (and todo (org-export-data todo info)))))
2117 (todo-type (org-element-property :todo-type inlinetask))
2118 (tags (and (plist-get info :with-tags)
2119 (org-export-get-tags inlinetask info)))
2120 (priority (and (plist-get info :with-priority)
2121 (org-element-property :priority inlinetask)))
2122 (contents (concat (org-latex--label inlinetask info) contents)))
2123 (funcall (plist-get info :latex-format-inlinetask-function)
2124 todo todo-type priority title tags contents info)))
2126 (defun org-latex-format-inlinetask-default-function
2127 (todo _todo-type priority title tags contents _info)
2128 "Default format function for inlinetasks.
2129 See `org-latex-format-inlinetask-function' for details."
2130 (let ((full-title
2131 (concat (when todo (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
2132 (when priority (format "\\framebox{\\#%c} " priority))
2133 title
2134 (when tags
2135 (format "\\hfill{}\\textsc{%s}"
2136 (org-make-tag-string
2137 (mapcar #'org-latex--protect-text tags)))))))
2138 (concat "\\begin{center}\n"
2139 "\\fbox{\n"
2140 "\\begin{minipage}[c]{.6\\textwidth}\n"
2141 full-title "\n\n"
2142 (and (org-string-nw-p contents)
2143 (concat "\\rule[.8em]{\\textwidth}{2pt}\n\n" contents))
2144 "\\end{minipage}\n"
2145 "}\n"
2146 "\\end{center}")))
2149 ;;;; Italic
2151 (defun org-latex-italic (_italic contents info)
2152 "Transcode ITALIC from Org to LaTeX.
2153 CONTENTS is the text with italic markup. INFO is a plist holding
2154 contextual information."
2155 (org-latex--text-markup contents 'italic info))
2158 ;;;; Item
2160 (defun org-latex-item (item contents info)
2161 "Transcode an ITEM element from Org to LaTeX.
2162 CONTENTS holds the contents of the item. INFO is a plist holding
2163 contextual information."
2164 (let* ((counter
2165 (let ((count (org-element-property :counter item))
2166 (level
2167 ;; Determine level of current item to determine the
2168 ;; correct LaTeX counter to use (enumi, enumii...).
2169 (let ((parent item) (level 0))
2170 (while (memq (org-element-type
2171 (setq parent (org-export-get-parent parent)))
2172 '(plain-list item))
2173 (when (and (eq (org-element-type parent) 'plain-list)
2174 (eq (org-element-property :type parent)
2175 'ordered))
2176 (cl-incf level)))
2177 level)))
2178 (and count
2179 (< level 5)
2180 (format "\\setcounter{enum%s}{%s}\n"
2181 (nth (1- level) '("i" "ii" "iii" "iv"))
2182 (1- count)))))
2183 (checkbox (cl-case (org-element-property :checkbox item)
2184 (on "$\\boxtimes$")
2185 (off "$\\square$")
2186 (trans "$\\boxminus$")))
2187 (tag (let ((tag (org-element-property :tag item)))
2188 (and tag (org-export-data tag info)))))
2189 (concat counter
2190 "\\item"
2191 (cond
2192 ((and checkbox tag) (format "[{%s %s}] " checkbox tag))
2193 ((or checkbox tag) (format "[{%s}] " (or checkbox tag)))
2194 ;; Without a tag or a check-box, if CONTENTS starts with
2195 ;; an opening square bracket, add "\relax" to "\item",
2196 ;; unless the brackets comes from an initial export
2197 ;; snippet (i.e. it is inserted willingly by the user).
2198 ((and contents
2199 (string-match-p "\\`[ \t]*\\[" contents)
2200 (not (let ((e (car (org-element-contents item))))
2201 (and (eq (org-element-type e) 'paragraph)
2202 (let ((o (car (org-element-contents e))))
2203 (and (eq (org-element-type o) 'export-snippet)
2204 (eq (org-export-snippet-backend o)
2205 'latex)))))))
2206 "\\relax ")
2207 (t " "))
2208 (and contents (org-trim contents))
2209 ;; If there are footnotes references in tag, be sure to
2210 ;; add their definition at the end of the item. This
2211 ;; workaround is necessary since "\footnote{}" command is
2212 ;; not supported in tags.
2213 (and tag
2214 (org-latex--delayed-footnotes-definitions
2215 (org-element-property :tag item) info)))))
2218 ;;;; Keyword
2220 (defun org-latex-keyword (keyword _contents info)
2221 "Transcode a KEYWORD element from Org to LaTeX.
2222 CONTENTS is nil. INFO is a plist holding contextual information."
2223 (let ((key (org-element-property :key keyword))
2224 (value (org-element-property :value keyword)))
2225 (cond
2226 ((string= key "LATEX") value)
2227 ((string= key "INDEX") (format "\\index{%s}" value))
2228 ((string= key "TOC")
2229 (let ((case-fold-search t))
2230 (cond
2231 ((string-match-p "\\<headlines\\>" value)
2232 (let* ((localp (string-match-p "\\<local\\>" value))
2233 (parent (org-element-lineage keyword '(headline)))
2234 (level (if (not (and localp parent)) 0
2235 (org-export-get-relative-level parent info)))
2236 (depth
2237 (and (string-match "\\<[0-9]+\\>" value)
2238 (format
2239 "\\setcounter{tocdepth}{%d}"
2240 (+ (string-to-number (match-string 0 value)) level)))))
2241 (if (and localp parent)
2242 ;; Start local TOC, assuming package "titletoc" is
2243 ;; required.
2244 (format "\\startcontents[level-%d]
2245 \\printcontents[level-%d]{}{0}{%s}"
2246 level level (or depth ""))
2247 (concat depth (and depth "\n") "\\tableofcontents"))))
2248 ((string-match-p "\\<tables\\>" value) "\\listoftables")
2249 ((string-match-p "\\<listings\\>" value)
2250 (cl-case (plist-get info :latex-listings)
2251 ((nil) "\\listoffigures")
2252 (minted "\\listoflistings")
2253 (otherwise "\\lstlistoflistings")))))))))
2256 ;;;; Latex Environment
2258 (defun org-latex--environment-type (latex-environment)
2259 "Return the TYPE of LATEX-ENVIRONMENT.
2261 The TYPE is determined from the actual latex environment, and
2262 could be a member of `org-latex-caption-above' or `math'."
2263 (let* ((latex-begin-re "\\\\begin{\\([A-Za-z0-9*]+\\)}")
2264 (value (org-remove-indentation
2265 (org-element-property :value latex-environment)))
2266 (env (or (and (string-match latex-begin-re value)
2267 (match-string 1 value))
2268 "")))
2269 (cond
2270 ((string-match-p org-latex-math-environments-re value) 'math)
2271 ((string-match-p
2272 (eval-when-compile
2273 (regexp-opt '("table" "longtable" "tabular" "tabu" "longtabu")))
2274 env)
2275 'table)
2276 ((string-match-p "figure" env) 'image)
2277 ((string-match-p
2278 (eval-when-compile
2279 (regexp-opt '("lstlisting" "listing" "verbatim" "minted")))
2280 env)
2281 'src-block)
2282 (t 'special-block))))
2284 (defun org-latex-latex-environment (latex-environment _contents info)
2285 "Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
2286 CONTENTS is nil. INFO is a plist holding contextual information."
2287 (when (plist-get info :with-latex)
2288 (let* ((value (org-remove-indentation
2289 (org-element-property :value latex-environment)))
2290 (type (org-latex--environment-type latex-environment))
2291 (caption (if (eq type 'math)
2292 (org-latex--label latex-environment info nil t)
2293 (org-latex--caption/label-string latex-environment info)))
2294 (caption-above-p
2295 (memq type (append (plist-get info :latex-caption-above) '(math)))))
2296 (if (not (or (org-element-property :name latex-environment)
2297 (org-element-property :caption latex-environment)))
2298 value
2299 ;; Environment is labeled: label must be within the environment
2300 ;; (otherwise, a reference pointing to that element will count
2301 ;; the section instead). Also insert caption if `latex-environment'
2302 ;; is not a math environment.
2303 (with-temp-buffer
2304 (insert value)
2305 (if caption-above-p
2306 (progn
2307 (goto-char (point-min))
2308 (forward-line))
2309 (goto-char (point-max))
2310 (forward-line -1))
2311 (insert caption)
2312 (buffer-string))))))
2314 ;;;; Latex Fragment
2316 (defun org-latex-latex-fragment (latex-fragment _contents _info)
2317 "Transcode a LATEX-FRAGMENT object from Org to LaTeX.
2318 CONTENTS is nil. INFO is a plist holding contextual information."
2319 (let ((value (org-element-property :value latex-fragment)))
2320 ;; Trim math markers since the fragment is enclosed within
2321 ;; a latex-math-block object anyway.
2322 (cond ((string-match-p "\\`\\$[^$]" value) (substring value 1 -1))
2323 ((string-prefix-p "\\(" value) (substring value 2 -2))
2324 (t value))))
2327 ;;;; Line Break
2329 (defun org-latex-line-break (_line-break _contents _info)
2330 "Transcode a LINE-BREAK object from Org to LaTeX.
2331 CONTENTS is nil. INFO is a plist holding contextual information."
2332 "\\\\\n")
2335 ;;;; Link
2337 (defun org-latex-image-link-filter (data _backend info)
2338 (org-export-insert-image-links data info org-latex-inline-image-rules))
2340 (defun org-latex--inline-image (link info)
2341 "Return LaTeX code for an inline image.
2342 LINK is the link pointing to the inline image. INFO is a plist
2343 used as a communication channel."
2344 (let* ((parent (org-export-get-parent-element link))
2345 (path (let ((raw-path (org-element-property :path link)))
2346 (if (not (file-name-absolute-p raw-path)) raw-path
2347 (expand-file-name raw-path))))
2348 (filetype (file-name-extension path))
2349 (caption (org-latex--caption/label-string parent info))
2350 (caption-above-p (org-latex--caption-above-p link info))
2351 ;; Retrieve latex attributes from the element around.
2352 (attr (org-export-read-attribute :attr_latex parent))
2353 (float (let ((float (plist-get attr :float)))
2354 (cond ((string= float "wrap") 'wrap)
2355 ((string= float "sideways") 'sideways)
2356 ((string= float "multicolumn") 'multicolumn)
2357 ((and (plist-member attr :float) (not float)) 'nonfloat)
2358 ((or float
2359 (org-element-property :caption parent)
2360 (org-string-nw-p (plist-get attr :caption)))
2361 'figure)
2362 (t 'nonfloat))))
2363 (placement
2364 (let ((place (plist-get attr :placement)))
2365 (cond
2366 (place (format "%s" place))
2367 ((eq float 'wrap) "{l}{0.5\\textwidth}")
2368 ((eq float 'figure)
2369 (format "[%s]" (plist-get info :latex-default-figure-position)))
2370 (t ""))))
2371 (center
2372 (if (plist-member attr :center) (plist-get attr :center)
2373 (plist-get info :latex-images-centered)))
2374 (comment-include (if (plist-get attr :comment-include) "%" ""))
2375 ;; It is possible to specify width and height in the
2376 ;; ATTR_LATEX line, and also via default variables.
2377 (width (cond ((plist-get attr :width))
2378 ((plist-get attr :height) "")
2379 ((eq float 'wrap) "0.48\\textwidth")
2380 (t (plist-get info :latex-image-default-width))))
2381 (height (cond ((plist-get attr :height))
2382 ((or (plist-get attr :width)
2383 (memq float '(figure wrap))) "")
2384 (t (plist-get info :latex-image-default-height))))
2385 (options (let ((opt (or (plist-get attr :options)
2386 (plist-get info :latex-image-default-option))))
2387 (if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt)) opt
2388 (match-string 1 opt))))
2389 image-code)
2390 (if (member filetype '("tikz" "pgf"))
2391 ;; For tikz images:
2392 ;; - use \input to read in image file.
2393 ;; - if options are present, wrap in a tikzpicture environment.
2394 ;; - if width or height are present, use \resizebox to change
2395 ;; the image size.
2396 (progn
2397 (setq image-code (format "\\input{%s}" path))
2398 (when (org-string-nw-p options)
2399 (setq image-code
2400 (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
2401 options
2402 image-code)))
2403 (when (or (org-string-nw-p width) (org-string-nw-p height))
2404 (setq image-code (format "\\resizebox{%s}{%s}{%s}"
2405 (if (org-string-nw-p width) width "!")
2406 (if (org-string-nw-p height) height "!")
2407 image-code))))
2408 ;; For other images:
2409 ;; - add width and height to options.
2410 ;; - include the image with \includegraphics.
2411 (when (org-string-nw-p width)
2412 (setq options (concat options ",width=" width)))
2413 (when (org-string-nw-p height)
2414 (setq options (concat options ",height=" height)))
2415 (let ((search-option (org-element-property :search-option link)))
2416 (when (and search-option
2417 (equal filetype "pdf")
2418 (string-match-p "\\`[0-9]+\\'" search-option)
2419 (not (string-match-p "page=" options)))
2420 (setq options (concat options ",page=" search-option))))
2421 (setq image-code
2422 (format "\\includegraphics%s{%s}"
2423 (cond ((not (org-string-nw-p options)) "")
2424 ((string-prefix-p "," options)
2425 (format "[%s]" (substring options 1)))
2426 (t (format "[%s]" options)))
2427 path))
2428 (when (equal filetype "svg")
2429 (setq image-code (replace-regexp-in-string "^\\\\includegraphics"
2430 "\\includesvg"
2431 image-code
2432 nil t))
2433 (setq image-code (replace-regexp-in-string "\\.svg}"
2435 image-code
2436 nil t))))
2437 ;; Return proper string, depending on FLOAT.
2438 (pcase float
2439 (`wrap (format "\\begin{wrapfigure}%s
2440 %s%s
2441 %s%s
2442 %s\\end{wrapfigure}"
2443 placement
2444 (if caption-above-p caption "")
2445 (if center "\\centering" "")
2446 comment-include image-code
2447 (if caption-above-p "" caption)))
2448 (`sideways (format "\\begin{sidewaysfigure}
2449 %s%s
2450 %s%s
2451 %s\\end{sidewaysfigure}"
2452 (if caption-above-p caption "")
2453 (if center "\\centering" "")
2454 comment-include image-code
2455 (if caption-above-p "" caption)))
2456 (`multicolumn (format "\\begin{figure*}%s
2457 %s%s
2458 %s%s
2459 %s\\end{figure*}"
2460 placement
2461 (if caption-above-p caption "")
2462 (if center "\\centering" "")
2463 comment-include image-code
2464 (if caption-above-p "" caption)))
2465 (`figure (format "\\begin{figure}%s
2466 %s%s
2467 %s%s
2468 %s\\end{figure}"
2469 placement
2470 (if caption-above-p caption "")
2471 (if center "\\centering" "")
2472 comment-include image-code
2473 (if caption-above-p "" caption)))
2474 ((guard center)
2475 (format "\\begin{center}
2476 %s%s
2477 %s\\end{center}"
2478 (if caption-above-p caption "")
2479 image-code
2480 (if caption-above-p "" caption)))
2482 (concat (if caption-above-p caption "")
2483 image-code
2484 (if caption-above-p caption ""))))))
2486 (defun org-latex-link (link desc info)
2487 "Transcode a LINK object from Org to LaTeX.
2489 DESC is the description part of the link, or the empty string.
2490 INFO is a plist holding contextual information. See
2491 `org-export-data'."
2492 (let* ((type (org-element-property :type link))
2493 (raw-path (org-element-property :path link))
2494 ;; Ensure DESC really exists, or set it to nil.
2495 (desc (and (not (string= desc "")) desc))
2496 (imagep (org-export-inline-image-p
2497 link (plist-get info :latex-inline-image-rules)))
2498 (path (org-latex--protect-text
2499 (cond ((member type '("http" "https" "ftp" "mailto" "doi"))
2500 (concat type ":" raw-path))
2501 ((string= type "file") (org-export-file-uri raw-path))
2502 (t raw-path)))))
2503 (cond
2504 ;; Link type is handled by a special function.
2505 ((org-export-custom-protocol-maybe link desc 'latex))
2506 ;; Image file.
2507 (imagep (org-latex--inline-image link info))
2508 ;; Radio link: Transcode target's contents and use them as link's
2509 ;; description.
2510 ((string= type "radio")
2511 (let ((destination (org-export-resolve-radio-link link info)))
2512 (if (not destination) desc
2513 (format "\\hyperref[%s]{%s}"
2514 (org-export-get-reference destination info)
2515 desc))))
2516 ;; Links pointing to a headline: Find destination and build
2517 ;; appropriate referencing command.
2518 ((member type '("custom-id" "fuzzy" "id"))
2519 (let ((destination (if (string= type "fuzzy")
2520 (org-export-resolve-fuzzy-link link info)
2521 (org-export-resolve-id-link link info))))
2522 (cl-case (org-element-type destination)
2523 ;; Id link points to an external file.
2524 (plain-text
2525 (if desc (format "\\href{%s}{%s}" destination desc)
2526 (format "\\url{%s}" destination)))
2527 ;; Fuzzy link points nowhere.
2528 ((nil)
2529 (format (plist-get info :latex-link-with-unknown-path-format)
2530 (or desc
2531 (org-export-data
2532 (org-element-property :raw-link link) info))))
2533 ;; LINK points to a headline. If headlines are numbered
2534 ;; and the link has no description, display headline's
2535 ;; number. Otherwise, display description or headline's
2536 ;; title.
2537 (headline
2538 (let ((label (org-latex--label destination info t)))
2539 (if (and (not desc)
2540 (org-export-numbered-headline-p destination info))
2541 (format "\\ref{%s}" label)
2542 (format "\\hyperref[%s]{%s}" label
2543 (or desc
2544 (org-export-data
2545 (org-element-property :title destination) info))))))
2546 ;; Fuzzy link points to a target. Do as above.
2547 (otherwise
2548 (let ((ref (org-latex--label destination info t)))
2549 (if (not desc) (format "\\ref{%s}" ref)
2550 (format "\\hyperref[%s]{%s}" ref desc)))))))
2551 ;; Coderef: replace link with the reference name or the
2552 ;; equivalent line number.
2553 ((string= type "coderef")
2554 (format (org-export-get-coderef-format path desc)
2555 (org-export-resolve-coderef path info)))
2556 ;; External link with a description part.
2557 ((and path desc) (format "\\href{%s}{%s}" path desc))
2558 ;; External link without a description part.
2559 (path (format "\\url{%s}" path))
2560 ;; No path, only description. Try to do something useful.
2561 (t (format (plist-get info :latex-link-with-unknown-path-format) desc)))))
2564 ;;;; Node Property
2566 (defun org-latex-node-property (node-property _contents _info)
2567 "Transcode a NODE-PROPERTY element from Org to LaTeX.
2568 CONTENTS is nil. INFO is a plist holding contextual
2569 information."
2570 (format "%s:%s"
2571 (org-element-property :key node-property)
2572 (let ((value (org-element-property :value node-property)))
2573 (if value (concat " " value) ""))))
2576 ;;;; Paragraph
2578 (defun org-latex-paragraph (_paragraph contents _info)
2579 "Transcode a PARAGRAPH element from Org to LaTeX.
2580 CONTENTS is the contents of the paragraph, as a string. INFO is
2581 the plist used as a communication channel."
2582 contents)
2585 ;;;; Plain List
2587 (defun org-latex-plain-list (plain-list contents info)
2588 "Transcode a PLAIN-LIST element from Org to LaTeX.
2589 CONTENTS is the contents of the list. INFO is a plist holding
2590 contextual information."
2591 (let* ((type (org-element-property :type plain-list))
2592 (attr (org-export-read-attribute :attr_latex plain-list))
2593 (latex-type (let ((env (plist-get attr :environment)))
2594 (cond (env (format "%s" env))
2595 ((eq type 'ordered) "enumerate")
2596 ((eq type 'descriptive) "description")
2597 (t "itemize")))))
2598 (org-latex--wrap-label
2599 plain-list
2600 (format "\\begin{%s}%s\n%s\\end{%s}"
2601 latex-type
2602 (or (plist-get attr :options) "")
2603 contents
2604 latex-type)
2605 info)))
2608 ;;;; Plain Text
2610 (defun org-latex-plain-text (text info)
2611 "Transcode a TEXT string from Org to LaTeX.
2612 TEXT is the string to transcode. INFO is a plist holding
2613 contextual information."
2614 (let* ((specialp (plist-get info :with-special-strings))
2615 (output
2616 ;; Turn LaTeX into \LaTeX{} and TeX into \TeX{}.
2617 (let ((case-fold-search nil))
2618 (replace-regexp-in-string
2619 "\\<\\(?:La\\)?TeX\\>" "\\\\\\&{}"
2620 ;; Protect ^, ~, %, #, &, $, _, { and }. Also protect \.
2621 ;; However, if special strings are used, be careful not
2622 ;; to protect "\" in "\-" constructs.
2623 (replace-regexp-in-string
2624 (concat "[%$#&{}_~^]\\|\\\\" (and specialp "\\([^-]\\|$\\)"))
2625 (lambda (m)
2626 (cl-case (string-to-char m)
2627 (?\\ "$\\\\backslash$\\1")
2628 (?~ "\\\\textasciitilde{}")
2629 (?^ "\\\\^{}")
2630 (t "\\\\\\&")))
2631 text)))))
2632 ;; Activate smart quotes. Be sure to provide original TEXT string
2633 ;; since OUTPUT may have been modified.
2634 (when (plist-get info :with-smart-quotes)
2635 (setq output (org-export-activate-smart-quotes output :latex info text)))
2636 ;; Convert special strings.
2637 (when specialp
2638 (setq output (replace-regexp-in-string "\\.\\.\\." "\\\\ldots{}" output)))
2639 ;; Handle break preservation if required.
2640 (when (plist-get info :preserve-breaks)
2641 (setq output (replace-regexp-in-string
2642 "\\(?:[ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n" output nil t)))
2643 ;; Return value.
2644 output))
2647 ;;;; Planning
2649 (defun org-latex-planning (planning _contents info)
2650 "Transcode a PLANNING element from Org to LaTeX.
2651 CONTENTS is nil. INFO is a plist holding contextual
2652 information."
2653 (concat
2654 "\\noindent"
2655 (mapconcat
2656 'identity
2657 (delq nil
2658 (list
2659 (let ((closed (org-element-property :closed planning)))
2660 (when closed
2661 (concat
2662 (format "\\textbf{%s} " org-closed-string)
2663 (format (plist-get info :latex-inactive-timestamp-format)
2664 (org-timestamp-translate closed)))))
2665 (let ((deadline (org-element-property :deadline planning)))
2666 (when deadline
2667 (concat
2668 (format "\\textbf{%s} " org-deadline-string)
2669 (format (plist-get info :latex-active-timestamp-format)
2670 (org-timestamp-translate deadline)))))
2671 (let ((scheduled (org-element-property :scheduled planning)))
2672 (when scheduled
2673 (concat
2674 (format "\\textbf{%s} " org-scheduled-string)
2675 (format (plist-get info :latex-active-timestamp-format)
2676 (org-timestamp-translate scheduled)))))))
2677 " ")
2678 "\\\\"))
2681 ;;;; Property Drawer
2683 (defun org-latex-property-drawer (_property-drawer contents _info)
2684 "Transcode a PROPERTY-DRAWER element from Org to LaTeX.
2685 CONTENTS holds the contents of the drawer. INFO is a plist
2686 holding contextual information."
2687 (and (org-string-nw-p contents)
2688 (format "\\begin{verbatim}\n%s\\end{verbatim}" contents)))
2691 ;;;; Pseudo Element: LaTeX Matrices
2693 ;; `latex-matrices' elements have the following properties:
2694 ;; `:caption', `:post-blank' and `:markup' (`inline', `equation' or
2695 ;; `math').
2697 (defun org-latex--wrap-latex-matrices (data info)
2698 "Merge contiguous tables with the same mode within a pseudo-element.
2699 DATA is a parse tree or a secondary string. INFO is a plist
2700 containing export options. Modify DATA by side-effect and return
2701 it."
2702 (org-element-map data 'table
2703 (lambda (table)
2704 (when (eq (org-element-property :type table) 'org)
2705 (let ((mode (or (org-export-read-attribute :attr_latex table :mode)
2706 (plist-get info :latex-default-table-mode))))
2707 (when (and (member mode '("inline-math" "math"))
2708 ;; Do not wrap twice the same table.
2709 (not (eq (org-element-type
2710 (org-element-property :parent table))
2711 'latex-matrices)))
2712 (let* ((caption (and (not (string= mode "inline-math"))
2713 (org-element-property :caption table)))
2714 (matrices
2715 (list 'latex-matrices
2716 (list :caption caption
2717 :markup
2718 (cond ((string= mode "inline-math") 'inline)
2719 (caption 'equation)
2720 (t 'math)))))
2721 (previous table)
2722 (next (org-export-get-next-element table info)))
2723 (org-element-insert-before matrices table)
2724 ;; Swallow all contiguous tables sharing the same mode.
2725 (while (and
2726 (zerop (or (org-element-property :post-blank previous) 0))
2727 (setq next (org-export-get-next-element previous info))
2728 (eq (org-element-type next) 'table)
2729 (eq (org-element-property :type next) 'org)
2730 (string= (or (org-export-read-attribute
2731 :attr_latex next :mode)
2732 (plist-get info :latex-default-table-mode))
2733 mode))
2734 (org-element-extract-element previous)
2735 (org-element-adopt-elements matrices previous)
2736 (setq previous next))
2737 ;; Inherit `:post-blank' from the value of the last
2738 ;; swallowed table. Set the latter's `:post-blank'
2739 ;; value to 0 so as to not duplicate empty lines.
2740 (org-element-put-property
2741 matrices :post-blank (org-element-property :post-blank previous))
2742 (org-element-put-property previous :post-blank 0)
2743 (org-element-extract-element previous)
2744 (org-element-adopt-elements matrices previous))))))
2745 info)
2746 data)
2748 (defun org-latex-matrices (matrices contents _info)
2749 "Transcode a MATRICES element from Org to LaTeX.
2750 CONTENTS is a string. INFO is a plist used as a communication
2751 channel."
2752 (format (cl-case (org-element-property :markup matrices)
2753 (inline "\\(%s\\)")
2754 (equation "\\begin{equation}\n%s\\end{equation}")
2755 (t "\\[\n%s\\]"))
2756 contents))
2759 ;;;; Pseudo Object: LaTeX Math Block
2761 ;; `latex-math-block' objects have the following property:
2762 ;; `:post-blank'.
2764 (defun org-latex--wrap-latex-math-block (data info)
2765 "Merge contiguous math objects in a pseudo-object container.
2766 DATA is a parse tree or a secondary string. INFO is a plist
2767 containing export options. Modify DATA by side-effect and return it."
2768 (let ((valid-object-p
2769 ;; Non-nil when OBJ can be added to the latex math block B.
2770 (lambda (obj b)
2771 (pcase (org-element-type obj)
2772 (`entity (org-element-property :latex-math-p obj))
2773 (`latex-fragment
2774 (let ((value (org-element-property :value obj)))
2775 (or (string-prefix-p "\\(" value)
2776 (string-match-p "\\`\\$[^$]" value))))
2777 ((and type (or `subscript `superscript))
2778 (not (memq type (mapcar #'org-element-type
2779 (org-element-contents b)))))))))
2780 (org-element-map data '(entity latex-fragment subscript superscript)
2781 (lambda (object)
2782 ;; Skip objects already wrapped.
2783 (when (and (not (eq (org-element-type
2784 (org-element-property :parent object))
2785 'latex-math-block))
2786 (funcall valid-object-p object nil))
2787 (let ((math-block (list 'latex-math-block nil))
2788 (next-elements (org-export-get-next-element object info t))
2789 (last object))
2790 ;; Wrap MATH-BLOCK around OBJECT in DATA.
2791 (org-element-insert-before math-block object)
2792 (org-element-extract-element object)
2793 (org-element-adopt-elements math-block object)
2794 (when (zerop (or (org-element-property :post-blank object) 0))
2795 ;; MATH-BLOCK swallows consecutive math objects.
2796 (catch 'exit
2797 (dolist (next next-elements)
2798 (unless (funcall valid-object-p next math-block)
2799 (throw 'exit nil))
2800 (org-element-extract-element next)
2801 (org-element-adopt-elements math-block next)
2802 ;; Eschew the case: \beta$x$ -> \(\betax\).
2803 (unless (memq (org-element-type next)
2804 '(subscript superscript))
2805 (org-element-put-property last :post-blank 1))
2806 (setq last next)
2807 (when (> (or (org-element-property :post-blank next) 0) 0)
2808 (throw 'exit nil)))))
2809 (org-element-put-property
2810 math-block :post-blank (org-element-property :post-blank last)))))
2811 info nil '(subscript superscript latex-math-block) t)
2812 ;; Return updated DATA.
2813 data))
2815 (defun org-latex-math-block (_math-block contents _info)
2816 "Transcode a MATH-BLOCK object from Org to LaTeX.
2817 CONTENTS is a string. INFO is a plist used as a communication
2818 channel."
2819 (when (org-string-nw-p contents)
2820 (format "\\(%s\\)" (org-trim contents))))
2822 ;;;; Quote Block
2824 (defun org-latex-quote-block (quote-block contents info)
2825 "Transcode a QUOTE-BLOCK element from Org to LaTeX.
2826 CONTENTS holds the contents of the block. INFO is a plist
2827 holding contextual information."
2828 (org-latex--wrap-label
2829 quote-block (format "\\begin{quote}\n%s\\end{quote}" contents) info))
2832 ;;;; Radio Target
2834 (defun org-latex-radio-target (radio-target text info)
2835 "Transcode a RADIO-TARGET object from Org to LaTeX.
2836 TEXT is the text of the target. INFO is a plist holding
2837 contextual information."
2838 (format "\\label{%s}%s" (org-export-get-reference radio-target info) text))
2841 ;;;; Section
2843 (defun org-latex-section (_section contents _info)
2844 "Transcode a SECTION element from Org to LaTeX.
2845 CONTENTS holds the contents of the section. INFO is a plist
2846 holding contextual information."
2847 contents)
2850 ;;;; Special Block
2852 (defun org-latex-special-block (special-block contents info)
2853 "Transcode a SPECIAL-BLOCK element from Org to LaTeX.
2854 CONTENTS holds the contents of the block. INFO is a plist
2855 holding contextual information."
2856 (let ((type (org-element-property :type special-block))
2857 (opt (org-export-read-attribute :attr_latex special-block :options))
2858 (caption (org-latex--caption/label-string special-block info))
2859 (caption-above-p (org-latex--caption-above-p special-block info)))
2860 (concat (format "\\begin{%s}%s\n" type (or opt ""))
2861 (and caption-above-p caption)
2862 contents
2863 (and (not caption-above-p) caption)
2864 (format "\\end{%s}" type))))
2867 ;;;; Src Block
2869 (defun org-latex-src-block (src-block _contents info)
2870 "Transcode a SRC-BLOCK element from Org to LaTeX.
2871 CONTENTS holds the contents of the item. INFO is a plist holding
2872 contextual information."
2873 (when (org-string-nw-p (org-element-property :value src-block))
2874 (let* ((lang (org-element-property :language src-block))
2875 (caption (org-element-property :caption src-block))
2876 (caption-above-p (org-latex--caption-above-p src-block info))
2877 (label (org-element-property :name src-block))
2878 (custom-env (and lang
2879 (cadr (assq (intern lang)
2880 org-latex-custom-lang-environments))))
2881 (num-start (org-export-get-loc src-block info))
2882 (retain-labels (org-element-property :retain-labels src-block))
2883 (attributes (org-export-read-attribute :attr_latex src-block))
2884 (float (plist-get attributes :float))
2885 (listings (plist-get info :latex-listings)))
2886 (cond
2887 ;; Case 1. No source fontification.
2888 ((not listings)
2889 (let* ((caption-str (org-latex--caption/label-string src-block info))
2890 (float-env
2891 (cond ((string= "multicolumn" float)
2892 (format "\\begin{figure*}[%s]\n%s%%s\n%s\\end{figure*}"
2893 (plist-get info :latex-default-figure-position)
2894 (if caption-above-p caption-str "")
2895 (if caption-above-p "" caption-str)))
2896 (caption (concat
2897 (if caption-above-p caption-str "")
2898 "%s"
2899 (if caption-above-p "" (concat "\n" caption-str))))
2900 (t "%s"))))
2901 (format
2902 float-env
2903 (concat (format "\\begin{verbatim}\n%s\\end{verbatim}"
2904 (org-export-format-code-default src-block info))))))
2905 ;; Case 2. Custom environment.
2906 (custom-env
2907 (let ((caption-str (org-latex--caption/label-string src-block info))
2908 (formatted-src (org-export-format-code-default src-block info)))
2909 (if (string-match-p "\\`[a-zA-Z0-9]+\\'" custom-env)
2910 (format "\\begin{%s}\n%s\\end{%s}\n"
2911 custom-env
2912 (concat (and caption-above-p caption-str)
2913 formatted-src
2914 (and (not caption-above-p) caption-str))
2915 custom-env)
2916 (format-spec custom-env
2917 `((?s . ,formatted-src)
2918 (?c . ,caption)
2919 (?f . ,float)
2920 (?l . ,(org-latex--label src-block info))
2921 (?o . ,(or (plist-get attributes :options) "")))))))
2922 ;; Case 3. Use minted package.
2923 ((eq listings 'minted)
2924 (let* ((caption-str (org-latex--caption/label-string src-block info))
2925 (float-env
2926 (cond
2927 ((string= "multicolumn" float)
2928 (format "\\begin{listing*}[%s]\n%s%%s\n%s\\end{listing*}"
2929 (plist-get info :latex-default-figure-position)
2930 (if caption-above-p caption-str "")
2931 (if caption-above-p "" caption-str)))
2932 (caption
2933 (format "\\begin{listing}[%s]\n%s%%s\n%s\\end{listing}"
2934 (plist-get info :latex-default-figure-position)
2935 (if caption-above-p caption-str "")
2936 (if caption-above-p "" caption-str)))
2937 ((string= "t" float)
2938 (concat (format "\\begin{listing}[%s]\n"
2939 (plist-get info :latex-default-figure-position))
2940 "%s\n\\end{listing}"))
2941 (t "%s")))
2942 (options (plist-get info :latex-minted-options))
2943 (body
2944 (format
2945 "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
2946 ;; Options.
2947 (concat
2948 (org-latex--make-option-string
2949 (if (or (not num-start) (assoc "linenos" options))
2950 options
2951 (append
2952 `(("linenos")
2953 ("firstnumber" ,(number-to-string (1+ num-start))))
2954 options)))
2955 (let ((local-options (plist-get attributes :options)))
2956 (and local-options (concat "," local-options))))
2957 ;; Language.
2958 (or (cadr (assq (intern lang)
2959 (plist-get info :latex-minted-langs)))
2960 (downcase lang))
2961 ;; Source code.
2962 (let* ((code-info (org-export-unravel-code src-block))
2963 (max-width
2964 (apply 'max
2965 (mapcar 'length
2966 (org-split-string (car code-info)
2967 "\n")))))
2968 (org-export-format-code
2969 (car code-info)
2970 (lambda (loc _num ref)
2971 (concat
2973 (when ref
2974 ;; Ensure references are flushed to the right,
2975 ;; separated with 6 spaces from the widest line
2976 ;; of code.
2977 (concat (make-string (+ (- max-width (length loc)) 6)
2978 ?\s)
2979 (format "(%s)" ref)))))
2980 nil (and retain-labels (cdr code-info)))))))
2981 ;; Return value.
2982 (format float-env body)))
2983 ;; Case 4. Use listings package.
2985 (let ((lst-lang
2986 (or (cadr (assq (intern lang)
2987 (plist-get info :latex-listings-langs)))
2988 lang))
2989 (caption-str
2990 (when caption
2991 (let ((main (org-export-get-caption src-block))
2992 (secondary (org-export-get-caption src-block t)))
2993 (if (not secondary)
2994 (format "{%s}" (org-export-data main info))
2995 (format "{[%s]%s}"
2996 (org-export-data secondary info)
2997 (org-export-data main info))))))
2998 (lst-opt (plist-get info :latex-listings-options)))
2999 (concat
3000 ;; Options.
3001 (format
3002 "\\lstset{%s}\n"
3003 (concat
3004 (org-latex--make-option-string
3005 (append
3006 lst-opt
3007 (cond
3008 ((and (not float) (plist-member attributes :float)) nil)
3009 ((string= "multicolumn" float) '(("float" "*")))
3010 ((and float (not (assoc "float" lst-opt)))
3011 `(("float" ,(plist-get info :latex-default-figure-position)))))
3012 `(("language" ,lst-lang))
3013 (if label
3014 `(("label" ,(org-latex--label src-block info)))
3015 '(("label" " ")))
3016 (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
3017 `(("captionpos" ,(if caption-above-p "t" "b")))
3018 (cond ((assoc "numbers" lst-opt) nil)
3019 ((not num-start) '(("numbers" "none")))
3020 (t `(("firstnumber" ,(number-to-string (1+ num-start)))
3021 ("numbers" "left"))))))
3022 (let ((local-options (plist-get attributes :options)))
3023 (and local-options (concat "," local-options)))))
3024 ;; Source code.
3025 (format
3026 "\\begin{lstlisting}\n%s\\end{lstlisting}"
3027 (let* ((code-info (org-export-unravel-code src-block))
3028 (max-width
3029 (apply 'max
3030 (mapcar 'length
3031 (org-split-string (car code-info) "\n")))))
3032 (org-export-format-code
3033 (car code-info)
3034 (lambda (loc _num ref)
3035 (concat
3037 (when ref
3038 ;; Ensure references are flushed to the right,
3039 ;; separated with 6 spaces from the widest line of
3040 ;; code
3041 (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
3042 (format "(%s)" ref)))))
3043 nil (and retain-labels (cdr code-info))))))))))))
3046 ;;;; Statistics Cookie
3048 (defun org-latex-statistics-cookie (statistics-cookie _contents _info)
3049 "Transcode a STATISTICS-COOKIE object from Org to LaTeX.
3050 CONTENTS is nil. INFO is a plist holding contextual information."
3051 (replace-regexp-in-string
3052 "%" "\\%" (org-element-property :value statistics-cookie) nil t))
3055 ;;;; Strike-Through
3057 (defun org-latex-strike-through (_strike-through contents info)
3058 "Transcode STRIKE-THROUGH from Org to LaTeX.
3059 CONTENTS is the text with strike-through markup. INFO is a plist
3060 holding contextual information."
3061 (org-latex--text-markup contents 'strike-through info))
3064 ;;;; Subscript
3066 (defun org-latex--script-size (object info)
3067 "Transcode a subscript or superscript object.
3068 OBJECT is an Org object. INFO is a plist used as a communication
3069 channel."
3070 (let ((output ""))
3071 (org-element-map (org-element-contents object)
3072 (cons 'plain-text org-element-all-objects)
3073 (lambda (obj)
3074 (cl-case (org-element-type obj)
3075 ((entity latex-fragment)
3076 (let ((data (org-trim (org-export-data obj info))))
3077 (string-match
3078 "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
3079 data)
3080 (setq output
3081 (concat output
3082 (match-string 1 data)
3083 (let ((blank (org-element-property :post-blank obj)))
3084 (and blank (> blank 0) "\\ "))))))
3085 (plain-text
3086 (setq output
3087 (format "%s\\text{%s}" output (org-export-data obj info))))
3088 (otherwise
3089 (setq output
3090 (concat output
3091 (org-export-data obj info)
3092 (let ((blank (org-element-property :post-blank obj)))
3093 (and blank (> blank 0) "\\ ")))))))
3094 info nil org-element-recursive-objects)
3095 ;; Result. Do not wrap into curly brackets if OUTPUT is a single
3096 ;; character.
3097 (concat (if (eq (org-element-type object) 'subscript) "_" "^")
3098 (and (> (length output) 1) "{")
3099 output
3100 (and (> (length output) 1) "}"))))
3102 (defun org-latex-subscript (subscript _contents info)
3103 "Transcode a SUBSCRIPT object from Org to LaTeX.
3104 CONTENTS is the contents of the object. INFO is a plist holding
3105 contextual information."
3106 (org-latex--script-size subscript info))
3109 ;;;; Superscript
3111 (defun org-latex-superscript (superscript _contents info)
3112 "Transcode a SUPERSCRIPT object from Org to LaTeX.
3113 CONTENTS is the contents of the object. INFO is a plist holding
3114 contextual information."
3115 (org-latex--script-size superscript info))
3118 ;;;; Table
3120 ;; `org-latex-table' is the entry point for table transcoding. It
3121 ;; takes care of tables with a "verbatim" mode. Otherwise, it
3122 ;; delegates the job to either `org-latex--table.el-table',
3123 ;; `org-latex--org-table' or `org-latex--math-table' functions,
3124 ;; depending of the type of the table and the mode requested.
3126 ;; `org-latex--align-string' is a subroutine used to build alignment
3127 ;; string for Org tables.
3129 (defun org-latex-table (table contents info)
3130 "Transcode a TABLE element from Org to LaTeX.
3131 CONTENTS is the contents of the table. INFO is a plist holding
3132 contextual information."
3133 (if (eq (org-element-property :type table) 'table.el)
3134 ;; "table.el" table. Convert it using appropriate tools.
3135 (org-latex--table.el-table table info)
3136 (let ((type (or (org-export-read-attribute :attr_latex table :mode)
3137 (plist-get info :latex-default-table-mode))))
3138 (cond
3139 ;; Case 1: Verbatim table.
3140 ((string= type "verbatim")
3141 (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
3142 ;; Re-create table, without affiliated keywords.
3143 (org-trim (org-element-interpret-data
3144 `(table nil ,@(org-element-contents table))))))
3145 ;; Case 2: Matrix.
3146 ((or (string= type "math") (string= type "inline-math"))
3147 (org-latex--math-table table info))
3148 ;; Case 3: Standard table.
3149 (t (concat (org-latex--org-table table contents info)
3150 ;; When there are footnote references within the
3151 ;; table, insert their definition just after it.
3152 (org-latex--delayed-footnotes-definitions table info)))))))
3154 (defun org-latex--align-string (table info &optional math?)
3155 "Return an appropriate LaTeX alignment string.
3156 TABLE is the considered table. INFO is a plist used as
3157 a communication channel. When optional argument MATH? is
3158 non-nil, TABLE is meant to be a matrix, where all cells are
3159 centered."
3160 (or (org-export-read-attribute :attr_latex table :align)
3161 (let (align)
3162 ;; Extract column groups and alignment from first (non-rule)
3163 ;; row.
3164 (org-element-map
3165 (org-element-map table 'table-row
3166 (lambda (row)
3167 (and (eq (org-element-property :type row) 'standard) row))
3168 info 'first-match)
3169 'table-cell
3170 (lambda (cell)
3171 (let ((borders (org-export-table-cell-borders cell info)))
3172 ;; Check left border for the first cell only.
3173 (when (and (memq 'left borders) (not align))
3174 (push "|" align))
3175 (push (if math? "c" ;center cells in matrices
3176 (cl-case (org-export-table-cell-alignment cell info)
3177 (left "l")
3178 (right "r")
3179 (center "c")))
3180 align)
3181 (when (memq 'right borders) (push "|" align))))
3182 info)
3183 (apply 'concat (nreverse align)))))
3185 (defun org-latex--org-table (table contents info)
3186 "Return appropriate LaTeX code for an Org table.
3188 TABLE is the table type element to transcode. CONTENTS is its
3189 contents, as a string. INFO is a plist used as a communication
3190 channel.
3192 This function assumes TABLE has `org' as its `:type' property and
3193 `table' as its `:mode' attribute."
3194 (let* ((caption (org-latex--caption/label-string table info))
3195 (attr (org-export-read-attribute :attr_latex table))
3196 ;; Determine alignment string.
3197 (alignment (org-latex--align-string table info))
3198 ;; Determine environment for the table: longtable, tabular...
3199 (table-env (or (plist-get attr :environment)
3200 (plist-get info :latex-default-table-environment)))
3201 ;; If table is a float, determine environment: table, table*
3202 ;; or sidewaystable.
3203 (float-env (unless (member table-env '("longtable" "longtabu"))
3204 (let ((float (plist-get attr :float)))
3205 (cond
3206 ((and (not float) (plist-member attr :float)) nil)
3207 ((or (string= float "sidewaystable")
3208 (string= float "sideways")) "sidewaystable")
3209 ((string= float "multicolumn") "table*")
3210 ((or float
3211 (org-element-property :caption table)
3212 (org-string-nw-p (plist-get attr :caption)))
3213 "table")))))
3214 ;; Extract others display options.
3215 (fontsize (let ((font (plist-get attr :font)))
3216 (and font (concat font "\n"))))
3217 ;; "tabular" environment doesn't allow to define a width.
3218 (width (and (not (equal table-env "tabular")) (plist-get attr :width)))
3219 (spreadp (plist-get attr :spread))
3220 (placement
3221 (or (plist-get attr :placement)
3222 (format "[%s]" (plist-get info :latex-default-figure-position))))
3223 (centerp (if (plist-member attr :center) (plist-get attr :center)
3224 (plist-get info :latex-tables-centered)))
3225 (caption-above-p (org-latex--caption-above-p table info)))
3226 ;; Prepare the final format string for the table.
3227 (cond
3228 ;; Longtable.
3229 ((equal "longtable" table-env)
3230 (concat (and fontsize (concat "{" fontsize))
3231 (format "\\begin{longtable}{%s}\n" alignment)
3232 (and caption-above-p
3233 (org-string-nw-p caption)
3234 (concat caption "\\\\\n"))
3235 contents
3236 (and (not caption-above-p)
3237 (org-string-nw-p caption)
3238 (concat caption "\\\\\n"))
3239 "\\end{longtable}\n"
3240 (and fontsize "}")))
3241 ;; Longtabu
3242 ((equal "longtabu" table-env)
3243 (concat (and fontsize (concat "{" fontsize))
3244 (format "\\begin{longtabu}%s{%s}\n"
3245 (if width
3246 (format " %s %s "
3247 (if spreadp "spread" "to") width) "")
3248 alignment)
3249 (and caption-above-p
3250 (org-string-nw-p caption)
3251 (concat caption "\\\\\n"))
3252 contents
3253 (and (not caption-above-p)
3254 (org-string-nw-p caption)
3255 (concat caption "\\\\\n"))
3256 "\\end{longtabu}\n"
3257 (and fontsize "}")))
3258 ;; Others.
3259 (t (concat (cond
3260 (float-env
3261 (concat (format "\\begin{%s}%s\n" float-env placement)
3262 (if caption-above-p caption "")
3263 (when centerp "\\centering\n")
3264 fontsize))
3265 ((and (not float-env) caption)
3266 (concat
3267 (and centerp "\\begin{center}\n" )
3268 (if caption-above-p caption "")
3269 (cond ((and fontsize centerp) fontsize)
3270 (fontsize (concat "{" fontsize)))))
3271 (centerp (concat "\\begin{center}\n" fontsize))
3272 (fontsize (concat "{" fontsize)))
3273 (cond ((equal "tabu" table-env)
3274 (format "\\begin{tabu}%s{%s}\n%s\\end{tabu}"
3275 (if width (format
3276 (if spreadp " spread %s " " to %s ")
3277 width) "")
3278 alignment
3279 contents))
3280 (t (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
3281 table-env
3282 (if width (format "{%s}" width) "")
3283 alignment
3284 contents
3285 table-env)))
3286 (cond
3287 (float-env
3288 (concat (if caption-above-p "" (concat "\n" caption))
3289 (format "\n\\end{%s}" float-env)))
3290 ((and (not float-env) caption)
3291 (concat
3292 (if caption-above-p "" (concat "\n" caption))
3293 (and centerp "\n\\end{center}")
3294 (and fontsize (not centerp) "}")))
3295 (centerp "\n\\end{center}")
3296 (fontsize "}")))))))
3298 (defun org-latex--table.el-table (table info)
3299 "Return appropriate LaTeX code for a table.el table.
3301 TABLE is the table type element to transcode. INFO is a plist
3302 used as a communication channel.
3304 This function assumes TABLE has `table.el' as its `:type'
3305 property."
3306 (require 'table)
3307 ;; Ensure "*org-export-table*" buffer is empty.
3308 (with-current-buffer (get-buffer-create "*org-export-table*")
3309 (erase-buffer))
3310 (let ((output (with-temp-buffer
3311 (insert (org-element-property :value table))
3312 (goto-char 1)
3313 (re-search-forward "^[ \t]*|[^|]" nil t)
3314 (table-generate-source 'latex "*org-export-table*")
3315 (with-current-buffer "*org-export-table*"
3316 (org-trim (buffer-string))))))
3317 (kill-buffer (get-buffer "*org-export-table*"))
3318 ;; Remove left out comments.
3319 (while (string-match "^%.*\n" output)
3320 (setq output (replace-match "" t t output)))
3321 (let ((attr (org-export-read-attribute :attr_latex table)))
3322 (when (plist-get attr :rmlines)
3323 ;; When the "rmlines" attribute is provided, remove all hlines
3324 ;; but the the one separating heading from the table body.
3325 (let ((n 0) (pos 0))
3326 (while (and (< (length output) pos)
3327 (setq pos (string-match "^\\\\hline\n?" output pos)))
3328 (cl-incf n)
3329 (unless (= n 2) (setq output (replace-match "" nil nil output))))))
3330 (let ((centerp (if (plist-member attr :center) (plist-get attr :center)
3331 (plist-get info :latex-tables-centered))))
3332 (if (not centerp) output
3333 (format "\\begin{center}\n%s\n\\end{center}" output))))))
3335 (defun org-latex--math-table (table info)
3336 "Return appropriate LaTeX code for a matrix.
3338 TABLE is the table type element to transcode. INFO is a plist
3339 used as a communication channel.
3341 This function assumes TABLE has `org' as its `:type' property and
3342 `inline-math' or `math' as its `:mode' attribute."
3343 (let* ((attr (org-export-read-attribute :attr_latex table))
3344 (env (or (plist-get attr :environment)
3345 (plist-get info :latex-default-table-environment)))
3346 (contents
3347 (mapconcat
3348 (lambda (row)
3349 (if (eq (org-element-property :type row) 'rule) "\\hline"
3350 ;; Return each cell unmodified.
3351 (concat
3352 (mapconcat
3353 (lambda (cell)
3354 (substring (org-element-interpret-data cell) 0 -1))
3355 (org-element-map row 'table-cell #'identity info) "&")
3356 (or (cdr (assoc env org-latex-table-matrix-macros)) "\\\\")
3357 "\n")))
3358 (org-element-map table 'table-row #'identity info) "")))
3359 (concat
3360 ;; Prefix.
3361 (plist-get attr :math-prefix)
3362 ;; Environment. Also treat special cases.
3363 (cond ((member env '("array" "tabular"))
3364 (format "\\begin{%s}{%s}\n%s\\end{%s}"
3365 env (org-latex--align-string table info t) contents env))
3366 ((assoc env org-latex-table-matrix-macros)
3367 (format "\\%s%s{\n%s}"
3369 (or (plist-get attr :math-arguments) "")
3370 contents))
3371 (t (format "\\begin{%s}\n%s\\end{%s}" env contents env)))
3372 ;; Suffix.
3373 (plist-get attr :math-suffix))))
3376 ;;;; Table Cell
3378 (defun org-latex-table-cell (table-cell contents info)
3379 "Transcode a TABLE-CELL element from Org to LaTeX.
3380 CONTENTS is the cell contents. INFO is a plist used as
3381 a communication channel."
3382 (concat
3383 (let ((scientific-format (plist-get info :latex-table-scientific-notation)))
3384 (if (and contents
3385 scientific-format
3386 (string-match orgtbl-exp-regexp contents))
3387 ;; Use appropriate format string for scientific
3388 ;; notation.
3389 (format scientific-format
3390 (match-string 1 contents)
3391 (match-string 2 contents))
3392 contents))
3393 (when (org-export-get-next-element table-cell info) " & ")))
3396 ;;;; Table Row
3398 (defun org-latex-table-row (table-row contents info)
3399 "Transcode a TABLE-ROW element from Org to LaTeX.
3400 CONTENTS is the contents of the row. INFO is a plist used as
3401 a communication channel."
3402 (let* ((attr (org-export-read-attribute :attr_latex
3403 (org-export-get-parent table-row)))
3404 (booktabsp (if (plist-member attr :booktabs) (plist-get attr :booktabs)
3405 (plist-get info :latex-tables-booktabs)))
3406 (longtablep
3407 (member (or (plist-get attr :environment)
3408 (plist-get info :latex-default-table-environment))
3409 '("longtable" "longtabu"))))
3410 (if (eq (org-element-property :type table-row) 'rule)
3411 (cond
3412 ((not booktabsp) "\\hline")
3413 ((not (org-export-get-previous-element table-row info)) "\\toprule")
3414 ((not (org-export-get-next-element table-row info)) "\\bottomrule")
3415 ((and longtablep
3416 (org-export-table-row-ends-header-p
3417 (org-export-get-previous-element table-row info) info))
3419 (t "\\midrule"))
3420 (concat
3421 ;; When BOOKTABS are activated enforce top-rule even when no
3422 ;; hline was specifically marked.
3423 (and booktabsp (not (org-export-get-previous-element table-row info))
3424 "\\toprule\n")
3425 contents "\\\\\n"
3426 (cond
3427 ;; Special case for long tables. Define header and footers.
3428 ((and longtablep (org-export-table-row-ends-header-p table-row info))
3429 (let ((columns (cdr (org-export-table-dimensions
3430 (org-export-get-parent-table table-row) info))))
3431 (format "%s
3432 \\endfirsthead
3433 \\multicolumn{%d}{l}{%s} \\\\
3435 %s \\\\\n
3437 \\endhead
3438 %s\\multicolumn{%d}{r}{%s} \\\\
3439 \\endfoot
3440 \\endlastfoot"
3441 (if booktabsp "\\midrule" "\\hline")
3442 columns
3443 (org-latex--translate "Continued from previous page" info)
3444 (cond
3445 ((not (org-export-table-row-starts-header-p table-row info))
3447 (booktabsp "\\toprule\n")
3448 (t "\\hline\n"))
3449 contents
3450 (if booktabsp "\\midrule" "\\hline")
3451 (if booktabsp "\\midrule" "\\hline")
3452 columns
3453 (org-latex--translate "Continued on next page" info))))
3454 ;; When BOOKTABS are activated enforce bottom rule even when
3455 ;; no hline was specifically marked.
3456 ((and booktabsp (not (org-export-get-next-element table-row info)))
3457 "\\bottomrule"))))))
3460 ;;;; Target
3462 (defun org-latex-target (target _contents info)
3463 "Transcode a TARGET object from Org to LaTeX.
3464 CONTENTS is nil. INFO is a plist holding contextual
3465 information."
3466 (format "\\label{%s}" (org-latex--label target info)))
3469 ;;;; Timestamp
3471 (defun org-latex-timestamp (timestamp _contents info)
3472 "Transcode a TIMESTAMP object from Org to LaTeX.
3473 CONTENTS is nil. INFO is a plist holding contextual
3474 information."
3475 (let ((value (org-latex-plain-text (org-timestamp-translate timestamp) info)))
3476 (format
3477 (plist-get info
3478 (cl-case (org-element-property :type timestamp)
3479 ((active active-range) :latex-active-timestamp-format)
3480 ((inactive inactive-range) :latex-inactive-timestamp-format)
3481 (otherwise :latex-diary-timestamp-format)))
3482 value)))
3485 ;;;; Underline
3487 (defun org-latex-underline (_underline contents info)
3488 "Transcode UNDERLINE from Org to LaTeX.
3489 CONTENTS is the text with underline markup. INFO is a plist
3490 holding contextual information."
3491 (org-latex--text-markup contents 'underline info))
3494 ;;;; Verbatim
3496 (defun org-latex-verbatim (verbatim _contents info)
3497 "Transcode a VERBATIM object from Org to LaTeX.
3498 CONTENTS is nil. INFO is a plist used as a communication
3499 channel."
3500 (org-latex--text-markup
3501 (org-element-property :value verbatim) 'verbatim info))
3504 ;;;; Verse Block
3506 (defun org-latex-verse-block (verse-block contents info)
3507 "Transcode a VERSE-BLOCK element from Org to LaTeX.
3508 CONTENTS is verse block contents. INFO is a plist holding
3509 contextual information."
3510 (org-latex--wrap-label
3511 verse-block
3512 ;; In a verse environment, add a line break to each newline
3513 ;; character and change each white space at beginning of a line
3514 ;; into a space of 1 em. Also change each blank line with
3515 ;; a vertical space of 1 em.
3516 (format "\\begin{verse}\n%s\\end{verse}"
3517 (replace-regexp-in-string
3518 "^[ \t]+" (lambda (m) (format "\\hspace*{%dem}" (length m)))
3519 (replace-regexp-in-string
3520 "^[ \t]*\\\\\\\\$" "\\vspace*{1em}"
3521 (replace-regexp-in-string
3522 "\\([ \t]*\\\\\\\\\\)?[ \t]*\n" "\\\\\n"
3523 contents nil t) nil t) nil t))
3524 info))
3528 ;;; End-user functions
3530 ;;;###autoload
3531 (defun org-latex-export-as-latex
3532 (&optional async subtreep visible-only body-only ext-plist)
3533 "Export current buffer as a LaTeX buffer.
3535 If narrowing is active in the current buffer, only export its
3536 narrowed part.
3538 If a region is active, export that region.
3540 A non-nil optional argument ASYNC means the process should happen
3541 asynchronously. The resulting buffer should be accessible
3542 through the `org-export-stack' interface.
3544 When optional argument SUBTREEP is non-nil, export the sub-tree
3545 at point, extracting information from the headline properties
3546 first.
3548 When optional argument VISIBLE-ONLY is non-nil, don't export
3549 contents of hidden elements.
3551 When optional argument BODY-ONLY is non-nil, only write code
3552 between \"\\begin{document}\" and \"\\end{document}\".
3554 EXT-PLIST, when provided, is a property list with external
3555 parameters overriding Org default settings, but still inferior to
3556 file-local settings.
3558 Export is done in a buffer named \"*Org LATEX Export*\", which
3559 will be displayed when `org-export-show-temporary-export-buffer'
3560 is non-nil."
3561 (interactive)
3562 (org-export-to-buffer 'latex "*Org LATEX Export*"
3563 async subtreep visible-only body-only ext-plist (lambda () (LaTeX-mode))))
3565 ;;;###autoload
3566 (defun org-latex-convert-region-to-latex ()
3567 "Assume the current region has Org syntax, and convert it to LaTeX.
3568 This can be used in any buffer. For example, you can write an
3569 itemized list in Org syntax in an LaTeX buffer and use this
3570 command to convert it."
3571 (interactive)
3572 (org-export-replace-region-by 'latex))
3574 ;;;###autoload
3575 (defun org-latex-export-to-latex
3576 (&optional async subtreep visible-only body-only ext-plist)
3577 "Export current buffer to a LaTeX file.
3579 If narrowing is active in the current buffer, only export its
3580 narrowed part.
3582 If a region is active, export that region.
3584 A non-nil optional argument ASYNC means the process should happen
3585 asynchronously. The resulting file should be accessible through
3586 the `org-export-stack' interface.
3588 When optional argument SUBTREEP is non-nil, export the sub-tree
3589 at point, extracting information from the headline properties
3590 first.
3592 When optional argument VISIBLE-ONLY is non-nil, don't export
3593 contents of hidden elements.
3595 When optional argument BODY-ONLY is non-nil, only write code
3596 between \"\\begin{document}\" and \"\\end{document}\".
3598 EXT-PLIST, when provided, is a property list with external
3599 parameters overriding Org default settings, but still inferior to
3600 file-local settings."
3601 (interactive)
3602 (let ((outfile (org-export-output-file-name ".tex" subtreep)))
3603 (org-export-to-file 'latex outfile
3604 async subtreep visible-only body-only ext-plist)))
3606 ;;;###autoload
3607 (defun org-latex-export-to-pdf
3608 (&optional async subtreep visible-only body-only ext-plist)
3609 "Export current buffer to LaTeX then process through to PDF.
3611 If narrowing is active in the current buffer, only export its
3612 narrowed part.
3614 If a region is active, export that region.
3616 A non-nil optional argument ASYNC means the process should happen
3617 asynchronously. The resulting file should be accessible through
3618 the `org-export-stack' interface.
3620 When optional argument SUBTREEP is non-nil, export the sub-tree
3621 at point, extracting information from the headline properties
3622 first.
3624 When optional argument VISIBLE-ONLY is non-nil, don't export
3625 contents of hidden elements.
3627 When optional argument BODY-ONLY is non-nil, only write code
3628 between \"\\begin{document}\" and \"\\end{document}\".
3630 EXT-PLIST, when provided, is a property list with external
3631 parameters overriding Org default settings, but still inferior to
3632 file-local settings.
3634 Return PDF file's name."
3635 (interactive)
3636 (let ((outfile (org-export-output-file-name ".tex" subtreep)))
3637 (org-export-to-file 'latex outfile
3638 async subtreep visible-only body-only ext-plist
3639 (lambda (file) (org-latex-compile file)))))
3641 (defun org-latex-compile (texfile &optional snippet)
3642 "Compile a TeX file.
3644 TEXFILE is the name of the file being compiled. Processing is
3645 done through the command specified in `org-latex-pdf-process',
3646 which see. Output is redirected to \"*Org PDF LaTeX Output*\"
3647 buffer.
3649 When optional argument SNIPPET is non-nil, TEXFILE is a temporary
3650 file used to preview a LaTeX snippet. In this case, do not
3651 create a log buffer and do not remove log files.
3653 Return PDF file name or raise an error if it couldn't be
3654 produced."
3655 (unless snippet (message "Processing LaTeX file %s..." texfile))
3656 (let* ((compiler
3657 (or (with-temp-buffer
3658 (save-excursion (insert-file-contents texfile))
3659 (and (search-forward-regexp (regexp-opt org-latex-compilers)
3660 (line-end-position 2)
3662 (progn (beginning-of-line) (looking-at-p "%"))
3663 (match-string 0)))
3664 "pdflatex"))
3665 (process (if (functionp org-latex-pdf-process) org-latex-pdf-process
3666 ;; Replace "%latex" and "%bibtex" with,
3667 ;; respectively, "%L" and "%B" so as to adhere to
3668 ;; `format-spec' specifications.
3669 (mapcar (lambda (command)
3670 (replace-regexp-in-string
3671 "%\\(?:bib\\|la\\)tex\\>"
3672 (lambda (m) (upcase (substring m 0 2)))
3673 command))
3674 org-latex-pdf-process)))
3675 (spec `((?B . ,(shell-quote-argument org-latex-bib-compiler))
3676 (?L . ,(shell-quote-argument compiler))))
3677 (log-buf-name "*Org PDF LaTeX Output*")
3678 (log-buf (and (not snippet) (get-buffer-create log-buf-name)))
3679 (outfile (org-compile-file texfile process "pdf"
3680 (format "See %S for details" log-buf-name)
3681 log-buf spec)))
3682 (unless snippet
3683 (when org-latex-remove-logfiles
3684 (mapc #'delete-file
3685 (directory-files
3686 (file-name-directory outfile)
3688 (concat (regexp-quote (file-name-base outfile))
3689 "\\(?:\\.[0-9]+\\)?\\."
3690 (regexp-opt org-latex-logfiles-extensions))
3691 t)))
3692 (let ((warnings (org-latex--collect-warnings log-buf)))
3693 (message (concat "PDF file produced"
3694 (cond
3695 ((eq warnings 'error) " with errors.")
3696 (warnings (concat " with warnings: " warnings))
3697 (t "."))))))
3698 ;; Return output file name.
3699 outfile))
3701 (defun org-latex--collect-warnings (buffer)
3702 "Collect some warnings from \"pdflatex\" command output.
3703 BUFFER is the buffer containing output. Return collected
3704 warnings types as a string, `error' if a LaTeX error was
3705 encountered or nil if there was none."
3706 (with-current-buffer buffer
3707 (save-excursion
3708 (goto-char (point-max))
3709 (when (re-search-backward "^[ \t]*This is .*?TeX.*?Version" nil t)
3710 (if (re-search-forward "^!" nil t) 'error
3711 (let ((case-fold-search t)
3712 (warnings ""))
3713 (dolist (warning org-latex-known-warnings)
3714 (when (save-excursion (re-search-forward (car warning) nil t))
3715 (setq warnings (concat warnings " " (cdr warning)))))
3716 (org-string-nw-p (org-trim warnings))))))))
3718 ;;;###autoload
3719 (defun org-latex-publish-to-latex (plist filename pub-dir)
3720 "Publish an Org file to LaTeX.
3722 FILENAME is the filename of the Org file to be published. PLIST
3723 is the property list for the given project. PUB-DIR is the
3724 publishing directory.
3726 Return output file name."
3727 (org-publish-org-to 'latex filename ".tex" plist pub-dir))
3729 ;;;###autoload
3730 (defun org-latex-publish-to-pdf (plist filename pub-dir)
3731 "Publish an Org file to PDF (via LaTeX).
3733 FILENAME is the filename of the Org file to be published. PLIST
3734 is the property list for the given project. PUB-DIR is the
3735 publishing directory.
3737 Return output file name."
3738 ;; Unlike to `org-latex-publish-to-latex', PDF file is generated
3739 ;; in working directory and then moved to publishing directory.
3740 (org-publish-attachment
3741 plist
3742 ;; Default directory could be anywhere when this function is
3743 ;; called. We ensure it is set to source file directory during
3744 ;; compilation so as to not break links to external documents.
3745 (let ((default-directory (file-name-directory filename)))
3746 (org-latex-compile
3747 (org-publish-org-to
3748 'latex filename ".tex" plist (file-name-directory filename))))
3749 pub-dir))
3752 (provide 'ox-latex)
3754 ;; Local variables:
3755 ;; generated-autoload-file: "org-loaddefs.el"
3756 ;; End:
3758 ;;; ox-latex.el ends here