1 ;;; org-e-latex.el --- LaTeX Back-End For Org Export Engine
3 ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; This library implements a LaTeX back-end for Org generic exporter.
25 ;; Depending on the desired output format, three commands are provided
26 ;; for export: `org-e-latex-export-as-latex' (temporary buffer),
27 ;; `org-e-latex-export-to-latex' ("tex" file) and
28 ;; `org-e-latex-export-to-pdf' ("pdf" file). Also, two publishing
29 ;; functions are available: `org-e-latex-publish-to-latex' and
30 ;; `org-e-latex-publish-to-pdf'.
32 ;; The library introduces three new buffer keywords: "LATEX_CLASS",
33 ;; "LATEX_CLASS_OPTIONS" and "LATEX_HEADER".
35 ;; Table export can be controlled with a number of attributes (through
36 ;; ATTR_LATEX keyword).
38 ;; - The main one is the `:mode' attribute, which can be set to
39 ;; `table', `math', `inline-math' and `verbatim'. In particular,
40 ;; when in `math' or `inline-math' mode, every cell is exported
41 ;; as-is and the table will be wrapped in a math environment. Also,
42 ;; horizontal rules are ignored. These modes are particularly
43 ;; useful to write matrices. Default mode is stored in
44 ;; `org-e-latex-default-table-mode'.
46 ;; - The second most important attribute is `:environment'. It is the
47 ;; environment used for the table and defaults to
48 ;; `org-e-latex-default-table-environment' value. It can be set to
49 ;; anything, including "tabularx", "longtable", "array",
52 ;; - `:float' attribute defines a float environment for the table.
53 ;; Possible values are `sidewaystable', `multicolumn' and `table'.
55 ;; - `:width' and `:align' attributes set, respectively, the width of
56 ;; the table and its alignment string.
58 ;; - `:booktabs', `:center' and `:rmlines' values are booleans. They
59 ;; toggle, respectively "booktabs" usage (assuming the package is
60 ;; properly loaded), table centering and removal of every horizontal
61 ;; rule but the first one (in a "table.el" table only).
63 ;; - `:math-prefix', `:math-suffix' and `:math-arguments' are string
64 ;; which will be inserted, respectively, before the table within the
65 ;; math environment, after the table within the math environment,
66 ;; and between the macro name and the contents of the table. The
67 ;; latter attribute is necessary to matrix macros that require more
68 ;; than one argument (i.e. "qbordermatrix").
70 ;; Plain lists accept two optional attributes: `:environment' and
71 ;; `:options'. The first one allows to use a non-standard environment
72 ;; (i.e. "inparaenum"). The second one allows to specify optional
73 ;; arguments for that environment (square brackets are not mandatory).
75 ;; This back-end also offers enhanced support for footnotes. Thus, it
76 ;; handles nested footnotes, footnotes in tables and footnotes in item
81 (eval-when-compile (require 'cl
))
83 (require 'org-e-publish
)
85 (defvar org-export-latex-default-packages-alist
)
86 (defvar org-export-latex-packages-alist
)
87 (defvar orgtbl-exp-regexp
)
93 (org-export-define-backend e-latex
94 ((bold . org-e-latex-bold
)
95 (center-block . org-e-latex-center-block
)
96 (clock . org-e-latex-clock
)
97 (code . org-e-latex-code
)
98 (drawer . org-e-latex-drawer
)
99 (dynamic-block . org-e-latex-dynamic-block
)
100 (entity . org-e-latex-entity
)
101 (example-block . org-e-latex-example-block
)
102 (export-block . org-e-latex-export-block
)
103 (export-snippet . org-e-latex-export-snippet
)
104 (fixed-width . org-e-latex-fixed-width
)
105 (footnote-definition . org-e-latex-footnote-definition
)
106 (footnote-reference . org-e-latex-footnote-reference
)
107 (headline . org-e-latex-headline
)
108 (horizontal-rule . org-e-latex-horizontal-rule
)
109 (inline-src-block . org-e-latex-inline-src-block
)
110 (inlinetask . org-e-latex-inlinetask
)
111 (italic . org-e-latex-italic
)
112 (item . org-e-latex-item
)
113 (keyword . org-e-latex-keyword
)
114 (latex-environment . org-e-latex-latex-environment
)
115 (latex-fragment . org-e-latex-latex-fragment
)
116 (line-break . org-e-latex-line-break
)
117 (link . org-e-latex-link
)
118 (paragraph . org-e-latex-paragraph
)
119 (plain-list . org-e-latex-plain-list
)
120 (plain-text . org-e-latex-plain-text
)
121 (planning . org-e-latex-planning
)
122 (property-drawer . org-e-latex-property-drawer
)
123 (quote-block . org-e-latex-quote-block
)
124 (quote-section . org-e-latex-quote-section
)
125 (radio-target . org-e-latex-radio-target
)
126 (section . org-e-latex-section
)
127 (special-block . org-e-latex-special-block
)
128 (src-block . org-e-latex-src-block
)
129 (statistics-cookie . org-e-latex-statistics-cookie
)
130 (strike-through . org-e-latex-strike-through
)
131 (subscript . org-e-latex-subscript
)
132 (superscript . org-e-latex-superscript
)
133 (table . org-e-latex-table
)
134 (table-cell . org-e-latex-table-cell
)
135 (table-row . org-e-latex-table-row
)
136 (target . org-e-latex-target
)
137 (template . org-e-latex-template
)
138 (timestamp . org-e-latex-timestamp
)
139 (underline . org-e-latex-underline
)
140 (verbatim . org-e-latex-verbatim
)
141 (verse-block . org-e-latex-verse-block
))
142 :export-block
("LATEX" "TEX")
144 (?l
"Export to LaTeX"
145 ((?L
"As TEX buffer" org-e-latex-export-as-latex
)
146 (?l
"As TEX file" org-e-latex-export-to-latex
)
147 (?p
"As PDF file" org-e-latex-export-to-pdf
)
148 (?o
"As PDF file and open"
149 (lambda (s v b
) (org-open-file (org-e-latex-export-to-pdf s v b
))))))
150 :options-alist
((:date
"DATE" nil org-e-latex-date-format t
)
151 (:latex-class
"LATEX_CLASS" nil org-e-latex-default-class t
)
152 (:latex-class-options
"LATEX_CLASS_OPTIONS" nil nil t
)
153 (:latex-header-extra
"LATEX_HEADER" nil nil newline
)))
157 ;;; Internal Variables
159 (defconst org-e-latex-babel-language-alist
160 '(("af" .
"afrikaans")
162 ("bt-br" .
"brazilian")
168 ("de-at" .
"naustrian")
169 ("de-de" .
"ngerman")
172 ("en-au" .
"australian")
173 ("en-ca" .
"canadian")
174 ("en-gb" .
"british")
176 ("en-nz" .
"newzealand")
177 ("en-us" .
"american")
183 ("fr-ca" .
"canadien")
187 ("id" .
"indonesian")
193 ("no-no" .
"nynorsk")
195 ("pt" .
"portuguese")
199 ("sb" .
"uppersorbian")
207 ("uk" .
"ukrainian"))
208 "Alist between language code and corresponding Babel option.")
210 (defconst org-e-latex-table-matrix-macros
'(("bordermatrix" .
"\\cr")
211 ("qbordermatrix" .
"\\cr")
212 ("kbordermatrix" .
"\\\\"))
213 "Alist between matrix macros and their row ending.")
217 ;;; User Configurable Variables
219 (defgroup org-export-e-latex nil
220 "Options for exporting Org mode files to LaTeX."
221 :tag
"Org Export LaTeX"
227 (defcustom org-e-latex-default-class
"article"
228 "The default LaTeX class."
229 :group
'org-export-e-latex
230 :type
'(string :tag
"LaTeX class"))
232 (defcustom org-e-latex-classes
234 "\\documentclass[11pt]{article}"
235 ("\\section{%s}" .
"\\section*{%s}")
236 ("\\subsection{%s}" .
"\\subsection*{%s}")
237 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}")
238 ("\\paragraph{%s}" .
"\\paragraph*{%s}")
239 ("\\subparagraph{%s}" .
"\\subparagraph*{%s}"))
241 "\\documentclass[11pt]{report}"
242 ("\\part{%s}" .
"\\part*{%s}")
243 ("\\chapter{%s}" .
"\\chapter*{%s}")
244 ("\\section{%s}" .
"\\section*{%s}")
245 ("\\subsection{%s}" .
"\\subsection*{%s}")
246 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}"))
248 "\\documentclass[11pt]{book}"
249 ("\\part{%s}" .
"\\part*{%s}")
250 ("\\chapter{%s}" .
"\\chapter*{%s}")
251 ("\\section{%s}" .
"\\section*{%s}")
252 ("\\subsection{%s}" .
"\\subsection*{%s}")
253 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}")))
254 "Alist of LaTeX classes and associated header and structure.
255 If #+LaTeX_CLASS is set in the buffer, use its value and the
256 associated information. Here is the structure of each cell:
260 \(numbered-section . unnumbered-section\)
266 The HEADER-STRING is the header that will be inserted into the
267 LaTeX file. It should contain the \\documentclass macro, and
268 anything else that is needed for this setup. To this header, the
269 following commands will be added:
271 - Calls to \\usepackage for all packages mentioned in the
272 variables `org-export-latex-default-packages-alist' and
273 `org-export-latex-packages-alist'. Thus, your header
274 definitions should avoid to also request these packages.
276 - Lines specified via \"#+LaTeX_HEADER:\"
278 If you need more control about the sequence in which the header
279 is built up, or if you want to exclude one of these building
280 blocks for a particular class, you can use the following
281 macro-like placeholders.
283 [DEFAULT-PACKAGES] \\usepackage statements for default packages
284 [NO-DEFAULT-PACKAGES] do not include any of the default packages
285 [PACKAGES] \\usepackage statements for packages
286 [NO-PACKAGES] do not include the packages
287 [EXTRA] the stuff from #+LaTeX_HEADER
288 [NO-EXTRA] do not include #+LaTeX_HEADER stuff
292 \\documentclass{article}
293 [NO-DEFAULT-PACKAGES]
295 \\providecommand{\\alert}[1]{\\textbf{#1}}
298 will omit the default packages, and will include the
299 #+LaTeX_HEADER lines, then have a call to \\providecommand, and
300 then place \\usepackage commands based on the content of
301 `org-export-latex-packages-alist'.
303 If your header, `org-export-latex-default-packages-alist' or
304 `org-export-latex-packages-alist' inserts
305 \"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be
306 replaced with a coding system derived from
307 `buffer-file-coding-system'. See also the variable
308 `org-e-latex-inputenc-alist' for a way to influence this
311 The sectioning structure
312 ------------------------
314 The sectioning structure of the class is given by the elements
315 following the header string. For each sectioning level, a number
316 of strings is specified. A %s formatter is mandatory in each
317 section string and will be replaced by the title of the section.
319 Instead of a cons cell \(numbered . unnumbered\), you can also
320 provide a list of 2 or 4 elements,
322 \(numbered-open numbered-close\)
326 \(numbered-open numbered-close unnumbered-open unnumbered-close\)
328 providing opening and closing strings for a LaTeX environment
329 that should represent the document section. The opening clause
330 should have a %s to represent the section title.
332 Instead of a list of sectioning commands, you can also specify
333 a function name. That function will be called with two
334 parameters, the \(reduced) level of the headline, and a predicate
335 non-nil when the headline should be numbered. It must return
336 a format string in which the section title will be added."
337 :group
'org-export-e-latex
339 (list (string :tag
"LaTeX class")
340 (string :tag
"LaTeX header")
341 (repeat :tag
"Levels" :inline t
344 (string :tag
" numbered")
345 (string :tag
"unnumbered"))
346 (list :tag
"Environment"
347 (string :tag
"Opening (numbered)")
348 (string :tag
"Closing (numbered)")
349 (string :tag
"Opening (unnumbered)")
350 (string :tag
"Closing (unnumbered)"))
351 (function :tag
"Hook computing sectioning"))))))
353 (defcustom org-e-latex-inputenc-alist nil
354 "Alist of inputenc coding system names, and what should really be used.
355 For example, adding an entry
357 (\"utf8\" . \"utf8x\")
359 will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
360 are written as utf8 files."
361 :group
'org-export-e-latex
364 (string :tag
"Derived from buffer")
365 (string :tag
"Use this instead"))))
367 (defcustom org-e-latex-date-format
369 "Format string for \\date{...}."
370 :group
'org-export-e-latex
373 (defcustom org-e-latex-title-command
"\\maketitle"
374 "The command used to insert the title just after \\begin{document}.
375 If this string contains the formatting specification \"%s\" then
376 it will be used as a formatting string, passing the title as an
378 :group
'org-export-e-latex
381 (defcustom org-e-latex-toc-command
"\\tableofcontents\n\\vspace*{1cm}\n\n"
382 "LaTeX command to set the table of contents, list of figures...
383 This command only applies to the table of contents generated with
384 toc:nil option, not to those generated with #+TOC keyword."
385 :group
'org-export-e-latex
390 (defcustom org-e-latex-format-headline-function nil
391 "Function to format headline text.
393 This function will be called with 5 arguments:
394 TODO the todo keyword (string or nil).
395 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
396 PRIORITY the priority of the headline (integer or nil)
397 TEXT the main headline text (string).
398 TAGS the tags as a list of strings (list of strings or nil).
400 The function result will be used in the section format string.
402 As an example, one could set the variable to the following, in
403 order to reproduce the default set-up:
405 \(defun org-e-latex-format-headline (todo todo-type priority text tags)
406 \"Default format function for an headline.\"
408 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
410 \(format \"\\\\framebox{\\\\#%c} \" priority))
413 \(format \"\\\\hfill{}\\\\textsc{%s}\"
414 \(mapconcat 'identity tags \":\"))))"
415 :group
'org-export-e-latex
421 (defcustom org-e-latex-footnote-separator
"\\textsuperscript{,}\\,"
422 "Text used to separate footnotes."
423 :group
'org-export-e-latex
429 (defcustom org-e-latex-active-timestamp-format
"\\textit{%s}"
430 "A printf format string to be applied to active timestamps."
431 :group
'org-export-e-latex
434 (defcustom org-e-latex-inactive-timestamp-format
"\\textit{%s}"
435 "A printf format string to be applied to inactive timestamps."
436 :group
'org-export-e-latex
439 (defcustom org-e-latex-diary-timestamp-format
"\\textit{%s}"
440 "A printf format string to be applied to diary timestamps."
441 :group
'org-export-e-latex
447 (defcustom org-e-latex-image-default-option
"width=.9\\linewidth"
448 "Default option for images."
449 :group
'org-export-e-latex
452 (defcustom org-e-latex-default-figure-position
"htb"
453 "Default position for latex figures."
454 :group
'org-export-e-latex
457 (defcustom org-e-latex-inline-image-rules
458 '(("file" .
"\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\)\\'"))
459 "Rules characterizing image files that can be inlined into LaTeX.
461 A rule consists in an association whose key is the type of link
462 to consider, and value is a regexp that will be matched against
465 Note that, by default, the image extension *actually* allowed
466 depend on the way the LaTeX file is processed. When used with
467 pdflatex, pdf, jpg and png images are OK. When processing
468 through dvi to Postscript, only ps and eps are allowed. The
469 default we use here encompasses both."
470 :group
'org-export-e-latex
471 :type
'(alist :key-type
(string :tag
"Type")
472 :value-type
(regexp :tag
"Path")))
474 (defcustom org-e-latex-link-with-unknown-path-format
"\\texttt{%s}"
475 "Format string for links with unknown path type."
476 :group
'org-export-latex
482 (defcustom org-e-latex-default-table-environment
"tabular"
483 "Default environment used to build tables."
484 :group
'org-export-e-latex
487 (defcustom org-e-latex-default-table-mode
'table
488 "Default mode for tables.
490 Value can be a symbol among:
492 `table' Regular LaTeX table.
494 `math' In this mode, every cell is considered as being in math
495 mode and the complete table will be wrapped within a math
496 environment. It is particularly useful to write matrices.
498 `inline-math' This mode is almost the same as `math', but the
499 math environment will be inlined.
501 `verbatim' The table is exported as it appears in the Org
502 buffer, within a verbatim environment.
504 This value can be overridden locally with, i.e. \":mode math\" in
507 When modifying this variable, it may be useful to change
508 `org-e-latex-default-table-environment' accordingly."
509 :group
'org-export-e-latex
510 :type
'(choice (const :tag
"Table" table
)
511 (const :tag
"Matrix" math
)
512 (const :tag
"Inline matrix" inline-math
)
513 (const :tag
"Verbatim" verbatim
)))
515 (defcustom org-e-latex-tables-centered t
516 "When non-nil, tables are exported in a center environment."
517 :group
'org-export-e-latex
520 (defcustom org-e-latex-tables-booktabs nil
521 "When non-nil, display tables in a formal \"booktabs\" style.
522 This option assumes that the \"booktabs\" package is properly
523 loaded in the header of the document. This value can be ignored
524 locally with \":booktabs t\" and \":booktabs nil\" LaTeX
526 :group
'org-export-e-latex
529 (defcustom org-e-latex-table-caption-above t
530 "When non-nil, place caption string at the beginning of the table.
531 Otherwise, place it near the end."
532 :group
'org-export-e-latex
535 (defcustom org-e-latex-table-scientific-notation
"%s\\,(%s)"
536 "Format string to display numbers in scientific notation.
537 The format should have \"%s\" twice, for mantissa and exponent
538 \(i.e. \"%s\\\\times10^{%s}\").
540 When nil, no transformation is made."
541 :group
'org-export-e-latex
543 (string :tag
"Format string")
544 (const :tag
"No formatting")))
549 (defcustom org-e-latex-text-markup-alist
'((bold .
"\\textbf{%s}")
551 (italic .
"\\emph{%s}")
552 (strike-through .
"\\st{%s}")
553 (underline .
"\\underline{%s}")
554 (verbatim . protectedtexttt
))
555 "Alist of LaTeX expressions to convert text markup.
557 The key must be a symbol among `bold', `code', `italic',
558 `strike-through', `underline' and `verbatim'. The value is
559 a formatting string to wrap fontified text with.
561 Value can also be set to the following symbols: `verb' and
562 `protectedtexttt'. For the former, Org will use \"\\verb\" to
563 create a format string and select a delimiter character that
564 isn't in the string. For the latter, Org will use \"\\texttt\"
565 to typeset and try to protect special characters.
567 If no association can be found for a given markup, text will be
569 :group
'org-export-e-latex
571 :options
'(bold code italic strike-through underline verbatim
))
576 (defcustom org-e-latex-format-drawer-function nil
577 "Function called to format a drawer in LaTeX code.
579 The function must accept two parameters:
580 NAME the drawer name, like \"LOGBOOK\"
581 CONTENTS the contents of the drawer.
583 The function should return the string to be exported.
585 For example, the variable could be set to the following function
586 in order to mimic default behaviour:
588 \(defun org-e-latex-format-drawer-default \(name contents\)
589 \"Format a drawer element for LaTeX export.\"
591 :group
'org-export-e-latex
597 (defcustom org-e-latex-format-inlinetask-function nil
598 "Function called to format an inlinetask in LaTeX code.
600 The function must accept six parameters:
601 TODO the todo keyword, as a string
602 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
603 PRIORITY the inlinetask priority, as a string
604 NAME the inlinetask name, as a string.
605 TAGS the inlinetask tags, as a list of strings.
606 CONTENTS the contents of the inlinetask, as a string.
608 The function should return the string to be exported.
610 For example, the variable could be set to the following function
611 in order to mimic default behaviour:
613 \(defun org-e-latex-format-inlinetask \(todo type priority name tags contents\)
614 \"Format an inline task element for LaTeX export.\"
618 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo))
619 \(when priority (format \"\\\\framebox{\\\\#%c} \" priority))
622 \(format \"\\\\hfill{}\\\\textsc{:%s:}\"
623 \(mapconcat 'identity tags \":\")))))
624 \(format (concat \"\\\\begin{center}\\n\"
626 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
628 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
630 \"\\\\end{minipage}}\"
632 full-title contents))"
633 :group
'org-export-e-latex
639 (defcustom org-e-latex-listings nil
640 "Non-nil means export source code using the listings package.
641 This package will fontify source code, possibly even with color.
642 If you want to use this, you also need to make LaTeX use the
643 listings package, and if you want to have color, the color
644 package. Just add these to `org-export-latex-packages-alist',
645 for example using customize, or with something like:
647 \(require 'org-e-latex)
648 \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"listings\"))
649 \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"color\"))
653 \(setq org-e-latex-listings 'minted)
655 causes source code to be exported using the minted package as
656 opposed to listings. If you want to use minted, you need to add
657 the minted package to `org-export-latex-packages-alist', for
658 example using customize, or with
660 \(require 'org-e-latex)
661 \(add-to-list 'org-export-latex-packages-alist '\(\"\" \"minted\"))
663 In addition, it is necessary to install pygments
664 \(http://pygments.org), and to configure the variable
665 `org-e-latex-pdf-process' so that the -shell-escape option is
667 :group
'org-export-e-latex
669 (const :tag
"Use listings" t
)
670 (const :tag
"Use minted" 'minted
)
671 (const :tag
"Export verbatim" nil
)))
673 (defcustom org-e-latex-listings-langs
674 '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp")
677 (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
678 (html "HTML") (xml "XML")
679 (tex "TeX") (latex "TeX")
680 (shell-script "bash")
682 (ocaml "Caml") (caml "Caml")
683 (sql "SQL") (sqlite "sql"))
684 "Alist mapping languages to their listing language counterpart.
685 The key is a symbol, the major mode symbol without the \"-mode\".
686 The value is the string that should be inserted as the language
687 parameter for the listings package. If the mode name and the
688 listings name are the same, the language does not need an entry
689 in this list - but it does not hurt if it is present."
690 :group
'org-export-e-latex
693 (symbol :tag
"Major mode ")
694 (string :tag
"Listings language"))))
696 (defcustom org-e-latex-listings-options nil
697 "Association list of options for the latex listings package.
699 These options are supplied as a comma-separated list to the
700 \\lstset command. Each element of the association list should be
701 a list containing two strings: the name of the option, and the
704 (setq org-e-latex-listings-options
705 '((\"basicstyle\" \"\\small\")
706 (\"keywordstyle\" \"\\color{black}\\bfseries\\underbar\")))
708 will typeset the code in a small size font with underlined, bold
711 Note that the same options will be applied to blocks of all
713 :group
'org-export-e-latex
716 (string :tag
"Listings option name ")
717 (string :tag
"Listings option value"))))
719 (defcustom org-e-latex-minted-langs
720 '((emacs-lisp "common-lisp")
723 (shell-script "bash")
725 "Alist mapping languages to their minted language counterpart.
726 The key is a symbol, the major mode symbol without the \"-mode\".
727 The value is the string that should be inserted as the language
728 parameter for the minted package. If the mode name and the
729 listings name are the same, the language does not need an entry
730 in this list - but it does not hurt if it is present.
732 Note that minted uses all lower case for language identifiers,
733 and that the full list of language identifiers can be obtained
736 pygmentize -L lexers"
737 :group
'org-export-e-latex
740 (symbol :tag
"Major mode ")
741 (string :tag
"Minted language"))))
743 (defcustom org-e-latex-minted-options nil
744 "Association list of options for the latex minted package.
746 These options are supplied within square brackets in
747 \\begin{minted} environments. Each element of the alist should
748 be a list containing two strings: the name of the option, and the
751 \(setq org-e-latex-minted-options
752 '\((\"bgcolor\" \"bg\") \(\"frame\" \"lines\")))
754 will result in src blocks being exported with
756 \\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
758 as the start of the minted environment. Note that the same
759 options will be applied to blocks of all languages."
760 :group
'org-export-e-latex
763 (string :tag
"Minted option name ")
764 (string :tag
"Minted option value"))))
766 (defvar org-e-latex-custom-lang-environments nil
767 "Alist mapping languages to language-specific LaTeX environments.
769 It is used during export of src blocks by the listings and minted
770 latex packages. For example,
772 \(setq org-e-latex-custom-lang-environments
773 '\(\(python \"pythoncode\"\)\)\)
775 would have the effect that if org encounters begin_src python
776 during latex export it will output
785 (defcustom org-e-latex-pdf-process
786 '("pdflatex -interaction nonstopmode -output-directory %o %f"
787 "pdflatex -interaction nonstopmode -output-directory %o %f"
788 "pdflatex -interaction nonstopmode -output-directory %o %f")
789 "Commands to process a LaTeX file to a PDF file.
790 This is a list of strings, each of them will be given to the
791 shell as a command. %f in the command will be replaced by the
792 full file name, %b by the file base name (i.e. without directory
793 and extension parts) and %o by the base directory of the file.
795 The reason why this is a list is that it usually takes several
796 runs of `pdflatex', maybe mixed with a call to `bibtex'. Org
797 does not have a clever mechanism to detect which of these
798 commands have to be run to get to a stable result, and it also
799 does not do any error checking.
801 By default, Org uses 3 runs of `pdflatex' to do the processing.
802 If you have texi2dvi on your system and if that does not cause
803 the infamous egrep/locale bug:
805 http://lists.gnu.org/archive/html/bug-texinfo/2010-03/msg00031.html
807 then `texi2dvi' is the superior choice. Org does offer it as one
808 of the customize options.
810 Alternatively, this may be a Lisp function that does the
811 processing, so you could use this to apply the machinery of
812 AUCTeX or the Emacs LaTeX mode. This function should accept the
813 file name as its single argument."
814 :group
'org-export-pdf
816 (repeat :tag
"Shell command sequence"
817 (string :tag
"Shell command"))
818 (const :tag
"2 runs of pdflatex"
819 ("pdflatex -interaction nonstopmode -output-directory %o %f"
820 "pdflatex -interaction nonstopmode -output-directory %o %f"))
821 (const :tag
"3 runs of pdflatex"
822 ("pdflatex -interaction nonstopmode -output-directory %o %f"
823 "pdflatex -interaction nonstopmode -output-directory %o %f"
824 "pdflatex -interaction nonstopmode -output-directory %o %f"))
825 (const :tag
"pdflatex,bibtex,pdflatex,pdflatex"
826 ("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
"2 runs of xelatex"
831 ("xelatex -interaction nonstopmode -output-directory %o %f"
832 "xelatex -interaction nonstopmode -output-directory %o %f"))
833 (const :tag
"3 runs of xelatex"
834 ("xelatex -interaction nonstopmode -output-directory %o %f"
835 "xelatex -interaction nonstopmode -output-directory %o %f"
836 "xelatex -interaction nonstopmode -output-directory %o %f"))
837 (const :tag
"xelatex,bibtex,xelatex,xelatex"
838 ("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
"texi2dvi"
843 ("texi2dvi -p -b -c -V %f"))
845 ("rubber -d --into %o %f"))
848 (defcustom org-e-latex-logfiles-extensions
849 '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
850 "The list of file extensions to consider as LaTeX logfiles."
851 :group
'org-export-e-latex
852 :type
'(repeat (string :tag
"Extension")))
854 (defcustom org-e-latex-remove-logfiles t
855 "Non-nil means remove the logfiles produced by PDF production.
856 These are the .aux, .log, .out, and .toc files."
857 :group
'org-export-e-latex
860 (defcustom org-e-latex-known-errors
861 '(("Reference.*?undefined" .
"[undefined reference]")
862 ("Citation.*?undefined" .
"[undefined citation]")
863 ("Undefined control sequence" .
"[undefined control sequence]")
864 ("^! LaTeX.*?Error" .
"[LaTeX error]")
865 ("^! Package.*?Error" .
"[package error]")
866 ("Runaway argument" .
"Runaway argument"))
867 "Alist of regular expressions and associated messages for the user.
868 The regular expressions are used to find possible errors in the
870 :group
'org-export-e-latex
873 (string :tag
"Regexp")
874 (string :tag
"Message"))))
878 ;;; Internal Functions
880 (defun org-e-latex--caption/label-string
(element info
)
881 "Return caption and label LaTeX string for ELEMENT.
883 INFO is a plist holding contextual information. If there's no
884 caption nor label, return the empty string.
886 For non-floats, see `org-e-latex--wrap-label'."
887 (let* ((label (org-element-property :name element
))
888 (label-str (if (not (org-string-nw-p label
)) ""
889 (format "\\label{%s}"
890 (org-export-solidify-link-text label
))))
891 (main (org-export-get-caption element
))
892 (short (org-export-get-caption element t
)))
894 ((and (not main
) (equal label-str
"")) "")
895 ((not main
) (concat label-str
"\n"))
896 ;; Option caption format with short name.
897 (short (format "\\caption[%s]{%s%s}\n"
898 (org-export-data short info
)
900 (org-export-data main info
)))
901 ;; Standard caption format.
902 (t (format "\\caption{%s%s}\n" label-str
(org-export-data main info
))))))
904 (defun org-e-latex--guess-babel-language (header info
)
905 "Set Babel's language according to LANGUAGE keyword.
907 HEADER is the LaTeX header string. INFO is the plist used as
908 a communication channel.
910 Insertion of guessed language only happens when Babel package has
911 explicitly been loaded. Then it is added to the rest of
914 Return the new header."
915 (let ((language-code (plist-get info
:language
)))
916 ;; If no language is set or Babel package is not loaded, return
918 (if (or (not (stringp language-code
))
919 (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header
)))
921 (let ((options (save-match-data
922 (org-split-string (match-string 1 header
) ",")))
923 (language (cdr (assoc language-code
924 org-e-latex-babel-language-alist
))))
925 ;; If LANGUAGE is already loaded, return header. Otherwise,
926 ;; append LANGUAGE to other options.
927 (if (member language options
) header
928 (replace-match (mapconcat 'identity
929 (append options
(list language
))
931 nil nil header
1))))))
933 (defun org-e-latex--guess-inputenc (header)
934 "Set the coding system in inputenc to what the buffer is.
935 HEADER is the LaTeX header string. Return the new header."
936 (let* ((cs (or (ignore-errors
937 (latexenc-coding-system-to-inputenc
938 buffer-file-coding-system
))
941 ;; First translate if that is requested.
942 (setq cs
(or (cdr (assoc cs org-e-latex-inputenc-alist
)) cs
))
943 ;; Then find the \usepackage statement and replace the option.
944 (replace-regexp-in-string "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
945 cs header t nil
1))))
947 (defun org-e-latex--find-verb-separator (s)
948 "Return a character not used in string S.
949 This is used to choose a separator for constructs like \\verb."
950 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
951 (loop for c across ll
952 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
953 return
(char-to-string c
))))
955 (defun org-e-latex--make-option-string (options)
956 "Return a comma separated string of keywords and values.
957 OPTIONS is an alist where the key is the options keyword as
958 a string, and the value a list containing the keyword value, or
960 (mapconcat (lambda (pair)
962 (when (> (length (second pair
)) 0)
963 (concat "=" (second pair
)))))
967 (defun org-e-latex--wrap-label (element output
)
968 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
969 This function shouldn't be used for floats. See
970 `org-e-latex--caption/label-string'."
971 (let ((label (org-element-property :name element
)))
972 (if (not (and (org-string-nw-p output
) (org-string-nw-p label
))) output
973 (concat (format "\\label{%s}\n" (org-export-solidify-link-text label
))
976 (defun org-e-latex--text-markup (text markup
)
977 "Format TEXT depending on MARKUP text markup.
978 See `org-e-latex-text-markup-alist' for details."
979 (let ((fmt (cdr (assq markup org-e-latex-text-markup-alist
))))
981 ;; No format string: Return raw text.
983 ;; Handle the `verb' special case: Find and appropriate separator
984 ;; and use "\\verb" command.
986 (let ((separator (org-e-latex--find-verb-separator text
)))
987 (concat "\\verb" separator text separator
)))
988 ;; Handle the `protectedtexttt' special case: Protect some
989 ;; special chars and use "\texttt{%s}" format string.
990 ((eq 'protectedtexttt fmt
)
992 (trans '(("\\" .
"\\textbackslash{}")
993 ("~" .
"\\textasciitilde{}")
994 ("^" .
"\\textasciicircum{}")))
997 (while (string-match "[\\{}$%&_#~^]" text
)
998 (setq char
(match-string 0 text
))
999 (if (> (match-beginning 0) 0)
1000 (setq rtn
(concat rtn
(substring text
0 (match-beginning 0)))))
1001 (setq text
(substring text
(1+ (match-beginning 0))))
1002 (setq char
(or (cdr (assoc char trans
)) (concat "\\" char
))
1003 rtn
(concat rtn char
)))
1004 (setq text
(concat rtn text
)
1006 (while (string-match "--" text
)
1007 (setq text
(replace-match "-{}-" t t text
)))
1009 ;; Else use format string.
1010 (t (format fmt text
)))))
1012 (defun org-e-latex--delayed-footnotes-definitions (element info
)
1013 "Return footnotes definitions in ELEMENT as a string.
1015 INFO is a plist used as a communication channel.
1017 Footnotes definitions are returned within \"\\footnotetxt{}\"
1020 This function is used within constructs that don't support
1021 \"\\footnote{}\" command (i.e. an item's tag). In that case,
1022 \"\\footnotemark\" is used within the construct and the function
1023 just outside of it."
1027 "\\footnotetext[%s]{%s}"
1028 (org-export-get-footnote-number ref info
)
1031 (org-export-get-footnote-definition ref info
) info
))))
1032 ;; Find every footnote reference in ELEMENT.
1034 search-refs
; For byte-compiler.
1038 ;; Return a list of all footnote references never seen
1041 data
'footnote-reference
1043 (when (org-export-footnote-first-reference-p ref info
)
1045 (when (eq (org-element-property :type ref
) 'standard
)
1046 (funcall search-refs
1047 (org-export-get-footnote-definition ref info
)))))
1049 (reverse all-refs
)))))
1050 (funcall search-refs element
))
1057 (defun org-e-latex-template (contents info
)
1058 "Return complete document string after LaTeX conversion.
1059 CONTENTS is the transcoded contents string. INFO is a plist
1060 holding export options."
1061 (let ((title (org-export-data (plist-get info
:title
) info
)))
1064 (and (plist-get info
:time-stamp-file
)
1065 (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
1066 ;; Document class and packages.
1067 (let ((class (plist-get info
:latex-class
))
1068 (class-options (plist-get info
:latex-class-options
)))
1069 (org-element-normalize-string
1070 (let* ((header (nth 1 (assoc class org-e-latex-classes
)))
1071 (document-class-string
1072 (and (stringp header
)
1073 (if (not class-options
) header
1074 (replace-regexp-in-string
1075 "^[ \t]*\\\\documentclass\\(\\(\\[.*\\]\\)?\\)"
1076 class-options header t nil
1)))))
1077 (when document-class-string
1078 (org-e-latex--guess-babel-language
1079 (org-e-latex--guess-inputenc
1080 (org-splice-latex-header
1081 document-class-string
1082 org-export-latex-default-packages-alist
; defined in org.el
1083 org-export-latex-packages-alist nil
; defined in org.el
1084 (plist-get info
:latex-header-extra
)))
1086 ;; Possibly limit depth for headline numbering.
1087 (let ((sec-num (plist-get info
:section-numbers
)))
1088 (when (integerp sec-num
)
1089 (format "\\setcounter{secnumdepth}{%d}\n" sec-num
)))
1091 (let ((author (and (plist-get info
:with-author
)
1092 (let ((auth (plist-get info
:author
)))
1093 (and auth
(org-export-data auth info
)))))
1094 (email (and (plist-get info
:with-email
)
1095 (org-export-data (plist-get info
:email
) info
))))
1096 (cond ((and author email
(not (string= "" email
)))
1097 (format "\\author{%s\\thanks{%s}}\n" author email
))
1098 ((or author email
) (format "\\author{%s}\n" (or author email
)))))
1100 (let ((date (and (plist-get info
:with-date
)
1101 (org-export-data (plist-get info
:date
) info
))))
1102 (format "\\date{%s}\n" (or date
"")))
1104 (format "\\title{%s}\n" title
)
1105 ;; Hyperref options.
1106 (format "\\hypersetup{\n pdfkeywords={%s},\n pdfsubject={%s},\n pdfcreator={%s}}\n"
1107 (or (plist-get info
:keywords
) "")
1108 (or (plist-get info
:description
) "")
1109 (if (not (plist-get info
:with-creator
)) ""
1110 (plist-get info
:creator
)))
1112 "\\begin{document}\n\n"
1114 (org-element-normalize-string
1115 (cond ((string= "" title
) nil
)
1116 ((not (stringp org-e-latex-title-command
)) nil
)
1117 ((string-match "\\(?:[^%]\\|^\\)%s"
1118 org-e-latex-title-command
)
1119 (format org-e-latex-title-command title
))
1120 (t org-e-latex-title-command
)))
1121 ;; Table of contents.
1122 (let ((depth (plist-get info
:with-toc
)))
1124 (concat (when (wholenump depth
)
1125 (format "\\setcounter{tocdepth}{%d}\n" depth
))
1126 org-e-latex-toc-command
)))
1130 (let ((creator-info (plist-get info
:with-creator
)))
1132 ((not creator-info
) "")
1133 ((eq creator-info
'comment
)
1134 (format "%% %s\n" (plist-get info
:creator
)))
1135 (t (concat (plist-get info
:creator
) "\n"))))
1137 "\\end{document}")))
1141 ;;; Transcode Functions
1145 (defun org-e-latex-bold (bold contents info
)
1146 "Transcode BOLD from Org to LaTeX.
1147 CONTENTS is the text with bold markup. INFO is a plist holding
1148 contextual information."
1149 (org-e-latex--text-markup contents
'bold
))
1154 (defun org-e-latex-center-block (center-block contents info
)
1155 "Transcode a CENTER-BLOCK element from Org to LaTeX.
1156 CONTENTS holds the contents of the center block. INFO is a plist
1157 holding contextual information."
1158 (org-e-latex--wrap-label
1160 (format "\\begin{center}\n%s\\end{center}" contents
)))
1165 (defun org-e-latex-clock (clock contents info
)
1166 "Transcode a CLOCK element from Org to LaTeX.
1167 CONTENTS is nil. INFO is a plist holding contextual
1171 (format "\\textbf{%s} " org-clock-string
)
1172 (format org-e-latex-inactive-timestamp-format
1173 (concat (org-translate-time
1174 (org-element-property :raw-value
1175 (org-element-property :value clock
)))
1176 (let ((time (org-element-property :duration clock
)))
1177 (and time
(format " (%s)" time
)))))
1183 (defun org-e-latex-code (code contents info
)
1184 "Transcode a CODE object from Org to LaTeX.
1185 CONTENTS is nil. INFO is a plist used as a communication
1187 (org-e-latex--text-markup (org-element-property :value code
) 'code
))
1192 (defun org-e-latex-drawer (drawer contents info
)
1193 "Transcode a DRAWER element from Org to LaTeX.
1194 CONTENTS holds the contents of the block. INFO is a plist
1195 holding contextual information."
1196 (let* ((name (org-element-property :drawer-name drawer
))
1197 (output (if (functionp org-e-latex-format-drawer-function
)
1198 (funcall org-e-latex-format-drawer-function
1200 ;; If there's no user defined function: simply
1201 ;; display contents of the drawer.
1203 (org-e-latex--wrap-label drawer output
)))
1208 (defun org-e-latex-dynamic-block (dynamic-block contents info
)
1209 "Transcode a DYNAMIC-BLOCK element from Org to LaTeX.
1210 CONTENTS holds the contents of the block. INFO is a plist
1211 holding contextual information. See `org-export-data'."
1212 (org-e-latex--wrap-label dynamic-block contents
))
1217 (defun org-e-latex-entity (entity contents info
)
1218 "Transcode an ENTITY object from Org to LaTeX.
1219 CONTENTS are the definition itself. INFO is a plist holding
1220 contextual information."
1221 (let ((ent (org-element-property :latex entity
)))
1222 (if (org-element-property :latex-math-p entity
) (format "$%s$" ent
) ent
)))
1227 (defun org-e-latex-example-block (example-block contents info
)
1228 "Transcode an EXAMPLE-BLOCK element from Org to LaTeX.
1229 CONTENTS is nil. INFO is a plist holding contextual
1231 (org-e-latex--wrap-label
1233 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1234 (org-export-format-code-default example-block info
))))
1239 (defun org-e-latex-export-block (export-block contents info
)
1240 "Transcode a EXPORT-BLOCK element from Org to LaTeX.
1241 CONTENTS is nil. INFO is a plist holding contextual information."
1242 (when (member (org-element-property :type export-block
) '("LATEX" "TEX"))
1243 (org-remove-indentation (org-element-property :value export-block
))))
1248 (defun org-e-latex-export-snippet (export-snippet contents info
)
1249 "Transcode a EXPORT-SNIPPET object from Org to LaTeX.
1250 CONTENTS is nil. INFO is a plist holding contextual information."
1251 (when (eq (org-export-snippet-backend export-snippet
) 'e-latex
)
1252 (org-element-property :value export-snippet
)))
1257 (defun org-e-latex-fixed-width (fixed-width contents info
)
1258 "Transcode a FIXED-WIDTH element from Org to LaTeX.
1259 CONTENTS is nil. INFO is a plist holding contextual information."
1260 (org-e-latex--wrap-label
1262 (format "\\begin{verbatim}\n%s\\end{verbatim}"
1263 (org-remove-indentation
1264 (org-element-property :value fixed-width
)))))
1267 ;;;; Footnote Reference
1269 ;; Footnote reference export is handled by
1270 ;; `org-e-latex-footnote-reference'.
1272 ;; Internally, `org-e-latex--get-footnote-counter' is used to restore
1273 ;; the value of the LaTeX "footnote" counter after a jump due to
1274 ;; a reference to an already defined footnote. It is only needed in
1275 ;; item tags since the optional argument to \footnotemark is not
1278 (defun org-e-latex--get-footnote-counter (footnote-reference info
)
1279 "Return \"footnote\" counter before FOOTNOTE-REFERENCE is encountered.
1280 INFO is a plist used as a communication channel."
1281 ;; Find original counter value by counting number of footnote
1282 ;; references appearing for the first time before the current
1283 ;; footnote reference.
1284 (let* ((label (org-element-property :label footnote-reference
))
1286 search-ref
; For byte-compiler.
1290 ;; Search footnote references through DATA, filling
1291 ;; SEEN-REFS along the way.
1293 data
'footnote-reference
1295 (let ((fn-lbl (org-element-property :label fn
)))
1297 ;; Anonymous footnote match: return number.
1298 ((eq fn footnote-reference
) (length seen-refs
))
1299 ;; Anonymous footnote: it's always a new one.
1300 ;; Also, be sure to return nil from the `cond' so
1301 ;; `first-match' doesn't get us out of the loop.
1302 ((not fn-lbl
) (push 'inline seen-refs
) nil
)
1303 ;; Label not seen so far: add it so SEEN-REFS.
1305 ;; Also search for subsequent references in
1306 ;; footnote definition so numbering follows reading
1307 ;; logic. Note that we don't have to care about
1308 ;; inline definitions, since `org-element-map'
1309 ;; already traverse them at the right time.
1310 ((not (member fn-lbl seen-refs
))
1311 (push fn-lbl seen-refs
)
1313 (org-export-get-footnote-definition fn info
))))))
1314 ;; Don't enter footnote definitions since it will happen
1315 ;; when their first reference is found.
1316 info
'first-match
'footnote-definition
)))))
1317 (funcall search-ref
(plist-get info
:parse-tree
))))
1319 (defun org-e-latex-footnote-reference (footnote-reference contents info
)
1320 "Transcode a FOOTNOTE-REFERENCE element from Org to LaTeX.
1321 CONTENTS is nil. INFO is a plist holding contextual information."
1323 ;; Insert separator between two footnotes in a row.
1324 (let ((prev (org-export-get-previous-element footnote-reference info
)))
1325 (when (eq (org-element-type prev
) 'footnote-reference
)
1326 org-e-latex-footnote-separator
))
1328 ;; Use \footnotemark if reference is within an item's tag.
1329 ((eq (org-element-type (org-export-get-parent-element footnote-reference
))
1331 (if (org-export-footnote-first-reference-p footnote-reference info
)
1333 ;; Since we can't specify footnote number as an optional
1334 ;; argument within an item tag, some extra work has to be done
1335 ;; when the footnote has already been referenced. In that
1336 ;; case, set footnote counter to the desired number, use the
1337 ;; footnotemark, then set counter back to its original value.
1339 "\\setcounter{footnote}{%s}\\footnotemark\\setcounter{footnote}{%s}"
1340 (1- (org-export-get-footnote-number footnote-reference info
))
1341 (org-e-latex--get-footnote-counter footnote-reference info
))))
1342 ;; Use \footnotemark if the footnote has already been defined.
1343 ((not (org-export-footnote-first-reference-p footnote-reference info
))
1344 (format "\\footnotemark[%s]{}"
1345 (org-export-get-footnote-number footnote-reference info
)))
1346 ;; Use \footnotemark if reference is within another footnote
1347 ;; reference, footnote definition or table cell.
1348 ((loop for parent in
(org-export-get-genealogy footnote-reference
)
1349 thereis
(memq (org-element-type parent
)
1350 '(footnote-reference footnote-definition table-cell
)))
1352 ;; Otherwise, define it with \footnote command.
1354 (let ((def (org-export-get-footnote-definition footnote-reference info
)))
1355 (unless (eq (org-element-type def
) 'org-data
)
1356 (setq def
(cons 'org-data
(cons nil def
))))
1358 (format "\\footnote{%s}" (org-trim (org-export-data def info
)))
1359 ;; Retrieve all footnote references within the footnote and
1360 ;; add their definition after it, since LaTeX doesn't support
1362 (org-e-latex--delayed-footnotes-definitions def info
)))))))
1367 (defun org-e-latex-headline (headline contents info
)
1368 "Transcode an HEADLINE element from Org to LaTeX.
1369 CONTENTS holds the contents of the headline. INFO is a plist
1370 holding contextual information."
1371 (let* ((class (plist-get info
:latex-class
))
1372 (level (org-export-get-relative-level headline info
))
1373 (numberedp (org-export-numbered-headline-p headline info
))
1374 (class-sectionning (assoc class org-e-latex-classes
))
1375 ;; Section formatting will set two placeholders: one for the
1376 ;; title and the other for the contents.
1378 (let ((sec (if (and (symbolp (nth 2 class-sectionning
))
1379 (fboundp (nth 2 class-sectionning
)))
1380 (funcall (nth 2 class-sectionning
) level numberedp
)
1381 (nth (1+ level
) class-sectionning
))))
1383 ;; No section available for that LEVEL.
1385 ;; Section format directly returned by a function.
1387 ;; (numbered-section . unnumbered-section)
1388 ((not (consp (cdr sec
)))
1389 (concat (funcall (if numberedp
#'car
#'cdr
) sec
) "\n%s"))
1390 ;; (numbered-open numbered-close)
1392 (when numberedp
(concat (car sec
) "\n%s" (nth 1 sec
))))
1393 ;; (num-in num-out no-num-in no-num-out)
1395 (if numberedp
(concat (car sec
) "\n%s" (nth 1 sec
))
1396 (concat (nth 2 sec
) "\n%s" (nth 3 sec
)))))))
1397 (text (org-export-data (org-element-property :title headline
) info
))
1399 (and (plist-get info
:with-todo-keywords
)
1400 (let ((todo (org-element-property :todo-keyword headline
)))
1401 (and todo
(org-export-data todo info
)))))
1402 (todo-type (and todo
(org-element-property :todo-type headline
)))
1403 (tags (and (plist-get info
:with-tags
)
1404 (org-export-get-tags headline info
)))
1405 (priority (and (plist-get info
:with-priority
)
1406 (org-element-property :priority headline
)))
1407 ;; Create the headline text along with a no-tag version. The
1408 ;; latter is required to remove tags from table of contents.
1409 (full-text (if (functionp org-e-latex-format-headline-function
)
1410 ;; User-defined formatting function.
1411 (funcall org-e-latex-format-headline-function
1412 todo todo-type priority text tags
)
1413 ;; Default formatting.
1416 (format "\\textbf{\\textsf{\\textsc{%s}}} " todo
))
1417 (when priority
(format "\\framebox{\\#%c} " priority
))
1420 (format "\\hfill{}\\textsc{:%s:}"
1421 (mapconcat 'identity tags
":"))))))
1423 (if (functionp org-e-latex-format-headline-function
)
1424 ;; User-defined formatting function.
1425 (funcall org-e-latex-format-headline-function
1426 todo todo-type priority text nil
)
1427 ;; Default formatting.
1429 (when todo
(format "\\textbf{\\textsf{\\textsc{%s}}} " todo
))
1430 (when priority
(format "\\framebox{\\#%c} " priority
))
1432 ;; Associate some \label to the headline for internal links.
1434 (format "\\label{sec-%s}\n"
1435 (mapconcat 'number-to-string
1436 (org-export-get-headline-number headline info
)
1439 (make-string (org-element-property :pre-blank headline
) 10)))
1441 ;; Case 1: This is a footnote section: ignore it.
1442 ((org-element-property :footnote-section-p headline
) nil
)
1443 ;; Case 2. This is a deep sub-tree: export it as a list item.
1444 ;; Also export as items headlines for which no section
1445 ;; format has been found.
1446 ((or (not section-fmt
) (org-export-low-level-p headline info
))
1447 ;; Build the real contents of the sub-tree.
1448 (let ((low-level-body
1450 ;; If the headline is the first sibling, start a list.
1451 (when (org-export-first-sibling-p headline info
)
1452 (format "\\begin{%s}\n" (if numberedp
'enumerate
'itemize
)))
1454 "\\item " full-text
"\n" headline-label pre-blanks contents
)))
1455 ;; If headline is not the last sibling simply return
1456 ;; LOW-LEVEL-BODY. Otherwise, also close the list, before any
1458 (if (not (org-export-last-sibling-p headline info
)) low-level-body
1459 (replace-regexp-in-string
1461 (format "\n\\\\end{%s}" (if numberedp
'enumerate
'itemize
))
1463 ;; Case 3. Standard headline. Export it as a section.
1466 ((not (and tags
(eq (plist-get info
:with-tags
) 'not-in-toc
)))
1467 ;; Regular section. Use specified format string.
1468 (format section-fmt full-text
1469 (concat headline-label pre-blanks contents
)))
1470 ((string-match "\\`\\\\\\(.*?\\){" section-fmt
)
1471 ;; If tags should be removed from table of contents, insert
1472 ;; title without tags as an alternative heading in sectioning
1474 (format (replace-match (concat (match-string 1 section-fmt
) "[%s]")
1475 nil nil section-fmt
1)
1476 ;; Replace square brackets with parenthesis since
1477 ;; square brackets are not supported in optional
1479 (replace-regexp-in-string
1481 (replace-regexp-in-string
1485 (concat headline-label pre-blanks contents
)))
1487 ;; Impossible to add an alternative heading. Fallback to
1488 ;; regular sectioning format string.
1489 (format section-fmt full-text
1490 (concat headline-label pre-blanks contents
))))))))
1493 ;;;; Horizontal Rule
1495 (defun org-e-latex-horizontal-rule (horizontal-rule contents info
)
1496 "Transcode an HORIZONTAL-RULE object from Org to LaTeX.
1497 CONTENTS is nil. INFO is a plist holding contextual information."
1498 (let ((attr (org-export-read-attribute :attr_latex horizontal-rule
))
1499 (prev (org-export-get-previous-element horizontal-rule info
)))
1501 ;; Make sure the rule doesn't start at the end of the current
1502 ;; line by separating it with a blank line from previous element.
1504 (let ((prev-blank (org-element-property :post-blank prev
)))
1505 (or (not prev-blank
) (zerop prev-blank
))))
1507 (org-e-latex--wrap-label
1509 (format "\\rule{%s}{%s}"
1510 (or (plist-get attr
:width
) "\\linewidth")
1511 (or (plist-get attr
:thickness
) "0.5pt"))))))
1514 ;;;; Inline Src Block
1516 (defun org-e-latex-inline-src-block (inline-src-block contents info
)
1517 "Transcode an INLINE-SRC-BLOCK element from Org to LaTeX.
1518 CONTENTS holds the contents of the item. INFO is a plist holding
1519 contextual information."
1520 (let* ((code (org-element-property :value inline-src-block
))
1521 (separator (org-e-latex--find-verb-separator code
)))
1523 ;; Do not use a special package: transcode it verbatim.
1524 ((not org-e-latex-listings
)
1525 (concat "\\verb" separator code separator
))
1526 ;; Use minted package.
1527 ((eq org-e-latex-listings
'minted
)
1528 (let* ((org-lang (org-element-property :language inline-src-block
))
1529 (mint-lang (or (cadr (assq (intern org-lang
)
1530 org-e-latex-minted-langs
))
1532 (options (org-e-latex--make-option-string
1533 org-e-latex-minted-options
)))
1534 (concat (format "\\mint%s{%s}"
1535 (if (string= options
"") "" (format "[%s]" options
))
1537 separator code separator
)))
1538 ;; Use listings package.
1540 ;; Maybe translate language's name.
1541 (let* ((org-lang (org-element-property :language inline-src-block
))
1542 (lst-lang (or (cadr (assq (intern org-lang
)
1543 org-e-latex-listings-langs
))
1545 (options (org-e-latex--make-option-string
1546 (append org-e-latex-listings-options
1547 `(("language" ,lst-lang
))))))
1548 (concat (format "\\lstinline[%s]" options
)
1549 separator code separator
))))))
1554 (defun org-e-latex-inlinetask (inlinetask contents info
)
1555 "Transcode an INLINETASK element from Org to LaTeX.
1556 CONTENTS holds the contents of the block. INFO is a plist
1557 holding contextual information."
1558 (let ((title (org-export-data (org-element-property :title inlinetask
) info
))
1559 (todo (and (plist-get info
:with-todo-keywords
)
1560 (let ((todo (org-element-property :todo-keyword inlinetask
)))
1561 (and todo
(org-export-data todo info
)))))
1562 (todo-type (org-element-property :todo-type inlinetask
))
1563 (tags (and (plist-get info
:with-tags
)
1564 (org-export-get-tags inlinetask info
)))
1565 (priority (and (plist-get info
:with-priority
)
1566 (org-element-property :priority inlinetask
))))
1567 ;; If `org-e-latex-format-inlinetask-function' is provided, call it
1568 ;; with appropriate arguments.
1569 (if (functionp org-e-latex-format-inlinetask-function
)
1570 (funcall org-e-latex-format-inlinetask-function
1571 todo todo-type priority title tags contents
)
1572 ;; Otherwise, use a default template.
1573 (org-e-latex--wrap-label
1577 (when todo
(format "\\textbf{\\textsf{\\textsc{%s}}} " todo
))
1578 (when priority
(format "\\framebox{\\#%c} " priority
))
1580 (when tags
(format "\\hfill{}\\textsc{:%s:}"
1581 (mapconcat 'identity tags
":"))))))
1582 (format (concat "\\begin{center}\n"
1584 "\\begin{minipage}[c]{.6\\textwidth}\n"
1586 "\\rule[.8em]{\\textwidth}{2pt}\n\n"
1591 full-title contents
))))))
1596 (defun org-e-latex-italic (italic contents info
)
1597 "Transcode ITALIC from Org to LaTeX.
1598 CONTENTS is the text with italic markup. INFO is a plist holding
1599 contextual information."
1600 (org-e-latex--text-markup contents
'italic
))
1605 (defun org-e-latex-item (item contents info
)
1606 "Transcode an ITEM element from Org to LaTeX.
1607 CONTENTS holds the contents of the item. INFO is a plist holding
1608 contextual information."
1610 (let ((count (org-element-property :counter item
))
1612 (loop for parent in
(org-export-get-genealogy item
)
1613 count
(eq (org-element-type parent
) 'plain-list
)
1614 until
(eq (org-element-type parent
) 'headline
))))
1617 (format "\\setcounter{enum%s}{%s}\n"
1618 (nth (1- level
) '("i" "ii" "iii" "iv"))
1620 (checkbox (case (org-element-property :checkbox item
)
1621 (on "$\\boxtimes$ ")
1623 (trans "$\\boxminus$ ")))
1624 (tag (let ((tag (org-element-property :tag item
)))
1625 ;; Check-boxes must belong to the tag.
1626 (and tag
(format "[%s] "
1628 (org-export-data tag info
)))))))
1629 (concat counter
"\\item" (or tag
(concat " " checkbox
))
1630 (and contents
(org-trim contents
))
1631 ;; If there are footnotes references in tag, be sure to
1632 ;; add their definition at the end of the item. This
1633 ;; workaround is necessary since "\footnote{}" command is
1634 ;; not supported in tags.
1636 (org-e-latex--delayed-footnotes-definitions
1637 (org-element-property :tag item
) info
)))))
1642 (defun org-e-latex-keyword (keyword contents info
)
1643 "Transcode a KEYWORD element from Org to LaTeX.
1644 CONTENTS is nil. INFO is a plist holding contextual information."
1645 (let ((key (org-element-property :key keyword
))
1646 (value (org-element-property :value keyword
)))
1648 ((string= key
"LATEX") value
)
1649 ((string= key
"INDEX") (format "\\index{%s}" value
))
1650 ;; Invisible targets.
1651 ((string= key
"TARGET") nil
)
1652 ((string= key
"TOC")
1653 (let ((value (downcase value
)))
1655 ((string-match "\\<headlines\\>" value
)
1656 (let ((depth (or (and (string-match "[0-9]+" value
)
1657 (string-to-number (match-string 0 value
)))
1658 (plist-get info
:with-toc
))))
1660 (when (wholenump depth
)
1661 (format "\\setcounter{tocdepth}{%s}\n" depth
))
1662 "\\tableofcontents")))
1663 ((string= "tables" value
) "\\listoftables")
1664 ((string= "figures" value
) "\\listoffigures")
1665 ((string= "listings" value
)
1667 ((eq org-e-latex-listings
'minted
) "\\listoflistings")
1668 (org-e-latex-listings "\\lstlistoflistings")
1669 ;; At the moment, src blocks with a caption are wrapped
1670 ;; into a figure environment.
1671 (t "\\listoffigures")))))))))
1674 ;;;; Latex Environment
1676 (defun org-e-latex-latex-environment (latex-environment contents info
)
1677 "Transcode a LATEX-ENVIRONMENT element from Org to LaTeX.
1678 CONTENTS is nil. INFO is a plist holding contextual information."
1679 (let ((label (org-element-property :name latex-environment
))
1680 (value (org-remove-indentation
1681 (org-element-property :value latex-environment
))))
1682 (if (not (org-string-nw-p label
)) value
1683 ;; Environment is labelled: label must be within the environment
1684 ;; (otherwise, a reference pointing to that element will count
1685 ;; the section instead).
1688 (goto-char (point-min))
1690 (insert (format "\\label{%s}\n" (org-export-solidify-link-text label
)))
1696 (defun org-e-latex-latex-fragment (latex-fragment contents info
)
1697 "Transcode a LATEX-FRAGMENT object from Org to LaTeX.
1698 CONTENTS is nil. INFO is a plist holding contextual information."
1699 (org-element-property :value latex-fragment
))
1704 (defun org-e-latex-line-break (line-break contents info
)
1705 "Transcode a LINE-BREAK object from Org to LaTeX.
1706 CONTENTS is nil. INFO is a plist holding contextual information."
1712 (defun org-e-latex-link--inline-image (link info
)
1713 "Return LaTeX code for an inline image.
1714 LINK is the link pointing to the inline image. INFO is a plist
1715 used as a communication channel."
1716 (let* ((parent (org-export-get-parent-element link
))
1717 (path (let ((raw-path (org-element-property :path link
)))
1718 (if (not (file-name-absolute-p raw-path
)) raw-path
1719 (expand-file-name raw-path
))))
1720 (caption (org-e-latex--caption/label-string parent info
))
1721 ;; Retrieve latex attributes from the element around.
1722 (attr (let ((raw-attr
1723 (mapconcat #'identity
1724 (org-element-property :attr_latex parent
)
1726 (unless (string= raw-attr
"") raw-attr
)))
1729 ((and attr
(string-match "\\<wrap\\>" attr
)) 'wrap
)
1730 ((and attr
(string-match "\\<multicolumn\\>" attr
)) 'multicolumn
)
1731 ((or (and attr
(string-match "\\<float\\>" attr
))
1732 (not (string= caption
"")))
1736 ((and attr
(string-match "\\<placement=\\(\\S-+\\)" attr
))
1737 (org-match-string-no-properties 1 attr
))
1738 ((eq disposition
'wrap
) "{l}{0.5\\textwidth}")
1739 ((eq disposition
'float
)
1740 (concat "[" org-e-latex-default-figure-position
"]"))
1742 ;; Now clear ATTR from any special keyword and set a default
1743 ;; value if nothing is left.
1747 (replace-regexp-in-string
1748 "\\(wrap\\|multicolumn\\|float\\|placement=\\S-+\\)" "" attr
))))
1749 (setq attr
(cond ((not (string= attr
"")) attr
)
1750 ((eq disposition
'float
) "width=0.7\\textwidth")
1751 ((eq disposition
'wrap
) "width=0.48\\textwidth")
1752 (t (or org-e-latex-image-default-option
""))))
1753 ;; Return proper string, depending on DISPOSITION.
1755 (wrap (format "\\begin{wrapfigure}%s
1757 \\includegraphics[%s]{%s}
1758 %s\\end{wrapfigure}" placement attr path caption
))
1759 (multicolumn (format "\\begin{figure*}%s
1761 \\includegraphics[%s]{%s}
1762 %s\\end{figure*}" placement attr path caption
))
1763 (float (format "\\begin{figure}%s
1765 \\includegraphics[%s]{%s}
1766 %s\\end{figure}" placement attr path caption
))
1767 (t (format "\\includegraphics[%s]{%s}" attr path
)))))
1769 (defun org-e-latex-link (link desc info
)
1770 "Transcode a LINK object from Org to LaTeX.
1772 DESC is the description part of the link, or the empty string.
1773 INFO is a plist holding contextual information. See
1775 (let* ((type (org-element-property :type link
))
1776 (raw-path (org-element-property :path link
))
1777 ;; Ensure DESC really exists, or set it to nil.
1778 (desc (and (not (string= desc
"")) desc
))
1779 (imagep (org-export-inline-image-p
1780 link org-e-latex-inline-image-rules
))
1782 ((member type
'("http" "https" "ftp" "mailto"))
1783 (concat type
":" raw-path
))
1784 ((string= type
"file")
1785 (if (file-name-absolute-p raw-path
)
1786 (concat "file://" (expand-file-name raw-path
))
1787 (concat "file://" raw-path
)))
1792 (imagep (org-e-latex-link--inline-image link info
))
1793 ;; Radio link: Transcode target's contents and use them as link's
1795 ((string= type
"radio")
1796 (let ((destination (org-export-resolve-radio-link link info
)))
1798 (format "\\hyperref[%s]{%s}"
1799 (org-export-solidify-link-text path
)
1800 (org-export-data (org-element-contents destination
) info
)))))
1801 ;; Links pointing to an headline: Find destination and build
1802 ;; appropriate referencing command.
1803 ((member type
'("custom-id" "fuzzy" "id"))
1804 (let ((destination (if (string= type
"fuzzy")
1805 (org-export-resolve-fuzzy-link link info
)
1806 (org-export-resolve-id-link link info
))))
1807 (case (org-element-type destination
)
1808 ;; Id link points to an external file.
1810 (if desc
(format "\\href{file://%s}{%s}" destination desc
)
1811 (format "\\url{file://%s}" destination
)))
1812 ;; Fuzzy link points nowhere.
1814 (format org-e-latex-link-with-unknown-path-format
1817 (org-element-property :raw-link link
) info
))))
1818 ;; Fuzzy link points to an invisible target.
1820 ;; LINK points to an headline. If headlines are numbered
1821 ;; and the link has no description, display headline's
1822 ;; number. Otherwise, display description or headline's
1829 (org-export-get-headline-number destination info
)
1831 (if (and (plist-get info
:section-numbers
) (not desc
))
1832 (format "\\ref{%s}" label
)
1833 (format "\\hyperref[%s]{%s}" label
1836 (org-element-property :title destination
) info
))))))
1837 ;; Fuzzy link points to a target. Do as above.
1839 (let ((path (org-export-solidify-link-text path
)))
1840 (if (not desc
) (format "\\ref{%s}" path
)
1841 (format "\\hyperref[%s]{%s}" path desc
)))))))
1842 ;; Coderef: replace link with the reference name or the
1843 ;; equivalent line number.
1844 ((string= type
"coderef")
1845 (format (org-export-get-coderef-format path desc
)
1846 (org-export-resolve-coderef path info
)))
1847 ;; Link type is handled by a special function.
1848 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
1849 (funcall protocol
(org-link-unescape path
) desc
'latex
))
1850 ;; External link with a description part.
1851 ((and path desc
) (format "\\href{%s}{%s}" path desc
))
1852 ;; External link without a description part.
1853 (path (format "\\url{%s}" path
))
1854 ;; No path, only description. Try to do something useful.
1855 (t (format org-e-latex-link-with-unknown-path-format desc
)))))
1860 (defun org-e-latex-paragraph (paragraph contents info
)
1861 "Transcode a PARAGRAPH element from Org to LaTeX.
1862 CONTENTS is the contents of the paragraph, as a string. INFO is
1863 the plist used as a communication channel."
1869 (defun org-e-latex-plain-list (plain-list contents info
)
1870 "Transcode a PLAIN-LIST element from Org to LaTeX.
1871 CONTENTS is the contents of the list. INFO is a plist holding
1872 contextual information."
1873 (let* ((type (org-element-property :type plain-list
))
1874 (attr (org-export-read-attribute :attr_latex plain-list
))
1875 (latex-type (let ((env (plist-get attr
:environment
)))
1876 (cond (env (format "%s" env
))
1877 ((eq type
'ordered
) "enumerate")
1878 ((eq type
'unordered
) "itemize")
1879 ((eq type
'descriptive
) "description")))))
1880 (org-e-latex--wrap-label
1882 (format "\\begin{%s}%s\n%s\\end{%s}"
1884 ;; Put optional arguments, if any inside square brackets
1886 (let ((options (format "%s" (or (plist-get attr
:options
) ""))))
1887 (cond ((equal options
"") "")
1888 ((string-match "\\`\\[.*\\]\\'" options
) options
)
1889 (t (format "[%s]" options
))))
1896 (defun org-e-latex-plain-text (text info
)
1897 "Transcode a TEXT string from Org to LaTeX.
1898 TEXT is the string to transcode. INFO is a plist holding
1899 contextual information."
1900 (let ((specialp (plist-get info
:with-special-strings
))
1902 ;; Protect %, #, &, $, ~, ^, _, { and }.
1903 (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" output
)
1906 (format "\\%s" (match-string 2 output
)) nil t output
2)))
1907 ;; Protect \. If special strings are used, be careful not to
1908 ;; protect "\" in "\-" constructs.
1909 (let ((symbols (if specialp
"-%$#&{}~^_\\" "%$#&{}~^_\\")))
1911 (replace-regexp-in-string
1912 (format "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%s]\\|$\\)" symbols
)
1913 "$\\backslash$" output nil t
1)))
1914 ;; Activate smart quotes. Be sure to provide original TEXT string
1915 ;; since OUTPUT may have been modified.
1916 (when (plist-get info
:with-smart-quotes
)
1917 (setq output
(org-export-activate-smart-quotes output
:latex info text
)))
1918 ;; LaTeX into \LaTeX{} and TeX into \TeX{}.
1919 (let ((case-fold-search nil
)
1921 (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" output start
)
1922 (setq output
(replace-match
1923 (format "\\%s{}" (match-string 1 output
)) nil t output
)
1924 start
(match-end 0))))
1925 ;; Convert special strings.
1928 (replace-regexp-in-string "\\.\\.\\." "\\ldots{}" output nil t
)))
1929 ;; Handle break preservation if required.
1930 (when (plist-get info
:preserve-breaks
)
1931 (setq output
(replace-regexp-in-string
1932 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" output
)))
1939 (defun org-e-latex-planning (planning contents info
)
1940 "Transcode a PLANNING element from Org to LaTeX.
1941 CONTENTS is nil. INFO is a plist holding contextual
1949 (let ((closed (org-element-property :closed planning
)))
1952 (format "\\textbf{%s} " org-closed-string
)
1953 (format org-e-latex-inactive-timestamp-format
1955 (org-element-property :raw-value closed
))))))
1956 (let ((deadline (org-element-property :deadline planning
)))
1959 (format "\\textbf{%s} " org-deadline-string
)
1960 (format org-e-latex-active-timestamp-format
1962 (org-element-property :raw-value deadline
))))))
1963 (let ((scheduled (org-element-property :scheduled planning
)))
1966 (format "\\textbf{%s} " org-scheduled-string
)
1967 (format org-e-latex-active-timestamp-format
1969 (org-element-property :raw-value scheduled
))))))))
1974 ;;;; Property Drawer
1976 (defun org-e-latex-property-drawer (property-drawer contents info
)
1977 "Transcode a PROPERTY-DRAWER element from Org to LaTeX.
1978 CONTENTS is nil. INFO is a plist holding contextual
1980 ;; The property drawer isn't exported but we want separating blank
1981 ;; lines nonetheless.
1987 (defun org-e-latex-quote-block (quote-block contents info
)
1988 "Transcode a QUOTE-BLOCK element from Org to LaTeX.
1989 CONTENTS holds the contents of the block. INFO is a plist
1990 holding contextual information."
1991 (org-e-latex--wrap-label
1993 (format "\\begin{quote}\n%s\\end{quote}" contents
)))
1998 (defun org-e-latex-quote-section (quote-section contents info
)
1999 "Transcode a QUOTE-SECTION element from Org to LaTeX.
2000 CONTENTS is nil. INFO is a plist holding contextual information."
2001 (let ((value (org-remove-indentation
2002 (org-element-property :value quote-section
))))
2003 (when value
(format "\\begin{verbatim}\n%s\\end{verbatim}" value
))))
2008 (defun org-e-latex-radio-target (radio-target text info
)
2009 "Transcode a RADIO-TARGET object from Org to LaTeX.
2010 TEXT is the text of the target. INFO is a plist holding
2011 contextual information."
2012 (format "\\label{%s}%s"
2013 (org-export-solidify-link-text
2014 (org-element-property :value radio-target
))
2020 (defun org-e-latex-section (section contents info
)
2021 "Transcode a SECTION element from Org to LaTeX.
2022 CONTENTS holds the contents of the section. INFO is a plist
2023 holding contextual information."
2029 (defun org-e-latex-special-block (special-block contents info
)
2030 "Transcode a SPECIAL-BLOCK element from Org to LaTeX.
2031 CONTENTS holds the contents of the block. INFO is a plist
2032 holding contextual information."
2033 (let ((type (downcase (org-element-property :type special-block
))))
2034 (concat (format "\\begin{%s}\n" type
)
2035 ;; Insert any label or caption within the block
2036 ;; (otherwise, a reference pointing to that element will
2037 ;; count the section instead).
2038 (org-e-latex--caption/label-string special-block info
)
2040 (format "\\end{%s}" type
))))
2045 (defun org-e-latex-src-block (src-block contents info
)
2046 "Transcode a SRC-BLOCK element from Org to LaTeX.
2047 CONTENTS holds the contents of the item. INFO is a plist holding
2048 contextual information."
2049 (let* ((lang (org-element-property :language src-block
))
2050 (caption (org-element-property :caption src-block
))
2051 (label (org-element-property :name src-block
))
2052 (custom-env (and lang
2053 (cadr (assq (intern lang
)
2054 org-e-latex-custom-lang-environments
))))
2055 (num-start (case (org-element-property :number-lines src-block
)
2056 (continued (org-export-get-loc src-block info
))
2058 (retain-labels (org-element-property :retain-labels src-block
)))
2060 ;; Case 1. No source fontification.
2061 ((not org-e-latex-listings
)
2062 (let ((caption-str (org-e-latex--caption/label-string src-block info
))
2063 (float-env (when caption
"\\begin{figure}[H]\n%s\n\\end{figure}")))
2067 (format "\\begin{verbatim}\n%s\\end{verbatim}"
2068 (org-export-format-code-default src-block info
))))))
2069 ;; Case 2. Custom environment.
2070 (custom-env (format "\\begin{%s}\n%s\\end{%s}\n"
2072 (org-export-format-code-default src-block info
)
2074 ;; Case 3. Use minted package.
2075 ((eq org-e-latex-listings
'minted
)
2077 (when (or label caption
)
2078 (format "\\begin{listing}[H]\n%%s\n%s\\end{listing}"
2079 (org-e-latex--caption/label-string src-block info
))))
2082 "\\begin{minted}[%s]{%s}\n%s\\end{minted}"
2084 (org-e-latex--make-option-string
2085 (if (not num-start
) org-e-latex-minted-options
2086 (append `(("linenos")
2087 ("firstnumber" ,(number-to-string (1+ num-start
))))
2088 org-e-latex-minted-options
)))
2090 (or (cadr (assq (intern lang
) org-e-latex-minted-langs
)) lang
)
2092 (let* ((code-info (org-export-unravel-code src-block
))
2096 (org-split-string (car code-info
) "\n")))))
2097 (org-export-format-code
2099 (lambda (loc num ref
)
2103 ;; Ensure references are flushed to the right,
2104 ;; separated with 6 spaces from the widest line
2106 (concat (make-string (+ (- max-width
(length loc
)) 6) ?
)
2107 (format "(%s)" ref
)))))
2108 nil
(and retain-labels
(cdr code-info
)))))))
2110 (if float-env
(format float-env body
) body
)))
2111 ;; Case 4. Use listings package.
2114 (or (cadr (assq (intern lang
) org-e-latex-listings-langs
)) lang
))
2117 (let ((main (org-export-get-caption src-block
))
2118 (secondary (org-export-get-caption src-block t
)))
2119 (if (not secondary
) (format "{%s}" (org-export-data main info
))
2121 (org-export-data secondary info
)
2122 (org-export-data main info
)))))))
2125 (format "\\lstset{%s}\n"
2126 (org-e-latex--make-option-string
2127 (append org-e-latex-listings-options
2128 `(("language" ,lst-lang
))
2129 (when label
`(("label" ,label
)))
2130 (when caption-str
`(("caption" ,caption-str
)))
2131 (cond ((not num-start
) '(("numbers" "none")))
2132 ((zerop num-start
) '(("numbers" "left")))
2133 (t `(("numbers" "left")
2135 ,(number-to-string (1+ num-start
)))))))))
2138 "\\begin{lstlisting}\n%s\\end{lstlisting}"
2139 (let* ((code-info (org-export-unravel-code src-block
))
2143 (org-split-string (car code-info
) "\n")))))
2144 (org-export-format-code
2146 (lambda (loc num ref
)
2150 ;; Ensure references are flushed to the right,
2151 ;; separated with 6 spaces from the widest line of
2153 (concat (make-string (+ (- max-width
(length loc
)) 6) ?
)
2154 (format "(%s)" ref
)))))
2155 nil
(and retain-labels
(cdr code-info
)))))))))))
2158 ;;;; Statistics Cookie
2160 (defun org-e-latex-statistics-cookie (statistics-cookie contents info
)
2161 "Transcode a STATISTICS-COOKIE object from Org to LaTeX.
2162 CONTENTS is nil. INFO is a plist holding contextual information."
2163 (replace-regexp-in-string
2164 "%" "\\%" (org-element-property :value statistics-cookie
) nil t
))
2169 (defun org-e-latex-strike-through (strike-through contents info
)
2170 "Transcode STRIKE-THROUGH from Org to LaTeX.
2171 CONTENTS is the text with strike-through markup. INFO is a plist
2172 holding contextual information."
2173 (org-e-latex--text-markup contents
'strike-through
))
2178 (defun org-e-latex-subscript (subscript contents info
)
2179 "Transcode a SUBSCRIPT object from Org to LaTeX.
2180 CONTENTS is the contents of the object. INFO is a plist holding
2181 contextual information."
2182 (if (= (length contents
) 1) (format "$_%s$" contents
)
2183 ;; Handle multiple objects in SUBSCRIPT by creating a subscript
2184 ;; command for each of them.
2185 (let ((prev-blanks 0))
2188 (case (org-element-type obj
)
2189 ((entity latex-fragment
)
2190 (setq prev-blanks
(org-element-property :post-blank obj
))
2191 (let ((data (org-trim (org-export-data obj info
))))
2193 "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
2195 (format "$_{%s}$" (match-string 1 data
))))
2197 (format "$_\\mathrm{%s}$"
2198 (concat (make-string prev-blanks ?
)
2199 ;; mathrm command doesn't handle spaces,
2200 ;; so we have to enforce them.
2201 (replace-regexp-in-string
2202 " " "\\\\ " (org-export-data obj info
)))))
2204 (setq prev-blanks
(org-element-property :post-blank obj
))
2205 (format "$_{%s}$" (org-export-data obj info
)))))
2206 (org-element-contents subscript
) ""))))
2211 (defun org-e-latex-superscript (superscript contents info
)
2212 "Transcode a SUPERSCRIPT object from Org to LaTeX.
2213 CONTENTS is the contents of the object. INFO is a plist holding
2214 contextual information."
2215 (if (= (length contents
) 1) (format "$^%s$" contents
)
2216 ;; Handle multiple objects in SUPERSCRIPT by creating
2217 ;; a superscript command for each of them.
2218 (let ((prev-blanks 0))
2221 (case (org-element-type obj
)
2222 ((entity latex-fragment
)
2223 (setq prev-blanks
(org-element-property :post-blank obj
))
2224 (let ((data (org-trim (org-export-data obj info
))))
2226 "\\`\\(?:\\\\[([]\\|\\$+\\)?\\(.*?\\)\\(?:\\\\[])]\\|\\$+\\)?\\'"
2228 (format "$^{%s}$" (match-string 1 data
))))
2230 (format "$^\\mathrm{%s}$"
2231 (concat (make-string prev-blanks ?
)
2232 ;; mathrm command doesn't handle spaces,
2233 ;; so we have to enforce them.
2234 (replace-regexp-in-string
2235 " " "\\\\ " (org-export-data obj info
)))))
2237 (setq prev-blanks
(org-element-property :post-blank obj
))
2238 (format "$^{%s}$" (org-export-data obj info
)))))
2239 (org-element-contents superscript
) ""))))
2244 ;; `org-e-latex-table' is the entry point for table transcoding. It
2245 ;; takes care of tables with a "verbatim" mode. Otherwise, it
2246 ;; delegates the job to either `org-e-latex--table.el-table',
2247 ;; `org-e-latex--org-table' or `org-e-latex--math-table' functions,
2248 ;; depending of the type of the table and the mode requested.
2250 ;; `org-e-latex--align-string' is a subroutine used to build alignment
2251 ;; string for Org tables.
2253 (defun org-e-latex-table (table contents info
)
2254 "Transcode a TABLE element from Org to LaTeX.
2255 CONTENTS is the contents of the table. INFO is a plist holding
2256 contextual information."
2257 (if (eq (org-element-property :type table
) 'table.el
)
2258 ;; "table.el" table. Convert it using appropriate tools.
2259 (org-e-latex--table.el-table table info
)
2260 (let ((type (or (org-export-read-attribute :attr_latex table
:mode
)
2261 org-e-latex-default-table-mode
)))
2263 ;; Case 1: Verbatim table.
2264 ((string= type
"verbatim")
2265 (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
2266 ;; Re-create table, without affiliated keywords.
2267 (org-trim (org-element-interpret-data
2268 `(table nil
,@(org-element-contents table
))))))
2270 ((or (string= type
"math") (string= type
"inline-math"))
2271 (org-e-latex--math-table table info
))
2272 ;; Case 3: Standard table.
2273 (t (concat (org-e-latex--org-table table contents info
)
2274 ;; When there are footnote references within the
2275 ;; table, insert their definition just after it.
2276 (org-e-latex--delayed-footnotes-definitions table info
)))))))
2278 (defun org-e-latex--align-string (table info
)
2279 "Return an appropriate LaTeX alignment string.
2280 TABLE is the considered table. INFO is a plist used as
2281 a communication channel."
2282 (or (org-export-read-attribute :attr_latex table
:align
)
2284 ;; Extract column groups and alignment from first (non-rule)
2290 (and (eq (org-element-property :type row
) 'standard
) row
))
2294 (let ((borders (org-export-table-cell-borders cell info
)))
2295 ;; Check left border for the first cell only.
2296 (when (and (memq 'left borders
) (not align
))
2298 (push (case (org-export-table-cell-alignment cell info
)
2303 (when (memq 'right borders
) (push "|" align
))))
2305 (apply 'concat
(nreverse align
)))))
2307 (defun org-e-latex--org-table (table contents info
)
2308 "Return appropriate LaTeX code for an Org table.
2310 TABLE is the table type element to transcode. CONTENTS is its
2311 contents, as a string. INFO is a plist used as a communication
2314 This function assumes TABLE has `org' as its `:type' property and
2315 `table' as its `:mode' attribute."
2316 (let* ((caption (org-e-latex--caption/label-string table info
))
2317 (attr (org-export-read-attribute :attr_latex table
))
2318 ;; Determine alignment string.
2319 (alignment (org-e-latex--align-string table info
))
2320 ;; Determine environment for the table: longtable, tabular...
2321 (table-env (let ((env (plist-get attr
:environment
)))
2322 (if env
(format "%s" env
)
2323 org-e-latex-default-table-environment
)))
2324 ;; If table is a float, determine environment: table, table*
2325 ;; or sidewaystable.
2326 (float-env (unless (equal "longtable" table-env
)
2327 (let ((float (plist-get attr
:float
)))
2329 ((string= float
"sidewaystable") "sidewaystable")
2330 ((string= float
"multicolumn") "table*")
2331 ((or (string= float
"table")
2332 (org-element-property :caption table
))
2334 ;; Extract others display options.
2335 (width (plist-get attr
:width
))
2336 (placement (or (plist-get attr
:placement
)
2337 (format "[%s]" org-e-latex-default-figure-position
)))
2338 (centerp (if (plist-member attr
:center
) (plist-get attr
:center
)
2339 org-e-latex-tables-centered
)))
2340 ;; Prepare the final format string for the table.
2343 ((equal "longtable" table-env
)
2345 "\\begin{longtable}{%s}\n%s%s%s\\end{longtable}"
2347 (if (or (not org-e-latex-table-caption-above
) (string= "" caption
)) ""
2348 (concat caption
"\\\\\n"))
2350 (if (or org-e-latex-table-caption-above
(string= "" caption
)) ""
2351 (concat caption
"\\\\\n"))))
2355 (concat (format "\\begin{%s}%s\n" float-env placement
)
2356 (if org-e-latex-table-caption-above caption
"")
2357 (when centerp
"\\centering\n")))
2358 (centerp "\\begin{center}\n"))
2359 (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
2361 (if width
(format "{%s}" width
) "")
2367 (concat (if org-e-latex-table-caption-above
"" caption
)
2368 (format "\n\\end{%s}" float-env
)))
2369 (centerp "\n\\end{center}")))))))
2371 (defun org-e-latex--table.el-table
(table info
)
2372 "Return appropriate LaTeX code for a table.el table.
2374 TABLE is the table type element to transcode. INFO is a plist
2375 used as a communication channel.
2377 This function assumes TABLE has `table.el' as its `:type'
2380 ;; Ensure "*org-export-table*" buffer is empty.
2381 (with-current-buffer (get-buffer-create "*org-export-table*")
2383 (let ((output (with-temp-buffer
2384 (insert (org-element-property :value table
))
2386 (re-search-forward "^[ \t]*|[^|]" nil t
)
2387 (table-generate-source 'latex
"*org-export-table*")
2388 (with-current-buffer "*org-export-table*"
2389 (org-trim (buffer-string))))))
2390 (kill-buffer (get-buffer "*org-export-table*"))
2391 ;; Remove left out comments.
2392 (while (string-match "^%.*\n" output
)
2393 (setq output
(replace-match "" t t output
)))
2394 ;; When the "rmlines" attribute is provided, remove all hlines but
2395 ;; the the one separating heading from the table body.
2396 (when (org-export-read-attribute :attr_latex table
:rmlines
)
2397 (let ((n 0) (pos 0))
2398 (while (and (< (length output
) pos
)
2399 (setq pos
(string-match "^\\\\hline\n?" output pos
)))
2401 (unless (= n
2) (setq output
(replace-match "" nil nil output
))))))
2402 (let ((centerp (if (plist-member attr
:center
) (plist-get attr
:center
)
2403 org-e-latex-tables-centered
)))
2404 (if (not centerp
) output
2405 (format "\\begin{center}\n%s\n\\end{center}" output
)))))
2407 (defun org-e-latex--math-table (table info
)
2408 "Return appropriate LaTeX code for a matrix.
2410 TABLE is the table type element to transcode. INFO is a plist
2411 used as a communication channel.
2413 This function assumes TABLE has `org' as its `:type' property and
2414 `inline-math' or `math' as its `:mode' attribute.."
2415 (let* ((caption (org-e-latex--caption/label-string table info
))
2416 (attr (org-export-read-attribute :attr_latex table
))
2417 (inlinep (eq (plist-get attr
:mode
) 'inline-math
))
2418 (env (let ((env (plist-get attr
:environment
)))
2419 (if env
(format "%s" env
)
2420 org-e-latex-default-table-environment
)))
2424 ;; Ignore horizontal rules.
2425 (when (eq (org-element-property :type row
) 'standard
)
2426 ;; Return each cell unmodified.
2430 (substring (org-element-interpret-data cell
) 0 -
1))
2431 (org-element-map row
'table-cell
'identity info
) "&")
2432 (or (cdr (assoc env org-e-latex-table-matrix-macros
)) "\\\\")
2434 (org-element-map table
'table-row
'identity info
) "")))
2437 (cond (inlinep "\\(")
2438 ((org-string-nw-p caption
) (concat "\\begin{equation}\n" caption
))
2440 ;; Prefix (make sure it is a string).
2441 (format "%s" (or (plist-get attr
:math-prefix
) ""))
2442 ;; Environment. Also treat special cases.
2443 (cond ((equal env
"array")
2444 (let ((align (org-e-latex--align-string table info
)))
2445 (format "\\begin{array}{%s}\n%s\\end{array}" align contents
)))
2446 ((assoc env org-e-latex-table-matrix-macros
)
2447 (format "\\%s%s{\n%s}" env
2448 (format "%s" (or (plist-get attr
:math-arguments
) ""))
2450 (t (format "\\begin{%s}\n%s\\end{%s}" env contents env
)))
2451 ;; Suffix (make sure it is a string).
2452 (format "%s" (or (plist-get attr
:math-suffix
) ""))
2454 (cond (inlinep "\\)")
2455 ((org-string-nw-p caption
) "\\end{equation}")
2461 (defun org-e-latex-table-cell (table-cell contents info
)
2462 "Transcode a TABLE-CELL element from Org to LaTeX.
2463 CONTENTS is the cell contents. INFO is a plist used as
2464 a communication channel."
2465 (concat (if (and contents
2466 org-e-latex-table-scientific-notation
2467 (string-match orgtbl-exp-regexp contents
))
2468 ;; Use appropriate format string for scientific
2470 (format org-e-latex-table-scientific-notation
2471 (match-string 1 contents
)
2472 (match-string 2 contents
))
2474 (when (org-export-get-next-element table-cell info
) " & ")))
2479 (defun org-e-latex-table-row (table-row contents info
)
2480 "Transcode a TABLE-ROW element from Org to LaTeX.
2481 CONTENTS is the contents of the row. INFO is a plist used as
2482 a communication channel."
2483 ;; Rules are ignored since table separators are deduced from
2484 ;; borders of the current row.
2485 (when (eq (org-element-property :type table-row
) 'standard
)
2486 (let* ((attr (org-export-read-attribute :attr_latex
2487 (org-export-get-parent table-row
)))
2488 (longtablep (string= (or (plist-get attr
:environment
)
2489 org-e-latex-default-table-environment
)
2491 (booktabsp (if (plist-member attr
:booktabs
)
2492 (plist-get attr
:booktabs
)
2493 org-e-latex-tables-booktabs
))
2494 ;; TABLE-ROW's borders are extracted from its first cell.
2495 (borders (org-export-table-cell-borders
2496 (car (org-element-contents table-row
)) info
)))
2498 ;; When BOOKTABS are activated enforce top-rule even when no
2499 ;; hline was specifically marked.
2500 (cond ((and booktabsp
(memq 'top borders
)) "\\toprule\n")
2501 ((and (memq 'top borders
) (memq 'above borders
)) "\\hline\n"))
2504 ;; Special case for long tables. Define header and footers.
2505 ((and longtablep
(org-export-table-row-ends-header-p table-row info
))
2508 %s\\multicolumn{%d}{r}{Continued on next page} \\\\
2511 (if booktabsp
"\\midrule" "\\hline")
2512 (if booktabsp
"\\midrule" "\\hline")
2513 ;; Number of columns.
2514 (cdr (org-export-table-dimensions
2515 (org-export-get-parent-table table-row
) info
))))
2516 ;; When BOOKTABS are activated enforce bottom rule even when
2517 ;; no hline was specifically marked.
2518 ((and booktabsp
(memq 'bottom borders
)) "\\bottomrule")
2519 ((and (memq 'bottom borders
) (memq 'below borders
)) "\\hline")
2520 ((memq 'below borders
) (if booktabsp
"\\midrule" "\\hline")))))))
2525 (defun org-e-latex-target (target contents info
)
2526 "Transcode a TARGET object from Org to LaTeX.
2527 CONTENTS is nil. INFO is a plist holding contextual
2529 (format "\\label{%s}"
2530 (org-export-solidify-link-text (org-element-property :value target
))))
2535 (defun org-e-latex-timestamp (timestamp contents info
)
2536 "Transcode a TIMESTAMP object from Org to LaTeX.
2537 CONTENTS is nil. INFO is a plist holding contextual
2539 (let ((value (org-translate-time
2540 (org-element-property :raw-value timestamp
))))
2541 (case (org-element-property :type timestamp
)
2542 (active (format org-e-latex-active-timestamp-format value
))
2544 (let ((timestamps (org-split-string value
"--")))
2546 (format org-e-latex-active-timestamp-format
(car timestamps
))
2548 (format org-e-latex-active-timestamp-format
(cdr timestamps
)))))
2549 (inactive (format org-e-latex-inactive-timestamp-format value
))
2551 (let ((timestamps (org-split-string value
"--")))
2553 (format org-e-latex-inactive-timestamp-format
(car timestamps
))
2555 (format org-e-latex-inactive-timestamp-format
(cdr timestamps
)))))
2556 (otherwise (format org-e-latex-diary-timestamp-format value
)))))
2561 (defun org-e-latex-underline (underline contents info
)
2562 "Transcode UNDERLINE from Org to LaTeX.
2563 CONTENTS is the text with underline markup. INFO is a plist
2564 holding contextual information."
2565 (org-e-latex--text-markup contents
'underline
))
2570 (defun org-e-latex-verbatim (verbatim contents info
)
2571 "Transcode a VERBATIM object from Org to LaTeX.
2572 CONTENTS is nil. INFO is a plist used as a communication
2574 (org-e-latex--text-markup (org-element-property :value verbatim
) 'verbatim
))
2579 (defun org-e-latex-verse-block (verse-block contents info
)
2580 "Transcode a VERSE-BLOCK element from Org to LaTeX.
2581 CONTENTS is verse block contents. INFO is a plist holding
2582 contextual information."
2583 (org-e-latex--wrap-label
2585 ;; In a verse environment, add a line break to each newline
2586 ;; character and change each white space at beginning of a line
2587 ;; into a space of 1 em. Also change each blank line with
2588 ;; a vertical space of 1 em.
2590 (setq contents
(replace-regexp-in-string
2591 "^ *\\\\\\\\$" "\\\\vspace*{1em}"
2592 (replace-regexp-in-string
2593 "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n" contents
)))
2594 (while (string-match "^[ \t]+" contents
)
2595 (let ((new-str (format "\\hspace*{%dem}"
2596 (length (match-string 0 contents
)))))
2597 (setq contents
(replace-match new-str nil t contents
))))
2598 (format "\\begin{verse}\n%s\\end{verse}" contents
))))
2602 ;;; End-user functions
2605 (defun org-e-latex-export-as-latex
2606 (&optional subtreep visible-only body-only ext-plist
)
2607 "Export current buffer as a LaTeX buffer.
2609 If narrowing is active in the current buffer, only export its
2612 If a region is active, export that region.
2614 When optional argument SUBTREEP is non-nil, export the sub-tree
2615 at point, extracting information from the headline properties
2618 When optional argument VISIBLE-ONLY is non-nil, don't export
2619 contents of hidden elements.
2621 When optional argument BODY-ONLY is non-nil, only write code
2622 between \"\\begin{document}\" and \"\\end{document}\".
2624 EXT-PLIST, when provided, is a property list with external
2625 parameters overriding Org default settings, but still inferior to
2626 file-local settings.
2628 Export is done in a buffer named \"*Org E-LATEX Export*\", which
2629 will be displayed when `org-export-show-temporary-export-buffer'
2632 (let ((outbuf (org-export-to-buffer
2633 'e-latex
"*Org E-LATEX Export*"
2634 subtreep visible-only body-only ext-plist
)))
2635 (with-current-buffer outbuf
(LaTeX-mode))
2636 (when org-export-show-temporary-export-buffer
2637 (switch-to-buffer-other-window outbuf
))))
2640 (defun org-e-latex-export-to-latex
2641 (&optional subtreep visible-only body-only ext-plist pub-dir
)
2642 "Export current buffer to a LaTeX file.
2644 If narrowing is active in the current buffer, only export its
2647 If a region is active, export that region.
2649 When optional argument SUBTREEP is non-nil, export the sub-tree
2650 at point, extracting information from the headline properties
2653 When optional argument VISIBLE-ONLY is non-nil, don't export
2654 contents of hidden elements.
2656 When optional argument BODY-ONLY is non-nil, only write code
2657 between \"\\begin{document}\" and \"\\end{document}\".
2659 EXT-PLIST, when provided, is a property list with external
2660 parameters overriding Org default settings, but still inferior to
2661 file-local settings.
2663 When optional argument PUB-DIR is set, use it as the publishing
2666 Return output file's name."
2668 (let ((outfile (org-export-output-file-name ".tex" subtreep pub-dir
)))
2670 'e-latex outfile subtreep visible-only body-only ext-plist
)))
2673 (defun org-e-latex-export-to-pdf
2674 (&optional subtreep visible-only body-only ext-plist pub-dir
)
2675 "Export current buffer to LaTeX then process through to PDF.
2677 If narrowing is active in the current buffer, only export its
2680 If a region is active, export that region.
2682 When optional argument SUBTREEP is non-nil, export the sub-tree
2683 at point, extracting information from the headline properties
2686 When optional argument VISIBLE-ONLY is non-nil, don't export
2687 contents of hidden elements.
2689 When optional argument BODY-ONLY is non-nil, only write code
2690 between \"\\begin{document}\" and \"\\end{document}\".
2692 EXT-PLIST, when provided, is a property list with external
2693 parameters overriding Org default settings, but still inferior to
2694 file-local settings.
2696 When optional argument PUB-DIR is set, use it as the publishing
2699 Return PDF file's name."
2701 (org-e-latex-compile
2702 (org-e-latex-export-to-latex
2703 subtreep visible-only body-only ext-plist pub-dir
)))
2705 (defun org-e-latex-compile (texfile)
2706 "Compile a TeX file.
2708 TEXFILE is the name of the file being compiled. Processing is
2709 done through the command specified in `org-e-latex-pdf-process'.
2711 Return PDF file name or an error if it couldn't be produced."
2712 (let* ((base-name (file-name-sans-extension (file-name-nondirectory texfile
)))
2713 (full-name (file-truename texfile
))
2714 (out-dir (file-name-directory texfile
))
2715 ;; Make sure `default-directory' is set to TEXFILE directory,
2716 ;; not to whatever value the current buffer may have.
2717 (default-directory (file-name-directory full-name
))
2719 (message (format "Processing LaTeX file %s ..." texfile
))
2720 (save-window-excursion
2722 ;; A function is provided: Apply it.
2723 ((functionp org-e-latex-pdf-process
)
2724 (funcall org-e-latex-pdf-process
(shell-quote-argument texfile
)))
2725 ;; A list is provided: Replace %b, %f and %o with appropriate
2726 ;; values in each command before applying it. Output is
2727 ;; redirected to "*Org PDF LaTeX Output*" buffer.
2728 ((consp org-e-latex-pdf-process
)
2729 (let ((outbuf (get-buffer-create "*Org PDF LaTeX Output*")))
2733 (replace-regexp-in-string
2734 "%b" (shell-quote-argument base-name
)
2735 (replace-regexp-in-string
2736 "%f" (shell-quote-argument full-name
)
2737 (replace-regexp-in-string
2738 "%o" (shell-quote-argument out-dir
) command t t
) t t
) t t
)
2740 org-e-latex-pdf-process
)
2741 ;; Collect standard errors from output buffer.
2742 (setq errors
(org-e-latex--collect-errors outbuf
))))
2743 (t (error "No valid command to process to PDF")))
2744 (let ((pdffile (concat out-dir base-name
".pdf")))
2745 ;; Check for process failure. Provide collected errors if
2747 (if (not (file-exists-p pdffile
))
2748 (error (concat (format "PDF file %s wasn't produced" pdffile
)
2749 (when errors
(concat ": " errors
))))
2750 ;; Else remove log files, when specified, and signal end of
2751 ;; process to user, along with any error encountered.
2752 (when org-e-latex-remove-logfiles
2753 (dolist (ext org-e-latex-logfiles-extensions
)
2754 (let ((file (concat out-dir base-name
"." ext
)))
2755 (when (file-exists-p file
) (delete-file file
)))))
2756 (message (concat "Process completed"
2757 (if (not errors
) "."
2758 (concat " with errors: " errors
)))))
2759 ;; Return output file name.
2762 (defun org-e-latex--collect-errors (buffer)
2763 "Collect some kind of errors from \"pdflatex\" command output.
2765 BUFFER is the buffer containing output.
2767 Return collected error types as a string, or nil if there was
2769 (with-current-buffer buffer
2771 (goto-char (point-max))
2772 (when (re-search-backward "^[ \t]*This is .*?TeX.*?Version" nil t
)
2773 (let ((case-fold-search t
)
2775 (dolist (latex-error org-e-latex-known-errors
)
2776 (when (save-excursion (re-search-forward (car latex-error
) nil t
))
2777 (setq errors
(concat errors
" " (cdr latex-error
)))))
2778 (and (org-string-nw-p errors
) (org-trim errors
)))))))
2781 (defun org-e-latex-publish-to-latex (plist filename pub-dir
)
2782 "Publish an Org file to LaTeX.
2784 FILENAME is the filename of the Org file to be published. PLIST
2785 is the property list for the given project. PUB-DIR is the
2786 publishing directory.
2788 Return output file name."
2789 (org-e-publish-org-to 'e-latex filename
".tex" plist pub-dir
))
2792 (defun org-e-latex-publish-to-pdf (plist filename pub-dir
)
2793 "Publish an Org file to PDF (via LaTeX).
2795 FILENAME is the filename of the Org file to be published. PLIST
2796 is the property list for the given project. PUB-DIR is the
2797 publishing directory.
2799 Return output file name."
2800 ;; Unlike to `org-e-latex-publish-to-latex', PDF file is generated
2801 ;; in working directory and then moved to publishing directory.
2802 (org-e-publish-attachment
2804 (org-e-latex-compile (org-e-publish-org-to 'e-latex filename
".tex" plist
))
2808 (provide 'org-e-latex
)
2809 ;;; org-e-latex.el ends here