1 ;;; ox-latex.el --- LaTeX Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;; This library implements a LaTeX back-end for Org generic exporter.
25 ;; Depending on the desired output format, three commands are provided
26 ;; for export: `org-latex-export-as-latex' (temporary buffer),
27 ;; `org-latex-export-to-latex' ("tex" file) and
28 ;; `org-latex-export-to-pdf' ("pdf" file). Also, two publishing
29 ;; functions are available: `org-latex-publish-to-latex' and
30 ;; `org-latex-publish-to-pdf'.
32 ;; The library introduces four new buffer keywords: "LATEX_CLASS",
33 ;; "LATEX_CLASS_OPTIONS", "LATEX_HEADER" and "LATEX_HEADER_EXTRA" (the
34 ;; latter will not be used to build LaTeX snippets). It also
35 ;; introduces a new OPTIONS item: "textht".
37 ;; Table export can be controlled with a number of attributes (through
38 ;; ATTR_LATEX keyword).
40 ;; - The main one is the `:mode' attribute, which can be set to
41 ;; `table', `math', `inline-math' and `verbatim'. In particular,
42 ;; when in `math' or `inline-math' mode, every cell is exported
43 ;; as-is, horizontal rules are ignored and the table will be wrapped
44 ;; in a math environment. Also, contiguous tables sharing the same
45 ;; math mode will be wrapped within the same environment. Default
46 ;; mode is stored in `org-latex-default-table-mode'.
48 ;; - The second most important attribute is `:environment'. It is the
49 ;; environment used for the table and defaults to
50 ;; `org-latex-default-table-environment' value. It can be set to
51 ;; anything, including "tabularx", "longtable", "array", "tabu",
54 ;; - `:float' attribute defines a float environment for the table.
55 ;; Possible values are `sidewaystable', `multicolumn' and `table'.
56 ;; If unspecified, a table with a caption will have a `table'
57 ;; environment. Moreover, `:placement' attribute can specify the
58 ;; positioning of the float
60 ;; - `:align', `:font' and `:width' attributes set, respectively, the
61 ;; alignment string of the table, its font size and its width. They
62 ;; only apply on regular tables.
64 ;; - `:spread' is a boolean attribute specific to the "tabu" and
65 ;; "longtabu" environments, and only takes effect when used in
66 ;; conjunction with the `:width' attribute. When `:spread' is
67 ;; non-nil, the table will be spread or shrunk by the value of
70 ;; - `:booktabs', `:center' and `:rmlines' values are booleans. They
71 ;; toggle, respectively "booktabs" usage (assuming the package is
72 ;; properly loaded), table centering and removal of every horizontal
73 ;; rule but the first one (in a "table.el" table only).
75 ;; - `:math-prefix', `:math-suffix' and `:math-arguments' are string
76 ;; which will be inserted, respectively, before the table within the
77 ;; math environment, after the table within the math environment,
78 ;; and between the macro name and the contents of the table. The
79 ;; latter attribute is necessary to matrix macros that require more
80 ;; than one argument (i.e. "qbordermatrix").
82 ;; Plain lists accept two optional attributes: `:environment' and
83 ;; `:options'. The first one allows to use a non-standard environment
84 ;; (i.e. "inparaenum"). The second one allows to specify optional
85 ;; arguments for that environment (square brackets are not mandatory).
87 ;; Images accept `:float', `:placement', `:comment-include', `:width',
88 ;; and `:height', and `:options' as attributes. `:float' accepts
89 ;; a symbol among `wrap', `multicolumn', and `figure', which defines
90 ;; the float environment for the image (if unspecified, an image with
91 ;; a caption will be set in a "figure" environment).
92 ;; `:comment-include' is a boolean that toggles whether to comment out
93 ;; the code which actually includes the image. `:placement' is
94 ;; a string that will be used as argument for the environment chosen.
95 ;; `:width' and `:height' control the width and height of the image.
96 ;; `:options' is a string that will be used as the optional argument
97 ;; for "includegraphics" macro or, in the case of tikz images, used as
98 ;; the optional argument for a `tikzpicture' environment which will
99 ;; surround the "\input" picture code.
101 ;; Special blocks accept `:options' as attribute. Its value will be
102 ;; appended as-is to the opening string of the environment created.
104 ;; Source blocks accept `:long-listing' attribute, which prevents the
105 ;; block to be wrapped within a float when non-nil.
107 ;; This back-end also offers enhanced support for footnotes. Thus, it
108 ;; handles nested footnotes, footnotes in tables and footnotes in item
111 ;; Smart quotes are activated by default.
115 (eval-when-compile (require 'cl
))
117 (require 'ox-publish
)
119 (defvar org-latex-default-packages-alist
)
120 (defvar org-latex-packages-alist
)
121 (defvar orgtbl-exp-regexp
)
127 (org-export-define-backend 'latex
128 '((bold . org-latex-bold
)
129 (center-block . org-latex-center-block
)
130 (clock . org-latex-clock
)
131 (code . org-latex-code
)
132 (comment .
(lambda (&rest args
) ""))
133 (comment-block .
(lambda (&rest args
) ""))
134 (drawer . org-latex-drawer
)
135 (dynamic-block . org-latex-dynamic-block
)
136 (entity . org-latex-entity
)
137 (example-block . org-latex-example-block
)
138 (export-block . org-latex-export-block
)
139 (export-snippet . org-latex-export-snippet
)
140 (fixed-width . org-latex-fixed-width
)
141 (footnote-definition . org-latex-footnote-definition
)
142 (footnote-reference . org-latex-footnote-reference
)
143 (headline . org-latex-headline
)
144 (horizontal-rule . org-latex-horizontal-rule
)
145 (inline-src-block . org-latex-inline-src-block
)
146 (inlinetask . org-latex-inlinetask
)
147 (italic . org-latex-italic
)
148 (item . org-latex-item
)
149 (keyword . org-latex-keyword
)
150 (latex-environment . org-latex-latex-environment
)
151 (latex-fragment . org-latex-latex-fragment
)
152 (line-break . org-latex-line-break
)
153 (link . org-latex-link
)
154 (paragraph . org-latex-paragraph
)
155 (plain-list . org-latex-plain-list
)
156 (plain-text . org-latex-plain-text
)
157 (planning . org-latex-planning
)
158 (property-drawer .
(lambda (&rest args
) ""))
159 (quote-block . org-latex-quote-block
)
160 (quote-section . org-latex-quote-section
)
161 (radio-target . org-latex-radio-target
)
162 (section . org-latex-section
)
163 (special-block . org-latex-special-block
)
164 (src-block . org-latex-src-block
)
165 (statistics-cookie . org-latex-statistics-cookie
)
166 (strike-through . org-latex-strike-through
)
167 (subscript . org-latex-subscript
)
168 (superscript . org-latex-superscript
)
169 (table . org-latex-table
)
170 (table-cell . org-latex-table-cell
)
171 (table-row . org-latex-table-row
)
172 (target . org-latex-target
)
173 (template . org-latex-template
)
174 (timestamp . org-latex-timestamp
)
175 (underline . org-latex-underline
)
176 (verbatim . org-latex-verbatim
)
177 (verse-block . org-latex-verse-block
))
178 :export-block
'("LATEX" "TEX")
180 '(?l
"Export to LaTeX"
181 ((?L
"As LaTeX buffer" org-latex-export-as-latex
)
182 (?l
"As LaTeX file" org-latex-export-to-latex
)
183 (?p
"As PDF file" org-latex-export-to-pdf
)
184 (?o
"As PDF file and open"
186 (if a
(org-latex-export-to-pdf t s v b
)
187 (org-open-file (org-latex-export-to-pdf nil s v b
)))))))
188 :options-alist
'((:latex-class
"LATEX_CLASS" nil org-latex-default-class t
)
189 (:latex-class-options
"LATEX_CLASS_OPTIONS" nil nil t
)
190 (:latex-header
"LATEX_HEADER" nil nil newline
)
191 (:latex-header-extra
"LATEX_HEADER_EXTRA" nil nil newline
)
192 (:latex-hyperref-p nil
"texht" org-latex-with-hyperref t
)
193 ;; Redefine regular options.
194 (:date
"DATE" nil
"\\today" t
)
195 (:with-smart-quotes nil
"'" t
)))
199 ;;; Internal Variables
201 (defconst org-latex-babel-language-alist
202 '(("af" .
"afrikaans")
204 ("bt-br" .
"brazilian")
210 ("de-at" .
"naustrian")
211 ("de-de" .
"ngerman")
214 ("en-au" .
"australian")
215 ("en-ca" .
"canadian")
216 ("en-gb" .
"british")
218 ("en-nz" .
"newzealand")
219 ("en-us" .
"american")
225 ("fr-ca" .
"canadien")
229 ("id" .
"indonesian")
235 ("no-no" .
"nynorsk")
237 ("pt" .
"portuguese")
241 ("sb" .
"uppersorbian")
249 ("uk" .
"ukrainian"))
250 "Alist between language code and corresponding Babel option.")
252 (defconst org-latex-table-matrix-macros
'(("bordermatrix" .
"\\cr")
253 ("qbordermatrix" .
"\\cr")
254 ("kbordermatrix" .
"\\\\"))
255 "Alist between matrix macros and their row ending.")
259 ;;; User Configurable Variables
261 (defgroup org-export-latex nil
262 "Options for exporting Org mode files to LaTeX."
263 :tag
"Org Export LaTeX"
269 (defcustom org-latex-default-class
"article"
270 "The default LaTeX class."
271 :group
'org-export-latex
272 :type
'(string :tag
"LaTeX class"))
274 (defcustom org-latex-classes
276 "\\documentclass[11pt]{article}"
277 ("\\section{%s}" .
"\\section*{%s}")
278 ("\\subsection{%s}" .
"\\subsection*{%s}")
279 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}")
280 ("\\paragraph{%s}" .
"\\paragraph*{%s}")
281 ("\\subparagraph{%s}" .
"\\subparagraph*{%s}"))
283 "\\documentclass[11pt]{report}"
284 ("\\part{%s}" .
"\\part*{%s}")
285 ("\\chapter{%s}" .
"\\chapter*{%s}")
286 ("\\section{%s}" .
"\\section*{%s}")
287 ("\\subsection{%s}" .
"\\subsection*{%s}")
288 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}"))
290 "\\documentclass[11pt]{book}"
291 ("\\part{%s}" .
"\\part*{%s}")
292 ("\\chapter{%s}" .
"\\chapter*{%s}")
293 ("\\section{%s}" .
"\\section*{%s}")
294 ("\\subsection{%s}" .
"\\subsection*{%s}")
295 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}")))
296 "Alist of LaTeX classes and associated header and structure.
297 If #+LaTeX_CLASS is set in the buffer, use its value and the
298 associated information. Here is the structure of each cell:
302 \(numbered-section . unnumbered-section\)
308 The HEADER-STRING is the header that will be inserted into the
309 LaTeX file. It should contain the \\documentclass macro, and
310 anything else that is needed for this setup. To this header, the
311 following commands will be added:
313 - Calls to \\usepackage for all packages mentioned in the
314 variables `org-latex-default-packages-alist' and
315 `org-latex-packages-alist'. Thus, your header definitions
316 should avoid to also request these packages.
318 - Lines specified via \"#+LaTeX_HEADER:\"
320 If you need more control about the sequence in which the header
321 is built up, or if you want to exclude one of these building
322 blocks for a particular class, you can use the following
323 macro-like placeholders.
325 [DEFAULT-PACKAGES] \\usepackage statements for default packages
326 [NO-DEFAULT-PACKAGES] do not include any of the default packages
327 [PACKAGES] \\usepackage statements for packages
328 [NO-PACKAGES] do not include the packages
329 [EXTRA] the stuff from #+LaTeX_HEADER
330 [NO-EXTRA] do not include #+LaTeX_HEADER stuff
334 \\documentclass{article}
335 [NO-DEFAULT-PACKAGES]
337 \\providecommand{\\alert}[1]{\\textbf{#1}}
340 will omit the default packages, and will include the
341 #+LaTeX_HEADER lines, then have a call to \\providecommand, and
342 then place \\usepackage commands based on the content of
343 `org-latex-packages-alist'.
345 If your header, `org-latex-default-packages-alist' or
346 `org-latex-packages-alist' inserts
347 \"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be
348 replaced with a coding system derived from
349 `buffer-file-coding-system'. See also the variable
350 `org-latex-inputenc-alist' for a way to influence this mechanism.
352 The sectioning structure
353 ------------------------
355 The sectioning structure of the class is given by the elements
356 following the header string. For each sectioning level, a number
357 of strings is specified. A %s formatter is mandatory in each
358 section string and will be replaced by the title of the section.
360 Instead of a cons cell \(numbered . unnumbered\), you can also
361 provide a list of 2 or 4 elements,
363 \(numbered-open numbered-close\)
367 \(numbered-open numbered-close unnumbered-open unnumbered-close\)
369 providing opening and closing strings for a LaTeX environment
370 that should represent the document section. The opening clause
371 should have a %s to represent the section title.
373 Instead of a list of sectioning commands, you can also specify
374 a function name. That function will be called with two
375 parameters, the \(reduced) level of the headline, and a predicate
376 non-nil when the headline should be numbered. It must return
377 a format string in which the section title will be added."
378 :group
'org-export-latex
380 (list (string :tag
"LaTeX class")
381 (string :tag
"LaTeX header")
382 (repeat :tag
"Levels" :inline t
385 (string :tag
" numbered")
386 (string :tag
"unnumbered"))
387 (list :tag
"Environment"
388 (string :tag
"Opening (numbered)")
389 (string :tag
"Closing (numbered)")
390 (string :tag
"Opening (unnumbered)")
391 (string :tag
"Closing (unnumbered)"))
392 (function :tag
"Hook computing sectioning"))))))
394 (defcustom org-latex-inputenc-alist nil
395 "Alist of inputenc coding system names, and what should really be used.
396 For example, adding an entry
398 (\"utf8\" . \"utf8x\")
400 will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
401 are written as utf8 files."
402 :group
'org-export-latex
405 (string :tag
"Derived from buffer")
406 (string :tag
"Use this instead"))))
408 (defcustom org-latex-title-command
"\\maketitle"
409 "The command used to insert the title just after \\begin{document}.
410 If this string contains the formatting specification \"%s\" then
411 it will be used as a formatting string, passing the title as an
413 :group
'org-export-latex
416 (defcustom org-latex-toc-command
"\\tableofcontents\n\n"
417 "LaTeX command to set the table of contents, list of figures, etc.
418 This command only applies to the table of contents generated with
419 the toc:nil option, not to those generated with #+TOC keyword."
420 :group
'org-export-latex
423 (defcustom org-latex-with-hyperref t
424 "Toggle insertion of \\hypersetup{...} in the preamble."
425 :group
'org-export-latex
431 (defcustom org-latex-format-headline-function
432 'org-latex-format-headline-default-function
433 "Function for formatting the headline's text.
435 This function will be called with 5 arguments:
436 TODO the todo keyword (string or nil).
437 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
438 PRIORITY the priority of the headline (integer or nil)
439 TEXT the main headline text (string).
440 TAGS the tags as a list of strings (list of strings or nil).
442 The function result will be used in the section format string.
444 Use `org-latex-format-headline-default-function' by default,
445 which format headlines like for Org version prior to 8.0."
446 :group
'org-export-latex
448 :package-version
'(Org .
"8.0")
454 (defcustom org-latex-footnote-separator
"\\textsuperscript{,}\\,"
455 "Text used to separate footnotes."
456 :group
'org-export-latex
462 (defcustom org-latex-active-timestamp-format
"\\textit{%s}"
463 "A printf format string to be applied to active timestamps."
464 :group
'org-export-latex
467 (defcustom org-latex-inactive-timestamp-format
"\\textit{%s}"
468 "A printf format string to be applied to inactive timestamps."
469 :group
'org-export-latex
472 (defcustom org-latex-diary-timestamp-format
"\\textit{%s}"
473 "A printf format string to be applied to diary timestamps."
474 :group
'org-export-latex
480 (defcustom org-latex-image-default-option
""
481 "Default option for images."
482 :group
'org-export-latex
484 :package-version
'(Org .
"8.0")
487 (defcustom org-latex-image-default-width
".9\\linewidth"
488 "Default width for images.
489 This value will not be used if a height is provided."
490 :group
'org-export-latex
492 :package-version
'(Org .
"8.0")
495 (defcustom org-latex-image-default-height
""
496 "Default height for images.
497 This value will not be used if a width is provided, or if the
498 image is wrapped within a \"figure\" or \"wrapfigure\"
500 :group
'org-export-latex
502 :package-version
'(Org .
"8.0")
505 (defcustom org-latex-default-figure-position
"htb"
506 "Default position for latex figures."
507 :group
'org-export-latex
510 (defcustom org-latex-inline-image-rules
511 '(("file" .
"\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\|tikz\\)\\'"))
512 "Rules characterizing image files that can be inlined into LaTeX.
514 A rule consists in an association whose key is the type of link
515 to consider, and value is a regexp that will be matched against
518 Note that, by default, the image extension *actually* allowed
519 depend on the way the LaTeX file is processed. When used with
520 pdflatex, pdf, jpg and png images are OK. When processing
521 through dvi to Postscript, only ps and eps are allowed. The
522 default we use here encompasses both."
523 :group
'org-export-latex
525 :package-version
'(Org .
"8.0")
526 :type
'(alist :key-type
(string :tag
"Type")
527 :value-type
(regexp :tag
"Path")))
529 (defcustom org-latex-link-with-unknown-path-format
"\\texttt{%s}"
530 "Format string for links with unknown path type."
531 :group
'org-export-latex
537 (defcustom org-latex-default-table-environment
"tabular"
538 "Default environment used to build tables."
539 :group
'org-export-latex
541 :package-version
'(Org .
"8.0")
544 (defcustom org-latex-default-table-mode
'table
545 "Default mode for tables.
547 Value can be a symbol among:
549 `table' Regular LaTeX table.
551 `math' In this mode, every cell is considered as being in math
552 mode and the complete table will be wrapped within a math
553 environment. It is particularly useful to write matrices.
555 `inline-math' This mode is almost the same as `math', but the
556 math environment will be inlined.
558 `verbatim' The table is exported as it appears in the Org
559 buffer, within a verbatim environment.
561 This value can be overridden locally with, i.e. \":mode math\" in
564 When modifying this variable, it may be useful to change
565 `org-latex-default-table-environment' accordingly."
566 :group
'org-export-latex
568 :package-version
'(Org .
"8.0")
569 :type
'(choice (const :tag
"Table" table
)
570 (const :tag
"Matrix" math
)
571 (const :tag
"Inline matrix" inline-math
)
572 (const :tag
"Verbatim" verbatim
)))
574 (defcustom org-latex-tables-centered t
575 "When non-nil, tables are exported in a center environment."
576 :group
'org-export-latex
579 (defcustom org-latex-tables-booktabs nil
580 "When non-nil, display tables in a formal \"booktabs\" style.
581 This option assumes that the \"booktabs\" package is properly
582 loaded in the header of the document. This value can be ignored
583 locally with \":booktabs t\" and \":booktabs nil\" LaTeX
585 :group
'org-export-latex
587 :package-version
'(Org .
"8.0")
590 (defcustom org-latex-table-caption-above t
591 "When non-nil, place caption string at the beginning of the table.
592 Otherwise, place it near the end."
593 :group
'org-export-latex
596 (defcustom org-latex-table-scientific-notation
"%s\\,(%s)"
597 "Format string to display numbers in scientific notation.
598 The format should have \"%s\" twice, for mantissa and exponent
599 \(i.e., \"%s\\\\times10^{%s}\").
601 When nil, no transformation is made."
602 :group
'org-export-latex
604 :package-version
'(Org .
"8.0")
606 (string :tag
"Format string")
607 (const :tag
"No formatting")))
612 (defcustom org-latex-text-markup-alist
'((bold .
"\\textbf{%s}")
614 (italic .
"\\emph{%s}")
615 (strike-through .
"\\st{%s}")
616 (underline .
"\\underline{%s}")
617 (verbatim . protectedtexttt
))
618 "Alist of LaTeX expressions to convert text markup.
620 The key must be a symbol among `bold', `code', `italic',
621 `strike-through', `underline' and `verbatim'. The value is
622 a formatting string to wrap fontified text with.
624 Value can also be set to the following symbols: `verb' and
625 `protectedtexttt'. For the former, Org will use \"\\verb\" to
626 create a format string and select a delimiter character that
627 isn't in the string. For the latter, Org will use \"\\texttt\"
628 to typeset and try to protect special characters.
630 If no association can be found for a given markup, text will be
632 :group
'org-export-latex
634 :options
'(bold code italic strike-through underline verbatim
))
639 (defcustom org-latex-format-drawer-function nil
640 "Function called to format a drawer in LaTeX code.
642 The function must accept two parameters:
643 NAME the drawer name, like \"LOGBOOK\"
644 CONTENTS the contents of the drawer.
646 The function should return the string to be exported.
648 For example, the variable could be set to the following function
649 in order to mimic default behaviour:
651 \(defun org-latex-format-drawer-default \(name contents\)
652 \"Format a drawer element for LaTeX export.\"
654 :group
'org-export-latex
660 (defcustom org-latex-format-inlinetask-function nil
661 "Function called to format an inlinetask in LaTeX code.
663 The function must accept six parameters:
664 TODO the todo keyword, as a string
665 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
666 PRIORITY the inlinetask priority, as a string
667 NAME the inlinetask name, as a string.
668 TAGS the inlinetask tags, as a list of strings.
669 CONTENTS the contents of the inlinetask, as a string.
671 The function should return the string to be exported.
673 For example, the variable could be set to the following function
674 in order to mimic default behaviour:
676 \(defun org-latex-format-inlinetask \(todo type priority name tags contents\)
677 \"Format an inline task element for LaTeX export.\"
681 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo))
682 \(when priority (format \"\\\\framebox{\\\\#%c} \" priority))
685 \(format \"\\\\hfill{}\\\\textsc{:%s:}\"
686 \(mapconcat 'identity tags \":\")))))
687 \(format (concat \"\\\\begin{center}\\n\"
689 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
691 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
693 \"\\\\end{minipage}}\"
695 full-title contents))"
696 :group
'org-export-latex
702 (defcustom org-latex-listings nil
703 "Non-nil means export source code using the listings package.
704 This package will fontify source code, possibly even with color.
705 If you want to use this, you also need to make LaTeX use the
706 listings package, and if you want to have color, the color
707 package. Just add these to `org-latex-packages-alist', for
708 example using customize, or with something like:
711 \(add-to-list 'org-latex-packages-alist '\(\"\" \"listings\"))
712 \(add-to-list 'org-latex-packages-alist '\(\"\" \"color\"))
716 \(setq org-latex-listings 'minted)
718 causes source code to be exported using the minted package as
719 opposed to listings. If you want to use minted, you need to add
720 the minted package to `org-latex-packages-alist', for example
721 using customize, or with
724 \(add-to-list 'org-latex-packages-alist '\(\"\" \"minted\"))
726 In addition, it is necessary to install pygments
727 \(http://pygments.org), and to configure the variable
728 `org-latex-pdf-process' so that the -shell-escape option is
730 :group
'org-export-latex
732 (const :tag
"Use listings" t
)
733 (const :tag
"Use minted" 'minted
)
734 (const :tag
"Export verbatim" nil
)))
736 (defcustom org-latex-listings-langs
737 '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
740 (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
741 (html "HTML") (xml "XML")
742 (tex "TeX") (latex "TeX")
743 (shell-script "bash")
745 (ocaml "Caml") (caml "Caml")
746 (sql "SQL") (sqlite "sql"))
747 "Alist mapping languages to their listing language counterpart.
748 The key is a symbol, the major mode symbol without the \"-mode\".
749 The value is the string that should be inserted as the language
750 parameter for the listings package. If the mode name and the
751 listings name are the same, the language does not need an entry
752 in this list - but it does not hurt if it is present."
753 :group
'org-export-latex
756 (symbol :tag
"Major mode ")
757 (string :tag
"Listings language"))))
759 (defcustom org-latex-listings-options nil
760 "Association list of options for the latex listings package.
762 These options are supplied as a comma-separated list to the
763 \\lstset command. Each element of the association list should be
764 a list containing two strings: the name of the option, and the
767 (setq org-latex-listings-options
768 '((\"basicstyle\" \"\\small\")
769 (\"keywordstyle\" \"\\color{black}\\bfseries\\underbar\")))
771 will typeset the code in a small size font with underlined, bold
774 Note that the same options will be applied to blocks of all
776 :group
'org-export-latex
779 (string :tag
"Listings option name ")
780 (string :tag
"Listings option value"))))
782 (defcustom org-latex-minted-langs
783 '((emacs-lisp "common-lisp")
786 (shell-script "bash")
788 "Alist mapping languages to their minted language counterpart.
789 The key is a symbol, the major mode symbol without the \"-mode\".
790 The value is the string that should be inserted as the language
791 parameter for the minted package. If the mode name and the
792 listings name are the same, the language does not need an entry
793 in this list - but it does not hurt if it is present.
795 Note that minted uses all lower case for language identifiers,
796 and that the full list of language identifiers can be obtained
799 pygmentize -L lexers"
800 :group
'org-export-latex
803 (symbol :tag
"Major mode ")
804 (string :tag
"Minted language"))))
806 (defcustom org-latex-minted-options nil
807 "Association list of options for the latex minted package.
809 These options are supplied within square brackets in
810 \\begin{minted} environments. Each element of the alist should
811 be a list containing two strings: the name of the option, and the
814 \(setq org-latex-minted-options
815 '\((\"bgcolor\" \"bg\") \(\"frame\" \"lines\")))
817 will result in src blocks being exported with
819 \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
821 as the start of the minted environment. Note that the same
822 options will be applied to blocks of all languages."
823 :group
'org-export-latex
826 (string :tag
"Minted option name ")
827 (string :tag
"Minted option value"))))
829 (defcustom org-latex-long-listings nil
830 "When non-nil no listing will be wrapped within a float.
832 Removing floats may break some functionalities. For example, it
833 will be impossible to use cross-references to listings when using
834 `minted' set-up when this variable is non-nil.
836 This value can be locally ignored with \":long-listing t\" and
837 \":long-listing nil\" LaTeX attributes."
838 :group
'org-export-latex
840 :package-version
'(Org .
"8.0")
843 (defvar org-latex-custom-lang-environments nil
844 "Alist mapping languages to language-specific LaTeX environments.
846 It is used during export of src blocks by the listings and minted
847 latex packages. For example,
849 \(setq org-latex-custom-lang-environments
850 '\(\(python \"pythoncode\"\)\)\)
852 would have the effect that if org encounters begin_src python
853 during latex export it will output
862 (defcustom org-latex-pdf-process
863 '("pdflatex -interaction nonstopmode -output-directory %o %f"
864 "pdflatex -interaction nonstopmode -output-directory %o %f"
865 "pdflatex -interaction nonstopmode -output-directory %o %f")
866 "Commands to process a LaTeX file to a PDF file.
867 This is a list of strings, each of them will be given to the
868 shell as a command. %f in the command will be replaced by the
869 full file name, %b by the file base name (i.e. without directory
870 and extension parts) and %o by the base directory of the file.
872 The reason why this is a list is that it usually takes several
873 runs of `pdflatex', maybe mixed with a call to `bibtex'. Org
874 does not have a clever mechanism to detect which of these
875 commands have to be run to get to a stable result, and it also
876 does not do any error checking.
878 By default, Org uses 3 runs of `pdflatex' to do the processing.
879 If you have texi2dvi on your system and if that does not cause
880 the infamous egrep/locale bug:
882 http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
884 then `texi2dvi' is the superior choice. Org does offer it as one
885 of the customize options.
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
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"
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"
917 "xelatex -interaction nonstopmode -output-directory %o %f"
918 "xelatex -interaction nonstopmode -output-directory %o %f"))
919 (const :tag
"texi2dvi"
920 ("texi2dvi -p -b -c -V %f"))
922 ("rubber -d --into %o %f"))
925 (defcustom org-latex-logfiles-extensions
926 '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
927 "The list of file extensions to consider as LaTeX logfiles.
928 The logfiles will be remove if `org-latex-remove-logfiles' is
930 :group
'org-export-latex
931 :type
'(repeat (string :tag
"Extension")))
933 (defcustom org-latex-remove-logfiles t
934 "Non-nil means remove the logfiles produced by PDF production.
935 By default, logfiles are files with these extensions: .aux, .idx,
936 .log, .out, .toc, .nav, .snm and .vrb. To define the set of
937 logfiles to remove, set `org-latex-logfiles-extensions'."
938 :group
'org-export-latex
941 (defcustom org-latex-known-errors
942 '(("Reference.*?undefined" .
"[undefined reference]")
943 ("Citation.*?undefined" .
"[undefined citation]")
944 ("Undefined control sequence" .
"[undefined control sequence]")
945 ("^! LaTeX.*?Error" .
"[LaTeX error]")
946 ("^! Package.*?Error" .
"[package error]")
947 ("Runaway argument" .
"Runaway argument"))
948 "Alist of regular expressions and associated messages for the user.
949 The regular expressions are used to find possible errors in the
951 :group
'org-export-latex
953 :package-version
'(Org .
"8.0")
956 (string :tag
"Regexp")
957 (string :tag
"Message"))))
961 ;;; Internal Functions
963 (defun org-latex--caption/label-string
(element info
)
964 "Return caption and label LaTeX string for ELEMENT.
966 INFO is a plist holding contextual information. If there's no
967 caption nor label, return the empty string.
969 For non-floats, see `org-latex--wrap-label'."
970 (let* ((label (org-element-property :name element
))
971 (label-str (if (not (org-string-nw-p label
)) ""
972 (format "\\label{%s}"
973 (org-export-solidify-link-text label
))))
974 (main (org-export-get-caption element
))
975 (short (org-export-get-caption element t
)))
977 ((and (not main
) (equal label-str
"")) "")
978 ((not main
) (concat label-str
"\n"))
979 ;; Option caption format with short name.
980 (short (format "\\caption[%s]{%s%s}\n"
981 (org-export-data short info
)
983 (org-export-data main info
)))
984 ;; Standard caption format.
985 (t (format "\\caption{%s%s}\n" label-str
(org-export-data main info
))))))
987 (defun org-latex-guess-inputenc (header)
988 "Set the coding system in inputenc to what the buffer is.
990 HEADER is the LaTeX header string. This function only applies
991 when specified inputenc option is \"AUTO\".
993 Return the new header, as a string."
994 (let* ((cs (or (ignore-errors
995 (latexenc-coding-system-to-inputenc
996 (or org-export-coding-system buffer-file-coding-system
)))
999 ;; First translate if that is requested.
1000 (setq cs
(or (cdr (assoc cs org-latex-inputenc-alist
)) cs
))
1001 ;; Then find the \usepackage statement and replace the option.
1002 (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
1003 cs header t nil
1))))
1005 (defun org-latex-guess-babel-language (header info
)
1006 "Set Babel's language according to LANGUAGE keyword.
1008 HEADER is the LaTeX header string. INFO is the plist used as
1009 a communication channel.
1011 Insertion of guessed language only happens when Babel package has
1012 explicitly been loaded. Then it is added to the rest of
1015 Return the new header."
1016 (let ((language-code (plist-get info
:language
)))
1017 ;; If no language is set or Babel package is not loaded, return
1019 (if (or (not (stringp language-code
))
1020 (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header
)))
1022 (let ((options (save-match-data
1023 (org-split-string (match-string 1 header
) ",")))
1024 (language (cdr (assoc language-code
1025 org-latex-babel-language-alist
))))
1026 ;; If LANGUAGE is already loaded, return header. Otherwise,
1027 ;; append LANGUAGE to other options.
1028 (if (member language options
) header
1029 (replace-match (mapconcat 'identity
1030 (append options
(list language
))
1032 nil nil header
1))))))
1034 (defun org-latex--find-verb-separator (s)
1035 "Return a character not used in string S.
1036 This is used to choose a separator for constructs like \\verb."
1037 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1038 (loop for c across ll
1039 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
1040 return
(char-to-string c
))))
1042 (defun org-latex--make-option-string (options)
1043 "Return a comma separated string of keywords and values.
1044 OPTIONS is an alist where the key is the options keyword as
1045 a string, and the value a list containing the keyword value, or
1047 (mapconcat (lambda (pair)
1048 (concat (first pair
)
1049 (when (> (length (second pair
)) 0)
1050 (concat "=" (second pair
)))))
1054 (defun org-latex--wrap-label (element output
)
1055 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1056 This function shouldn't be used for floats. See
1057 `org-latex--caption/label-string'."
1058 (let ((label (org-element-property :name element
)))
1059 (if (not (and (org-string-nw-p output
) (org-string-nw-p label
))) output
1060 (concat (format "\\label{%s}\n" (org-export-solidify-link-text label
))
1063 (defun org-latex--text-markup (text markup
)
1064 "Format TEXT depending on MARKUP text markup.
1065 See `org-latex-text-markup-alist' for details."
1066 (let ((fmt (cdr (assq markup org-latex-text-markup-alist
))))
1068 ;; No format string: Return raw text.
1070 ;; Handle the `verb' special case: Find and appropriate separator
1071 ;; and use "\\verb" command.
1073 (let ((separator (org-latex--find-verb-separator text
)))
1074 (concat "\\verb" separator text separator
)))
1075 ;; Handle the `protectedtexttt' special case: Protect some
1076 ;; special chars and use "\texttt{%s}" format string.
1077 ((eq 'protectedtexttt fmt
)
1079 (trans '(("\\" .
"\\textbackslash{}")
1080 ("~" .
"\\textasciitilde{}")
1081 ("^" .
"\\textasciicircum{}")))
1084 (while (string-match "[\\{}$%&_#~^]" text
)
1085 (setq char
(match-string 0 text
))
1086 (if (> (match-beginning 0) 0)
1087 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
1088 (setq text
(substring text
(1+ (match-beginning 0))))
1089 (setq char
(or (cdr (assoc char trans
)) (concat "\\" char
))
1090 rtn
(concat rtn char
)))
1091 (setq text
(concat rtn text
)
1093 (while (string-match "--" text
)
1094 (setq text
(replace-match "-{}-" t t text
)))
1096 ;; Else use format string.
1097 (t (format fmt text
)))))
1099 (defun org-latex--delayed-footnotes-definitions (element info
)
1100 "Return footnotes definitions in ELEMENT as a string.
1102 INFO is a plist used as a communication channel.
1104 Footnotes definitions are returned within \"\\footnotetxt{}\"
1107 This function is used within constructs that don't support
1108 \"\\footnote{}\" command (i.e. an item's tag). In that case,
1109 \"\\footnotemark\" is used within the construct and the function
1110 just outside of it."
1114 "\\footnotetext[%s]{%s}"
1115 (org-export-get-footnote-number ref info
)
1118 (org-export-get-footnote-definition ref info
) info
))))
1119 ;; Find every footnote reference in ELEMENT.
1121 search-refs
; For byte-compiler.
1125 ;; Return a list of all footnote references never seen
1127 (org-element-map data
'footnote-reference
1129 (when (org-export-footnote-first-reference-p ref info
)
1131 (when (eq (org-element-property :type ref
) 'standard
)
1132 (funcall search-refs
1133 (org-export-get-footnote-definition ref info
)))))
1135 (reverse all-refs
)))))
1136 (funcall search-refs element
))
1143 (defun org-latex-template (contents info
)
1144 "Return complete document string after LaTeX conversion.
1145 CONTENTS is the transcoded contents string. INFO is a plist
1146 holding export options."
1147 (let ((title (org-export-data (plist-get info
:title
) info
)))
1150 (and (plist-get info
:time-stamp-file
)
1151 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
1152 ;; Document class and packages.
1153 (let ((class (plist-get info
:latex-class
))
1154 (class-options (plist-get info
:latex-class-options
)))
1155 (org-element-normalize-string
1156 (let* ((header (nth 1 (assoc class org-latex-classes
)))
1157 (document-class-string
1158 (and (stringp header
)
1159 (if (not class-options
) header
1160 (replace-regexp-in-string
1161 "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
1162 class-options header t nil
1)))))
1163 (if (not document-class-string
)
1164 (user-error "Unknown LaTeX class `%s'" class
)
1165 (org-latex-guess-babel-language
1166 (org-latex-guess-inputenc
1167 (org-splice-latex-header
1168 document-class-string
1169 org-latex-default-packages-alist
1170 org-latex-packages-alist nil
1171 (concat (plist-get info
:latex-header
)
1172 (plist-get info
:latex-header-extra
))))
1174 ;; Possibly limit depth for headline numbering.
1175 (let ((sec-num (plist-get info
:section-numbers
)))
1176 (when (integerp sec-num
)
1177 (format "\\setcounter{secnumdepth}{%d}\n" sec-num
)))
1179 (let ((author (and (plist-get info
:with-author
)
1180 (let ((auth (plist-get info
:author
)))
1181 (and auth
(org-export-data auth info
)))))
1182 (email (and (plist-get info
:with-email
)
1183 (org-export-data (plist-get info
:email
) info
))))
1184 (cond ((and author email
(not (string= "" email
)))
1185 (format "\\author{%s\\thanks{%s}}\n" author email
))
1186 ((or author email
) (format "\\author{%s}\n" (or author email
)))))
1188 (let ((date (and (plist-get info
:with-date
) (org-export-get-date info
))))
1189 (format "\\date{%s}\n" (org-export-data date info
)))
1191 (format "\\title{%s}\n" title
)
1192 ;; Hyperref options.
1193 (when (plist-get info
:latex-hyperref-p
)
1194 (format "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={%s}}\n"
1195 (or (plist-get info
:keywords
) "")
1196 (or (plist-get info
:description
) "")
1197 (if (not (plist-get info
:with-creator
)) ""
1198 (plist-get info
:creator
))))
1200 "\\begin{document}\n\n"
1202 (org-element-normalize-string
1203 (cond ((string= "" title
) nil
)
1204 ((not (stringp org-latex-title-command
)) nil
)
1205 ((string-match "\\(?:[^%]\\|^\\)%s"
1206 org-latex-title-command
)
1207 (format org-latex-title-command title
))
1208 (t org-latex-title-command
)))
1209 ;; Table of contents.
1210 (let ((depth (plist-get info
:with-toc
)))
1212 (concat (when (wholenump depth
)
1213 (format "\\setcounter{tocdepth}{%d}\n" depth
))
1214 org-latex-toc-command
)))
1218 (let ((creator-info (plist-get info
:with-creator
)))
1220 ((not creator-info
) "")
1221 ((eq creator-info
'comment
)
1222 (format "%% %s\n" (plist-get info
:creator
)))
1223 (t (concat (plist-get info
:creator
) "\n"))))
1225 "\\end{document}")))
1229 ;;; Transcode Functions
1233 (defun org-latex-bold (bold contents info
)
1234 "Transcode BOLD from Org to LaTeX.
1235 CONTENTS is the text with bold markup. INFO is a plist holding
1236 contextual information."
1237 (org-latex--text-markup contents
'bold
))
1242 (defun org-latex-center-block (center-block contents info
)
1243 "Transcode a CENTER-BLOCK element from Org to LaTeX.
1244 CONTENTS holds the contents of the center block. INFO is a plist
1245 holding contextual information."
1246 (org-latex--wrap-label
1248 (format "\\begin{center}\n%s\\end{center}" contents
)))
1253 (defun org-latex-clock (clock contents info
)
1254 "Transcode a CLOCK element from Org to LaTeX.
1255 CONTENTS is nil. INFO is a plist holding contextual
1259 (format "\\textbf{%s} " org-clock-string
)
1260 (format org-latex-inactive-timestamp-format
1261 (concat (org-translate-time
1262 (org-element-property :raw-value
1263 (org-element-property :value clock
)))
1264 (let ((time (org-element-property :duration clock
)))
1265 (and time
(format " (%s)" time
)))))
1271 (defun org-latex-code (code contents info
)
1272 "Transcode a CODE object from Org to LaTeX.
1273 CONTENTS is nil. INFO is a plist used as a communication
1275 (org-latex--text-markup (org-element-property :value code
) 'code
))
1280 (defun org-latex-drawer (drawer contents info
)
1281 "Transcode a DRAWER element from Org to LaTeX.
1282 CONTENTS holds the contents of the block. INFO is a plist
1283 holding contextual information."
1284 (let* ((name (org-element-property :drawer-name drawer
))
1285 (output (if (functionp org-latex-format-drawer-function
)
1286 (funcall org-latex-format-drawer-function
1288 ;; If there's no user defined function: simply
1289 ;; display contents of the drawer.
1291 (org-latex--wrap-label drawer output
)))
1296 (defun org-latex-dynamic-block (dynamic-block contents info
)
1297 "Transcode a DYNAMIC-BLOCK element from Org to LaTeX.
1298 CONTENTS holds the contents of the block. INFO is a plist
1299 holding contextual information. See `org-export-data'."
1300 (org-latex--wrap-label dynamic-block contents
))
1305 (defun org-latex-entity (entity contents info
)
1306 "Transcode an ENTITY object from Org to LaTeX.
1307 CONTENTS are the definition itself. INFO is a plist holding
1308 contextual information."
1309 (let ((ent (org-element-property :latex entity
)))
1310 (if (org-element-property :latex-math-p entity
) (format "$%s$" ent
) ent
)))
1315 (defun org-latex-example-block (example-block contents info
)
1316 "Transcode an EXAMPLE-BLOCK element from Org to LaTeX.
1317 CONTENTS is nil. INFO is a plist holding contextual
1319 (when (org-string-nw-p (org-element-property :value example-block
))
1320 (org-latex--wrap-label
1322 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1323 (org-export-format-code-default example-block info
)))))
1328 (defun org-latex-export-block (export-block contents info
)
1329 "Transcode a EXPORT-BLOCK element from Org to LaTeX.
1330 CONTENTS is nil. INFO is a plist holding contextual information."
1331 (when (member (org-element-property :type export-block
) '("LATEX" "TEX"))
1332 (org-remove-indentation (org-element-property :value export-block
))))
1337 (defun org-latex-export-snippet (export-snippet contents info
)
1338 "Transcode a EXPORT-SNIPPET object from Org to LaTeX.
1339 CONTENTS is nil. INFO is a plist holding contextual information."
1340 (when (eq (org-export-snippet-backend export-snippet
) 'latex
)
1341 (org-element-property :value export-snippet
)))
1346 (defun org-latex-fixed-width (fixed-width contents info
)
1347 "Transcode a FIXED-WIDTH element from Org to LaTeX.
1348 CONTENTS is nil. INFO is a plist holding contextual information."
1349 (org-latex--wrap-label
1351 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1352 (org-remove-indentation
1353 (org-element-property :value fixed-width
)))))
1356 ;;;; Footnote Reference
1358 ;; Footnote reference export is handled by
1359 ;; `org-latex-footnote-reference'.
1361 ;; Internally, `org-latex--get-footnote-counter' is used to restore
1362 ;; the value of the LaTeX "footnote" counter after a jump due to
1363 ;; a reference to an already defined footnote. It is only needed in
1364 ;; item tags since the optional argument to \footnotemark is not
1367 (defun org-latex--get-footnote-counter (footnote-reference info
)
1368 "Return \"footnote\" counter before FOOTNOTE-REFERENCE is encountered.
1369 INFO is a plist used as a communication channel."
1370 ;; Find original counter value by counting number of footnote
1371 ;; references appearing for the first time before the current
1372 ;; footnote reference.
1373 (let* ((label (org-element-property :label footnote-reference
))
1375 search-ref
; For byte-compiler.
1379 ;; Search footnote references through DATA, filling
1380 ;; SEEN-REFS along the way.
1381 (org-element-map data
'footnote-reference
1383 (let ((fn-lbl (org-element-property :label fn
)))
1385 ;; Anonymous footnote match: return number.
1386 ((eq fn footnote-reference
) (length seen-refs
))
1387 ;; Anonymous footnote: it's always a new one.
1388 ;; Also, be sure to return nil from the `cond' so
1389 ;; `first-match' doesn't get us out of the loop.
1390 ((not fn-lbl
) (push 'inline seen-refs
) nil
)
1391 ;; Label not seen so far: add it so SEEN-REFS.
1393 ;; Also search for subsequent references in
1394 ;; footnote definition so numbering follows
1395 ;; reading logic. Note that we don't care about
1396 ;; inline definitions, since `org-element-map'
1397 ;; already traverses them at the right time.
1398 ((not (member fn-lbl seen-refs
))
1399 (push fn-lbl seen-refs
)
1401 (org-export-get-footnote-definition fn info
))))))
1402 ;; Don't enter footnote definitions since it will
1403 ;; happen when their first reference is found.
1404 info
'first-match
'footnote-definition
)))))
1405 (funcall search-ref
(plist-get info
:parse-tree
))))
1407 (defun org-latex-footnote-reference (footnote-reference contents info
)
1408 "Transcode a FOOTNOTE-REFERENCE element from Org to LaTeX.
1409 CONTENTS is nil. INFO is a plist holding contextual information."
1411 ;; Insert separator between two footnotes in a row.
1412 (let ((prev (org-export-get-previous-element footnote-reference info
)))
1413 (when (eq (org-element-type prev
) 'footnote-reference
)
1414 org-latex-footnote-separator
))
1416 ;; Use \footnotemark if reference is within an item's tag.
1417 ((eq (org-element-type (org-export-get-parent-element footnote-reference
))
1419 (if (org-export-footnote-first-reference-p footnote-reference info
)
1421 ;; Since we can't specify footnote number as an optional
1422 ;; argument within an item tag, some extra work has to be done
1423 ;; when the footnote has already been referenced. In that
1424 ;; case, set footnote counter to the desired number, use the
1425 ;; footnotemark, then set counter back to its original value.
1427 "\\setcounter{footnote}{%s}\\footnotemark\\setcounter{footnote}{%s}"
1428 (1- (org-export-get-footnote-number footnote-reference info
))
1429 (org-latex--get-footnote-counter footnote-reference info
))))
1430 ;; Use \footnotemark if the footnote has already been defined.
1431 ((not (org-export-footnote-first-reference-p footnote-reference info
))
1432 (format "\\footnotemark[%s]{}"
1433 (org-export-get-footnote-number footnote-reference info
)))
1434 ;; Use \footnotemark if reference is within another footnote
1435 ;; reference, footnote definition or table cell.
1436 ((loop for parent in
(org-export-get-genealogy footnote-reference
)
1437 thereis
(memq (org-element-type parent
)
1438 '(footnote-reference footnote-definition table-cell
)))
1440 ;; Otherwise, define it with \footnote command.
1442 (let ((def (org-export-get-footnote-definition footnote-reference info
)))
1444 (format "\\footnote{%s}" (org-trim (org-export-data def info
)))
1445 ;; Retrieve all footnote references within the footnote and
1446 ;; add their definition after it, since LaTeX doesn't support
1448 (org-latex--delayed-footnotes-definitions def info
)))))))
1453 (defun org-latex-headline (headline contents info
)
1454 "Transcode a HEADLINE element from Org to LaTeX.
1455 CONTENTS holds the contents of the headline. INFO is a plist
1456 holding contextual information."
1457 (unless (org-element-property :footnote-section-p headline
)
1458 (let* ((class (plist-get info
:latex-class
))
1459 (level (org-export-get-relative-level headline info
))
1460 (numberedp (org-export-numbered-headline-p headline info
))
1461 (class-sectionning (assoc class org-latex-classes
))
1462 ;; Section formatting will set two placeholders: one for
1463 ;; the title and the other for the contents.
1465 (let ((sec (if (functionp (nth 2 class-sectionning
))
1466 (funcall (nth 2 class-sectionning
) level numberedp
)
1467 (nth (1+ level
) class-sectionning
))))
1469 ;; No section available for that LEVEL.
1471 ;; Section format directly returned by a function. Add
1472 ;; placeholder for contents.
1473 ((stringp sec
) (concat sec
"\n%s"))
1474 ;; (numbered-section . unnumbered-section)
1475 ((not (consp (cdr sec
)))
1476 (concat (funcall (if numberedp
#'car
#'cdr
) sec
) "\n%s"))
1477 ;; (numbered-open numbered-close)
1479 (when numberedp
(concat (car sec
) "\n%s" (nth 1 sec
))))
1480 ;; (num-in num-out no-num-in no-num-out)
1482 (if numberedp
(concat (car sec
) "\n%s" (nth 1 sec
))
1483 (concat (nth 2 sec
) "\n%s" (nth 3 sec
)))))))
1484 (text (org-export-data (org-element-property :title headline
) info
))
1486 (and (plist-get info
:with-todo-keywords
)
1487 (let ((todo (org-element-property :todo-keyword headline
)))
1488 (and todo
(org-export-data todo info
)))))
1489 (todo-type (and todo
(org-element-property :todo-type headline
)))
1490 (tags (and (plist-get info
:with-tags
)
1491 (org-export-get-tags headline info
)))
1492 (priority (and (plist-get info
:with-priority
)
1493 (org-element-property :priority headline
)))
1494 ;; Create the headline text along with a no-tag version.
1495 ;; The latter is required to remove tags from toc.
1496 (full-text (funcall org-latex-format-headline-function
1497 todo todo-type priority text tags
))
1498 ;; Associate \label to the headline for internal links.
1500 (format "\\label{sec-%s}\n"
1501 (mapconcat 'number-to-string
1502 (org-export-get-headline-number headline info
)
1505 (make-string (org-element-property :pre-blank headline
) 10)))
1506 (if (or (not section-fmt
) (org-export-low-level-p headline info
))
1507 ;; This is a deep sub-tree: export it as a list item. Also
1508 ;; export as items headlines for which no section format has
1510 (let ((low-level-body
1512 ;; If headline is the first sibling, start a list.
1513 (when (org-export-first-sibling-p headline info
)
1514 (format "\\begin{%s}\n" (if numberedp
'enumerate
'itemize
)))
1516 "\\item " full-text
"\n" headline-label pre-blanks contents
)))
1517 ;; If headline is not the last sibling simply return
1518 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before
1520 (if (not (org-export-last-sibling-p headline info
)) low-level-body
1521 (replace-regexp-in-string
1523 (format "\n\\\\end{%s}" (if numberedp
'enumerate
'itemize
))
1525 ;; This is a standard headline. Export it as a section. Add
1526 ;; an alternative heading when possible.
1528 (funcall org-latex-format-headline-function
1529 todo todo-type priority
1531 (org-export-get-alt-title headline info
) info
)
1532 (and (eq (plist-get info
:with-tags
) t
) tags
))))
1533 (if (and numberedp opt-title
1534 (string-match "\\`\\\\\\(.*?[^*]\\){" section-fmt
))
1535 (format (replace-match "\\1[%s]" nil nil section-fmt
1)
1536 ;; Replace square brackets with parenthesis
1537 ;; since square brackets are not supported in
1538 ;; optional arguments.
1539 (replace-regexp-in-string
1540 "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title
))
1542 (concat headline-label pre-blanks contents
))
1543 ;; Impossible to add an alternative heading. Fallback to
1544 ;; regular sectioning format string.
1545 (format section-fmt full-text
1546 (concat headline-label pre-blanks contents
))))))))
1548 (defun org-latex-format-headline-default-function
1549 (todo todo-type priority text tags
)
1550 "Default format function for a headline.
1551 See `org-latex-format-headline-function' for details."
1553 (and todo
(format "{\\bfseries\\sffamily %s} " todo
))
1554 (and priority
(format "\\framebox{\\#%c} " priority
))
1557 (format "\\hfill{}\\textsc{%s}" (mapconcat 'identity tags
":")))))
1560 ;;;; Horizontal Rule
1562 (defun org-latex-horizontal-rule (horizontal-rule contents info
)
1563 "Transcode an HORIZONTAL-RULE object from Org to LaTeX.
1564 CONTENTS is nil. INFO is a plist holding contextual information."
1565 (let ((attr (org-export-read-attribute :attr_latex horizontal-rule
))
1566 (prev (org-export-get-previous-element horizontal-rule info
)))
1568 ;; Make sure the rule doesn't start at the end of the current
1569 ;; line by separating it with a blank line from previous element.
1571 (let ((prev-blank (org-element-property :post-blank prev
)))
1572 (or (not prev-blank
) (zerop prev-blank
))))
1574 (org-latex--wrap-label
1576 (format "\\rule{%s}{%s}"
1577 (or (plist-get attr
:width
) "\\linewidth")
1578 (or (plist-get attr
:thickness
) "0.5pt"))))))
1581 ;;;; Inline Src Block
1583 (defun org-latex-inline-src-block (inline-src-block contents info
)
1584 "Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
1585 CONTENTS holds the contents of the item. INFO is a plist holding
1586 contextual information."
1587 (let* ((code (org-element-property :value inline-src-block
))
1588 (separator (org-latex--find-verb-separator code
)))
1590 ;; Do not use a special package: transcode it verbatim.
1591 ((not org-latex-listings
)
1592 (concat "\\verb" separator code separator
))
1593 ;; Use minted package.
1594 ((eq org-latex-listings
'minted
)
1595 (let* ((org-lang (org-element-property :language inline-src-block
))
1596 (mint-lang (or (cadr (assq (intern org-lang
)
1597 org-latex-minted-langs
))
1599 (options (org-latex--make-option-string
1600 org-latex-minted-options
)))
1601 (concat (format "\\mint%s{%s}"
1602 (if (string= options
"") "" (format "[%s]" options
))
1604 separator code separator
)))
1605 ;; Use listings package.
1607 ;; Maybe translate language's name.
1608 (let* ((org-lang (org-element-property :language inline-src-block
))
1609 (lst-lang (or (cadr (assq (intern org-lang
)
1610 org-latex-listings-langs
))
1612 (options (org-latex--make-option-string
1613 (append org-latex-listings-options
1614 `(("language" ,lst-lang
))))))
1615 (concat (format "\\lstinline[%s]" options
)
1616 separator code separator
))))))
1621 (defun org-latex-inlinetask (inlinetask contents info
)
1622 "Transcode an INLINETASK element from Org to LaTeX.
1623 CONTENTS holds the contents of the block. INFO is a plist
1624 holding contextual information."
1625 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1626 (todo (and (plist-get info
:with-todo-keywords
)
1627 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1628 (and todo
(org-export-data todo info
)))))
1629 (todo-type (org-element-property :todo-type inlinetask
))
1630 (tags (and (plist-get info
:with-tags
)
1631 (org-export-get-tags inlinetask info
)))
1632 (priority (and (plist-get info
:with-priority
)
1633 (org-element-property :priority inlinetask
))))
1634 ;; If `org-latex-format-inlinetask-function' is provided, call it
1635 ;; with appropriate arguments.
1636 (if (functionp org-latex-format-inlinetask-function
)
1637 (funcall org-latex-format-inlinetask-function
1638 todo todo-type priority title tags contents
)
1639 ;; Otherwise, use a default template.
1640 (org-latex--wrap-label
1644 (when todo
(format "\\textbf{\\textsf{\\textsc{%s}}} " todo
))
1645 (when priority
(format "\\framebox{\\#%c} " priority
))
1647 (when tags
(format "\\hfill{}\\textsc{:%s:}"
1648 (mapconcat 'identity tags
":"))))))
1649 (format (concat "\\begin{center}\n"
1651 "\\begin{minipage}[c]{.6\\textwidth}\n"
1653 "\\rule[.8em]{\\textwidth}{2pt}\n\n"
1658 full-title contents
))))))
1663 (defun org-latex-italic (italic contents info
)
1664 "Transcode ITALIC from Org to LaTeX.
1665 CONTENTS is the text with italic markup. INFO is a plist holding
1666 contextual information."
1667 (org-latex--text-markup contents
'italic
))
1672 (defun org-latex-item (item contents info
)
1673 "Transcode an ITEM element from Org to LaTeX.
1674 CONTENTS holds the contents of the item. INFO is a plist holding
1675 contextual information."
1677 (let ((count (org-element-property :counter item
))
1679 ;; Determine level of current item to determine the
1680 ;; correct LaTeX counter to use (enumi, enumii...).
1681 (let ((parent item
) (level 0))
1682 (while (memq (org-element-type
1683 (setq parent
(org-export-get-parent parent
)))
1685 (when (and (eq (org-element-type parent
) 'plain-list
)
1686 (eq (org-element-property :type parent
)
1692 (format "\\setcounter{enum%s}{%s}\n"
1693 (nth (1- level
) '("i" "ii" "iii" "iv"))
1695 (checkbox (case (org-element-property :checkbox item
)
1696 (on "$\\boxtimes$ ")
1698 (trans "$\\boxminus$ ")))
1699 (tag (let ((tag (org-element-property :tag item
)))
1700 ;; Check-boxes must belong to the tag.
1701 (and tag
(format "[%s] "
1703 (org-export-data tag info
)))))))
1704 (concat counter
"\\item" (or tag
(concat " " checkbox
))
1705 (and contents
(org-trim contents
))
1706 ;; If there are footnotes references in tag, be sure to
1707 ;; add their definition at the end of the item. This
1708 ;; workaround is necessary since "\footnote{}" command is
1709 ;; not supported in tags.
1711 (org-latex--delayed-footnotes-definitions
1712 (org-element-property :tag item
) info
)))))
1717 (defun org-latex-keyword (keyword contents info
)
1718 "Transcode a KEYWORD element from Org to LaTeX.
1719 CONTENTS is nil. INFO is a plist holding contextual information."
1720 (let ((key (org-element-property :key keyword
))
1721 (value (org-element-property :value keyword
)))
1723 ((string= key
"LATEX") value
)
1724 ((string= key
"INDEX") (format "\\index{%s}" value
))
1725 ;; Invisible targets.
1726 ((string= key
"TARGET") nil
)
1727 ((string= key
"TOC")
1728 (let ((value (downcase value
)))
1730 ((string-match "\\<headlines\\>" value
)
1731 (let ((depth (or (and (string-match "[0-9]+" value
)
1732 (string-to-number (match-string 0 value
)))
1733 (plist-get info
:with-toc
))))
1735 (when (wholenump depth
)
1736 (format "\\setcounter{tocdepth}{%s}\n" depth
))
1737 "\\tableofcontents")))
1738 ((string= "tables" value
) "\\listoftables")
1739 ((string= "listings" value
)
1741 ((eq org-latex-listings
'minted
) "\\listoflistings")
1742 (org-latex-listings "\\lstlistoflistings")
1743 ;; At the moment, src blocks with a caption are wrapped
1744 ;; into a figure environment.
1745 (t "\\listoffigures")))))))))
1748 ;;;; Latex Environment
1750 (defun org-latex-latex-environment (latex-environment contents info
)
1751 "Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
1752 CONTENTS is nil. INFO is a plist holding contextual information."
1753 (when (plist-get info
:with-latex
)
1754 (let ((label (org-element-property :name latex-environment
))
1755 (value (org-remove-indentation
1756 (org-element-property :value latex-environment
))))
1757 (if (not (org-string-nw-p label
)) value
1758 ;; Environment is labelled: label must be within the environment
1759 ;; (otherwise, a reference pointing to that element will count
1760 ;; the section instead).
1763 (goto-char (point-min))
1766 (format "\\label{%s}\n" (org-export-solidify-link-text label
)))
1767 (buffer-string))))))
1772 (defun org-latex-latex-fragment (latex-fragment contents info
)
1773 "Transcode a LATEX-FRAGMENT object from Org to LaTeX.
1774 CONTENTS is nil. INFO is a plist holding contextual information."
1775 (when (plist-get info
:with-latex
)
1776 (org-element-property :value latex-fragment
)))
1781 (defun org-latex-line-break (line-break contents info
)
1782 "Transcode a LINE-BREAK object from Org to LaTeX.
1783 CONTENTS is nil. INFO is a plist holding contextual information."
1789 (defun org-latex--inline-image (link info
)
1790 "Return LaTeX code for an inline image.
1791 LINK is the link pointing to the inline image. INFO is a plist
1792 used as a communication channel."
1793 (let* ((parent (org-export-get-parent-element link
))
1794 (path (let ((raw-path (org-element-property :path link
)))
1795 (if (not (file-name-absolute-p raw-path
)) raw-path
1796 (expand-file-name raw-path
))))
1797 (filetype (file-name-extension path
))
1798 (caption (org-latex--caption/label-string parent info
))
1799 ;; Retrieve latex attributes from the element around.
1800 (attr (org-export-read-attribute :attr_latex parent
))
1801 (float (let ((float (plist-get attr
:float
)))
1802 (cond ((string= float
"wrap") 'wrap
)
1803 ((string= float
"multicolumn") 'multicolumn
)
1804 ((or (string= float
"figure")
1805 (org-element-property :caption parent
))
1808 (let ((place (plist-get attr
:placement
)))
1809 (cond (place (format "%s" place
))
1810 ((eq float
'wrap
) "{l}{0.5\\textwidth}")
1812 (format "[%s]" org-latex-default-figure-position
))
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
'figure
) "0.7\\textwidth")
1820 ((eq float
'wrap
) "0.48\\textwidth")
1821 (t org-latex-image-default-width
)))
1822 (height (cond ((plist-get attr
:height
))
1823 ((or (plist-get attr
:width
)
1824 (memq float
'(figure wrap
))) "")
1825 (t org-latex-image-default-height
)))
1826 (options (let ((opt (or (plist-get attr
:options
)
1827 org-latex-image-default-option
)))
1828 (if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt
)) opt
1829 (match-string 1 opt
))))
1831 (if (equal filetype
"tikz")
1833 ;; - use \input to read in image file.
1834 ;; - if options are present, wrap in a tikzpicture environment.
1835 ;; - if width or height are present, use \resizebox to change
1838 (setq image-code
(format "\\input{%s}" path
))
1839 (when (org-string-nw-p options
)
1841 (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
1844 (when (or (org-string-nw-p width
) (org-string-nw-p height
))
1845 (setq image-code
(format "\\resizebox{%s}{%s}{%s}"
1846 (if (org-string-nw-p width
) width
"!")
1847 (if (org-string-nw-p height
) height
"!")
1849 ;; For other images:
1850 ;; - add width and height to options.
1851 ;; - include the image with \includegraphics.
1852 (when (org-string-nw-p width
)
1853 (setq options
(concat options
",width=" width
)))
1854 (when (org-string-nw-p height
)
1855 (setq options
(concat options
",height=" height
)))
1857 (format "\\includegraphics%s{%s}"
1858 (cond ((not (org-string-nw-p options
)) "")
1859 ((= (aref options
0) ?
,)
1860 (format "[%s]"(substring options
1)))
1861 (t (format "[%s]" options
)))
1863 ;; Return proper string, depending on FLOAT.
1865 (wrap (format "\\begin{wrapfigure}%s
1868 %s\\end{wrapfigure}" placement comment-include image-code caption
))
1869 (multicolumn (format "\\begin{figure*}%s
1872 %s\\end{figure*}" placement comment-include image-code caption
))
1873 (figure (format "\\begin{figure}%s
1876 %s\\end{figure}" placement comment-include image-code caption
))
1877 (otherwise image-code
))))
1879 (defun org-latex-link (link desc info
)
1880 "Transcode a LINK object from Org to LaTeX.
1882 DESC is the description part of the link, or the empty string.
1883 INFO is a plist holding contextual information. See
1885 (let* ((type (org-element-property :type link
))
1886 (raw-path (org-element-property :path link
))
1887 ;; Ensure DESC really exists, or set it to nil.
1888 (desc (and (not (string= desc
"")) desc
))
1889 (imagep (org-export-inline-image-p
1890 link org-latex-inline-image-rules
))
1892 ((member type
'("http" "https" "ftp" "mailto"))
1893 (concat type
":" raw-path
))
1894 ((string= type
"file")
1895 (if (not (file-name-absolute-p raw-path
)) raw-path
1896 (concat "file://" (expand-file-name raw-path
))))
1901 (imagep (org-latex--inline-image link info
))
1902 ;; Radio link: Transcode target's contents and use them as link's
1904 ((string= type
"radio")
1905 (let ((destination (org-export-resolve-radio-link link info
)))
1907 (format "\\hyperref[%s]{%s}"
1908 (org-export-solidify-link-text path
)
1909 (org-export-data (org-element-contents destination
) info
)))))
1910 ;; Links pointing to a headline: Find destination and build
1911 ;; appropriate referencing command.
1912 ((member type
'("custom-id" "fuzzy" "id"))
1913 (let ((destination (if (string= type
"fuzzy")
1914 (org-export-resolve-fuzzy-link link info
)
1915 (org-export-resolve-id-link link info
))))
1916 (case (org-element-type destination
)
1917 ;; Id link points to an external file.
1919 (if desc
(format "\\href{%s}{%s}" destination desc
)
1920 (format "\\url{%s}" destination
)))
1921 ;; Fuzzy link points nowhere.
1923 (format org-latex-link-with-unknown-path-format
1926 (org-element-property :raw-link link
) info
))))
1927 ;; Fuzzy link points to an invisible target.
1929 ;; LINK points to a headline. If headlines are numbered
1930 ;; and the link has no description, display headline's
1931 ;; number. Otherwise, display description or headline's
1938 (org-export-get-headline-number destination info
)
1940 (if (and (plist-get info
:section-numbers
) (not desc
))
1941 (format "\\ref{%s}" label
)
1942 (format "\\hyperref[%s]{%s}" label
1945 (org-element-property :title destination
) info
))))))
1946 ;; Fuzzy link points to a target. Do as above.
1948 (let ((path (org-export-solidify-link-text path
)))
1949 (if (not desc
) (format "\\ref{%s}" path
)
1950 (format "\\hyperref[%s]{%s}" path desc
)))))))
1951 ;; Coderef: replace link with the reference name or the
1952 ;; equivalent line number.
1953 ((string= type
"coderef")
1954 (format (org-export-get-coderef-format path desc
)
1955 (org-export-resolve-coderef path info
)))
1956 ;; Link type is handled by a special function.
1957 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
1958 (funcall protocol
(org-link-unescape path
) desc
'latex
))
1959 ;; External link with a description part.
1960 ((and path desc
) (format "\\href{%s}{%s}" path desc
))
1961 ;; External link without a description part.
1962 (path (format "\\url{%s}" path
))
1963 ;; No path, only description. Try to do something useful.
1964 (t (format org-latex-link-with-unknown-path-format desc
)))))
1969 (defun org-latex-paragraph (paragraph contents info
)
1970 "Transcode a PARAGRAPH element from Org to LaTeX.
1971 CONTENTS is the contents of the paragraph, as a string. INFO is
1972 the plist used as a communication channel."
1978 (defun org-latex-plain-list (plain-list contents info
)
1979 "Transcode a PLAIN-LIST element from Org to LaTeX.
1980 CONTENTS is the contents of the list. INFO is a plist holding
1981 contextual information."
1982 (let* ((type (org-element-property :type plain-list
))
1983 (attr (org-export-read-attribute :attr_latex plain-list
))
1984 (latex-type (let ((env (plist-get attr
:environment
)))
1985 (cond (env (format "%s" env
))
1986 ((eq type
'ordered
) "enumerate")
1987 ((eq type
'unordered
) "itemize")
1988 ((eq type
'descriptive
) "description")))))
1989 (org-latex--wrap-label
1991 (format "\\begin{%s}%s\n%s\\end{%s}"
1993 ;; Put optional arguments, if any inside square brackets
1995 (let ((options (format "%s" (or (plist-get attr
:options
) ""))))
1996 (cond ((equal options
"") "")
1997 ((string-match "\\`\\[.*\\]\\'" options
) options
)
1998 (t (format "[%s]" options
))))
2005 (defun org-latex-plain-text (text info
)
2006 "Transcode a TEXT string from Org to LaTeX.
2007 TEXT is the string to transcode. INFO is a plist holding
2008 contextual information."
2009 (let ((specialp (plist-get info
:with-special-strings
))
2011 ;; Protect %, #, &, $, ^, _, { and }.
2012 (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}^_]\\)" output
)
2015 (format "\\%s" (match-string 2 output
)) nil t output
2)))
2016 ;; Protect \. If special strings are used, be careful not to
2017 ;; protect "\" in "\-" constructs.
2018 (let ((symbols (if specialp
"-%$#&{}^_\\" "%$#&{}^_\\")))
2020 (replace-regexp-in-string
2021 (format "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%s]\\|$\\)" symbols
)
2022 "$\\backslash$" output nil t
1)))
2025 (replace-regexp-in-string
2026 "\\([^\\]\\|^\\)\\(~\\)" "\\textasciitilde{}" output nil t
2))
2027 ;; Activate smart quotes. Be sure to provide original TEXT string
2028 ;; since OUTPUT may have been modified.
2029 (when (plist-get info
:with-smart-quotes
)
2030 (setq output
(org-export-activate-smart-quotes output
:latex info text
)))
2031 ;; LaTeX into \LaTeX{} and TeX into \TeX{}.
2032 (let ((case-fold-search nil
)
2034 (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" output start
)
2035 (setq output
(replace-match
2036 (format "\\%s{}" (match-string 1 output
)) nil t output
)
2037 start
(match-end 0))))
2038 ;; Convert special strings.
2041 (replace-regexp-in-string "\\.\\.\\." "\\ldots{}" output nil t
)))
2042 ;; Handle break preservation if required.
2043 (when (plist-get info
:preserve-breaks
)
2044 (setq output
(replace-regexp-in-string
2045 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" output
)))
2052 (defun org-latex-planning (planning contents info
)
2053 "Transcode a PLANNING element from Org to LaTeX.
2054 CONTENTS is nil. INFO is a plist holding contextual
2062 (let ((closed (org-element-property :closed planning
)))
2065 (format "\\textbf{%s} " org-closed-string
)
2066 (format org-latex-inactive-timestamp-format
2068 (org-element-property :raw-value closed
))))))
2069 (let ((deadline (org-element-property :deadline planning
)))
2072 (format "\\textbf{%s} " org-deadline-string
)
2073 (format org-latex-active-timestamp-format
2075 (org-element-property :raw-value deadline
))))))
2076 (let ((scheduled (org-element-property :scheduled planning
)))
2079 (format "\\textbf{%s} " org-scheduled-string
)
2080 (format org-latex-active-timestamp-format
2082 (org-element-property :raw-value scheduled
))))))))
2089 (defun org-latex-quote-block (quote-block contents info
)
2090 "Transcode a QUOTE-BLOCK element from Org to LaTeX.
2091 CONTENTS holds the contents of the block. INFO is a plist
2092 holding contextual information."
2093 (org-latex--wrap-label
2095 (format "\\begin{quote}\n%s\\end{quote}" contents
)))
2100 (defun org-latex-quote-section (quote-section contents info
)
2101 "Transcode a QUOTE-SECTION element from Org to LaTeX.
2102 CONTENTS is nil. INFO is a plist holding contextual information."
2103 (let ((value (org-remove-indentation
2104 (org-element-property :value quote-section
))))
2105 (when value
(format "\\begin{verbatim}\n%s\\end{verbatim}" value
))))
2110 (defun org-latex-radio-target (radio-target text info
)
2111 "Transcode a RADIO-TARGET object from Org to LaTeX.
2112 TEXT is the text of the target. INFO is a plist holding
2113 contextual information."
2114 (format "\\label{%s}%s"
2115 (org-export-solidify-link-text
2116 (org-element-property :value radio-target
))
2122 (defun org-latex-section (section contents info
)
2123 "Transcode a SECTION element from Org to LaTeX.
2124 CONTENTS holds the contents of the section. INFO is a plist
2125 holding contextual information."
2131 (defun org-latex-special-block (special-block contents info
)
2132 "Transcode a SPECIAL-BLOCK element from Org to LaTeX.
2133 CONTENTS holds the contents of the block. INFO is a plist
2134 holding contextual information."
2135 (let ((type (downcase (org-element-property :type special-block
)))
2136 (opt (org-export-read-attribute :attr_latex special-block
:options
)))
2137 (concat (format "\\begin{%s}%s\n" type
(or opt
""))
2138 ;; Insert any label or caption within the block
2139 ;; (otherwise, a reference pointing to that element will
2140 ;; count the section instead).
2141 (org-latex--caption/label-string special-block info
)
2143 (format "\\end{%s}" type
))))
2148 (defun org-latex-src-block (src-block contents info
)
2149 "Transcode a SRC-BLOCK element from Org to LaTeX.
2150 CONTENTS holds the contents of the item. INFO is a plist holding
2151 contextual information."
2152 (when (org-string-nw-p (org-element-property :value src-block
))
2153 (let* ((lang (org-element-property :language src-block
))
2154 (caption (org-element-property :caption src-block
))
2155 (label (org-element-property :name src-block
))
2156 (custom-env (and lang
2157 (cadr (assq (intern lang
)
2158 org-latex-custom-lang-environments
))))
2159 (num-start (case (org-element-property :number-lines src-block
)
2160 (continued (org-export-get-loc src-block info
))
2162 (retain-labels (org-element-property :retain-labels src-block
))
2164 (let ((attr (org-export-read-attribute :attr_latex src-block
)))
2165 (if (plist-member attr
:long-listing
)
2166 (plist-get attr
:long-listing
)
2167 org-latex-long-listings
))))
2169 ;; Case 1. No source fontification.
2170 ((not org-latex-listings
)
2171 (let* ((caption-str (org-latex--caption/label-string src-block info
))
2172 (float-env (and (not long-listing
)
2174 (format "\\begin{figure}[H]\n%s%%s\n\\end{figure}"
2178 (concat (format "\\begin{verbatim}\n%s\\end{verbatim}"
2179 (org-export-format-code-default src-block info
))))))
2180 ;; Case 2. Custom environment.
2181 (custom-env (format "\\begin{%s}\n%s\\end{%s}\n"
2183 (org-export-format-code-default src-block info
)
2185 ;; Case 3. Use minted package.
2186 ((eq org-latex-listings
'minted
)
2188 (and (not long-listing
)
2190 (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
2191 (org-latex--caption/label-string src-block info
))))
2194 "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
2196 (org-latex--make-option-string
2197 (if (or (not num-start
)
2198 (assoc "linenos" org-latex-minted-options
))
2199 org-latex-minted-options
2200 (append `(("linenos")
2201 ("firstnumber" ,(number-to-string (1+ num-start
))))
2202 org-latex-minted-options
)))
2204 (or (cadr (assq (intern lang
) org-latex-minted-langs
)) lang
)
2206 (let* ((code-info (org-export-unravel-code src-block
))
2210 (org-split-string (car code-info
)
2212 (org-export-format-code
2214 (lambda (loc num ref
)
2218 ;; Ensure references are flushed to the right,
2219 ;; separated with 6 spaces from the widest line
2221 (concat (make-string (+ (- max-width
(length loc
)) 6)
2223 (format "(%s)" ref
)))))
2224 nil
(and retain-labels
(cdr code-info
)))))))
2226 (if float-env
(format float-env body
) body
)))
2227 ;; Case 4. Use listings package.
2230 (or (cadr (assq (intern lang
) org-latex-listings-langs
)) lang
))
2233 (let ((main (org-export-get-caption src-block
))
2234 (secondary (org-export-get-caption src-block t
)))
2236 (format "{%s}" (org-export-data main info
))
2238 (org-export-data secondary info
)
2239 (org-export-data main info
)))))))
2242 (format "\\lstset{%s}\n"
2243 (org-latex--make-option-string
2245 org-latex-listings-options
2246 `(("language" ,lst-lang
))
2247 (when label
`(("label" ,label
)))
2248 (when caption-str
`(("caption" ,caption-str
)))
2249 (cond ((assoc "numbers" org-latex-listings-options
) nil
)
2250 ((not num-start
) '(("numbers" "none")))
2251 ((zerop num-start
) '(("numbers" "left")))
2252 (t `(("numbers" "left")
2254 ,(number-to-string (1+ num-start
)))))))))
2257 "\\begin{lstlisting}\n%s\\end{lstlisting}"
2258 (let* ((code-info (org-export-unravel-code src-block
))
2262 (org-split-string (car code-info
) "\n")))))
2263 (org-export-format-code
2265 (lambda (loc num ref
)
2269 ;; Ensure references are flushed to the right,
2270 ;; separated with 6 spaces from the widest line of
2272 (concat (make-string (+ (- max-width
(length loc
)) 6) ?
)
2273 (format "(%s)" ref
)))))
2274 nil
(and retain-labels
(cdr code-info
))))))))))))
2277 ;;;; Statistics Cookie
2279 (defun org-latex-statistics-cookie (statistics-cookie contents info
)
2280 "Transcode a STATISTICS-COOKIE object from Org to LaTeX.
2281 CONTENTS is nil. INFO is a plist holding contextual information."
2282 (replace-regexp-in-string
2283 "%" "\\%" (org-element-property :value statistics-cookie
) nil t
))
2288 (defun org-latex-strike-through (strike-through contents info
)
2289 "Transcode STRIKE-THROUGH from Org to LaTeX.
2290 CONTENTS is the text with strike-through markup. INFO is a plist
2291 holding contextual information."
2292 (org-latex--text-markup contents
'strike-through
))
2297 (defun org-latex-subscript (subscript contents info
)
2298 "Transcode a SUBSCRIPT object from Org to LaTeX.
2299 CONTENTS is the contents of the object. INFO is a plist holding
2300 contextual information."
2301 (if (= (length contents
) 1) (format "$_%s$" contents
)
2302 ;; Handle multiple objects in SUBSCRIPT by creating a subscript
2303 ;; command for each of them.
2304 (let ((prev-blanks 0))
2307 (case (org-element-type obj
)
2308 ((entity latex-fragment
)
2309 (setq prev-blanks
(org-element-property :post-blank obj
))
2310 (let ((data (org-trim (org-export-data obj info
))))
2312 "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
2314 (format "$_{%s}$" (match-string 1 data
))))
2316 (format "$_\\mathrm{%s}$"
2317 (concat (make-string prev-blanks ?
)
2318 ;; mathrm command doesn't handle spaces,
2319 ;; so we have to enforce them.
2320 (replace-regexp-in-string
2321 " " "\\\\ " (org-export-data obj info
)))))
2323 (setq prev-blanks
(org-element-property :post-blank obj
))
2324 (format "$_{%s}$" (org-export-data obj info
)))))
2325 (org-element-contents subscript
) ""))))
2330 (defun org-latex-superscript (superscript contents info
)
2331 "Transcode a SUPERSCRIPT object from Org to LaTeX.
2332 CONTENTS is the contents of the object. INFO is a plist holding
2333 contextual information."
2334 (if (= (length contents
) 1) (format "$^%s$" contents
)
2335 ;; Handle multiple objects in SUPERSCRIPT by creating
2336 ;; a superscript command for each of them.
2337 (let ((prev-blanks 0))
2340 (case (org-element-type obj
)
2341 ((entity latex-fragment
)
2342 (setq prev-blanks
(org-element-property :post-blank obj
))
2343 (let ((data (org-trim (org-export-data obj info
))))
2345 "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
2347 (format "$^{%s}$" (match-string 1 data
))))
2349 (format "$^\\mathrm{%s}$"
2350 (concat (make-string prev-blanks ?
)
2351 ;; mathrm command doesn't handle spaces,
2352 ;; so we have to enforce them.
2353 (replace-regexp-in-string
2354 " " "\\\\ " (org-export-data obj info
)))))
2356 (setq prev-blanks
(org-element-property :post-blank obj
))
2357 (format "$^{%s}$" (org-export-data obj info
)))))
2358 (org-element-contents superscript
) ""))))
2363 ;; `org-latex-table' is the entry point for table transcoding. It
2364 ;; takes care of tables with a "verbatim" mode. Otherwise, it
2365 ;; delegates the job to either `org-latex--table.el-table',
2366 ;; `org-latex--org-table' or `org-latex--math-table' functions,
2367 ;; depending of the type of the table and the mode requested.
2369 ;; `org-latex--align-string' is a subroutine used to build alignment
2370 ;; string for Org tables.
2372 (defun org-latex-table (table contents info
)
2373 "Transcode a TABLE element from Org to LaTeX.
2374 CONTENTS is the contents of the table. INFO is a plist holding
2375 contextual information."
2376 (if (eq (org-element-property :type table
) 'table.el
)
2377 ;; "table.el" table. Convert it using appropriate tools.
2378 (org-latex--table.el-table table info
)
2379 (let ((type (or (org-export-read-attribute :attr_latex table
:mode
)
2380 org-latex-default-table-mode
)))
2382 ;; Case 1: Verbatim table.
2383 ((string= type
"verbatim")
2384 (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
2385 ;; Re-create table, without affiliated keywords.
2386 (org-trim (org-element-interpret-data
2387 `(table nil
,@(org-element-contents table
))))))
2389 ((or (string= type
"math") (string= type
"inline-math"))
2390 (org-latex--math-table table info
))
2391 ;; Case 3: Standard table.
2392 (t (concat (org-latex--org-table table contents info
)
2393 ;; When there are footnote references within the
2394 ;; table, insert their definition just after it.
2395 (org-latex--delayed-footnotes-definitions table info
)))))))
2397 (defun org-latex--align-string (table info
)
2398 "Return an appropriate LaTeX alignment string.
2399 TABLE is the considered table. INFO is a plist used as
2400 a communication channel."
2401 (or (org-export-read-attribute :attr_latex table
:align
)
2403 ;; Extract column groups and alignment from first (non-rule)
2406 (org-element-map table
'table-row
2408 (and (eq (org-element-property :type row
) 'standard
) row
))
2412 (let ((borders (org-export-table-cell-borders cell info
)))
2413 ;; Check left border for the first cell only.
2414 (when (and (memq 'left borders
) (not align
))
2416 (push (case (org-export-table-cell-alignment cell info
)
2421 (when (memq 'right borders
) (push "|" align
))))
2423 (apply 'concat
(nreverse align
)))))
2425 (defun org-latex--org-table (table contents info
)
2426 "Return appropriate LaTeX code for an Org table.
2428 TABLE is the table type element to transcode. CONTENTS is its
2429 contents, as a string. INFO is a plist used as a communication
2432 This function assumes TABLE has `org' as its `:type' property and
2433 `table' as its `:mode' attribute."
2434 (let* ((caption (org-latex--caption/label-string table info
))
2435 (attr (org-export-read-attribute :attr_latex table
))
2436 ;; Determine alignment string.
2437 (alignment (org-latex--align-string table info
))
2438 ;; Determine environment for the table: longtable, tabular...
2439 (table-env (or (plist-get attr
:environment
)
2440 org-latex-default-table-environment
))
2441 ;; If table is a float, determine environment: table, table*
2442 ;; or sidewaystable.
2443 (float-env (unless (member table-env
'("longtable" "longtabu"))
2444 (let ((float (plist-get attr
:float
)))
2446 ((string= float
"sidewaystable") "sidewaystable")
2447 ((string= float
"multicolumn") "table*")
2448 ((or (string= float
"table")
2449 (org-element-property :caption table
))
2451 ;; Extract others display options.
2452 (fontsize (let ((font (plist-get attr
:font
)))
2453 (and font
(concat font
"\n"))))
2454 (width (plist-get attr
:width
))
2455 (spreadp (plist-get attr
:spread
))
2456 (placement (or (plist-get attr
:placement
)
2457 (format "[%s]" org-latex-default-figure-position
)))
2458 (centerp (if (plist-member attr
:center
) (plist-get attr
:center
)
2459 org-latex-tables-centered
)))
2460 ;; Prepare the final format string for the table.
2463 ((equal "longtable" table-env
)
2464 (concat (and fontsize
(concat "{" fontsize
))
2465 (format "\\begin{longtable}{%s}\n" alignment
)
2466 (and org-latex-table-caption-above
2467 (org-string-nw-p caption
)
2468 (concat caption
"\\\\\n"))
2470 (and (not org-latex-table-caption-above
)
2471 (org-string-nw-p caption
)
2472 (concat caption
"\\\\\n"))
2473 "\\end{longtable}\n"
2474 (and fontsize
"}")))
2476 ((equal "longtabu" table-env
)
2477 (concat (and fontsize
(concat "{" fontsize
))
2478 (format "\\begin{longtabu}%s{%s}\n"
2481 (if spreadp
"spread" "to") width
) "")
2483 (and org-latex-table-caption-above
2484 (org-string-nw-p caption
)
2485 (concat caption
"\\\\\n"))
2487 (and (not org-latex-table-caption-above
)
2488 (org-string-nw-p caption
)
2489 (concat caption
"\\\\\n"))
2491 (and fontsize
"}")))
2495 (concat (format "\\begin{%s}%s\n" float-env placement
)
2496 (if org-latex-table-caption-above caption
"")
2497 (when centerp
"\\centering\n")
2499 (centerp (concat "\\begin{center}\n" fontsize
))
2500 (fontsize (concat "{" fontsize
)))
2501 (cond ((equal "tabu" table-env
)
2502 (format "\\begin{tabu}%s{%s}\n%s\\end{tabu}"
2504 (if spreadp
" spread %s " " to %s ")
2508 (t (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
2510 (if width
(format "{%s}" width
) "")
2516 (concat (if org-latex-table-caption-above
"" caption
)
2517 (format "\n\\end{%s}" float-env
)))
2518 (centerp "\n\\end{center}")
2519 (fontsize "}")))))))
2521 (defun org-latex--table.el-table
(table info
)
2522 "Return appropriate LaTeX code for a table.el table.
2524 TABLE is the table type element to transcode. INFO is a plist
2525 used as a communication channel.
2527 This function assumes TABLE has `table.el' as its `:type'
2530 ;; Ensure "*org-export-table*" buffer is empty.
2531 (with-current-buffer (get-buffer-create "*org-export-table*")
2533 (let ((output (with-temp-buffer
2534 (insert (org-element-property :value table
))
2536 (re-search-forward "^[ \t]*|[^|]" nil t
)
2537 (table-generate-source 'latex
"*org-export-table*")
2538 (with-current-buffer "*org-export-table*"
2539 (org-trim (buffer-string))))))
2540 (kill-buffer (get-buffer "*org-export-table*"))
2541 ;; Remove left out comments.
2542 (while (string-match "^%.*\n" output
)
2543 (setq output
(replace-match "" t t output
)))
2544 (let ((attr (org-export-read-attribute :attr_latex table
)))
2545 (when (plist-get attr
:rmlines
)
2546 ;; When the "rmlines" attribute is provided, remove all hlines
2547 ;; but the the one separating heading from the table body.
2548 (let ((n 0) (pos 0))
2549 (while (and (< (length output
) pos
)
2550 (setq pos
(string-match "^\\\\hline\n?" output pos
)))
2552 (unless (= n
2) (setq output
(replace-match "" nil nil output
))))))
2553 (let ((centerp (if (plist-member attr
:center
) (plist-get attr
:center
)
2554 org-latex-tables-centered
)))
2555 (if (not centerp
) output
2556 (format "\\begin{center}\n%s\n\\end{center}" output
))))))
2558 (defun org-latex--math-table (table info
)
2559 "Return appropriate LaTeX code for a matrix.
2561 TABLE is the table type element to transcode. INFO is a plist
2562 used as a communication channel.
2564 This function assumes TABLE has `org' as its `:type' property and
2565 `inline-math' or `math' as its `:mode' attribute.."
2566 (let* ((caption (org-latex--caption/label-string table info
))
2567 (attr (org-export-read-attribute :attr_latex table
))
2568 (inlinep (eq (plist-get attr
:mode
) 'inline-math
))
2569 (env (or (plist-get attr
:environment
)
2570 org-latex-default-table-environment
))
2574 ;; Ignore horizontal rules.
2575 (when (eq (org-element-property :type row
) 'standard
)
2576 ;; Return each cell unmodified.
2580 (substring (org-element-interpret-data cell
) 0 -
1))
2581 (org-element-map row
'table-cell
'identity info
) "&")
2582 (or (cdr (assoc env org-latex-table-matrix-macros
)) "\\\\")
2584 (org-element-map table
'table-row
'identity info
) ""))
2585 ;; Variables related to math clusters (contiguous math tables
2586 ;; of the same type).
2587 (mode (org-export-read-attribute :attr_latex table
:mode
))
2588 (prev (org-export-get-previous-element table info
))
2589 (next (org-export-get-next-element table info
))
2592 ;; Non-nil when TABLE has the same mode as current table.
2593 (string= (or (org-export-read-attribute :attr_latex table
:mode
)
2594 org-latex-default-table-mode
)
2597 ;; Opening string. If TABLE is in the middle of a table cluster,
2598 ;; do not insert any.
2600 (eq (org-element-type prev
) 'table
)
2601 (memq (org-element-property :post-blank prev
) '(0 nil
))
2602 (funcall same-mode-p prev
))
2605 ((org-string-nw-p caption
) (concat "\\begin{equation}\n" caption
))
2608 (or (plist-get attr
:math-prefix
) "")
2609 ;; Environment. Also treat special cases.
2610 (cond ((equal env
"array")
2611 (let ((align (org-latex--align-string table info
)))
2612 (format "\\begin{array}{%s}\n%s\\end{array}" align contents
)))
2613 ((assoc env org-latex-table-matrix-macros
)
2614 (format "\\%s%s{\n%s}"
2616 (or (plist-get attr
:math-arguments
) "")
2618 (t (format "\\begin{%s}\n%s\\end{%s}" env contents env
)))
2620 (or (plist-get attr
:math-suffix
) "")
2621 ;; Closing string. If TABLE is in the middle of a table cluster,
2622 ;; do not insert any. If it closes such a cluster, be sure to
2623 ;; close the cluster with a string matching the opening string.
2625 (eq (org-element-type next
) 'table
)
2626 (memq (org-element-property :post-blank table
) '(0 nil
))
2627 (funcall same-mode-p next
))
2630 ;; Find cluster beginning to know which environment to use.
2631 ((let ((cluster-beg table
) prev
)
2632 (while (and (setq prev
(org-export-get-previous-element
2634 (memq (org-element-property :post-blank prev
)
2636 (funcall same-mode-p prev
))
2637 (setq cluster-beg prev
))
2638 (and (or (org-element-property :caption cluster-beg
)
2639 (org-element-property :name cluster-beg
))
2640 "\n\\end{equation}")))
2646 (defun org-latex-table-cell (table-cell contents info
)
2647 "Transcode a TABLE-CELL element from Org to LaTeX.
2648 CONTENTS is the cell contents. INFO is a plist used as
2649 a communication channel."
2650 (concat (if (and contents
2651 org-latex-table-scientific-notation
2652 (string-match orgtbl-exp-regexp contents
))
2653 ;; Use appropriate format string for scientific
2655 (format org-latex-table-scientific-notation
2656 (match-string 1 contents
)
2657 (match-string 2 contents
))
2659 (when (org-export-get-next-element table-cell info
) " & ")))
2664 (defun org-latex-table-row (table-row contents info
)
2665 "Transcode a TABLE-ROW element from Org to LaTeX.
2666 CONTENTS is the contents of the row. INFO is a plist used as
2667 a communication channel."
2668 ;; Rules are ignored since table separators are deduced from
2669 ;; borders of the current row.
2670 (when (eq (org-element-property :type table-row
) 'standard
)
2671 (let* ((attr (org-export-read-attribute :attr_latex
2672 (org-export-get-parent table-row
)))
2673 (longtablep (member (or (plist-get attr
:environment
)
2674 org-latex-default-table-environment
)
2675 '("longtable" "longtabu")))
2676 (booktabsp (if (plist-member attr
:booktabs
)
2677 (plist-get attr
:booktabs
)
2678 org-latex-tables-booktabs
))
2679 ;; TABLE-ROW's borders are extracted from its first cell.
2680 (borders (org-export-table-cell-borders
2681 (car (org-element-contents table-row
)) info
)))
2683 ;; When BOOKTABS are activated enforce top-rule even when no
2684 ;; hline was specifically marked.
2685 (cond ((and booktabsp
(memq 'top borders
)) "\\toprule\n")
2686 ((and (memq 'top borders
) (memq 'above borders
)) "\\hline\n"))
2689 ;; Special case for long tables. Define header and footers.
2690 ((and longtablep
(org-export-table-row-ends-header-p table-row info
))
2693 %s\\multicolumn{%d}{r}{Continued on next page} \\\\
2696 (if booktabsp
"\\midrule" "\\hline")
2697 (if booktabsp
"\\midrule" "\\hline")
2698 ;; Number of columns.
2699 (cdr (org-export-table-dimensions
2700 (org-export-get-parent-table table-row
) info
))))
2701 ;; When BOOKTABS are activated enforce bottom rule even when
2702 ;; no hline was specifically marked.
2703 ((and booktabsp
(memq 'bottom borders
)) "\\bottomrule")
2704 ((and (memq 'bottom borders
) (memq 'below borders
)) "\\hline")
2705 ((memq 'below borders
) (if booktabsp
"\\midrule" "\\hline")))))))
2710 (defun org-latex-target (target contents info
)
2711 "Transcode a TARGET object from Org to LaTeX.
2712 CONTENTS is nil. INFO is a plist holding contextual
2714 (format "\\label{%s}"
2715 (org-export-solidify-link-text (org-element-property :value target
))))
2720 (defun org-latex-timestamp (timestamp contents info
)
2721 "Transcode a TIMESTAMP object from Org to LaTeX.
2722 CONTENTS is nil. INFO is a plist holding contextual
2724 (let ((value (org-latex-plain-text
2725 (org-timestamp-translate timestamp
) info
)))
2726 (case (org-element-property :type timestamp
)
2727 ((active active-range
) (format org-latex-active-timestamp-format value
))
2728 ((inactive inactive-range
)
2729 (format org-latex-inactive-timestamp-format value
))
2730 (otherwise (format org-latex-diary-timestamp-format value
)))))
2735 (defun org-latex-underline (underline contents info
)
2736 "Transcode UNDERLINE from Org to LaTeX.
2737 CONTENTS is the text with underline markup. INFO is a plist
2738 holding contextual information."
2739 (org-latex--text-markup contents
'underline
))
2744 (defun org-latex-verbatim (verbatim contents info
)
2745 "Transcode a VERBATIM object from Org to LaTeX.
2746 CONTENTS is nil. INFO is a plist used as a communication
2748 (org-latex--text-markup (org-element-property :value verbatim
) 'verbatim
))
2753 (defun org-latex-verse-block (verse-block contents info
)
2754 "Transcode a VERSE-BLOCK element from Org to LaTeX.
2755 CONTENTS is verse block contents. INFO is a plist holding
2756 contextual information."
2757 (org-latex--wrap-label
2759 ;; In a verse environment, add a line break to each newline
2760 ;; character and change each white space at beginning of a line
2761 ;; into a space of 1 em. Also change each blank line with
2762 ;; a vertical space of 1 em.
2764 (setq contents
(replace-regexp-in-string
2765 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
2766 (replace-regexp-in-string
2767 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" contents
)))
2768 (while (string-match "^[ \t]+" contents
)
2769 (let ((new-str (format "\\hspace*{%dem}"
2770 (length (match-string 0 contents
)))))
2771 (setq contents
(replace-match new-str nil t contents
))))
2772 (format "\\begin{verse}\n%s\\end{verse}" contents
))))
2776 ;;; End-user functions
2779 (defun org-latex-export-as-latex
2780 (&optional async subtreep visible-only body-only ext-plist
)
2781 "Export current buffer as a LaTeX buffer.
2783 If narrowing is active in the current buffer, only export its
2786 If a region is active, export that region.
2788 A non-nil optional argument ASYNC means the process should happen
2789 asynchronously. The resulting buffer should be accessible
2790 through the `org-export-stack' interface.
2792 When optional argument SUBTREEP is non-nil, export the sub-tree
2793 at point, extracting information from the headline properties
2796 When optional argument VISIBLE-ONLY is non-nil, don't export
2797 contents of hidden elements.
2799 When optional argument BODY-ONLY is non-nil, only write code
2800 between \"\\begin{document}\" and \"\\end{document}\".
2802 EXT-PLIST, when provided, is a property list with external
2803 parameters overriding Org default settings, but still inferior to
2804 file-local settings.
2806 Export is done in a buffer named \"*Org LATEX Export*\", which
2807 will be displayed when `org-export-show-temporary-export-buffer'
2811 (org-export-async-start
2813 (with-current-buffer (get-buffer-create "*Org LATEX Export*")
2816 (goto-char (point-min))
2818 (org-export-add-to-stack (current-buffer) 'latex
)))
2819 `(org-export-as 'latex
,subtreep
,visible-only
,body-only
2822 (org-export-to-buffer 'latex
"*Org LATEX Export*"
2823 subtreep visible-only body-only ext-plist
)))
2824 (with-current-buffer outbuf
(LaTeX-mode))
2825 (when org-export-show-temporary-export-buffer
2826 (switch-to-buffer-other-window outbuf
)))))
2829 (defun org-latex-export-to-latex
2830 (&optional async subtreep visible-only body-only ext-plist
)
2831 "Export current buffer to a LaTeX file.
2833 If narrowing is active in the current buffer, only export its
2836 If a region is active, export that region.
2838 A non-nil optional argument ASYNC means the process should happen
2839 asynchronously. The resulting file should be accessible through
2840 the `org-export-stack' interface.
2842 When optional argument SUBTREEP is non-nil, export the sub-tree
2843 at point, extracting information from the headline properties
2846 When optional argument VISIBLE-ONLY is non-nil, don't export
2847 contents of hidden elements.
2849 When optional argument BODY-ONLY is non-nil, only write code
2850 between \"\\begin{document}\" and \"\\end{document}\".
2852 EXT-PLIST, when provided, is a property list with external
2853 parameters overriding Org default settings, but still inferior to
2854 file-local settings.
2856 Return output file's name."
2858 (let ((outfile (org-export-output-file-name ".tex" subtreep
)))
2860 (org-export-async-start
2861 (lambda (f) (org-export-add-to-stack f
'latex
))
2864 'latex
,outfile
,subtreep
,visible-only
,body-only
',ext-plist
)))
2866 'latex outfile subtreep visible-only body-only ext-plist
))))
2869 (defun org-latex-export-to-pdf
2870 (&optional async subtreep visible-only body-only ext-plist
)
2871 "Export current buffer to LaTeX then process through to PDF.
2873 If narrowing is active in the current buffer, only export its
2876 If a region is active, export that region.
2878 A non-nil optional argument ASYNC means the process should happen
2879 asynchronously. The resulting file should be accessible through
2880 the `org-export-stack' interface.
2882 When optional argument SUBTREEP is non-nil, export the sub-tree
2883 at point, extracting information from the headline properties
2886 When optional argument VISIBLE-ONLY is non-nil, don't export
2887 contents of hidden elements.
2889 When optional argument BODY-ONLY is non-nil, only write code
2890 between \"\\begin{document}\" and \"\\end{document}\".
2892 EXT-PLIST, when provided, is a property list with external
2893 parameters overriding Org default settings, but still inferior to
2894 file-local settings.
2896 Return PDF file's name."
2899 (let ((outfile (org-export-output-file-name ".tex" subtreep
)))
2900 (org-export-async-start
2901 (lambda (f) (org-export-add-to-stack f
'latex
))
2905 'latex
,outfile
,subtreep
,visible-only
,body-only
2908 (org-latex-export-to-latex
2909 nil subtreep visible-only body-only ext-plist
))))
2911 (defun org-latex-compile (texfile &optional snippet
)
2912 "Compile a TeX file.
2914 TEXFILE is the name of the file being compiled. Processing is
2915 done through the command specified in `org-latex-pdf-process'.
2917 When optional argument SNIPPET is non-nil, TEXFILE is a temporary
2918 file used to preview a LaTeX snippet. In this case, do not
2919 create a log buffer and do not bother removing log files.
2921 Return PDF file name or an error if it couldn't be produced."
2922 (let* ((base-name (file-name-sans-extension (file-name-nondirectory texfile
)))
2923 (full-name (file-truename texfile
))
2924 (out-dir (file-name-directory texfile
))
2925 ;; Make sure `default-directory' is set to TEXFILE directory,
2926 ;; not to whatever value the current buffer may have.
2927 (default-directory (file-name-directory full-name
))
2929 (unless snippet
(message (format "Processing LaTeX file %s ..." texfile
)))
2930 (save-window-excursion
2932 ;; A function is provided: Apply it.
2933 ((functionp org-latex-pdf-process
)
2934 (funcall org-latex-pdf-process
(shell-quote-argument texfile
)))
2935 ;; A list is provided: Replace %b, %f and %o with appropriate
2936 ;; values in each command before applying it. Output is
2937 ;; redirected to "*Org PDF LaTeX Output*" buffer.
2938 ((consp org-latex-pdf-process
)
2939 (let ((outbuf (and (not snippet
)
2940 (get-buffer-create "*Org PDF LaTeX Output*"))))
2944 (replace-regexp-in-string
2945 "%b" (shell-quote-argument base-name
)
2946 (replace-regexp-in-string
2947 "%f" (shell-quote-argument full-name
)
2948 (replace-regexp-in-string
2949 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
2951 org-latex-pdf-process
)
2952 ;; Collect standard errors from output buffer.
2953 (setq errors
(and (not snippet
) (org-latex--collect-errors outbuf
)))))
2954 (t (error "No valid command to process to PDF")))
2955 (let ((pdffile (concat out-dir base-name
".pdf")))
2956 ;; Check for process failure. Provide collected errors if
2958 (if (not (file-exists-p pdffile
))
2959 (error (concat (format "PDF file %s wasn't produced" pdffile
)
2960 (when errors
(concat ": " errors
))))
2961 ;; Else remove log files, when specified, and signal end of
2962 ;; process to user, along with any error encountered.
2963 (when (and (not snippet
) org-latex-remove-logfiles
)
2964 (dolist (ext org-latex-logfiles-extensions
)
2965 (let ((file (concat out-dir base-name
"." ext
)))
2966 (when (file-exists-p file
) (delete-file file
)))))
2967 (message (concat "Process completed"
2968 (if (not errors
) "."
2969 (concat " with errors: " errors
)))))
2970 ;; Return output file name.
2973 (defun org-latex--collect-errors (buffer)
2974 "Collect some kind of errors from \"pdflatex\" command output.
2976 BUFFER is the buffer containing output.
2978 Return collected error types as a string, or nil if there was
2980 (with-current-buffer buffer
2982 (goto-char (point-max))
2983 (when (re-search-backward "^[ \t]*This is .*?TeX.*?Version" nil t
)
2984 (let ((case-fold-search t
)
2986 (dolist (latex-error org-latex-known-errors
)
2987 (when (save-excursion (re-search-forward (car latex-error
) nil t
))
2988 (setq errors
(concat errors
" " (cdr latex-error
)))))
2989 (and (org-string-nw-p errors
) (org-trim errors
)))))))
2992 (defun org-latex-publish-to-latex (plist filename pub-dir
)
2993 "Publish an Org file to LaTeX.
2995 FILENAME is the filename of the Org file to be published. PLIST
2996 is the property list for the given project. PUB-DIR is the
2997 publishing directory.
2999 Return output file name."
3000 (org-publish-org-to 'latex filename
".tex" plist pub-dir
))
3003 (defun org-latex-publish-to-pdf (plist filename pub-dir
)
3004 "Publish an Org file to PDF (via LaTeX).
3006 FILENAME is the filename of the Org file to be published. PLIST
3007 is the property list for the given project. PUB-DIR is the
3008 publishing directory.
3010 Return output file name."
3011 ;; Unlike to `org-latex-publish-to-latex', PDF file is generated
3012 ;; in working directory and then moved to publishing directory.
3013 (org-publish-attachment
3015 (org-latex-compile (org-publish-org-to 'latex filename
".tex" plist
))
3022 ;; generated-autoload-file: "org-loaddefs.el"
3025 ;;; ox-latex.el ends here