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