;;; ox-latex.el --- LaTeX Back-End for Org Export Engine -*- lexical-binding: t; -*- ;; Copyright (C) 2011-2022 Free Software Foundation, Inc. ;; Author: Nicolas Goaziou ;; Maintainer: Daniel Fleischer ;; Keywords: outlines, hypermedia, calendar, wp ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; ;; See Org manual for details. ;;; Code: (require 'org-macs) (org-assert-version) (require 'cl-lib) (require 'ox) (require 'ox-publish) ;;; Function Declarations (defvar org-latex-default-packages-alist) (defvar org-latex-packages-alist) (defvar orgtbl-exp-regexp) (declare-function engrave-faces-latex-gen-preamble "ext:engrave-faces-latex") (declare-function engrave-faces-latex-buffer "ext:engrave-faces-latex") (declare-function engrave-faces-latex-gen-preamble-line "ext:engrave-faces-latex") (declare-function engrave-faces-get-theme "ext:engrave-faces") (defvar engrave-faces-latex-output-style) (defvar engrave-faces-current-preset-style) (defvar engrave-faces-latex-mathescape) ;;; Define Back-End (org-export-define-backend 'latex '((bold . org-latex-bold) (center-block . org-latex-center-block) (clock . org-latex-clock) (code . org-latex-code) (drawer . org-latex-drawer) (dynamic-block . org-latex-dynamic-block) (entity . org-latex-entity) (example-block . org-latex-example-block) (export-block . org-latex-export-block) (export-snippet . org-latex-export-snippet) (fixed-width . org-latex-fixed-width) (footnote-definition . org-latex-footnote-definition) (footnote-reference . org-latex-footnote-reference) (headline . org-latex-headline) (horizontal-rule . org-latex-horizontal-rule) (inline-src-block . org-latex-inline-src-block) (inlinetask . org-latex-inlinetask) (italic . org-latex-italic) (item . org-latex-item) (keyword . org-latex-keyword) (latex-environment . org-latex-latex-environment) (latex-fragment . org-latex-latex-fragment) (line-break . org-latex-line-break) (link . org-latex-link) (node-property . org-latex-node-property) (paragraph . org-latex-paragraph) (plain-list . org-latex-plain-list) (plain-text . org-latex-plain-text) (planning . org-latex-planning) (property-drawer . org-latex-property-drawer) (quote-block . org-latex-quote-block) (radio-target . org-latex-radio-target) (section . org-latex-section) (special-block . org-latex-special-block) (src-block . org-latex-src-block) (statistics-cookie . org-latex-statistics-cookie) (strike-through . org-latex-strike-through) (subscript . org-latex-subscript) (superscript . org-latex-superscript) (table . org-latex-table) (table-cell . org-latex-table-cell) (table-row . org-latex-table-row) (target . org-latex-target) (template . org-latex-template) (timestamp . org-latex-timestamp) (underline . org-latex-underline) (verbatim . org-latex-verbatim) (verse-block . org-latex-verse-block) ;; Pseudo objects and elements. (latex-math-block . org-latex-math-block) (latex-matrices . org-latex-matrices)) :menu-entry '(?l "Export to LaTeX" ((?L "As LaTeX buffer" org-latex-export-as-latex) (?l "As LaTeX file" org-latex-export-to-latex) (?p "As PDF file" org-latex-export-to-pdf) (?o "As PDF file and open" (lambda (a s v b) (if a (org-latex-export-to-pdf t s v b) (org-open-file (org-latex-export-to-pdf nil s v b))))))) :filters-alist '((:filter-options . org-latex-math-block-options-filter) (:filter-paragraph . org-latex-clean-invalid-line-breaks) (:filter-parse-tree org-latex-math-block-tree-filter org-latex-matrices-tree-filter org-latex-image-link-filter) (:filter-verse-block . org-latex-clean-invalid-line-breaks)) :options-alist '((:latex-class "LATEX_CLASS" nil org-latex-default-class t) (:latex-class-options "LATEX_CLASS_OPTIONS" nil nil t) (:latex-header "LATEX_HEADER" nil nil newline) (:latex-header-extra "LATEX_HEADER_EXTRA" nil nil newline) (:description "DESCRIPTION" nil nil parse) (:keywords "KEYWORDS" nil nil parse) (:subtitle "SUBTITLE" nil nil parse) ;; Other variables. (:latex-active-timestamp-format nil nil org-latex-active-timestamp-format) (:latex-caption-above nil nil org-latex-caption-above) (:latex-classes nil nil org-latex-classes) (:latex-default-figure-position nil nil org-latex-default-figure-position) (:latex-default-table-environment nil nil org-latex-default-table-environment) (:latex-default-quote-environment nil nil org-latex-default-quote-environment) (:latex-default-table-mode nil nil org-latex-default-table-mode) (:latex-diary-timestamp-format nil nil org-latex-diary-timestamp-format) (:latex-engraved-options nil nil org-latex-engraved-options) (:latex-engraved-preamble nil nil org-latex-engraved-preamble) (:latex-engraved-theme "LATEX_ENGRAVED_THEME" nil org-latex-engraved-theme) (:latex-footnote-defined-format nil nil org-latex-footnote-defined-format) (:latex-footnote-separator nil nil org-latex-footnote-separator) (:latex-format-drawer-function nil nil org-latex-format-drawer-function) (:latex-format-headline-function nil nil org-latex-format-headline-function) (:latex-format-inlinetask-function nil nil org-latex-format-inlinetask-function) (:latex-hyperref-template nil nil org-latex-hyperref-template t) (:latex-image-default-scale nil nil org-latex-image-default-scale) (:latex-image-default-height nil nil org-latex-image-default-height) (:latex-image-default-option nil nil org-latex-image-default-option) (:latex-image-default-width nil nil org-latex-image-default-width) (:latex-images-centered nil nil org-latex-images-centered) (:latex-inactive-timestamp-format nil nil org-latex-inactive-timestamp-format) (:latex-inline-image-rules nil nil org-latex-inline-image-rules) (:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format) (:latex-src-block-backend nil nil org-latex-src-block-backend) (:latex-listings-langs nil nil org-latex-listings-langs) (:latex-listings-options nil nil org-latex-listings-options) (:latex-minted-langs nil nil org-latex-minted-langs) (:latex-minted-options nil nil org-latex-minted-options) (:latex-prefer-user-labels nil nil org-latex-prefer-user-labels) (:latex-subtitle-format nil nil org-latex-subtitle-format) (:latex-subtitle-separate nil nil org-latex-subtitle-separate) (:latex-table-scientific-notation nil nil org-latex-table-scientific-notation) (:latex-tables-booktabs nil nil org-latex-tables-booktabs) (:latex-tables-centered nil nil org-latex-tables-centered) (:latex-text-markup-alist nil nil org-latex-text-markup-alist) (:latex-title-command nil nil org-latex-title-command) (:latex-toc-command nil nil org-latex-toc-command) (:latex-compiler "LATEX_COMPILER" nil org-latex-compiler) ;; Redefine regular options. (:date "DATE" nil "\\today" parse))) ;;; Internal Variables (defconst org-latex-language-alist '(("am" :babel-ini-only "amharic" :polyglossia "amharic" :lang-name "Amharic") ("ar" :babel "arabic" :polyglossia "arabic" :lang-name "Arabic") ("ast" :babel-ini-only "asturian" :polyglossia "asturian" :lang-name "Asturian") ("bg" :babel "bulgarian" :polyglossia "bulgarian" :lang-name "Bulgarian") ("bn" :babel-ini-only "bengali" :polyglossia "bengali" :lang-name "Bengali") ("bo" :babel-ini-only "tibetan" :polyglossia "tibetan" :lang-name "Tibetan") ("br" :babel "breton" :polyglossia "breton" :lang-name "Breton") ("ca" :babel "catalan" :polyglossia "catalan" :lang-name "Catalan") ("cop" :babel-ini-only "coptic" :polyglossia "coptic" :lang-name "Coptic") ("cs" :babel "czech" :polyglossia "czech" :lang-name "Czech") ("cy" :babel "welsh" :polyglossia "welsh" :lang-name "Welsh") ("da" :babel "danish" :polyglossia "danish" :lang-name "Danish") ("de" :babel "ngerman" :polyglossia "german" :polyglossia-variant "german" :lang-name "German") ("de-at" :babel "naustrian" :polyglossia "german" :polyglossia-variant "austrian" :lang-name "German") ("dsb" :babel "lsorbian" :polyglossia "sorbian" :polyglossia-variant "lower" :lang-name "Lower Sorbian") ("dv" :babel-ini-only "divehi" :polyglossia "divehi" :lang-name "Divehi") ("el" :babel "greek" :polyglossia "greek" :lang-name "Greek") ("el-polyton" :babel "polutonikogreek" :polyglossia "greek" :polyglossia-variant "polytonic" :lang-name "Polytonic Greek") ("en" :babel "american" :polyglossia "english" :polyglossia-variant "usmax" :lang-name "English") ("en-au" :babel "australian" :polyglossia "english" :polyglossia-variant "australian" :lang-name "English") ("en-gb" :babel "british" :polyglossia "english" :polyglossia-variant "uk" :lang-name "English") ("en-nz" :babel "newzealand" :polyglossia "english" :polyglossia-variant "newzealand" :lang-name "English") ("en-us" :babel "american" :polyglossia "english" :polyglossia-variant "usmax" :lang-name "English") ("eo" :babel "esperanto" :polyglossia "esperanto" :lang-name "Esperanto") ("es" :babel "spanish" :polyglossia "spanish" :lang-name "Spanish") ("es-mx" :babel "spanishmx" :polyglossia "spanish" :polyglossia-variant "mexican" :lang-name "Spanish") ("et" :babel "estonian" :polyglossia "estonian" :lang-name "Estonian") ("eu" :babel "basque" :polyglossia "basque" :lang-name "Basque") ("fa" :babel "farsi" :polyglossia "farsi" :lang-name "Farsi") ("fi" :babel "finnish" :polyglossia "finnish" :lang-name "Finnish") ("fr" :babel "french" :polyglossia "french" :lang-name "French") ("fr-ca" :babel "canadien" :polyglossia "french" :polyglossia-variant "canadian" :lang-name "French") ("fur" :babel "friulan" :polyglossia "friulan" :lang-name "Friulian") ("ga" :babel "irish" :polyglossia "irish" :lang-name "Irish") ("gd" :babel "scottish" :polyglossia "scottish" :lang-name "Scottish Gaelic") ("gl" :babel "galician" :polyglossia "galician" :lang-name "Galician") ("he" :babel "hebrew" :polyglossia "hebrew" :lang-name "Hebrew") ("hi" :babel "hindi" :polyglossia "hindi" :lang-name "Hindi") ("hr" :babel "croatian" :polyglossia "croatian" :lang-name "Croatian") ("hsb" :babel "uppersorbian" :polyglossia "sorbian" :polyglossia-variant "upper" :lang-name "Upper Sorbian") ("hu" :babel "magyar" :polyglossia "magyar" :lang-name "Magyar") ("hy" :babel-ini-only "armenian" :polyglossia "armenian" :lang-name "Armenian") ("ia" :babel "interlingua" :polyglossia "interlingua" :lang-name "Interlingua") ("id" :babel-ini-only "bahasai" :polyglossia "bahasai" :lang-name "Bahasai") ("is" :babel "icelandic" :polyglossia "icelandic" :lang-name "Icelandic") ("it" :babel "italian" :polyglossia "italian" :lang-name "Italian") ("kn" :babel-ini-only "kannada" :polyglossia "kannada" :lang-name "Kannada") ("la" :babel "latin" :polyglossia "latin" :lang-name "Latin") ("la-classic" :babel "classiclatin" :polyglossia "latin" :polyglossia-variant "classic" :lang-name "Classic Latin") ("la-medieval" :babel "medievallatin" :polyglossia "latin" :polyglossia-variant "medieval" :lang-name "Medieval Latin") ("la-ecclesiastic" :babel "ecclesiasticlatin" :polyglossia "latin" :polyglossia-variant "ecclesiastic" :lang-name "Ecclesiastic Latin") ("lo" :babel-ini-only "lao" :polyglossia "lao" :lang-name "Lao") ("lt" :babel "lithuanian" :polyglossia "lithuanian" :lang-name "Lithuanian") ("lv" :babel "latvian" :polyglossia "latvian" :lang-name "Latvian") ("ml" :babel-ini-only "malayalam" :polyglossia "malayalam" :lang-name "Malayalam") ("mr" :babel-ini-only "maranthi" :polyglossia "maranthi" :lang-name "Maranthi") ("nb" :babel "norsk" :polyglossia "norwegian" :polyglossia-variant "bokmal" :lang-name "Norwegian Bokmål") ("nl" :babel "dutch" :polyglossia "dutch" :lang-name "Dutch") ("nn" :babel "nynorsk" :polyglossia "norwegian" :polyglossia-variant "nynorsk" :lang-name "Norwegian Nynorsk") ("no" :babel "norsk" :polyglossia "norsk" :lang-name "Norwegian") ("oc" :babel "occitan" :polyglossia "occitan" :lang-name "Occitan") ("pl" :babel "polish" :polyglossia "polish" :lang-name "Polish") ("pms" :babel "piedmontese" :polyglossia "piedmontese" :lang-name "Piedmontese") ("pt" :babel "portuges" :polyglossia "portuges" :lang-name "Portuges") ("pt-br" :babel "brazilian" :polyglossia "brazilian" :lang-name "Portuges") ("rm" :babel-ini-only "romansh" :polyglossia "romansh" :lang-name "Romansh") ("ro" :babel "romanian" :polyglossia "romanian" :lang-name "Romanian") ("ru" :babel "russian" :polyglossia "russian" :lang-name "Russian") ("sa" :babel-ini-only "sanskrit" :polyglossia "sanskrit" :lang-name "Sanskrit") ("sk" :babel "slovak" :polyglossia "slovak" :lang-name "Slovak") ("sl" :babel "slovene" :polyglossia "slovene" :lang-name "Slovene") ("sq" :babel "albanian" :polyglossia "albanian" :lang-name "Albanian") ("sr" :babel "serbian" :polyglossia "serbian" :lang-name "Serbian") ("sv" :babel "swedish" :polyglossia "swedish" :lang-name "Swedish") ("syr" :babel-ini-only "syriac" :polyglossia "syriac" :lang-name "Syriac") ("ta" :babel-ini-only "tamil" :polyglossia "tamil" :lang-name "Tamil") ("te" :babel-ini-only "telugu" :polyglossia "telugu" :lang-name "Telugu") ("th" :babel "thai" :polyglossia "thai" :lang-name "Thai") ("tk" :babel "turkmen" :polyglossia "turkmen" :lang-name "Turkmen") ("tr" :babel "turkish" :polyglossia "turkish" :lang-name "Turkish") ("uk" :babel "ukrainian" :polyglossia "ukrainian" :lang-name "Ukrainian") ("ur" :babel-ini-only "urdu" :polyglossia "urdu" :lang-name "Urdu") ("vi" :babel "vietnamese" :polyglossia "vietnamese" :lang-name "Vietnamese")) "Alist between language code and its properties for LaTeX export. In each element of the list car is always the code of the language and cdr is a property list. Valid keywords for this list can be: - `:babel' the name of the language loaded by the Babel LaTeX package - `:polyglossia' the name of the language loaded by the Polyglossia LaTeX package - `:babel-ini-only' the name of the language loaded by Babel exclusively through the new ini files method. See `http://mirrors.ctan.org/macros/latex/required/babel/base/babel.pdf' - `:polyglossia-variant' the language variant loaded by Polyglossia - `:lang-name' the actual name of the language.") (defconst org-latex-line-break-safe "\\\\\\relax" "Linebreak protecting the following [...]. Without \"\\relax\" it would be interpreted as an optional argument to the \\\\. This constant, for example, makes the below code not err: \\begin{tabular}{c|c} [t] & s\\\\\\relax [I] & A\\\\\\relax [m] & kg \\end{tabular}") (defconst org-latex-table-matrix-macros `(("bordermatrix" . "\\cr") ("qbordermatrix" . "\\cr") ("kbordermatrix" . ,org-latex-line-break-safe)) "Alist between matrix macros and their row ending.") (defconst org-latex-math-environments-re (format "\\`[ \t]*\\\\begin{%s\\*?}" (regexp-opt '("equation" "eqnarray" "math" "displaymath" "align" "gather" "multline" "flalign" "alignat" "xalignat" "xxalignat" "subequations" ;; breqn "dmath" "dseries" "dgroup" "darray" ;; empheq "empheq"))) "Regexp of LaTeX math environments.") ;;; User Configurable Variables (defgroup org-export-latex nil "Options for exporting Org mode files to LaTeX." :tag "Org Export LaTeX" :group 'org-export) ;;;; Generic (defcustom org-latex-caption-above '(table) "When non-nil, place caption string at the beginning of elements. Otherwise, place it near the end. When value is a list of symbols, put caption above selected elements only. Allowed symbols are: `image', `table', `src-block' and `special-block'." :group 'org-export-latex :version "26.1" :package-version '(Org . "8.3") :type '(choice (const :tag "For all elements" t) (const :tag "For no element" nil) (set :tag "For the following elements only" :greedy t (const :tag "Images" image) (const :tag "Tables" table) (const :tag "Source code" src-block) (const :tag "Special blocks" special-block)))) (defcustom org-latex-prefer-user-labels nil "Use user-provided labels instead of internal ones when non-nil. When this variable is non-nil, Org will use the value of CUSTOM_ID property, NAME keyword or Org target as the key for the \\label commands generated. By default, Org generates its own internal labels during LaTeX export. This process ensures that the \\label keys are unique and valid, but it means the keys are not available in advance of the export process. Setting this variable gives you control over how Org generates labels during LaTeX export, so that you may know their keys in advance. One reason to do this is that it allows you to refer to various elements using a single label both in Org's link syntax and in embedded LaTeX code. For example, when this variable is non-nil, a headline like this: ** Some section :PROPERTIES: :CUSTOM_ID: sec:foo :END: This is section [[#sec:foo]]. #+BEGIN_EXPORT latex And this is still section \\ref{sec:foo}. #+END_EXPORT will be exported to LaTeX as: \\subsection{Some section} \\label{sec:foo} This is section \\ref{sec:foo}. And this is still section \\ref{sec:foo}. A non-default value of `org-latex-reference-command' will change the command (\\ref by default) used to create label references. Note, however, that setting this variable introduces a limitation on the possible values for CUSTOM_ID and NAME. When this variable is non-nil, Org passes their value to \\label unchanged. You are responsible for ensuring that the value is a valid LaTeX \\label key, and that no other \\label commands with the same key appear elsewhere in your document. (Keys may contain letters, numbers, and the following punctuation: `_' `.' `-' `:'.) There are no such limitations on CUSTOM_ID and NAME when this variable is nil. For headlines that do not define the CUSTOM_ID property or elements without a NAME, Org will continue to use its default labeling scheme to generate labels and resolve links into proper references." :group 'org-export-latex :type 'boolean :version "26.1" :package-version '(Org . "8.3")) (defcustom org-latex-reference-command "\\ref{%s}" "Format string that takes a reference to produce a LaTeX reference command. The reference is a label such as sec:intro. A format string of \"\\ref{%s}\" produces numbered references and will always work. It may be desirable to make use of a package such as hyperref or cleveref and then change the format string to \"\\autoref{%s}\" or \"\\cref{%s}\" for example." :group 'org-export-latex :type 'string :package-version '(Org . "9.5") :safe #'stringp) ;;;; Preamble (defcustom org-latex-default-class "article" "The default LaTeX class." :group 'org-export-latex :type '(string :tag "LaTeX class")) (defcustom org-latex-classes '(("article" "\\documentclass[11pt]{article}" ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparagraph{%s}" . "\\subparagraph*{%s}")) ("report" "\\documentclass[11pt]{report}" ("\\part{%s}" . "\\part*{%s}") ("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}")) ("book" "\\documentclass[11pt]{book}" ("\\part{%s}" . "\\part*{%s}") ("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))) "Alist of LaTeX classes and associated header and structure. If #+LATEX_CLASS is set in the buffer, use its value and the associated information. Here is the structure of each cell: (class-name header-string (numbered-section . unnumbered-section) ...) The header string ----------------- The HEADER-STRING is the header that will be inserted into the LaTeX file. It should contain the \\documentclass macro, and anything else that is needed for this setup. To this header, the following commands will be added: - Calls to \\usepackage for all packages mentioned in the variables `org-latex-default-packages-alist' and `org-latex-packages-alist'. Thus, your header definitions should avoid to also request these packages. - Lines specified via \"#+LATEX_HEADER:\" and \"#+LATEX_HEADER_EXTRA:\" keywords. If you need more control about the sequence in which the header is built up, or if you want to exclude one of these building blocks for a particular class, you can use the following macro-like placeholders. [DEFAULT-PACKAGES] \\usepackage statements for default packages [NO-DEFAULT-PACKAGES] do not include any of the default packages [PACKAGES] \\usepackage statements for packages [NO-PACKAGES] do not include the packages [EXTRA] the stuff from #+LATEX_HEADER(_EXTRA) [NO-EXTRA] do not include #+LATEX_HEADER(_EXTRA) stuff So a header like \\documentclass{article} [NO-DEFAULT-PACKAGES] [EXTRA] \\providecommand{\\alert}[1]{\\textbf{#1}} [PACKAGES] will omit the default packages, and will include the #+LATEX_HEADER and #+LATEX_HEADER_EXTRA lines, then have a call to \\providecommand, and then place \\usepackage commands based on the content of `org-latex-packages-alist'. If your header, `org-latex-default-packages-alist' or `org-latex-packages-alist' inserts \"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be replaced with a coding system derived from `buffer-file-coding-system'. See also the variable `org-latex-inputenc-alist' for a way to influence this mechanism. Likewise, if your header contains \"\\usepackage[AUTO]{babel}\" or \"\\usepackage[AUTO]{polyglossia}\", AUTO will be replaced with the language related to the language code specified by `org-export-default-language'. Note that constructions such as \"\\usepackage[french,AUTO,english]{babel}\" are permitted. For Polyglossia the language will be set via the macros \"\\setmainlanguage\" and \"\\setotherlanguage\". See also `org-latex-guess-babel-language' and `org-latex-guess-polyglossia-language'. The sectioning structure ------------------------ The sectioning structure of the class is given by the elements following the header string. For each sectioning level, a number of strings is specified. A %s formatter is mandatory in each section string and will be replaced by the title of the section. Instead of a cons cell (numbered . unnumbered), you can also provide a list of 2 or 4 elements, (numbered-open numbered-close) or (numbered-open numbered-close unnumbered-open unnumbered-close) providing opening and closing strings for a LaTeX environment that should represent the document section. The opening clause should have a %s to represent the section title. Instead of a list of sectioning commands, you can also specify a function name. That function will be called with two parameters, the (reduced) level of the headline, and a predicate non-nil when the headline should be numbered. It must return a format string in which the section title will be added." :group 'org-export-latex :type '(repeat (list (string :tag "LaTeX class") (string :tag "LaTeX header") (repeat :tag "Levels" :inline t (choice (cons :tag "Heading" (string :tag " numbered") (string :tag "unnumbered")) (list :tag "Environment" (string :tag "Opening (numbered)") (string :tag "Closing (numbered)") (string :tag "Opening (unnumbered)") (string :tag "Closing (unnumbered)")) (function :tag "Hook computing sectioning")))))) (defcustom org-latex-inputenc-alist nil "Alist of inputenc coding system names, and what should really be used. For example, adding an entry (\"utf8\" . \"utf8x\") will cause \\usepackage[utf8x]{inputenc} to be used for buffers that are written as utf8 files." :group 'org-export-latex :type '(repeat (cons (string :tag "Derived from buffer") (string :tag "Use this instead")))) (defcustom org-latex-title-command "\\maketitle" "The command used to insert the title just after \\begin{document}. This format string may contain these elements: %a for AUTHOR keyword %t for TITLE keyword %s for SUBTITLE keyword %k for KEYWORDS line %d for DESCRIPTION line %c for CREATOR line %l for Language keyword %L for capitalized language keyword %D for DATE keyword If you need to use a \"%\" character, you need to escape it like that: \"%%\". Setting :latex-title-command in publishing projects will take precedence over this variable." :group 'org-export-latex :type '(string :tag "Format string")) (defcustom org-latex-subtitle-format "\\\\\\medskip\n\\large %s" "Format string used for transcoded subtitle. The format string should have at most one \"%s\"-expression, which is replaced with the subtitle." :group 'org-export-latex :version "26.1" :package-version '(Org . "8.3") :type '(string :tag "Format string")) (defcustom org-latex-subtitle-separate nil "Non-nil means the subtitle is not typeset as part of title." :group 'org-export-latex :version "26.1" :package-version '(Org . "8.3") :type 'boolean) (defcustom org-latex-toc-command "\\tableofcontents\n\n" "LaTeX command to set the table of contents, list of figures, etc. This command only applies to the table of contents generated with the toc:nil option, not to those generated with #+TOC keyword." :group 'org-export-latex :type 'string) (defcustom org-latex-hyperref-template "\\hypersetup{\n pdfauthor={%a},\n pdftitle={%t},\n pdfkeywords={%k}, pdfsubject={%d},\n pdfcreator={%c}, \n pdflang={%L}}\n" "Template for hyperref package options. This format string may contain these elements: %a for AUTHOR keyword %t for TITLE keyword %s for SUBTITLE keyword %k for KEYWORDS line %d for DESCRIPTION line %c for CREATOR line %l for Language keyword %L for capitalized language keyword %D for DATE keyword If you need to use a \"%\" character, you need to escape it like that: \"%%\". As a special case, a nil value prevents template from being inserted. Setting :latex-hyperref-template in publishing projects will take precedence over this variable." :group 'org-export-latex :version "26.1" :package-version '(Org . "8.3") :type '(choice (const :tag "No template" nil) (string :tag "Format string"))) ;;;; Headline (defcustom org-latex-format-headline-function 'org-latex-format-headline-default-function "Function for formatting the headline's text. This function will be called with six arguments: TODO the todo keyword (string or nil) TODO-TYPE the type of todo (symbol: `todo', `done', nil) PRIORITY the priority of the headline (integer or nil) TEXT the main headline text (string) TAGS the tags (list of strings or nil) INFO the export options (plist) The function result will be used in the section format string." :group 'org-export-latex :version "24.4" :package-version '(Org . "8.0") :type 'function) ;;;; Footnotes (defcustom org-latex-footnote-separator "\\textsuperscript{,}\\," "Text used to separate footnotes." :group 'org-export-latex :type 'string) (defcustom org-latex-footnote-defined-format "\\textsuperscript{\\ref{%s}}" "Format string used to format reference to footnote already defined. %s will be replaced by the label of the referred footnote." :group 'org-export-latex :type '(choice (const :tag "Use plain superscript (default)" "\\textsuperscript{\\ref{%s}}") (const :tag "Use Memoir/KOMA-Script footref" "\\footref{%s}") (string :tag "Other format string")) :version "26.1" :package-version '(Org . "9.0")) ;;;; Timestamps (defcustom org-latex-active-timestamp-format "\\textit{%s}" "A printf format string to be applied to active timestamps." :group 'org-export-latex :type 'string) (defcustom org-latex-inactive-timestamp-format "\\textit{%s}" "A printf format string to be applied to inactive timestamps." :group 'org-export-latex :type 'string) (defcustom org-latex-diary-timestamp-format "\\textit{%s}" "A printf format string to be applied to diary timestamps." :group 'org-export-latex :type 'string) ;;;; Links (defcustom org-latex-images-centered t "When non-nil, images are centered." :group 'org-export-latex :version "26.1" :package-version '(Org . "9.0") :type 'boolean :safe #'booleanp) (defcustom org-latex-image-default-option "" "Default option for images." :group 'org-export-latex :version "24.4" :package-version '(Org . "8.0") :type 'string) (defcustom org-latex-image-default-width ".9\\linewidth" "Default width for images. This value will not be used if a height is provided." :group 'org-export-latex :version "24.4" :package-version '(Org . "8.0") :type 'string) (defcustom org-latex-image-default-scale "" "Default scale for images. This value will not be used if a width or a scale is provided, or if the image is wrapped within a \"wrapfigure\" environment. Scale overrides width and height." :group 'org-export-latex :package-version '(Org . "9.3") :type 'string :safe #'stringp) (defcustom org-latex-image-default-height "" "Default height for images. This value will not be used if a width is provided, or if the image is wrapped within a \"figure\" or \"wrapfigure\" environment." :group 'org-export-latex :version "24.4" :package-version '(Org . "8.0") :type 'string) (defcustom org-latex-default-figure-position "htbp" "Default position for LaTeX figures." :group 'org-export-latex :type 'string :version "26.1" :package-version '(Org . "9.0") :safe #'stringp) (defcustom org-latex-inline-image-rules `(("file" . ,(rx "." (or "pdf" "jpeg" "jpg" "png" "ps" "eps" "tikz" "pgf" "svg") eos)) ("https" . ,(rx "." (or "jpeg" "jpg" "png" "ps" "eps" "tikz" "pgf" "svg") eos))) "Rules characterizing image files that can be inlined into LaTeX. A rule consists in an association whose key is the type of link to consider, and value is a regexp that will be matched against link's path. Note that, by default, the image extension *actually* allowed depend on the way the LaTeX file is processed. When used with pdflatex, pdf, jpg and png images are OK. When processing through dvi to Postscript, only ps and eps are allowed. The default we use here encompasses both." :group 'org-export-latex :package-version '(Org . "9.4") :type '(alist :key-type (string :tag "Type") :value-type (regexp :tag "Path"))) (defcustom org-latex-link-with-unknown-path-format "\\texttt{%s}" "Format string for links with unknown path type." :group 'org-export-latex :type 'string) ;;;; Tables (defcustom org-latex-default-table-environment "tabular" "Default environment used to build tables." :group 'org-export-latex :version "24.4" :package-version '(Org . "8.0") :type 'string) (defcustom org-latex-default-quote-environment "quote" "Default environment used to `quote' blocks." :group 'org-export-latex :package-version '(Org . "9.5") :type 'string :safe #'stringp) (defcustom org-latex-default-table-mode 'table "Default mode for tables. Value can be a symbol among: `table' Regular LaTeX table. `math' In this mode, every cell is considered as being in math mode and the complete table will be wrapped within a math environment. It is particularly useful to write matrices. `inline-math' This mode is almost the same as `math', but the math environment will be inlined. `verbatim' The table is exported as it appears in the Org buffer, within a verbatim environment. This value can be overridden locally with, i.e. \":mode math\" in LaTeX attributes. When modifying this variable, it may be useful to change `org-latex-default-table-environment' accordingly." :group 'org-export-latex :version "24.4" :package-version '(Org . "8.0") :type '(choice (const :tag "Table" table) (const :tag "Matrix" math) (const :tag "Inline matrix" inline-math) (const :tag "Verbatim" verbatim)) :safe (lambda (s) (memq s '(table math inline-math verbatim)))) (defcustom org-latex-tables-centered t "When non-nil, tables are exported in a center environment." :group 'org-export-latex :type 'boolean :safe #'booleanp) (defcustom org-latex-tables-booktabs nil "When non-nil, display tables in a formal \"booktabs\" style. This option assumes that the \"booktabs\" package is properly loaded in the header of the document. This value can be ignored locally with \":booktabs t\" and \":booktabs nil\" LaTeX attributes." :group 'org-export-latex :version "24.4" :package-version '(Org . "8.0") :type 'boolean :safe #'booleanp) (defcustom org-latex-table-scientific-notation nil "Format string to display numbers in scientific notation. The format should have \"%s\" twice, for mantissa and exponent \(i.e., \"%s\\\\times10^{%s}\"). When nil, no transformation is made." :group 'org-export-latex :version "24.4" :package-version '(Org . "8.0") :type '(choice (string :tag "Format string") (const :tag "No formatting" nil))) ;;;; Text markup (defcustom org-latex-text-markup-alist '((bold . "\\textbf{%s}") (code . protectedtexttt) (italic . "\\emph{%s}") (strike-through . "\\sout{%s}") (underline . "\\uline{%s}") (verbatim . protectedtexttt)) "Alist of LaTeX expressions to convert text markup. The key must be a symbol among `bold', `code', `italic', `strike-through', `underline' and `verbatim'. The value is a formatting string to wrap fontified text with. Value can also be set to the following symbols: `verb' and `protectedtexttt'. For the former, Org will use \"\\verb\" to create a format string and select a delimiter character that isn't in the string. For the latter, Org will use \"\\texttt\" to typeset and try to protect special characters. If no association can be found for a given markup, text will be returned as-is." :group 'org-export-latex :version "26.1" :package-version '(Org . "8.3") :type 'alist :options '(bold code italic strike-through underline verbatim)) ;;;; Drawers (defcustom org-latex-format-drawer-function (lambda (_ contents) contents) "Function called to format a drawer in LaTeX code. The function must accept two parameters: NAME the drawer name, like \"LOGBOOK\" CONTENTS the contents of the drawer. The function should return the string to be exported. The default function simply returns the value of CONTENTS." :group 'org-export-latex :version "26.1" :package-version '(Org . "8.3") :type 'function) ;;;; Inlinetasks (defcustom org-latex-format-inlinetask-function 'org-latex-format-inlinetask-default-function "Function called to format an inlinetask in LaTeX code. The function must accept seven parameters: TODO the todo keyword (string or nil) TODO-TYPE the todo type (symbol: `todo', `done', nil) PRIORITY the inlinetask priority (integer or nil) NAME the inlinetask name (string) TAGS the inlinetask tags (list of strings or nil) CONTENTS the contents of the inlinetask (string or nil) INFO the export options (plist) The function should return the string to be exported." :group 'org-export-latex :type 'function :version "26.1" :package-version '(Org . "8.3")) ;; Src blocks (defcustom org-latex-src-block-backend 'verbatim "Backend used to generate source code listings. This sets the behaviour for fontifying source code, possibly even with color. There are four implementations of this functionality you may choose from (ordered from least to most capable): 1. Verbatim 2. Listings 3. Minted 4. Engraved The first two options provide basic syntax highlighting (listings), or none at all (verbatim). When using listings, you also need to make use of LaTeX package \"listings\". The \"color\" LaTeX package is also needed if you would like color too. These can simply be added to `org-latex-packages-alist', using customise or something like: (require \\='ox-latex) (add-to-list \\='org-latex-packages-alist \\='(\"\" \"listings\")) (add-to-list \\='org-latex-packages-alist \\='(\"\" \"color\")) There are two further options for more comprehensive fontification. The first can be set with, (setq org-latex-src-block-backend \\='minted) which causes source code to be exported using the LaTeX package minted as opposed to listings. If you want to use minted, you need to add the minted package to `org-latex-packages-alist', for example using customize, or with (require \\='ox-latex) (add-to-list \\='org-latex-packages-alist \\='(\"newfloat\" \"minted\")) In addition, it is necessary to install pygments \(URL `https://pygments.org>'), and to configure the variable `org-latex-pdf-process' so that the -shell-escape option is passed to pdflatex. The minted choice has possible repercussions on the preview of latex fragments (see `org-preview-latex-fragment'). If you run into previewing problems, please consult URL `https://orgmode.org/worg/org-tutorials/org-latex-preview.html'. The most comprehensive option can be set with, (setq org-latex-src-block-backend \\='engraved) which causes source code to be run through `engrave-faces-latex-buffer', which generates colorings using Emacs' font-lock information. This requires the Emacs package engrave-faces (available from ELPA), and the LaTeX package fvextra be installed. The styling of the engraved result can be customised with `org-latex-engraved-preamble' and `org-latex-engraved-options'. The default preamble also uses the LaTeX package tcolorbox in addition to fvextra." :group 'org-export-latex :type '(choice (const :tag "Use listings" listings) (const :tag "Use minted" minted) (const :tag "Use engrave-faces-latex" engraved) (const :tag "Export verbatim" verbatim)) :safe (lambda (s) (memq s '(listings minted engraved verbatim)))) (defcustom org-latex-listings-langs '((emacs-lisp "Lisp") (lisp "Lisp") (clojure "Lisp") (c "C") (cc "C++") (fortran "fortran") (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby") (html "HTML") (xml "XML") (tex "TeX") (latex "[LaTeX]TeX") (shell-script "bash") (gnuplot "Gnuplot") (ocaml "[Objective]Caml") (caml "Caml") (sql "SQL") (sqlite "sql") (makefile "make") (R "r")) "Alist mapping languages to their listing language counterpart. The key is a symbol, the major mode symbol without the \"-mode\". The value is the string that should be inserted as the language parameter for the listings package. If the mode name and the listings name are the same, the language does not need an entry in this list - but it does not hurt if it is present." :group 'org-export-latex :version "26.1" :package-version '(Org . "8.3") :type '(repeat (list (symbol :tag "Major mode ") (string :tag "Listings language")))) (defcustom org-latex-listings-options nil "Association list of options for the latex listings package. These options are supplied as a comma-separated list to the \\lstset command. Each element of the association list should be a list or cons cell containing two strings: the name of the option, and the value. For example, (setq org-latex-listings-options \\='((\"basicstyle\" \"\\\\small\") (\"keywordstyle\" \"\\\\color{black}\\\\bfseries\\\\underbar\"))) ; or (setq org-latex-listings-options \\='((\"basicstyle\" . \"\\\\small\") (\"keywordstyle\" . \"\\\\color{black}\\\\bfseries\\\\underbar\"))) will typeset the code in a small size font with underlined, bold black keywords. Note that the same options will be applied to blocks of all languages. If you need block-specific options, you may use the following syntax: #+ATTR_LATEX: :options key1=value1,key2=value2 #+BEGIN_SRC ... #+END_SRC" :group 'org-export-latex :type '(repeat (list (string :tag "Listings option name ") (string :tag "Listings option value")))) (defcustom org-latex-minted-langs '((emacs-lisp "common-lisp") (cc "c++") (cperl "perl") (shell-script "bash") (caml "ocaml")) "Alist mapping languages to their minted language counterpart. The key is a symbol, the major mode symbol without the \"-mode\". The value is the string that should be inserted as the language parameter for the minted package. If the mode name and the listings name are the same, the language does not need an entry in this list - but it does not hurt if it is present. Note that minted uses all lower case for language identifiers, and that the full list of language identifiers can be obtained with: pygmentize -L lexers" :group 'org-export-latex :type '(repeat (list (symbol :tag "Major mode ") (string :tag "Minted language")))) (defcustom org-latex-minted-options nil "Association list of options for the latex minted package. These options are supplied within square brackets in \\begin{minted} environments. Each element of the alist should be a list or cons cell containing two strings: the name of the option, and the value. For example, (setq org-latex-minted-options \\='((\"bgcolor\" \"bg\") (\"frame\" \"lines\"))) ; or (setq org-latex-minted-options \\='((\"bgcolor\" . \"bg\") (\"frame\" . \"lines\"))) will result in source blocks being exported with \\begin{minted}[bgcolor=bg,frame=lines]{} as the start of the minted environment. Note that the same options will be applied to blocks of all languages. If you need block-specific options, you may use the following syntax: #+ATTR_LATEX: :options key1=value1,key2=value2 #+BEGIN_SRC ... #+END_SRC" :group 'org-export-latex :type '(repeat (list (string :tag "Minted option name ") (string :tag "Minted option value")))) (defcustom org-latex-custom-lang-environments nil "Alist mapping languages to language-specific LaTeX environments. It is used during export of source blocks by the listings and minted LaTeX packages. The environment may be a simple string, composed of only letters and numbers. In this case, the string is directly the name of the LaTeX environment to use. The environment may also be a format string. In this case the format string will be directly exported. This format string may contain these elements: %s for the formatted source %c for the caption %f for the float attribute %l for an appropriate label %o for the LaTeX attributes For example, (setq org-latex-custom-lang-environments \\='((python \"pythoncode\") (ocaml \"\\\\begin{listing} \\\\begin{minted}[%o]{ocaml} %s\\\\end{minted} \\\\caption{%c} \\\\label{%l}\"))) would have the effect that if Org encounters a Python source block during LaTeX export it will produce \\begin{pythoncode} \\end{pythoncode} and if Org encounters an Ocaml source block during LaTeX export it will produce \\begin{listing} \\begin{minted}[]{ocaml} \\end{minted} \\caption{} \\label{