1 ;;; ox-latex.el --- LaTeX Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; See Org manual for details.
29 (eval-when-compile (require 'cl
))
33 (defvar org-latex-default-packages-alist
)
34 (defvar org-latex-packages-alist
)
35 (defvar orgtbl-exp-regexp
)
41 (org-export-define-backend 'latex
42 '((bold . org-latex-bold
)
43 (center-block . org-latex-center-block
)
44 (clock . org-latex-clock
)
45 (code . org-latex-code
)
46 (comment .
(lambda (&rest args
) ""))
47 (comment-block .
(lambda (&rest args
) ""))
48 (drawer . org-latex-drawer
)
49 (dynamic-block . org-latex-dynamic-block
)
50 (entity . org-latex-entity
)
51 (example-block . org-latex-example-block
)
52 (export-block . org-latex-export-block
)
53 (export-snippet . org-latex-export-snippet
)
54 (fixed-width . org-latex-fixed-width
)
55 (footnote-definition . org-latex-footnote-definition
)
56 (footnote-reference . org-latex-footnote-reference
)
57 (headline . org-latex-headline
)
58 (horizontal-rule . org-latex-horizontal-rule
)
59 (inline-src-block . org-latex-inline-src-block
)
60 (inlinetask . org-latex-inlinetask
)
61 (italic . org-latex-italic
)
62 (item . org-latex-item
)
63 (keyword . org-latex-keyword
)
64 (latex-environment . org-latex-latex-environment
)
65 (latex-fragment . org-latex-latex-fragment
)
66 (line-break . org-latex-line-break
)
67 (link . org-latex-link
)
68 (node-property . org-latex-node-property
)
69 (paragraph . org-latex-paragraph
)
70 (plain-list . org-latex-plain-list
)
71 (plain-text . org-latex-plain-text
)
72 (planning . org-latex-planning
)
73 (property-drawer . org-latex-property-drawer
)
74 (quote-block . org-latex-quote-block
)
75 (quote-section . org-latex-quote-section
)
76 (radio-target . org-latex-radio-target
)
77 (section . org-latex-section
)
78 (special-block . org-latex-special-block
)
79 (src-block . org-latex-src-block
)
80 (statistics-cookie . org-latex-statistics-cookie
)
81 (strike-through . org-latex-strike-through
)
82 (subscript . org-latex-subscript
)
83 (superscript . org-latex-superscript
)
84 (table . org-latex-table
)
85 (table-cell . org-latex-table-cell
)
86 (table-row . org-latex-table-row
)
87 (target . org-latex-target
)
88 (template . org-latex-template
)
89 (timestamp . org-latex-timestamp
)
90 (underline . org-latex-underline
)
91 (verbatim . org-latex-verbatim
)
92 (verse-block . org-latex-verse-block
)
94 (latex-math-block . org-latex-math-block
))
95 :export-block
'("LATEX" "TEX")
97 '(?l
"Export to LaTeX"
98 ((?L
"As LaTeX buffer" org-latex-export-as-latex
)
99 (?l
"As LaTeX file" org-latex-export-to-latex
)
100 (?p
"As PDF file" org-latex-export-to-pdf
)
101 (?o
"As PDF file and open"
103 (if a
(org-latex-export-to-pdf t s v b
)
104 (org-open-file (org-latex-export-to-pdf nil s v b
)))))))
105 :options-alist
'((:latex-class
"LATEX_CLASS" nil org-latex-default-class t
)
106 (:latex-class-options
"LATEX_CLASS_OPTIONS" nil nil t
)
107 (:latex-header
"LATEX_HEADER" nil nil newline
)
108 (:latex-header-extra
"LATEX_HEADER_EXTRA" nil nil newline
)
109 (:latex-hyperref-p nil
"texht" org-latex-with-hyperref t
)
110 ;; Redefine regular options.
111 (:date
"DATE" nil
"\\today" t
))
112 :filters-alist
'((:filter-options . org-latex-math-block-options-filter
)
113 (:filter-parse-tree . org-latex-math-block-tree-filter
)))
117 ;;; Internal Variables
119 (defconst org-latex-babel-language-alist
120 '(("af" .
"afrikaans")
122 ("bt-br" .
"brazilian")
128 ("de-at" .
"naustrian")
129 ("de-de" .
"ngerman")
132 ("en-au" .
"australian")
133 ("en-ca" .
"canadian")
134 ("en-gb" .
"british")
136 ("en-nz" .
"newzealand")
137 ("en-us" .
"american")
143 ("fr-ca" .
"canadien")
147 ("id" .
"indonesian")
157 ("pt" .
"portuguese")
161 ("sb" .
"uppersorbian")
169 ("uk" .
"ukrainian"))
170 "Alist between language code and corresponding Babel option.")
172 (defconst org-latex-table-matrix-macros
'(("bordermatrix" .
"\\cr")
173 ("qbordermatrix" .
"\\cr")
174 ("kbordermatrix" .
"\\\\"))
175 "Alist between matrix macros and their row ending.")
177 (defconst org-latex-pseudo-objects
'(latex-math-block)
178 "List of pseudo-object types introduced in the back-end.")
182 ;;; User Configurable Variables
184 (defgroup org-export-latex nil
185 "Options for exporting Org mode files to LaTeX."
186 :tag
"Org Export LaTeX"
192 (defcustom org-latex-default-class
"article"
193 "The default LaTeX class."
194 :group
'org-export-latex
195 :type
'(string :tag
"LaTeX class"))
197 (defcustom org-latex-classes
199 "\\documentclass[11pt]{article}"
200 ("\\section{%s}" .
"\\section*{%s}")
201 ("\\subsection{%s}" .
"\\subsection*{%s}")
202 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}")
203 ("\\paragraph{%s}" .
"\\paragraph*{%s}")
204 ("\\subparagraph{%s}" .
"\\subparagraph*{%s}"))
206 "\\documentclass[11pt]{report}"
207 ("\\part{%s}" .
"\\part*{%s}")
208 ("\\chapter{%s}" .
"\\chapter*{%s}")
209 ("\\section{%s}" .
"\\section*{%s}")
210 ("\\subsection{%s}" .
"\\subsection*{%s}")
211 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}"))
213 "\\documentclass[11pt]{book}"
214 ("\\part{%s}" .
"\\part*{%s}")
215 ("\\chapter{%s}" .
"\\chapter*{%s}")
216 ("\\section{%s}" .
"\\section*{%s}")
217 ("\\subsection{%s}" .
"\\subsection*{%s}")
218 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}")))
219 "Alist of LaTeX classes and associated header and structure.
220 If #+LATEX_CLASS is set in the buffer, use its value and the
221 associated information. Here is the structure of each cell:
225 \(numbered-section . unnumbered-section)
231 The HEADER-STRING is the header that will be inserted into the
232 LaTeX file. It should contain the \\documentclass macro, and
233 anything else that is needed for this setup. To this header, the
234 following commands will be added:
236 - Calls to \\usepackage for all packages mentioned in the
237 variables `org-latex-default-packages-alist' and
238 `org-latex-packages-alist'. Thus, your header definitions
239 should avoid to also request these packages.
241 - Lines specified via \"#+LATEX_HEADER:\" and
242 \"#+LATEX_HEADER_EXTRA:\" keywords.
244 If you need more control about the sequence in which the header
245 is built up, or if you want to exclude one of these building
246 blocks for a particular class, you can use the following
247 macro-like placeholders.
249 [DEFAULT-PACKAGES] \\usepackage statements for default packages
250 [NO-DEFAULT-PACKAGES] do not include any of the default packages
251 [PACKAGES] \\usepackage statements for packages
252 [NO-PACKAGES] do not include the packages
253 [EXTRA] the stuff from #+LATEX_HEADER(_EXTRA)
254 [NO-EXTRA] do not include #+LATEX_HEADER(_EXTRA) stuff
258 \\documentclass{article}
259 [NO-DEFAULT-PACKAGES]
261 \\providecommand{\\alert}[1]{\\textbf{#1}}
264 will omit the default packages, and will include the
265 #+LATEX_HEADER and #+LATEX_HEADER_EXTRA lines, then have a call
266 to \\providecommand, and then place \\usepackage commands based
267 on the content of `org-latex-packages-alist'.
269 If your header, `org-latex-default-packages-alist' or
270 `org-latex-packages-alist' inserts \"\\usepackage[AUTO]{inputenc}\",
271 AUTO will automatically be replaced with a coding system derived
272 from `buffer-file-coding-system'. See also the variable
273 `org-latex-inputenc-alist' for a way to influence this mechanism.
275 Likewise, if your header contains \"\\usepackage[AUTO]{babel}\",
276 AUTO will be replaced with the language related to the language
277 code specified by `org-export-default-language', which see. Note
278 that constructions such as \"\\usepackage[french,AUTO,english]{babel}\"
281 The sectioning structure
282 ------------------------
284 The sectioning structure of the class is given by the elements
285 following the header string. For each sectioning level, a number
286 of strings is specified. A %s formatter is mandatory in each
287 section string and will be replaced by the title of the section.
289 Instead of a cons cell (numbered . unnumbered), you can also
290 provide a list of 2 or 4 elements,
292 \(numbered-open numbered-close)
296 \(numbered-open numbered-close unnumbered-open unnumbered-close)
298 providing opening and closing strings for a LaTeX environment
299 that should represent the document section. The opening clause
300 should have a %s to represent the section title.
302 Instead of a list of sectioning commands, you can also specify
303 a function name. That function will be called with two
304 parameters, the (reduced) level of the headline, and a predicate
305 non-nil when the headline should be numbered. It must return
306 a format string in which the section title will be added."
307 :group
'org-export-latex
309 (list (string :tag
"LaTeX class")
310 (string :tag
"LaTeX header")
311 (repeat :tag
"Levels" :inline t
314 (string :tag
" numbered")
315 (string :tag
"unnumbered"))
316 (list :tag
"Environment"
317 (string :tag
"Opening (numbered)")
318 (string :tag
"Closing (numbered)")
319 (string :tag
"Opening (unnumbered)")
320 (string :tag
"Closing (unnumbered)"))
321 (function :tag
"Hook computing sectioning"))))))
323 (defcustom org-latex-inputenc-alist nil
324 "Alist of inputenc coding system names, and what should really be used.
325 For example, adding an entry
327 (\"utf8\" . \"utf8x\")
329 will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
330 are written as utf8 files."
331 :group
'org-export-latex
334 (string :tag
"Derived from buffer")
335 (string :tag
"Use this instead"))))
337 (defcustom org-latex-title-command
"\\maketitle"
338 "The command used to insert the title just after \\begin{document}.
339 If this string contains the formatting specification \"%s\" then
340 it will be used as a formatting string, passing the title as an
342 :group
'org-export-latex
345 (defcustom org-latex-toc-command
"\\tableofcontents\n\n"
346 "LaTeX command to set the table of contents, list of figures, etc.
347 This command only applies to the table of contents generated with
348 the toc:nil option, not to those generated with #+TOC keyword."
349 :group
'org-export-latex
352 (defcustom org-latex-with-hyperref t
353 "Toggle insertion of \\hypersetup{...} in the preamble."
354 :group
'org-export-latex
360 (defcustom org-latex-format-headline-function
361 'org-latex-format-headline-default-function
362 "Function for formatting the headline's text.
364 This function will be called with 5 arguments:
365 TODO the todo keyword (string or nil).
366 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
367 PRIORITY the priority of the headline (integer or nil)
368 TEXT the main headline text (string).
369 TAGS the tags as a list of strings (list of strings or nil).
371 The function result will be used in the section format string.
373 Use `org-latex-format-headline-default-function' by default,
374 which format headlines like for Org version prior to 8.0."
375 :group
'org-export-latex
377 :package-version
'(Org .
"8.0")
383 (defcustom org-latex-footnote-separator
"\\textsuperscript{,}\\,"
384 "Text used to separate footnotes."
385 :group
'org-export-latex
391 (defcustom org-latex-active-timestamp-format
"\\textit{%s}"
392 "A printf format string to be applied to active timestamps."
393 :group
'org-export-latex
396 (defcustom org-latex-inactive-timestamp-format
"\\textit{%s}"
397 "A printf format string to be applied to inactive timestamps."
398 :group
'org-export-latex
401 (defcustom org-latex-diary-timestamp-format
"\\textit{%s}"
402 "A printf format string to be applied to diary timestamps."
403 :group
'org-export-latex
409 (defcustom org-latex-image-default-option
""
410 "Default option for images."
411 :group
'org-export-latex
413 :package-version
'(Org .
"8.0")
416 (defcustom org-latex-image-default-width
".9\\linewidth"
417 "Default width for images.
418 This value will not be used if a height is provided."
419 :group
'org-export-latex
421 :package-version
'(Org .
"8.0")
424 (defcustom org-latex-image-default-height
""
425 "Default height for images.
426 This value will not be used if a width is provided, or if the
427 image is wrapped within a \"figure\" or \"wrapfigure\"
429 :group
'org-export-latex
431 :package-version
'(Org .
"8.0")
434 (defcustom org-latex-default-figure-position
"htb"
435 "Default position for latex figures."
436 :group
'org-export-latex
439 (defcustom org-latex-inline-image-rules
440 '(("file" .
"\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\|tikz\\|pgf\\|svg\\)\\'"))
441 "Rules characterizing image files that can be inlined into LaTeX.
443 A rule consists in an association whose key is the type of link
444 to consider, and value is a regexp that will be matched against
447 Note that, by default, the image extension *actually* allowed
448 depend on the way the LaTeX file is processed. When used with
449 pdflatex, pdf, jpg and png images are OK. When processing
450 through dvi to Postscript, only ps and eps are allowed. The
451 default we use here encompasses both."
452 :group
'org-export-latex
454 :package-version
'(Org .
"8.0")
455 :type
'(alist :key-type
(string :tag
"Type")
456 :value-type
(regexp :tag
"Path")))
458 (defcustom org-latex-link-with-unknown-path-format
"\\texttt{%s}"
459 "Format string for links with unknown path type."
460 :group
'org-export-latex
466 (defcustom org-latex-default-table-environment
"tabular"
467 "Default environment used to build tables."
468 :group
'org-export-latex
470 :package-version
'(Org .
"8.0")
473 (defcustom org-latex-default-table-mode
'table
474 "Default mode for tables.
476 Value can be a symbol among:
478 `table' Regular LaTeX table.
480 `math' In this mode, every cell is considered as being in math
481 mode and the complete table will be wrapped within a math
482 environment. It is particularly useful to write matrices.
484 `inline-math' This mode is almost the same as `math', but the
485 math environment will be inlined.
487 `verbatim' The table is exported as it appears in the Org
488 buffer, within a verbatim environment.
490 This value can be overridden locally with, i.e. \":mode math\" in
493 When modifying this variable, it may be useful to change
494 `org-latex-default-table-environment' accordingly."
495 :group
'org-export-latex
497 :package-version
'(Org .
"8.0")
498 :type
'(choice (const :tag
"Table" table
)
499 (const :tag
"Matrix" math
)
500 (const :tag
"Inline matrix" inline-math
)
501 (const :tag
"Verbatim" verbatim
))
502 :safe
(lambda (s) (memq s
'(table math inline-math verbatim
))))
504 (defcustom org-latex-tables-centered t
505 "When non-nil, tables are exported in a center environment."
506 :group
'org-export-latex
510 (defcustom org-latex-tables-booktabs nil
511 "When non-nil, display tables in a formal \"booktabs\" style.
512 This option assumes that the \"booktabs\" package is properly
513 loaded in the header of the document. This value can be ignored
514 locally with \":booktabs t\" and \":booktabs nil\" LaTeX
516 :group
'org-export-latex
518 :package-version
'(Org .
"8.0")
522 (defcustom org-latex-table-caption-above t
523 "When non-nil, place caption string at the beginning of the table.
524 Otherwise, place it near the end."
525 :group
'org-export-latex
529 (defcustom org-latex-table-scientific-notation
"%s\\,(%s)"
530 "Format string to display numbers in scientific notation.
531 The format should have \"%s\" twice, for mantissa and exponent
532 \(i.e., \"%s\\\\times10^{%s}\").
534 When nil, no transformation is made."
535 :group
'org-export-latex
537 :package-version
'(Org .
"8.0")
539 (string :tag
"Format string")
540 (const :tag
"No formatting")))
544 (defcustom org-latex-text-markup-alist
'((bold .
"\\textbf{%s}")
546 (italic .
"\\emph{%s}")
547 (strike-through .
"\\sout{%s}")
548 (underline .
"\\uline{%s}")
549 (verbatim . protectedtexttt
))
550 "Alist of LaTeX expressions to convert text markup.
552 The key must be a symbol among `bold', `code', `italic',
553 `strike-through', `underline' and `verbatim'. The value is
554 a formatting string to wrap fontified text with.
556 Value can also be set to the following symbols: `verb' and
557 `protectedtexttt'. For the former, Org will use \"\\verb\" to
558 create a format string and select a delimiter character that
559 isn't in the string. For the latter, Org will use \"\\texttt\"
560 to typeset and try to protect special characters.
562 If no association can be found for a given markup, text will be
564 :group
'org-export-latex
566 :options
'(bold code italic strike-through underline verbatim
))
571 (defcustom org-latex-format-drawer-function
572 (lambda (name contents
) contents
)
573 "Function called to format a drawer in LaTeX code.
575 The function must accept two parameters:
576 NAME the drawer name, like \"LOGBOOK\"
577 CONTENTS the contents of the drawer.
579 The function should return the string to be exported.
581 The default function simply returns the value of CONTENTS."
582 :group
'org-export-latex
584 :package-version
'(Org .
"8.3")
590 (defcustom org-latex-format-inlinetask-function
'ignore
591 "Function called to format an inlinetask in LaTeX code.
593 The function must accept six parameters:
594 TODO the todo keyword, as a string
595 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
596 PRIORITY the inlinetask priority, as a string
597 NAME the inlinetask name, as a string.
598 TAGS the inlinetask tags, as a list of strings.
599 CONTENTS the contents of the inlinetask, as a string.
601 The function should return the string to be exported.
603 For example, the variable could be set to the following function
604 in order to mimic default behaviour:
606 \(defun org-latex-format-inlinetask \(todo type priority name tags contents\)
607 \"Format an inline task element for LaTeX export.\"
611 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo))
612 \(when priority (format \"\\\\framebox{\\\\#%c} \" priority))
615 \(format \"\\\\hfill{}\\\\textsc{:%s:}\"
616 \(mapconcat 'identity tags \":\")))))
617 \(format (concat \"\\\\begin{center}\\n\"
619 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
621 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
623 \"\\\\end{minipage}}\"
625 full-title contents))"
626 :group
'org-export-latex
632 (defcustom org-latex-listings nil
633 "Non-nil means export source code using the listings package.
635 This package will fontify source code, possibly even with color.
636 If you want to use this, you also need to make LaTeX use the
637 listings package, and if you want to have color, the color
638 package. Just add these to `org-latex-packages-alist', for
639 example using customize, or with something like:
642 \(add-to-list 'org-latex-packages-alist '(\"\" \"listings\"))
643 \(add-to-list 'org-latex-packages-alist '(\"\" \"color\"))
647 \(setq org-latex-listings 'minted)
649 causes source code to be exported using the minted package as
650 opposed to listings. If you want to use minted, you need to add
651 the minted package to `org-latex-packages-alist', for example
652 using customize, or with
655 \(add-to-list 'org-latex-packages-alist '(\"\" \"minted\"))
657 In addition, it is necessary to install pygments
658 \(http://pygments.org), and to configure the variable
659 `org-latex-pdf-process' so that the -shell-escape option is
662 The minted choice has possible repercussions on the preview of
663 latex fragments (see `org-preview-latex-fragment'). If you run
664 into previewing problems, please consult
666 http://orgmode.org/worg/org-tutorials/org-latex-preview.html"
667 :group
'org-export-latex
669 (const :tag
"Use listings" t
)
670 (const :tag
"Use minted" minted
)
671 (const :tag
"Export verbatim" nil
))
672 :safe
(lambda (s) (memq s
'(t nil minted
))))
674 (defcustom org-latex-listings-langs
675 '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
678 (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
679 (html "HTML") (xml "XML")
680 (tex "TeX") (latex "[LaTeX]TeX")
681 (shell-script "bash")
683 (ocaml "Caml") (caml "Caml")
684 (sql "SQL") (sqlite "sql"))
685 "Alist mapping languages to their listing language counterpart.
686 The key is a symbol, the major mode symbol without the \"-mode\".
687 The value is the string that should be inserted as the language
688 parameter for the listings package. If the mode name and the
689 listings name are the same, the language does not need an entry
690 in this list - but it does not hurt if it is present."
691 :group
'org-export-latex
694 (symbol :tag
"Major mode ")
695 (string :tag
"Listings language"))))
697 (defcustom org-latex-listings-options nil
698 "Association list of options for the latex listings package.
700 These options are supplied as a comma-separated list to the
701 \\lstset command. Each element of the association list should be
702 a list containing two strings: the name of the option, and the
705 (setq org-latex-listings-options
706 '((\"basicstyle\" \"\\\\small\")
707 (\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\")))
709 will typeset the code in a small size font with underlined, bold
712 Note that the same options will be applied to blocks of all
714 :group
'org-export-latex
717 (string :tag
"Listings option name ")
718 (string :tag
"Listings option value"))))
720 (defcustom org-latex-minted-langs
721 '((emacs-lisp "common-lisp")
724 (shell-script "bash")
726 "Alist mapping languages to their minted language counterpart.
727 The key is a symbol, the major mode symbol without the \"-mode\".
728 The value is the string that should be inserted as the language
729 parameter for the minted package. If the mode name and the
730 listings name are the same, the language does not need an entry
731 in this list - but it does not hurt if it is present.
733 Note that minted uses all lower case for language identifiers,
734 and that the full list of language identifiers can be obtained
737 pygmentize -L lexers"
738 :group
'org-export-latex
741 (symbol :tag
"Major mode ")
742 (string :tag
"Minted language"))))
744 (defcustom org-latex-minted-options nil
745 "Association list of options for the latex minted package.
747 These options are supplied within square brackets in
748 \\begin{minted} environments. Each element of the alist should
749 be a list containing two strings: the name of the option, and the
752 \(setq org-latex-minted-options
753 '\((\"bgcolor\" \"bg\") \(\"frame\" \"lines\")))
755 will result in src blocks being exported with
757 \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
759 as the start of the minted environment. Note that the same
760 options will be applied to blocks of all languages."
761 :group
'org-export-latex
764 (string :tag
"Minted option name ")
765 (string :tag
"Minted option value"))))
767 (defvar org-latex-custom-lang-environments nil
768 "Alist mapping languages to language-specific LaTeX environments.
770 It is used during export of src blocks by the listings and minted
771 latex packages. For example,
773 \(setq org-latex-custom-lang-environments
774 '\(\(python \"pythoncode\"\)\)\)
776 would have the effect that if org encounters begin_src python
777 during latex export it will output
786 (defcustom org-latex-pdf-process
787 '("pdflatex -interaction nonstopmode -output-directory %o %f"
788 "pdflatex -interaction nonstopmode -output-directory %o %f"
789 "pdflatex -interaction nonstopmode -output-directory %o %f")
790 "Commands to process a LaTeX file to a PDF file.
791 This is a list of strings, each of them will be given to the
792 shell as a command. %f in the command will be replaced by the
793 full file name, %b by the file base name (i.e. without directory
794 and extension parts) and %o by the base directory of the file.
796 The reason why this is a list is that it usually takes several
797 runs of `pdflatex', maybe mixed with a call to `bibtex'. Org
798 does not have a clever mechanism to detect which of these
799 commands have to be run to get to a stable result, and it also
800 does not do any error checking.
802 By default, Org uses 3 runs of `pdflatex' to do the processing.
803 If you have texi2dvi on your system and if that does not cause
804 the infamous egrep/locale bug:
806 http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
808 then `texi2dvi' is the superior choice as it automates the LaTeX
809 build process by calling the \"correct\" combinations of
810 auxiliary programs. Org does offer `texi2dvi' as one of the
811 customize options. Alternatively, `rubber' and `latexmk' also
812 provide similar functionality. The latter supports `biber' out
815 Alternatively, this may be a Lisp function that does the
816 processing, so you could use this to apply the machinery of
817 AUCTeX or the Emacs LaTeX mode. This function should accept the
818 file name as its single argument."
819 :group
'org-export-pdf
821 (repeat :tag
"Shell command sequence"
822 (string :tag
"Shell command"))
823 (const :tag
"2 runs of pdflatex"
824 ("pdflatex -interaction nonstopmode -output-directory %o %f"
825 "pdflatex -interaction nonstopmode -output-directory %o %f"))
826 (const :tag
"3 runs of pdflatex"
827 ("pdflatex -interaction nonstopmode -output-directory %o %f"
828 "pdflatex -interaction nonstopmode -output-directory %o %f"
829 "pdflatex -interaction nonstopmode -output-directory %o %f"))
830 (const :tag
"pdflatex,bibtex,pdflatex,pdflatex"
831 ("pdflatex -interaction nonstopmode -output-directory %o %f"
833 "pdflatex -interaction nonstopmode -output-directory %o %f"
834 "pdflatex -interaction nonstopmode -output-directory %o %f"))
835 (const :tag
"2 runs of xelatex"
836 ("xelatex -interaction nonstopmode -output-directory %o %f"
837 "xelatex -interaction nonstopmode -output-directory %o %f"))
838 (const :tag
"3 runs of xelatex"
839 ("xelatex -interaction nonstopmode -output-directory %o %f"
840 "xelatex -interaction nonstopmode -output-directory %o %f"
841 "xelatex -interaction nonstopmode -output-directory %o %f"))
842 (const :tag
"xelatex,bibtex,xelatex,xelatex"
843 ("xelatex -interaction nonstopmode -output-directory %o %f"
845 "xelatex -interaction nonstopmode -output-directory %o %f"
846 "xelatex -interaction nonstopmode -output-directory %o %f"))
847 (const :tag
"texi2dvi"
848 ("texi2dvi -p -b -V %f"))
850 ("rubber -d --into %o %f"))
851 (const :tag
"latexmk"
852 ("latexmk -g -pdf %f"))
855 (defcustom org-latex-logfiles-extensions
856 '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
857 "The list of file extensions to consider as LaTeX logfiles.
858 The logfiles will be remove if `org-latex-remove-logfiles' is
860 :group
'org-export-latex
861 :type
'(repeat (string :tag
"Extension")))
863 (defcustom org-latex-remove-logfiles t
864 "Non-nil means remove the logfiles produced by PDF production.
865 By default, logfiles are files with these extensions: .aux, .idx,
866 .log, .out, .toc, .nav, .snm and .vrb. To define the set of
867 logfiles to remove, set `org-latex-logfiles-extensions'."
868 :group
'org-export-latex
871 (defcustom org-latex-known-errors
872 '(("Reference.*?undefined" .
"[undefined reference]")
873 ("Citation.*?undefined" .
"[undefined citation]")
874 ("Undefined control sequence" .
"[undefined control sequence]")
875 ("^! LaTeX.*?Error" .
"[LaTeX error]")
876 ("^! Package.*?Error" .
"[package error]")
877 ("Runaway argument" .
"Runaway argument"))
878 "Alist of regular expressions and associated messages for the user.
879 The regular expressions are used to find possible errors in the
881 :group
'org-export-latex
883 :package-version
'(Org .
"8.0")
886 (string :tag
"Regexp")
887 (string :tag
"Message"))))
891 ;;; Internal Functions
893 (defun org-latex--caption/label-string
(element info
)
894 "Return caption and label LaTeX string for ELEMENT.
896 INFO is a plist holding contextual information. If there's no
897 caption nor label, return the empty string.
899 For non-floats, see `org-latex--wrap-label'."
900 (let* ((label (org-element-property :name element
))
901 (label-str (if (not (org-string-nw-p label
)) ""
902 (format "\\label{%s}"
903 (org-export-solidify-link-text label
))))
904 (main (org-export-get-caption element
))
905 (short (org-export-get-caption element t
))
906 (caption-from-attr-latex (org-export-read-attribute :attr_latex element
:caption
)))
908 ((org-string-nw-p caption-from-attr-latex
)
909 (concat caption-from-attr-latex
"\n"))
910 ((and (not main
) (equal label-str
"")) "")
911 ((not main
) (concat label-str
"\n"))
912 ;; Option caption format with short name.
913 (short (format "\\caption[%s]{%s%s}\n"
914 (org-export-data short info
)
916 (org-export-data main info
)))
917 ;; Standard caption format.
918 (t (format "\\caption{%s%s}\n" label-str
(org-export-data main info
))))))
920 (defun org-latex-guess-inputenc (header)
921 "Set the coding system in inputenc to what the buffer is.
923 HEADER is the LaTeX header string. This function only applies
924 when specified inputenc option is \"AUTO\".
926 Return the new header, as a string."
927 (let* ((cs (or (ignore-errors
928 (latexenc-coding-system-to-inputenc
929 (or org-export-coding-system buffer-file-coding-system
)))
932 ;; First translate if that is requested.
933 (setq cs
(or (cdr (assoc cs org-latex-inputenc-alist
)) cs
))
934 ;; Then find the \usepackage statement and replace the option.
935 (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
936 cs header t nil
1))))
938 (defun org-latex-guess-babel-language (header info
)
939 "Set Babel's language according to LANGUAGE keyword.
941 HEADER is the LaTeX header string. INFO is the plist used as
942 a communication channel.
944 Insertion of guessed language only happens when Babel package has
945 explicitly been loaded. Then it is added to the rest of
948 The argument to Babel may be \"AUTO\" which is then replaced with
949 the language of the document or `org-export-default-language'
950 unless language in question is already loaded.
952 Return the new header."
953 (let ((language-code (plist-get info
:language
)))
954 ;; If no language is set or Babel package is not loaded, return
956 (if (or (not (stringp language-code
))
957 (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header
)))
959 (let ((options (save-match-data
960 (org-split-string (match-string 1 header
) ",[ \t]*")))
961 (language (cdr (assoc language-code
962 org-latex-babel-language-alist
))))
963 ;; If LANGUAGE is already loaded, return header without AUTO.
964 ;; Otherwise, replace AUTO with language or append language if
965 ;; AUTO is not present.
967 (mapconcat (lambda (option) (if (equal "AUTO" option
) language option
))
968 (cond ((member language options
) (delete "AUTO" options
))
969 ((member "AUTO" options
) options
)
970 (t (append options
(list language
))))
974 (defun org-latex--find-verb-separator (s)
975 "Return a character not used in string S.
976 This is used to choose a separator for constructs like \\verb."
977 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
978 (loop for c across ll
979 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
980 return
(char-to-string c
))))
982 (defun org-latex--make-option-string (options)
983 "Return a comma separated string of keywords and values.
984 OPTIONS is an alist where the key is the options keyword as
985 a string, and the value a list containing the keyword value, or
987 (mapconcat (lambda (pair)
989 (when (> (length (second pair
)) 0)
990 (concat "=" (second pair
)))))
994 (defun org-latex--wrap-label (element output
)
995 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
996 This function shouldn't be used for floats. See
997 `org-latex--caption/label-string'."
998 (let ((label (org-element-property :name element
)))
999 (if (not (and (org-string-nw-p output
) (org-string-nw-p label
))) output
1000 (concat (format "\\label{%s}\n" (org-export-solidify-link-text label
))
1003 (defun org-latex--text-markup (text markup
)
1004 "Format TEXT depending on MARKUP text markup.
1005 See `org-latex-text-markup-alist' for details."
1006 (let ((fmt (cdr (assq markup org-latex-text-markup-alist
))))
1008 ;; No format string: Return raw text.
1010 ;; Handle the `verb' special case: Find and appropriate separator
1011 ;; and use "\\verb" command.
1013 (let ((separator (org-latex--find-verb-separator text
)))
1014 (concat "\\verb" separator text separator
)))
1015 ;; Handle the `protectedtexttt' special case: Protect some
1016 ;; special chars and use "\texttt{%s}" format string.
1017 ((eq 'protectedtexttt fmt
)
1019 (trans '(("\\" .
"\\textbackslash{}")
1020 ("~" .
"\\textasciitilde{}")
1021 ("^" .
"\\textasciicircum{}")))
1024 (while (string-match "[\\{}$%&_#~^]" text
)
1025 (setq char
(match-string 0 text
))
1026 (if (> (match-beginning 0) 0)
1027 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
1028 (setq text
(substring text
(1+ (match-beginning 0))))
1029 (setq char
(or (cdr (assoc char trans
)) (concat "\\" char
))
1030 rtn
(concat rtn char
)))
1031 (setq text
(concat rtn text
)
1033 (while (string-match "--" text
)
1034 (setq text
(replace-match "-{}-" t t text
)))
1036 ;; Else use format string.
1037 (t (format fmt text
)))))
1039 (defun org-latex--delayed-footnotes-definitions (element info
)
1040 "Return footnotes definitions in ELEMENT as a string.
1042 INFO is a plist used as a communication channel.
1044 Footnotes definitions are returned within \"\\footnotetxt{}\"
1047 This function is used within constructs that don't support
1048 \"\\footnote{}\" command (i.e. an item's tag). In that case,
1049 \"\\footnotemark\" is used within the construct and the function
1050 just outside of it."
1054 "\\footnotetext[%s]{%s}"
1055 (org-export-get-footnote-number ref info
)
1058 (org-export-get-footnote-definition ref info
) info
))))
1059 ;; Find every footnote reference in ELEMENT.
1061 search-refs
; For byte-compiler.
1065 ;; Return a list of all footnote references never seen
1067 (org-element-map data
'footnote-reference
1069 (when (org-export-footnote-first-reference-p ref info
)
1071 (when (eq (org-element-property :type ref
) 'standard
)
1072 (funcall search-refs
1073 (org-export-get-footnote-definition ref info
)))))
1075 (reverse all-refs
)))))
1076 (funcall search-refs element
))
1079 (defun org-latex--translate (s info
)
1080 "Translate string S according to specified language.
1081 INFO is a plist used as a communication channel."
1082 (org-export-translate s
:latex info
))
1088 (defun org-latex-template (contents info
)
1089 "Return complete document string after LaTeX conversion.
1090 CONTENTS is the transcoded contents string. INFO is a plist
1091 holding export options."
1092 (let ((title (org-export-data (plist-get info
:title
) info
)))
1095 (and (plist-get info
:time-stamp-file
)
1096 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
1097 ;; Document class and packages.
1098 (let* ((class (plist-get info
:latex-class
))
1099 (class-options (plist-get info
:latex-class-options
))
1100 (header (nth 1 (assoc class org-latex-classes
)))
1101 (document-class-string
1102 (and (stringp header
)
1103 (if (not class-options
) header
1104 (replace-regexp-in-string
1105 "^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
1106 class-options header t nil
1)))))
1107 (if (not document-class-string
)
1108 (user-error "Unknown LaTeX class `%s'" class
)
1109 (org-latex-guess-babel-language
1110 (org-latex-guess-inputenc
1111 (org-element-normalize-string
1112 (org-splice-latex-header
1113 document-class-string
1114 org-latex-default-packages-alist
1115 org-latex-packages-alist nil
1116 (concat (org-element-normalize-string
1117 (plist-get info
:latex-header
))
1118 (plist-get info
:latex-header-extra
)))))
1120 ;; Possibly limit depth for headline numbering.
1121 (let ((sec-num (plist-get info
:section-numbers
)))
1122 (when (integerp sec-num
)
1123 (format "\\setcounter{secnumdepth}{%d}\n" sec-num
)))
1125 (let ((author (and (plist-get info
:with-author
)
1126 (let ((auth (plist-get info
:author
)))
1127 (and auth
(org-export-data auth info
)))))
1128 (email (and (plist-get info
:with-email
)
1129 (org-export-data (plist-get info
:email
) info
))))
1130 (cond ((and author email
(not (string= "" email
)))
1131 (format "\\author{%s\\thanks{%s}}\n" author email
))
1132 ((or author email
) (format "\\author{%s}\n" (or author email
)))))
1134 (let ((date (and (plist-get info
:with-date
) (org-export-get-date info
))))
1135 (format "\\date{%s}\n" (org-export-data date info
)))
1137 (format "\\title{%s}\n" title
)
1138 ;; Hyperref options.
1139 (when (plist-get info
:latex-hyperref-p
)
1140 (format "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={%s}}\n"
1141 (or (plist-get info
:keywords
) "")
1142 (or (plist-get info
:description
) "")
1143 (if (not (plist-get info
:with-creator
)) ""
1144 (plist-get info
:creator
))))
1146 "\\begin{document}\n\n"
1148 (org-element-normalize-string
1149 (cond ((string= "" title
) nil
)
1150 ((not (stringp org-latex-title-command
)) nil
)
1151 ((string-match "\\(?:[^%]\\|^\\)%s"
1152 org-latex-title-command
)
1153 (format org-latex-title-command title
))
1154 (t org-latex-title-command
)))
1155 ;; Table of contents.
1156 (let ((depth (plist-get info
:with-toc
)))
1158 (concat (when (wholenump depth
)
1159 (format "\\setcounter{tocdepth}{%d}\n" depth
))
1160 org-latex-toc-command
)))
1164 (let ((creator-info (plist-get info
:with-creator
)))
1166 ((not creator-info
) "")
1167 ((eq creator-info
'comment
)
1168 (format "%% %s\n" (plist-get info
:creator
)))
1169 (t (concat (plist-get info
:creator
) "\n"))))
1171 "\\end{document}")))
1175 ;;; Transcode Functions
1179 (defun org-latex-bold (bold contents info
)
1180 "Transcode BOLD from Org to LaTeX.
1181 CONTENTS is the text with bold markup. INFO is a plist holding
1182 contextual information."
1183 (org-latex--text-markup contents
'bold
))
1188 (defun org-latex-center-block (center-block contents info
)
1189 "Transcode a CENTER-BLOCK element from Org to LaTeX.
1190 CONTENTS holds the contents of the center block. INFO is a plist
1191 holding contextual information."
1192 (org-latex--wrap-label
1194 (format "\\begin{center}\n%s\\end{center}" contents
)))
1199 (defun org-latex-clock (clock contents info
)
1200 "Transcode a CLOCK element from Org to LaTeX.
1201 CONTENTS is nil. INFO is a plist holding contextual
1205 (format "\\textbf{%s} " org-clock-string
)
1206 (format org-latex-inactive-timestamp-format
1207 (concat (org-translate-time
1208 (org-element-property :raw-value
1209 (org-element-property :value clock
)))
1210 (let ((time (org-element-property :duration clock
)))
1211 (and time
(format " (%s)" time
)))))
1217 (defun org-latex-code (code contents info
)
1218 "Transcode a CODE object from Org to LaTeX.
1219 CONTENTS is nil. INFO is a plist used as a communication
1221 (org-latex--text-markup (org-element-property :value code
) 'code
))
1226 (defun org-latex-drawer (drawer contents info
)
1227 "Transcode a DRAWER element from Org to LaTeX.
1228 CONTENTS holds the contents of the block. INFO is a plist
1229 holding contextual information."
1230 (let* ((name (org-element-property :drawer-name drawer
))
1231 (output (funcall org-latex-format-drawer-function
1233 (org-latex--wrap-label drawer output
)))
1238 (defun org-latex-dynamic-block (dynamic-block contents info
)
1239 "Transcode a DYNAMIC-BLOCK element from Org to LaTeX.
1240 CONTENTS holds the contents of the block. INFO is a plist
1241 holding contextual information. See `org-export-data'."
1242 (org-latex--wrap-label dynamic-block contents
))
1247 (defun org-latex-entity (entity contents info
)
1248 "Transcode an ENTITY object from Org to LaTeX.
1249 CONTENTS are the definition itself. INFO is a plist holding
1250 contextual information."
1251 (org-element-property :latex entity
))
1256 (defun org-latex-example-block (example-block contents info
)
1257 "Transcode an EXAMPLE-BLOCK element from Org to LaTeX.
1258 CONTENTS is nil. INFO is a plist holding contextual
1260 (when (org-string-nw-p (org-element-property :value example-block
))
1261 (org-latex--wrap-label
1263 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1264 (org-export-format-code-default example-block info
)))))
1269 (defun org-latex-export-block (export-block contents info
)
1270 "Transcode a EXPORT-BLOCK element from Org to LaTeX.
1271 CONTENTS is nil. INFO is a plist holding contextual information."
1272 (when (member (org-element-property :type export-block
) '("LATEX" "TEX"))
1273 (org-remove-indentation (org-element-property :value export-block
))))
1278 (defun org-latex-export-snippet (export-snippet contents info
)
1279 "Transcode a EXPORT-SNIPPET object from Org to LaTeX.
1280 CONTENTS is nil. INFO is a plist holding contextual information."
1281 (when (eq (org-export-snippet-backend export-snippet
) 'latex
)
1282 (org-element-property :value export-snippet
)))
1287 (defun org-latex-fixed-width (fixed-width contents info
)
1288 "Transcode a FIXED-WIDTH element from Org to LaTeX.
1289 CONTENTS is nil. INFO is a plist holding contextual information."
1290 (org-latex--wrap-label
1292 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1293 (org-remove-indentation
1294 (org-element-property :value fixed-width
)))))
1297 ;;;; Footnote Reference
1299 (defun org-latex-footnote-reference (footnote-reference contents info
)
1300 "Transcode a FOOTNOTE-REFERENCE element from Org to LaTeX.
1301 CONTENTS is nil. INFO is a plist holding contextual information."
1303 ;; Insert separator between two footnotes in a row.
1304 (let ((prev (org-export-get-previous-element footnote-reference info
)))
1305 (when (eq (org-element-type prev
) 'footnote-reference
)
1306 org-latex-footnote-separator
))
1308 ;; Use \footnotemark if the footnote has already been defined.
1309 ((not (org-export-footnote-first-reference-p footnote-reference info
))
1310 (format "\\footnotemark[%s]{}"
1311 (org-export-get-footnote-number footnote-reference info
)))
1312 ;; Use \footnotemark if reference is within another footnote
1313 ;; reference, footnote definition or table cell.
1314 ((loop for parent in
(org-export-get-genealogy footnote-reference
)
1315 thereis
(memq (org-element-type parent
)
1316 '(footnote-reference footnote-definition table-cell
)))
1318 ;; Otherwise, define it with \footnote command.
1320 (let ((def (org-export-get-footnote-definition footnote-reference info
)))
1322 (format "\\footnote{%s}" (org-trim (org-export-data def info
)))
1323 ;; Retrieve all footnote references within the footnote and
1324 ;; add their definition after it, since LaTeX doesn't support
1326 (org-latex--delayed-footnotes-definitions def info
)))))))
1331 (defun org-latex-headline (headline contents info
)
1332 "Transcode a HEADLINE element from Org to LaTeX.
1333 CONTENTS holds the contents of the headline. INFO is a plist
1334 holding contextual information."
1335 (unless (org-element-property :footnote-section-p headline
)
1336 (let* ((class (plist-get info
:latex-class
))
1337 (level (org-export-get-relative-level headline info
))
1338 (numberedp (org-export-numbered-headline-p headline info
))
1339 (class-sectioning (assoc class org-latex-classes
))
1340 ;; Section formatting will set two placeholders: one for
1341 ;; the title and the other for the contents.
1343 (let ((sec (if (functionp (nth 2 class-sectioning
))
1344 (funcall (nth 2 class-sectioning
) level numberedp
)
1345 (nth (1+ level
) class-sectioning
))))
1347 ;; No section available for that LEVEL.
1349 ;; Section format directly returned by a function. Add
1350 ;; placeholder for contents.
1351 ((stringp sec
) (concat sec
"\n%s"))
1352 ;; (numbered-section . unnumbered-section)
1353 ((not (consp (cdr sec
)))
1354 (concat (funcall (if numberedp
#'car
#'cdr
) sec
) "\n%s"))
1355 ;; (numbered-open numbered-close)
1357 (when numberedp
(concat (car sec
) "\n%s" (nth 1 sec
))))
1358 ;; (num-in num-out no-num-in no-num-out)
1360 (if numberedp
(concat (car sec
) "\n%s" (nth 1 sec
))
1361 (concat (nth 2 sec
) "\n%s" (nth 3 sec
)))))))
1362 (text (org-export-data (org-element-property :title headline
) info
))
1364 (and (plist-get info
:with-todo-keywords
)
1365 (let ((todo (org-element-property :todo-keyword headline
)))
1366 (and todo
(org-export-data todo info
)))))
1367 (todo-type (and todo
(org-element-property :todo-type headline
)))
1368 (tags (and (plist-get info
:with-tags
)
1369 (org-export-get-tags headline info
)))
1370 (priority (and (plist-get info
:with-priority
)
1371 (org-element-property :priority headline
)))
1372 ;; Create the headline text along with a no-tag version.
1373 ;; The latter is required to remove tags from toc.
1374 (full-text (funcall org-latex-format-headline-function
1375 todo todo-type priority text tags
))
1376 ;; Associate \label to the headline for internal links.
1378 (format "\\label{sec-%s}\n"
1379 (mapconcat 'number-to-string
1380 (org-export-get-headline-number headline info
)
1383 (make-string (org-element-property :pre-blank headline
) 10)))
1384 (if (or (not section-fmt
) (org-export-low-level-p headline info
))
1385 ;; This is a deep sub-tree: export it as a list item. Also
1386 ;; export as items headlines for which no section format has
1388 (let ((low-level-body
1390 ;; If headline is the first sibling, start a list.
1391 (when (org-export-first-sibling-p headline info
)
1392 (format "\\begin{%s}\n" (if numberedp
'enumerate
'itemize
)))
1395 (and full-text
(org-string-match-p "\\`[ \t]*\\[" full-text
)
1401 ;; If headline is not the last sibling simply return
1402 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before
1404 (if (not (org-export-last-sibling-p headline info
)) low-level-body
1405 (replace-regexp-in-string
1407 (format "\n\\\\end{%s}" (if numberedp
'enumerate
'itemize
))
1409 ;; This is a standard headline. Export it as a section. Add
1410 ;; an alternative heading when possible, and when this is not
1411 ;; identical to the usual heading.
1413 (funcall org-latex-format-headline-function
1414 todo todo-type priority
1416 (org-export-get-alt-title headline info
) info
)
1417 (and (eq (plist-get info
:with-tags
) t
) tags
))))
1418 (if (and numberedp opt-title
1419 (not (equal opt-title full-text
))
1420 (string-match "\\`\\\\\\(.*?[^*]\\){" section-fmt
))
1421 (format (replace-match "\\1[%s]" nil nil section-fmt
1)
1422 ;; Replace square brackets with parenthesis
1423 ;; since square brackets are not supported in
1424 ;; optional arguments.
1425 (replace-regexp-in-string
1426 "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title
))
1428 (concat headline-label pre-blanks contents
))
1429 ;; Impossible to add an alternative heading. Fallback to
1430 ;; regular sectioning format string.
1431 (format section-fmt full-text
1432 (concat headline-label pre-blanks contents
))))))))
1434 (defun org-latex-format-headline-default-function
1435 (todo todo-type priority text tags
)
1436 "Default format function for a headline.
1437 See `org-latex-format-headline-function' for details."
1439 (and todo
(format "{\\bfseries\\sffamily %s} " todo
))
1440 (and priority
(format "\\framebox{\\#%c} " priority
))
1443 (format "\\hfill{}\\textsc{%s}" (mapconcat 'identity tags
":")))))
1446 ;;;; Horizontal Rule
1448 (defun org-latex-horizontal-rule (horizontal-rule contents info
)
1449 "Transcode an HORIZONTAL-RULE object from Org to LaTeX.
1450 CONTENTS is nil. INFO is a plist holding contextual information."
1451 (let ((attr (org-export-read-attribute :attr_latex horizontal-rule
))
1452 (prev (org-export-get-previous-element horizontal-rule info
)))
1454 ;; Make sure the rule doesn't start at the end of the current
1455 ;; line by separating it with a blank line from previous element.
1457 (let ((prev-blank (org-element-property :post-blank prev
)))
1458 (or (not prev-blank
) (zerop prev-blank
))))
1460 (org-latex--wrap-label
1462 (format "\\rule{%s}{%s}"
1463 (or (plist-get attr
:width
) "\\linewidth")
1464 (or (plist-get attr
:thickness
) "0.5pt"))))))
1467 ;;;; Inline Src Block
1469 (defun org-latex-inline-src-block (inline-src-block contents info
)
1470 "Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
1471 CONTENTS holds the contents of the item. INFO is a plist holding
1472 contextual information."
1473 (let* ((code (org-element-property :value inline-src-block
))
1474 (separator (org-latex--find-verb-separator code
)))
1476 ;; Do not use a special package: transcode it verbatim.
1477 ((not org-latex-listings
)
1478 (concat "\\verb" separator code separator
))
1479 ;; Use minted package.
1480 ((eq org-latex-listings
'minted
)
1481 (let* ((org-lang (org-element-property :language inline-src-block
))
1482 (mint-lang (or (cadr (assq (intern org-lang
)
1483 org-latex-minted-langs
))
1485 (options (org-latex--make-option-string
1486 org-latex-minted-options
)))
1487 (concat (format "\\mint%s{%s}"
1488 (if (string= options
"") "" (format "[%s]" options
))
1490 separator code separator
)))
1491 ;; Use listings package.
1493 ;; Maybe translate language's name.
1494 (let* ((org-lang (org-element-property :language inline-src-block
))
1495 (lst-lang (or (cadr (assq (intern org-lang
)
1496 org-latex-listings-langs
))
1498 (options (org-latex--make-option-string
1499 (append org-latex-listings-options
1500 `(("language" ,lst-lang
))))))
1501 (concat (format "\\lstinline[%s]" options
)
1502 separator code separator
))))))
1507 (defun org-latex-inlinetask (inlinetask contents info
)
1508 "Transcode an INLINETASK element from Org to LaTeX.
1509 CONTENTS holds the contents of the block. INFO is a plist
1510 holding contextual information."
1511 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1512 (todo (and (plist-get info
:with-todo-keywords
)
1513 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1514 (and todo
(org-export-data todo info
)))))
1515 (todo-type (org-element-property :todo-type inlinetask
))
1516 (tags (and (plist-get info
:with-tags
)
1517 (org-export-get-tags inlinetask info
)))
1518 (priority (and (plist-get info
:with-priority
)
1519 (org-element-property :priority inlinetask
))))
1520 ;; If `org-latex-format-inlinetask-function' is provided, call it
1521 ;; with appropriate arguments.
1522 (if (not (eq org-latex-format-inlinetask-function
'ignore
))
1523 (funcall org-latex-format-inlinetask-function
1524 todo todo-type priority title tags contents
)
1525 ;; Otherwise, use a default template.
1526 (org-latex--wrap-label
1530 (when todo
(format "\\textbf{\\textsf{\\textsc{%s}}} " todo
))
1531 (when priority
(format "\\framebox{\\#%c} " priority
))
1533 (when tags
(format "\\hfill{}\\textsc{:%s:}"
1534 (mapconcat 'identity tags
":"))))))
1535 (format (concat "\\begin{center}\n"
1537 "\\begin{minipage}[c]{.6\\textwidth}\n"
1539 "\\rule[.8em]{\\textwidth}{2pt}\n\n"
1544 full-title contents
))))))
1549 (defun org-latex-italic (italic contents info
)
1550 "Transcode ITALIC from Org to LaTeX.
1551 CONTENTS is the text with italic markup. INFO is a plist holding
1552 contextual information."
1553 (org-latex--text-markup contents
'italic
))
1558 (defun org-latex-item (item contents info
)
1559 "Transcode an ITEM element from Org to LaTeX.
1560 CONTENTS holds the contents of the item. INFO is a plist holding
1561 contextual information."
1563 (let ((count (org-element-property :counter item
))
1565 ;; Determine level of current item to determine the
1566 ;; correct LaTeX counter to use (enumi, enumii...).
1567 (let ((parent item
) (level 0))
1568 (while (memq (org-element-type
1569 (setq parent
(org-export-get-parent parent
)))
1571 (when (and (eq (org-element-type parent
) 'plain-list
)
1572 (eq (org-element-property :type parent
)
1578 (format "\\setcounter{enum%s}{%s}\n"
1579 (nth (1- level
) '("i" "ii" "iii" "iv"))
1581 (checkbox (case (org-element-property :checkbox item
)
1582 (on "$\\boxtimes$ ")
1584 (trans "$\\boxminus$ ")))
1585 (tag (let ((tag (org-element-property :tag item
)))
1586 ;; Check-boxes must belong to the tag.
1587 (and tag
(format "[{%s}] "
1589 (org-export-data tag info
)))))))
1594 (checkbox (concat " " checkbox
))
1595 ;; Without a tag or a check-box, if CONTENTS starts with
1596 ;; an opening square bracket, add "\relax" to "\item",
1597 ;; unless the brackets comes from an initial export
1598 ;; snippet (i.e. it is inserted willingly by the user).
1600 (org-string-match-p "\\`[ \t]*\\[" contents
)
1601 (not (let ((e (car (org-element-contents item
))))
1602 (and (eq (org-element-type e
) 'paragraph
)
1603 (let ((o (car (org-element-contents e
))))
1604 (and (eq (org-element-type o
) 'export-snippet
)
1605 (eq (org-export-snippet-backend o
)
1609 (and contents
(org-trim contents
))
1610 ;; If there are footnotes references in tag, be sure to
1611 ;; add their definition at the end of the item. This
1612 ;; workaround is necessary since "\footnote{}" command is
1613 ;; not supported in tags.
1615 (org-latex--delayed-footnotes-definitions
1616 (org-element-property :tag item
) info
)))))
1621 (defun org-latex-keyword (keyword contents info
)
1622 "Transcode a KEYWORD element from Org to LaTeX.
1623 CONTENTS is nil. INFO is a plist holding contextual information."
1624 (let ((key (org-element-property :key keyword
))
1625 (value (org-element-property :value keyword
)))
1627 ((string= key
"LATEX") value
)
1628 ((string= key
"INDEX") (format "\\index{%s}" value
))
1629 ((string= key
"TOC")
1630 (let ((value (downcase value
)))
1632 ((string-match "\\<headlines\\>" value
)
1633 (let ((depth (or (and (string-match "[0-9]+" value
)
1634 (string-to-number (match-string 0 value
)))
1635 (plist-get info
:with-toc
))))
1637 (when (wholenump depth
)
1638 (format "\\setcounter{tocdepth}{%s}\n" depth
))
1639 "\\tableofcontents")))
1640 ((string= "tables" value
) "\\listoftables")
1641 ((string= "listings" value
)
1643 ((eq org-latex-listings
'minted
) "\\listoflistings")
1644 (org-latex-listings "\\lstlistoflistings")
1645 ;; At the moment, src blocks with a caption are wrapped
1646 ;; into a figure environment.
1647 (t "\\listoffigures")))))))))
1650 ;;;; Latex Environment
1652 (defun org-latex-latex-environment (latex-environment contents info
)
1653 "Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
1654 CONTENTS is nil. INFO is a plist holding contextual information."
1655 (when (plist-get info
:with-latex
)
1656 (let ((label (org-element-property :name latex-environment
))
1657 (value (org-remove-indentation
1658 (org-element-property :value latex-environment
))))
1659 (if (not (org-string-nw-p label
)) value
1660 ;; Environment is labeled: label must be within the environment
1661 ;; (otherwise, a reference pointing to that element will count
1662 ;; the section instead).
1665 (goto-char (point-min))
1668 (format "\\label{%s}\n" (org-export-solidify-link-text label
)))
1669 (buffer-string))))))
1674 (defun org-latex-latex-fragment (latex-fragment contents info
)
1675 "Transcode a LATEX-FRAGMENT object from Org to LaTeX.
1676 CONTENTS is nil. INFO is a plist holding contextual information."
1677 (let ((value (org-element-property :value latex-fragment
)))
1678 ;; Trim math markers since the fragment is enclosed within
1679 ;; a latex-math-block object anyway.
1680 (cond ((string-match "\\`\\(\\$\\{1,2\\}\\)\\([^\000]*\\)\\1\\'" value
)
1681 (match-string 2 value
))
1682 ((string-match "\\`\\\\(\\([^\000]*\\)\\\\)\\'" value
)
1683 (match-string 1 value
))
1689 (defun org-latex-line-break (line-break contents info
)
1690 "Transcode a LINE-BREAK object from Org to LaTeX.
1691 CONTENTS is nil. INFO is a plist holding contextual information."
1697 (defun org-latex--inline-image (link info
)
1698 "Return LaTeX code for an inline image.
1699 LINK is the link pointing to the inline image. INFO is a plist
1700 used as a communication channel."
1701 (let* ((parent (org-export-get-parent-element link
))
1702 (path (let ((raw-path (org-element-property :path link
)))
1703 (if (not (file-name-absolute-p raw-path
)) raw-path
1704 (expand-file-name raw-path
))))
1705 (filetype (file-name-extension path
))
1706 (caption (org-latex--caption/label-string parent info
))
1707 ;; Retrieve latex attributes from the element around.
1708 (attr (org-export-read-attribute :attr_latex parent
))
1709 (float (let ((float (plist-get attr
:float
)))
1710 (cond ((and (not float
) (plist-member attr
:float
)) nil
)
1711 ((string= float
"wrap") 'wrap
)
1712 ((string= float
"multicolumn") 'multicolumn
)
1714 (org-element-property :caption parent
)
1715 (org-string-nw-p (plist-get attr
:caption
)))
1718 (let ((place (plist-get attr
:placement
)))
1719 (cond (place (format "%s" place
))
1720 ((eq float
'wrap
) "{l}{0.5\\textwidth}")
1722 (format "[%s]" org-latex-default-figure-position
))
1724 (comment-include (if (plist-get attr
:comment-include
) "%" ""))
1725 ;; It is possible to specify width and height in the
1726 ;; ATTR_LATEX line, and also via default variables.
1727 (width (cond ((plist-get attr
:width
))
1728 ((plist-get attr
:height
) "")
1729 ((eq float
'wrap
) "0.48\\textwidth")
1730 (t org-latex-image-default-width
)))
1731 (height (cond ((plist-get attr
:height
))
1732 ((or (plist-get attr
:width
)
1733 (memq float
'(figure wrap
))) "")
1734 (t org-latex-image-default-height
)))
1735 (options (let ((opt (or (plist-get attr
:options
)
1736 org-latex-image-default-option
)))
1737 (if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt
)) opt
1738 (match-string 1 opt
))))
1740 (if (member filetype
'("tikz" "pgf"))
1742 ;; - use \input to read in image file.
1743 ;; - if options are present, wrap in a tikzpicture environment.
1744 ;; - if width or height are present, use \resizebox to change
1747 (setq image-code
(format "\\input{%s}" path
))
1748 (when (org-string-nw-p options
)
1750 (format "\\begin{tikzpicture}[%s]\n%s\n\\end{tikzpicture}"
1753 (when (or (org-string-nw-p width
) (org-string-nw-p height
))
1754 (setq image-code
(format "\\resizebox{%s}{%s}{%s}"
1755 (if (org-string-nw-p width
) width
"!")
1756 (if (org-string-nw-p height
) height
"!")
1758 ;; For other images:
1759 ;; - add width and height to options.
1760 ;; - include the image with \includegraphics.
1761 (when (org-string-nw-p width
)
1762 (setq options
(concat options
",width=" width
)))
1763 (when (org-string-nw-p height
)
1764 (setq options
(concat options
",height=" height
)))
1766 (format "\\includegraphics%s{%s}"
1767 (cond ((not (org-string-nw-p options
)) "")
1768 ((= (aref options
0) ?
,)
1769 (format "[%s]"(substring options
1)))
1770 (t (format "[%s]" options
)))
1772 (when (equal filetype
"svg")
1773 (setq image-code
(replace-regexp-in-string "^\\\\includegraphics"
1777 (setq image-code
(replace-regexp-in-string "\\.svg}"
1781 ;; Return proper string, depending on FLOAT.
1783 (wrap (format "\\begin{wrapfigure}%s
1786 %s\\end{wrapfigure}" placement comment-include image-code caption
))
1787 (multicolumn (format "\\begin{figure*}%s
1790 %s\\end{figure*}" placement comment-include image-code caption
))
1791 (figure (format "\\begin{figure}%s
1794 %s\\end{figure}" placement comment-include image-code caption
))
1795 (otherwise image-code
))))
1797 (defun org-latex-link (link desc info
)
1798 "Transcode a LINK object from Org to LaTeX.
1800 DESC is the description part of the link, or the empty string.
1801 INFO is a plist holding contextual information. See
1803 (let* ((type (org-element-property :type link
))
1804 (raw-path (org-element-property :path link
))
1805 ;; Ensure DESC really exists, or set it to nil.
1806 (desc (and (not (string= desc
"")) desc
))
1807 (imagep (org-export-inline-image-p
1808 link org-latex-inline-image-rules
))
1810 ((member type
'("http" "https" "ftp" "mailto"))
1811 (concat type
":" raw-path
))
1812 ((string= type
"file")
1813 (if (not (file-name-absolute-p raw-path
)) raw-path
1814 (concat "file://" (expand-file-name raw-path
))))
1819 (imagep (org-latex--inline-image link info
))
1820 ;; Radio link: Transcode target's contents and use them as link's
1822 ((string= type
"radio")
1823 (let ((destination (org-export-resolve-radio-link link info
)))
1825 (format "\\hyperref[%s]{%s}"
1826 (org-export-solidify-link-text path
)
1827 (org-export-data (org-element-contents destination
) info
)))))
1828 ;; Links pointing to a headline: Find destination and build
1829 ;; appropriate referencing command.
1830 ((member type
'("custom-id" "fuzzy" "id"))
1831 (let ((destination (if (string= type
"fuzzy")
1832 (org-export-resolve-fuzzy-link link info
)
1833 (org-export-resolve-id-link link info
))))
1834 (case (org-element-type destination
)
1835 ;; Id link points to an external file.
1837 (if desc
(format "\\href{%s}{%s}" destination desc
)
1838 (format "\\url{%s}" destination
)))
1839 ;; Fuzzy link points nowhere.
1841 (format org-latex-link-with-unknown-path-format
1844 (org-element-property :raw-link link
) info
))))
1845 ;; LINK points to a headline. If headlines are numbered
1846 ;; and the link has no description, display headline's
1847 ;; number. Otherwise, display description or headline's
1854 (org-export-get-headline-number destination info
)
1856 (if (and (plist-get info
:section-numbers
) (not desc
))
1857 (format "\\ref{%s}" label
)
1858 (format "\\hyperref[%s]{%s}" label
1861 (org-element-property :title destination
) info
))))))
1862 ;; Fuzzy link points to a target. Do as above.
1864 (let ((path (org-export-solidify-link-text path
)))
1865 (if (not desc
) (format "\\ref{%s}" path
)
1866 (format "\\hyperref[%s]{%s}" path desc
)))))))
1867 ;; Coderef: replace link with the reference name or the
1868 ;; equivalent line number.
1869 ((string= type
"coderef")
1870 (format (org-export-get-coderef-format path desc
)
1871 (org-export-resolve-coderef path info
)))
1872 ;; Link type is handled by a special function.
1873 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
1874 (funcall protocol
(org-link-unescape path
) desc
'latex
))
1875 ;; External link with a description part.
1876 ((and path desc
) (format "\\href{%s}{%s}" path desc
))
1877 ;; External link without a description part.
1878 (path (format "\\url{%s}" path
))
1879 ;; No path, only description. Try to do something useful.
1880 (t (format org-latex-link-with-unknown-path-format desc
)))))
1885 (defun org-latex-node-property (node-property contents info
)
1886 "Transcode a NODE-PROPERTY element from Org to LaTeX.
1887 CONTENTS is nil. INFO is a plist holding contextual
1890 (org-element-property :key node-property
)
1891 (let ((value (org-element-property :value node-property
)))
1892 (if value
(concat " " value
) ""))))
1897 (defun org-latex-paragraph (paragraph contents info
)
1898 "Transcode a PARAGRAPH element from Org to LaTeX.
1899 CONTENTS is the contents of the paragraph, as a string. INFO is
1900 the plist used as a communication channel."
1906 (defun org-latex-plain-list (plain-list contents info
)
1907 "Transcode a PLAIN-LIST element from Org to LaTeX.
1908 CONTENTS is the contents of the list. INFO is a plist holding
1909 contextual information."
1910 (let* ((type (org-element-property :type plain-list
))
1911 (attr (org-export-read-attribute :attr_latex plain-list
))
1912 (latex-type (let ((env (plist-get attr
:environment
)))
1913 (cond (env (format "%s" env
))
1914 ((eq type
'ordered
) "enumerate")
1915 ((eq type
'unordered
) "itemize")
1916 ((eq type
'descriptive
) "description")))))
1917 (org-latex--wrap-label
1919 (format "\\begin{%s}%s\n%s\\end{%s}"
1921 ;; Put optional arguments, if any inside square brackets
1923 (let ((options (format "%s" (or (plist-get attr
:options
) ""))))
1924 (cond ((equal options
"") "")
1925 ((string-match "\\`\\[.*\\]\\'" options
) options
)
1926 (t (format "[%s]" options
))))
1933 (defun org-latex-plain-text (text info
)
1934 "Transcode a TEXT string from Org to LaTeX.
1935 TEXT is the string to transcode. INFO is a plist holding
1936 contextual information."
1937 (let ((specialp (plist-get info
:with-special-strings
))
1939 ;; Protect %, #, &, $, _, { and }.
1940 (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}_]\\)" output
)
1943 (format "\\%s" (match-string 2 output
)) nil t output
2)))
1946 (replace-regexp-in-string
1947 "\\([^\\]\\|^\\)\\(\\^\\)" "\\\\^{}" output nil nil
2))
1948 ;; Protect \. If special strings are used, be careful not to
1949 ;; protect "\" in "\-" constructs.
1950 (let ((symbols (if specialp
"-%$#&{}^_\\" "%$#&{}^_\\")))
1952 (replace-regexp-in-string
1953 (format "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%s]\\|$\\)" symbols
)
1954 "$\\backslash$" output nil t
1)))
1957 (replace-regexp-in-string
1958 "\\([^\\]\\|^\\)\\(~\\)" "\\textasciitilde{}" output nil t
2))
1959 ;; Activate smart quotes. Be sure to provide original TEXT string
1960 ;; since OUTPUT may have been modified.
1961 (when (plist-get info
:with-smart-quotes
)
1962 (setq output
(org-export-activate-smart-quotes output
:latex info text
)))
1963 ;; LaTeX into \LaTeX{} and TeX into \TeX{}.
1964 (let ((case-fold-search nil
)
1966 (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" output start
)
1967 (setq output
(replace-match
1968 (format "\\%s{}" (match-string 1 output
)) nil t output
)
1969 start
(match-end 0))))
1970 ;; Convert special strings.
1973 (replace-regexp-in-string "\\.\\.\\." "\\ldots{}" output nil t
)))
1974 ;; Handle break preservation if required.
1975 (when (plist-get info
:preserve-breaks
)
1976 (setq output
(replace-regexp-in-string
1977 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" output
)))
1984 (defun org-latex-planning (planning contents info
)
1985 "Transcode a PLANNING element from Org to LaTeX.
1986 CONTENTS is nil. INFO is a plist holding contextual
1994 (let ((closed (org-element-property :closed planning
)))
1997 (format "\\textbf{%s} " org-closed-string
)
1998 (format org-latex-inactive-timestamp-format
2000 (org-element-property :raw-value closed
))))))
2001 (let ((deadline (org-element-property :deadline planning
)))
2004 (format "\\textbf{%s} " org-deadline-string
)
2005 (format org-latex-active-timestamp-format
2007 (org-element-property :raw-value deadline
))))))
2008 (let ((scheduled (org-element-property :scheduled planning
)))
2011 (format "\\textbf{%s} " org-scheduled-string
)
2012 (format org-latex-active-timestamp-format
2014 (org-element-property :raw-value scheduled
))))))))
2019 ;;;; Property Drawer
2021 (defun org-latex-property-drawer (property-drawer contents info
)
2022 "Transcode a PROPERTY-DRAWER element from Org to LaTeX.
2023 CONTENTS holds the contents of the drawer. INFO is a plist
2024 holding contextual information."
2025 (and (org-string-nw-p contents
)
2026 (format "\\begin{verbatim}\n%s\\end{verbatim}" contents
)))
2029 ;;;; Pseudo Object: LaTeX Math Block
2031 (defun org-latex--wrap-latex-math-block (data info
)
2032 "Merge contiguous math objects in a pseudo-object container.
2033 DATA is a parse tree or a secondary string. INFO is a plist
2034 containing export options. Modify DATA by side-effect and return it."
2035 (let ((valid-object-p
2037 ;; Non-nil when OBJ can be added to the latex math block.
2039 (case (org-element-type obj
)
2040 (entity (org-element-property :latex-math-p obj
))
2042 (let ((value (org-element-property :value obj
)))
2043 (or (org-string-match-p "\\`\\\\([^\000]*\\\\)\\'" value
)
2044 (org-string-match-p "\\`\\$[^\000]*\\$\\'" value
))))
2045 ((subscript superscript
) t
))))))
2046 (org-element-map data
'(entity latex-fragment subscript superscript
)
2048 ;; Skip objects already wrapped.
2049 (when (and (not (eq (org-element-type
2050 (org-element-property :parent object
))
2052 (funcall valid-object-p object
))
2053 (let ((math-block (list 'latex-math-block nil
))
2054 (next-elements (org-export-get-next-element object info t
))
2056 ;; Wrap MATH-BLOCK around OBJECT in DATA.
2057 (org-element-insert-before math-block object
)
2058 (org-element-extract-element object
)
2059 (org-element-adopt-elements math-block object
)
2060 (when (zerop (or (org-element-property :post-blank object
) 0))
2061 ;; MATH-BLOCK swallows consecutive math objects.
2063 (dolist (next next-elements
)
2064 (if (not (funcall valid-object-p next
)) (throw 'exit nil
)
2065 (org-element-extract-element next
)
2066 (org-element-adopt-elements math-block next
)
2067 ;; Eschew the case: \beta$x$ -> \(\betax\).
2068 (unless (memq (org-element-type next
)
2069 '(subscript superscript
))
2070 (org-element-put-property last
:post-blank
1))
2072 (when (> (or (org-element-property :post-blank next
) 0) 0)
2073 (throw 'exit nil
))))))
2074 (org-element-put-property
2075 math-block
:post-blank
(org-element-property :post-blank last
)))))
2076 info nil
'(subscript superscript latex-math-block
) t
)
2077 ;; Return updated DATA.
2080 (defun org-latex-math-block-tree-filter (tree backend info
)
2081 (org-latex--wrap-latex-math-block tree info
))
2083 (defun org-latex-math-block-options-filter (info backend
)
2084 (dolist (prop '(:author
:date
:title
) info
)
2085 (plist-put info prop
2086 (org-latex--wrap-latex-math-block (plist-get info prop
) info
))))
2088 (defun org-latex-math-block (math-block contents info
)
2089 "Transcode a MATH-BLOCK object from Org to LaTeX.
2090 CONTENTS is a string. INFO is a plist used as a communication
2092 (when (org-string-nw-p contents
)
2093 (format "\\(%s\\)" (org-trim contents
))))
2097 (defun org-latex-quote-block (quote-block contents info
)
2098 "Transcode a QUOTE-BLOCK element from Org to LaTeX.
2099 CONTENTS holds the contents of the block. INFO is a plist
2100 holding contextual information."
2101 (org-latex--wrap-label
2103 (format "\\begin{quote}\n%s\\end{quote}" contents
)))
2108 (defun org-latex-quote-section (quote-section contents info
)
2109 "Transcode a QUOTE-SECTION element from Org to LaTeX.
2110 CONTENTS is nil. INFO is a plist holding contextual information."
2111 (let ((value (org-remove-indentation
2112 (org-element-property :value quote-section
))))
2113 (when value
(format "\\begin{verbatim}\n%s\\end{verbatim}" value
))))
2118 (defun org-latex-radio-target (radio-target text info
)
2119 "Transcode a RADIO-TARGET object from Org to LaTeX.
2120 TEXT is the text of the target. INFO is a plist holding
2121 contextual information."
2122 (format "\\label{%s}%s"
2123 (org-export-solidify-link-text
2124 (org-element-property :value radio-target
))
2130 (defun org-latex-section (section contents info
)
2131 "Transcode a SECTION element from Org to LaTeX.
2132 CONTENTS holds the contents of the section. INFO is a plist
2133 holding contextual information."
2139 (defun org-latex-special-block (special-block contents info
)
2140 "Transcode a SPECIAL-BLOCK element from Org to LaTeX.
2141 CONTENTS holds the contents of the block. INFO is a plist
2142 holding contextual information."
2143 (let ((type (downcase (org-element-property :type special-block
)))
2144 (opt (org-export-read-attribute :attr_latex special-block
:options
)))
2145 (concat (format "\\begin{%s}%s\n" type
(or opt
""))
2146 ;; Insert any label or caption within the block
2147 ;; (otherwise, a reference pointing to that element will
2148 ;; count the section instead).
2149 (org-latex--caption/label-string special-block info
)
2151 (format "\\end{%s}" type
))))
2156 (defun org-latex-src-block (src-block contents info
)
2157 "Transcode a SRC-BLOCK element from Org to LaTeX.
2158 CONTENTS holds the contents of the item. INFO is a plist holding
2159 contextual information."
2160 (when (org-string-nw-p (org-element-property :value src-block
))
2161 (let* ((lang (org-element-property :language src-block
))
2162 (caption (org-element-property :caption src-block
))
2163 (label (org-element-property :name src-block
))
2164 (custom-env (and lang
2165 (cadr (assq (intern lang
)
2166 org-latex-custom-lang-environments
))))
2167 (num-start (case (org-element-property :number-lines src-block
)
2168 (continued (org-export-get-loc src-block info
))
2170 (retain-labels (org-element-property :retain-labels src-block
))
2171 (attributes (org-export-read-attribute :attr_latex src-block
))
2172 (float (plist-get attributes
:float
)))
2174 ;; Case 1. No source fontification.
2175 ((not org-latex-listings
)
2176 (let* ((caption-str (org-latex--caption/label-string src-block info
))
2178 (cond ((and (not float
) (plist-member attributes
:float
)) "%s")
2179 ((string= "multicolumn" float
)
2180 (format "\\begin{figure*}[%s]\n%%s%s\n\\end{figure*}"
2181 org-latex-default-figure-position
2184 (format "\\begin{figure}[H]\n%%s%s\n\\end{figure}"
2189 (concat (format "\\begin{verbatim}\n%s\\end{verbatim}"
2190 (org-export-format-code-default src-block info
))))))
2191 ;; Case 2. Custom environment.
2192 (custom-env (format "\\begin{%s}\n%s\\end{%s}\n"
2194 (org-export-format-code-default src-block info
)
2196 ;; Case 3. Use minted package.
2197 ((eq org-latex-listings
'minted
)
2198 (let* ((caption-str (org-latex--caption/label-string src-block info
))
2200 (cond ((and (not float
) (plist-member attributes
:float
)) "%s")
2201 ((string= "multicolumn" float
)
2202 (format "\\begin{listing*}\n%%s\n%s\\end{listing*}"
2205 (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
2210 "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
2212 (org-latex--make-option-string
2213 (if (or (not num-start
)
2214 (assoc "linenos" org-latex-minted-options
))
2215 org-latex-minted-options
2218 ("firstnumber" ,(number-to-string (1+ num-start
))))
2219 org-latex-minted-options
)))
2221 (or (cadr (assq (intern lang
) org-latex-minted-langs
)) lang
)
2223 (let* ((code-info (org-export-unravel-code src-block
))
2227 (org-split-string (car code-info
)
2229 (org-export-format-code
2231 (lambda (loc num ref
)
2235 ;; Ensure references are flushed to the right,
2236 ;; separated with 6 spaces from the widest line
2238 (concat (make-string (+ (- max-width
(length loc
)) 6)
2240 (format "(%s)" ref
)))))
2241 nil
(and retain-labels
(cdr code-info
)))))))
2243 (format float-env body
)))
2244 ;; Case 4. Use listings package.
2247 (or (cadr (assq (intern lang
) org-latex-listings-langs
)) lang
))
2250 (let ((main (org-export-get-caption src-block
))
2251 (secondary (org-export-get-caption src-block t
)))
2253 (format "{%s}" (org-export-data main info
))
2255 (org-export-data secondary info
)
2256 (org-export-data main info
)))))))
2261 (org-latex--make-option-string
2263 org-latex-listings-options
2265 ((and (not float
) (plist-member attributes
:float
)) nil
)
2266 ((string= "multicolumn" float
) '(("float" "*")))
2267 ((and float
(not (assoc "float" org-latex-listings-options
)))
2268 `(("float" ,org-latex-default-figure-position
))))
2269 `(("language" ,lst-lang
))
2270 (when label
`(("label" ,label
)))
2271 (when caption-str
`(("caption" ,caption-str
)))
2272 (cond ((assoc "numbers" org-latex-listings-options
) nil
)
2273 ((not num-start
) '(("numbers" "none")))
2274 ((zerop num-start
) '(("numbers" "left")))
2275 (t `(("numbers" "left")
2277 ,(number-to-string (1+ num-start
)))))))))
2280 "\\begin{lstlisting}\n%s\\end{lstlisting}"
2281 (let* ((code-info (org-export-unravel-code src-block
))
2285 (org-split-string (car code-info
) "\n")))))
2286 (org-export-format-code
2288 (lambda (loc num ref
)
2292 ;; Ensure references are flushed to the right,
2293 ;; separated with 6 spaces from the widest line of
2295 (concat (make-string (+ (- max-width
(length loc
)) 6) ?
)
2296 (format "(%s)" ref
)))))
2297 nil
(and retain-labels
(cdr code-info
))))))))))))
2300 ;;;; Statistics Cookie
2302 (defun org-latex-statistics-cookie (statistics-cookie contents info
)
2303 "Transcode a STATISTICS-COOKIE object from Org to LaTeX.
2304 CONTENTS is nil. INFO is a plist holding contextual information."
2305 (replace-regexp-in-string
2306 "%" "\\%" (org-element-property :value statistics-cookie
) nil t
))
2311 (defun org-latex-strike-through (strike-through contents info
)
2312 "Transcode STRIKE-THROUGH from Org to LaTeX.
2313 CONTENTS is the text with strike-through markup. INFO is a plist
2314 holding contextual information."
2315 (org-latex--text-markup contents
'strike-through
))
2320 (defun org-latex--script-size (object info
)
2321 "Transcode a subscript or superscript object.
2322 OBJECT is an Org object. INFO is a plist used as a communication
2324 (let ((type (org-element-type object
))
2326 (org-element-map (org-element-contents object
)
2327 (cons 'plain-text org-element-all-objects
)
2329 (case (org-element-type obj
)
2330 ((entity latex-fragment
)
2331 (let ((data (org-trim (org-export-data obj info
))))
2333 "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
2337 (match-string 1 data
)
2338 (let ((blank (org-element-property :post-blank obj
)))
2339 (and blank
(> blank
0) "\\ "))))))
2342 (format "%s\\text{%s}" output
(org-export-data obj info
))))
2346 (org-export-data obj info
)
2347 (let ((blank (org-element-property :post-blank obj
)))
2348 (and blank
(> blank
0) "\\ ")))))))
2349 info nil org-element-recursive-objects
)
2350 ;; Result. Do not wrap into curly brackets if OUTPUT is a single
2352 (concat (if (eq (org-element-type object
) 'subscript
) "_" "^")
2353 (and (> (length output
) 1) "{")
2355 (and (> (length output
) 1) "}"))))
2357 (defun org-latex-subscript (subscript contents info
)
2358 "Transcode a SUBSCRIPT object from Org to LaTeX.
2359 CONTENTS is the contents of the object. INFO is a plist holding
2360 contextual information."
2361 (org-latex--script-size subscript info
))
2366 (defun org-latex-superscript (superscript contents info
)
2367 "Transcode a SUPERSCRIPT object from Org to LaTeX.
2368 CONTENTS is the contents of the object. INFO is a plist holding
2369 contextual information."
2370 (org-latex--script-size superscript info
))
2375 ;; `org-latex-table' is the entry point for table transcoding. It
2376 ;; takes care of tables with a "verbatim" mode. Otherwise, it
2377 ;; delegates the job to either `org-latex--table.el-table',
2378 ;; `org-latex--org-table' or `org-latex--math-table' functions,
2379 ;; depending of the type of the table and the mode requested.
2381 ;; `org-latex--align-string' is a subroutine used to build alignment
2382 ;; string for Org tables.
2384 (defun org-latex-table (table contents info
)
2385 "Transcode a TABLE element from Org to LaTeX.
2386 CONTENTS is the contents of the table. INFO is a plist holding
2387 contextual information."
2388 (if (eq (org-element-property :type table
) 'table.el
)
2389 ;; "table.el" table. Convert it using appropriate tools.
2390 (org-latex--table.el-table table info
)
2391 (let ((type (or (org-export-read-attribute :attr_latex table
:mode
)
2392 org-latex-default-table-mode
)))
2394 ;; Case 1: Verbatim table.
2395 ((string= type
"verbatim")
2396 (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
2397 ;; Re-create table, without affiliated keywords.
2398 (org-trim (org-element-interpret-data
2399 `(table nil
,@(org-element-contents table
))
2400 org-latex-pseudo-objects
))))
2402 ((or (string= type
"math") (string= type
"inline-math"))
2403 (org-latex--math-table table info
))
2404 ;; Case 3: Standard table.
2405 (t (concat (org-latex--org-table table contents info
)
2406 ;; When there are footnote references within the
2407 ;; table, insert their definition just after it.
2408 (org-latex--delayed-footnotes-definitions table info
)))))))
2410 (defun org-latex--align-string (table info
)
2411 "Return an appropriate LaTeX alignment string.
2412 TABLE is the considered table. INFO is a plist used as
2413 a communication channel."
2414 (or (org-export-read-attribute :attr_latex table
:align
)
2416 ;; Extract column groups and alignment from first (non-rule)
2419 (org-element-map table
'table-row
2421 (and (eq (org-element-property :type row
) 'standard
) row
))
2425 (let ((borders (org-export-table-cell-borders cell info
)))
2426 ;; Check left border for the first cell only.
2427 (when (and (memq 'left borders
) (not align
))
2429 (push (case (org-export-table-cell-alignment cell info
)
2434 (when (memq 'right borders
) (push "|" align
))))
2436 (apply 'concat
(nreverse align
)))))
2438 (defun org-latex--org-table (table contents info
)
2439 "Return appropriate LaTeX code for an Org table.
2441 TABLE is the table type element to transcode. CONTENTS is its
2442 contents, as a string. INFO is a plist used as a communication
2445 This function assumes TABLE has `org' as its `:type' property and
2446 `table' as its `:mode' attribute."
2447 (let* ((caption (org-latex--caption/label-string table info
))
2448 (attr (org-export-read-attribute :attr_latex table
))
2449 ;; Determine alignment string.
2450 (alignment (org-latex--align-string table info
))
2451 ;; Determine environment for the table: longtable, tabular...
2452 (table-env (or (plist-get attr
:environment
)
2453 org-latex-default-table-environment
))
2454 ;; If table is a float, determine environment: table, table*
2455 ;; or sidewaystable.
2456 (float-env (unless (member table-env
'("longtable" "longtabu"))
2457 (let ((float (plist-get attr
:float
)))
2459 ((and (not float
) (plist-member attr
:float
)) nil
)
2460 ((string= float
"sidewaystable") "sidewaystable")
2461 ((string= float
"multicolumn") "table*")
2463 (org-element-property :caption table
)
2464 (org-string-nw-p (plist-get attr
:caption
)))
2466 ;; Extract others display options.
2467 (fontsize (let ((font (plist-get attr
:font
)))
2468 (and font
(concat font
"\n"))))
2469 (width (plist-get attr
:width
))
2470 (spreadp (plist-get attr
:spread
))
2471 (placement (or (plist-get attr
:placement
)
2472 (format "[%s]" org-latex-default-figure-position
)))
2473 (centerp (if (plist-member attr
:center
) (plist-get attr
:center
)
2474 org-latex-tables-centered
)))
2475 ;; Prepare the final format string for the table.
2478 ((equal "longtable" table-env
)
2479 (concat (and fontsize
(concat "{" fontsize
))
2480 (format "\\begin{longtable}{%s}\n" alignment
)
2481 (and org-latex-table-caption-above
2482 (org-string-nw-p caption
)
2483 (concat caption
"\\\\\n"))
2485 (and (not org-latex-table-caption-above
)
2486 (org-string-nw-p caption
)
2487 (concat caption
"\\\\\n"))
2488 "\\end{longtable}\n"
2489 (and fontsize
"}")))
2491 ((equal "longtabu" table-env
)
2492 (concat (and fontsize
(concat "{" fontsize
))
2493 (format "\\begin{longtabu}%s{%s}\n"
2496 (if spreadp
"spread" "to") width
) "")
2498 (and org-latex-table-caption-above
2499 (org-string-nw-p caption
)
2500 (concat caption
"\\\\\n"))
2502 (and (not org-latex-table-caption-above
)
2503 (org-string-nw-p caption
)
2504 (concat caption
"\\\\\n"))
2506 (and fontsize
"}")))
2510 (concat (format "\\begin{%s}%s\n" float-env placement
)
2511 (if org-latex-table-caption-above caption
"")
2512 (when centerp
"\\centering\n")
2514 (centerp (concat "\\begin{center}\n" fontsize
))
2515 (fontsize (concat "{" fontsize
)))
2516 (cond ((equal "tabu" table-env
)
2517 (format "\\begin{tabu}%s{%s}\n%s\\end{tabu}"
2519 (if spreadp
" spread %s " " to %s ")
2523 (t (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
2525 (if width
(format "{%s}" width
) "")
2531 (concat (if org-latex-table-caption-above
"" caption
)
2532 (format "\n\\end{%s}" float-env
)))
2533 (centerp "\n\\end{center}")
2534 (fontsize "}")))))))
2536 (defun org-latex--table.el-table
(table info
)
2537 "Return appropriate LaTeX code for a table.el table.
2539 TABLE is the table type element to transcode. INFO is a plist
2540 used as a communication channel.
2542 This function assumes TABLE has `table.el' as its `:type'
2545 ;; Ensure "*org-export-table*" buffer is empty.
2546 (with-current-buffer (get-buffer-create "*org-export-table*")
2548 (let ((output (with-temp-buffer
2549 (insert (org-element-property :value table
))
2551 (re-search-forward "^[ \t]*|[^|]" nil t
)
2552 (table-generate-source 'latex
"*org-export-table*")
2553 (with-current-buffer "*org-export-table*"
2554 (org-trim (buffer-string))))))
2555 (kill-buffer (get-buffer "*org-export-table*"))
2556 ;; Remove left out comments.
2557 (while (string-match "^%.*\n" output
)
2558 (setq output
(replace-match "" t t output
)))
2559 (let ((attr (org-export-read-attribute :attr_latex table
)))
2560 (when (plist-get attr
:rmlines
)
2561 ;; When the "rmlines" attribute is provided, remove all hlines
2562 ;; but the the one separating heading from the table body.
2563 (let ((n 0) (pos 0))
2564 (while (and (< (length output
) pos
)
2565 (setq pos
(string-match "^\\\\hline\n?" output pos
)))
2567 (unless (= n
2) (setq output
(replace-match "" nil nil output
))))))
2568 (let ((centerp (if (plist-member attr
:center
) (plist-get attr
:center
)
2569 org-latex-tables-centered
)))
2570 (if (not centerp
) output
2571 (format "\\begin{center}\n%s\n\\end{center}" output
))))))
2573 (defun org-latex--math-table (table info
)
2574 "Return appropriate LaTeX code for a matrix.
2576 TABLE is the table type element to transcode. INFO is a plist
2577 used as a communication channel.
2579 This function assumes TABLE has `org' as its `:type' property and
2580 `inline-math' or `math' as its `:mode' attribute.."
2581 (let* ((caption (org-latex--caption/label-string table info
))
2582 (attr (org-export-read-attribute :attr_latex table
))
2583 (inlinep (equal (plist-get attr
:mode
) "inline-math"))
2584 (env (or (plist-get attr
:environment
)
2585 org-latex-default-table-environment
))
2589 ;; Ignore horizontal rules.
2590 (when (eq (org-element-property :type row
) 'standard
)
2591 ;; Return each cell unmodified.
2596 (org-element-interpret-data cell org-latex-pseudo-objects
)
2598 (org-element-map row
'table-cell
'identity info
) "&")
2599 (or (cdr (assoc env org-latex-table-matrix-macros
)) "\\\\")
2601 (org-element-map table
'table-row
'identity info
) ""))
2602 ;; Variables related to math clusters (contiguous math tables
2603 ;; of the same type).
2604 (mode (org-export-read-attribute :attr_latex table
:mode
))
2605 (prev (org-export-get-previous-element table info
))
2606 (next (org-export-get-next-element table info
))
2609 ;; Non-nil when TABLE has the same mode as current table.
2610 (string= (or (org-export-read-attribute :attr_latex table
:mode
)
2611 org-latex-default-table-mode
)
2614 ;; Opening string. If TABLE is in the middle of a table cluster,
2615 ;; do not insert any.
2617 (eq (org-element-type prev
) 'table
)
2618 (memq (org-element-property :post-blank prev
) '(0 nil
))
2619 (funcall same-mode-p prev
))
2622 ((org-string-nw-p caption
) (concat "\\begin{equation}\n" caption
))
2625 (or (plist-get attr
:math-prefix
) "")
2626 ;; Environment. Also treat special cases.
2627 (cond ((equal env
"array")
2628 (let ((align (org-latex--align-string table info
)))
2629 (format "\\begin{array}{%s}\n%s\\end{array}" align contents
)))
2630 ((assoc env org-latex-table-matrix-macros
)
2631 (format "\\%s%s{\n%s}"
2633 (or (plist-get attr
:math-arguments
) "")
2635 (t (format "\\begin{%s}\n%s\\end{%s}" env contents env
)))
2637 (or (plist-get attr
:math-suffix
) "")
2638 ;; Closing string. If TABLE is in the middle of a table cluster,
2639 ;; do not insert any. If it closes such a cluster, be sure to
2640 ;; close the cluster with a string matching the opening string.
2642 (eq (org-element-type next
) 'table
)
2643 (memq (org-element-property :post-blank table
) '(0 nil
))
2644 (funcall same-mode-p next
))
2647 ;; Find cluster beginning to know which environment to use.
2648 ((let ((cluster-beg table
) prev
)
2649 (while (and (setq prev
(org-export-get-previous-element
2651 (memq (org-element-property :post-blank prev
)
2653 (funcall same-mode-p prev
))
2654 (setq cluster-beg prev
))
2655 (and (or (org-element-property :caption cluster-beg
)
2656 (org-element-property :name cluster-beg
))
2657 "\n\\end{equation}")))
2663 (defun org-latex-table-cell (table-cell contents info
)
2664 "Transcode a TABLE-CELL element from Org to LaTeX.
2665 CONTENTS is the cell contents. INFO is a plist used as
2666 a communication channel."
2667 (concat (if (and contents
2668 org-latex-table-scientific-notation
2669 (string-match orgtbl-exp-regexp contents
))
2670 ;; Use appropriate format string for scientific
2672 (format org-latex-table-scientific-notation
2673 (match-string 1 contents
)
2674 (match-string 2 contents
))
2676 (when (org-export-get-next-element table-cell info
) " & ")))
2681 (defun org-latex-table-row (table-row contents info
)
2682 "Transcode a TABLE-ROW element from Org to LaTeX.
2683 CONTENTS is the contents of the row. INFO is a plist used as
2684 a communication channel."
2685 ;; Rules are ignored since table separators are deduced from
2686 ;; borders of the current row.
2687 (when (eq (org-element-property :type table-row
) 'standard
)
2688 (let* ((attr (org-export-read-attribute :attr_latex
2689 (org-export-get-parent table-row
)))
2690 (longtablep (member (or (plist-get attr
:environment
)
2691 org-latex-default-table-environment
)
2692 '("longtable" "longtabu")))
2693 (booktabsp (if (plist-member attr
:booktabs
)
2694 (plist-get attr
:booktabs
)
2695 org-latex-tables-booktabs
))
2696 ;; TABLE-ROW's borders are extracted from its first cell.
2697 (borders (org-export-table-cell-borders
2698 (car (org-element-contents table-row
)) info
)))
2700 ;; When BOOKTABS are activated enforce top-rule even when no
2701 ;; hline was specifically marked.
2702 (cond ((and booktabsp
(memq 'top borders
)) "\\toprule\n")
2703 ((and (memq 'top borders
) (memq 'above borders
)) "\\hline\n"))
2706 ;; Special case for long tables. Define header and footers.
2707 ((and longtablep
(org-export-table-row-ends-header-p table-row info
))
2710 \\multicolumn{%d}{l}{%s} \\\\
2715 %s\\multicolumn{%d}{r}{%s} \\\\
2718 (if booktabsp
"\\midrule" "\\hline")
2719 (cdr (org-export-table-dimensions
2720 (org-export-get-parent-table table-row
) info
))
2721 (org-latex--translate "Continued from previous page" info
)
2722 (cond ((and booktabsp
(memq 'top borders
)) "\\toprule\n")
2723 ((and (memq 'top borders
)
2724 (memq 'above borders
)) "\\hline\n")
2727 (if booktabsp
"\\midrule" "\\hline")
2728 (if booktabsp
"\\midrule" "\\hline")
2729 ;; Number of columns.
2730 (cdr (org-export-table-dimensions
2731 (org-export-get-parent-table table-row
) info
))
2732 (org-latex--translate "Continued on next page" info
)))
2733 ;; When BOOKTABS are activated enforce bottom rule even when
2734 ;; no hline was specifically marked.
2735 ((and booktabsp
(memq 'bottom borders
)) "\\bottomrule")
2736 ((and (memq 'bottom borders
) (memq 'below borders
)) "\\hline")
2737 ((memq 'below borders
) (if booktabsp
"\\midrule" "\\hline")))))))
2742 (defun org-latex-target (target contents info
)
2743 "Transcode a TARGET object from Org to LaTeX.
2744 CONTENTS is nil. INFO is a plist holding contextual
2746 (format "\\label{%s}"
2747 (org-export-solidify-link-text (org-element-property :value target
))))
2752 (defun org-latex-timestamp (timestamp contents info
)
2753 "Transcode a TIMESTAMP object from Org to LaTeX.
2754 CONTENTS is nil. INFO is a plist holding contextual
2756 (let ((value (org-latex-plain-text
2757 (org-timestamp-translate timestamp
) info
)))
2758 (case (org-element-property :type timestamp
)
2759 ((active active-range
) (format org-latex-active-timestamp-format value
))
2760 ((inactive inactive-range
)
2761 (format org-latex-inactive-timestamp-format value
))
2762 (otherwise (format org-latex-diary-timestamp-format value
)))))
2767 (defun org-latex-underline (underline contents info
)
2768 "Transcode UNDERLINE from Org to LaTeX.
2769 CONTENTS is the text with underline markup. INFO is a plist
2770 holding contextual information."
2771 (org-latex--text-markup contents
'underline
))
2776 (defun org-latex-verbatim (verbatim contents info
)
2777 "Transcode a VERBATIM object from Org to LaTeX.
2778 CONTENTS is nil. INFO is a plist used as a communication
2780 (org-latex--text-markup (org-element-property :value verbatim
) 'verbatim
))
2785 (defun org-latex-verse-block (verse-block contents info
)
2786 "Transcode a VERSE-BLOCK element from Org to LaTeX.
2787 CONTENTS is verse block contents. INFO is a plist holding
2788 contextual information."
2789 (org-latex--wrap-label
2791 ;; In a verse environment, add a line break to each newline
2792 ;; character and change each white space at beginning of a line
2793 ;; into a space of 1 em. Also change each blank line with
2794 ;; a vertical space of 1 em.
2796 (setq contents
(replace-regexp-in-string
2797 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
2798 (replace-regexp-in-string
2799 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" contents
)))
2800 (while (string-match "^[ \t]+" contents
)
2801 (let ((new-str (format "\\hspace*{%dem}"
2802 (length (match-string 0 contents
)))))
2803 (setq contents
(replace-match new-str nil t contents
))))
2804 (format "\\begin{verse}\n%s\\end{verse}" contents
))))
2808 ;;; End-user functions
2811 (defun org-latex-export-as-latex
2812 (&optional async subtreep visible-only body-only ext-plist
)
2813 "Export current buffer as a LaTeX buffer.
2815 If narrowing is active in the current buffer, only export its
2818 If a region is active, export that region.
2820 A non-nil optional argument ASYNC means the process should happen
2821 asynchronously. The resulting buffer should be accessible
2822 through the `org-export-stack' interface.
2824 When optional argument SUBTREEP is non-nil, export the sub-tree
2825 at point, extracting information from the headline properties
2828 When optional argument VISIBLE-ONLY is non-nil, don't export
2829 contents of hidden elements.
2831 When optional argument BODY-ONLY is non-nil, only write code
2832 between \"\\begin{document}\" and \"\\end{document}\".
2834 EXT-PLIST, when provided, is a property list with external
2835 parameters overriding Org default settings, but still inferior to
2836 file-local settings.
2838 Export is done in a buffer named \"*Org LATEX Export*\", which
2839 will be displayed when `org-export-show-temporary-export-buffer'
2842 (org-export-to-buffer 'latex
"*Org LATEX Export*"
2843 async subtreep visible-only body-only ext-plist
(lambda () (LaTeX-mode))))
2846 (defun org-latex-convert-region-to-latex ()
2847 "Assume the current region has org-mode syntax, and convert it to LaTeX.
2848 This can be used in any buffer. For example, you can write an
2849 itemized list in org-mode syntax in an LaTeX buffer and use this
2850 command to convert it."
2852 (org-export-replace-region-by 'latex
))
2855 (defun org-latex-export-to-latex
2856 (&optional async subtreep visible-only body-only ext-plist
)
2857 "Export current buffer to a LaTeX file.
2859 If narrowing is active in the current buffer, only export its
2862 If a region is active, export that region.
2864 A non-nil optional argument ASYNC means the process should happen
2865 asynchronously. The resulting file should be accessible through
2866 the `org-export-stack' interface.
2868 When optional argument SUBTREEP is non-nil, export the sub-tree
2869 at point, extracting information from the headline properties
2872 When optional argument VISIBLE-ONLY is non-nil, don't export
2873 contents of hidden elements.
2875 When optional argument BODY-ONLY is non-nil, only write code
2876 between \"\\begin{document}\" and \"\\end{document}\".
2878 EXT-PLIST, when provided, is a property list with external
2879 parameters overriding Org default settings, but still inferior to
2880 file-local settings."
2882 (let ((outfile (org-export-output-file-name ".tex" subtreep
)))
2883 (org-export-to-file 'latex outfile
2884 async subtreep visible-only body-only ext-plist
)))
2887 (defun org-latex-export-to-pdf
2888 (&optional async subtreep visible-only body-only ext-plist
)
2889 "Export current buffer to LaTeX then process through to PDF.
2891 If narrowing is active in the current buffer, only export its
2894 If a region is active, export that region.
2896 A non-nil optional argument ASYNC means the process should happen
2897 asynchronously. The resulting file should be accessible through
2898 the `org-export-stack' interface.
2900 When optional argument SUBTREEP is non-nil, export the sub-tree
2901 at point, extracting information from the headline properties
2904 When optional argument VISIBLE-ONLY is non-nil, don't export
2905 contents of hidden elements.
2907 When optional argument BODY-ONLY is non-nil, only write code
2908 between \"\\begin{document}\" and \"\\end{document}\".
2910 EXT-PLIST, when provided, is a property list with external
2911 parameters overriding Org default settings, but still inferior to
2912 file-local settings.
2914 Return PDF file's name."
2916 (let ((outfile (org-export-output-file-name ".tex" subtreep
)))
2917 (org-export-to-file 'latex outfile
2918 async subtreep visible-only body-only ext-plist
2919 (lambda (file) (org-latex-compile file
)))))
2921 (defun org-latex-compile (texfile &optional snippet
)
2922 "Compile a TeX file.
2924 TEXFILE is the name of the file being compiled. Processing is
2925 done through the command specified in `org-latex-pdf-process'.
2927 When optional argument SNIPPET is non-nil, TEXFILE is a temporary
2928 file used to preview a LaTeX snippet. In this case, do not
2929 create a log buffer and do not bother removing log files.
2931 Return PDF file name or an error if it couldn't be produced."
2932 (let* ((base-name (file-name-sans-extension (file-name-nondirectory texfile
)))
2933 (full-name (file-truename texfile
))
2934 (out-dir (file-name-directory texfile
))
2935 ;; Properly set working directory for compilation.
2936 (default-directory (if (file-name-absolute-p texfile
)
2937 (file-name-directory full-name
)
2940 (unless snippet
(message (format "Processing LaTeX file %s..." texfile
)))
2941 (save-window-excursion
2943 ;; A function is provided: Apply it.
2944 ((functionp org-latex-pdf-process
)
2945 (funcall org-latex-pdf-process
(shell-quote-argument texfile
)))
2946 ;; A list is provided: Replace %b, %f and %o with appropriate
2947 ;; values in each command before applying it. Output is
2948 ;; redirected to "*Org PDF LaTeX Output*" buffer.
2949 ((consp org-latex-pdf-process
)
2950 (let ((outbuf (and (not snippet
)
2951 (get-buffer-create "*Org PDF LaTeX Output*"))))
2955 (replace-regexp-in-string
2956 "%b" (shell-quote-argument base-name
)
2957 (replace-regexp-in-string
2958 "%f" (shell-quote-argument full-name
)
2959 (replace-regexp-in-string
2960 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
2962 org-latex-pdf-process
)
2963 ;; Collect standard errors from output buffer.
2964 (setq errors
(and (not snippet
) (org-latex--collect-errors outbuf
)))))
2965 (t (error "No valid command to process to PDF")))
2966 (let ((pdffile (concat out-dir base-name
".pdf")))
2967 ;; Check for process failure. Provide collected errors if
2969 (if (not (file-exists-p pdffile
))
2970 (error (concat (format "PDF file %s wasn't produced" pdffile
)
2971 (when errors
(concat ": " errors
))))
2972 ;; Else remove log files, when specified, and signal end of
2973 ;; process to user, along with any error encountered.
2974 (when (and (not snippet
) org-latex-remove-logfiles
)
2975 (dolist (file (directory-files
2977 (concat (regexp-quote base-name
)
2978 "\\(?:\\.[0-9]+\\)?"
2980 (regexp-opt org-latex-logfiles-extensions
))))
2981 (delete-file file
)))
2982 (message (concat "Process completed"
2983 (if (not errors
) "."
2984 (concat " with errors: " errors
)))))
2985 ;; Return output file name.
2988 (defun org-latex--collect-errors (buffer)
2989 "Collect some kind of errors from \"pdflatex\" command output.
2991 BUFFER is the buffer containing output.
2993 Return collected error types as a string, or nil if there was
2995 (with-current-buffer buffer
2997 (goto-char (point-max))
2998 (when (re-search-backward "^[ \t]*This is .*?TeX.*?Version" nil t
)
2999 (let ((case-fold-search t
)
3001 (dolist (latex-error org-latex-known-errors
)
3002 (when (save-excursion (re-search-forward (car latex-error
) nil t
))
3003 (setq errors
(concat errors
" " (cdr latex-error
)))))
3004 (and (org-string-nw-p errors
) (org-trim errors
)))))))
3007 (defun org-latex-publish-to-latex (plist filename pub-dir
)
3008 "Publish an Org file to LaTeX.
3010 FILENAME is the filename of the Org file to be published. PLIST
3011 is the property list for the given project. PUB-DIR is the
3012 publishing directory.
3014 Return output file name."
3015 (org-publish-org-to 'latex filename
".tex" plist pub-dir
))
3018 (defun org-latex-publish-to-pdf (plist filename pub-dir
)
3019 "Publish an Org file to PDF (via LaTeX).
3021 FILENAME is the filename of the Org file to be published. PLIST
3022 is the property list for the given project. PUB-DIR is the
3023 publishing directory.
3025 Return output file name."
3026 ;; Unlike to `org-latex-publish-to-latex', PDF file is generated
3027 ;; in working directory and then moved to publishing directory.
3028 (org-publish-attachment
3030 (org-latex-compile (org-publish-org-to 'latex filename
".tex" plist
))
3037 ;; generated-autoload-file: "org-loaddefs.el"
3040 ;;; ox-latex.el ends here