org-latex.el 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164
  1. ;;; org-latex.el --- LaTeX exporter for org-mode
  2. ;;
  3. ;; Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
  4. ;;
  5. ;; Emacs Lisp Archive Entry
  6. ;; Filename: org-latex.el
  7. ;; Version: 6.33trans
  8. ;; Author: Bastien Guerry <bzg AT altern DOT org>
  9. ;; Maintainer: Carsten Dominik <carsten.dominik AT gmail DOT com>
  10. ;; Keywords: org, wp, tex
  11. ;; Description: Converts an org-mode buffer into LaTeX
  12. ;; This file is part of GNU Emacs.
  13. ;; GNU Emacs is free software: you can redistribute it and/or modify
  14. ;; it under the terms of the GNU General Public License as published by
  15. ;; the Free Software Foundation, either version 3 of the License, or
  16. ;; (at your option) any later version.
  17. ;; GNU Emacs is distributed in the hope that it will be useful,
  18. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. ;; GNU General Public License for more details.
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  23. ;;; Commentary:
  24. ;;
  25. ;; This library implements a LaTeX exporter for org-mode.
  26. ;;
  27. ;; It is part of Org and will be autoloaded
  28. ;;
  29. ;; The interactive functions are similar to those of the HTML exporter:
  30. ;;
  31. ;; M-x `org-export-as-latex'
  32. ;; M-x `org-export-as-pdf'
  33. ;; M-x `org-export-as-pdf-and-open'
  34. ;; M-x `org-export-as-latex-batch'
  35. ;; M-x `org-export-as-latex-to-buffer'
  36. ;; M-x `org-export-region-as-latex'
  37. ;; M-x `org-replace-region-by-latex'
  38. ;;
  39. ;;; Code:
  40. (eval-when-compile
  41. (require 'cl))
  42. (require 'footnote)
  43. (require 'org)
  44. (require 'org-exp)
  45. (require 'org-macs)
  46. (require 'org-beamer)
  47. ;;; Variables:
  48. (defvar org-export-latex-class nil)
  49. (defvar org-export-latex-class-options nil)
  50. (defvar org-export-latex-header nil)
  51. (defvar org-export-latex-append-header nil)
  52. (defvar org-export-latex-options-plist nil)
  53. (defvar org-export-latex-todo-keywords-1 nil)
  54. (defvar org-export-latex-complex-heading-re nil)
  55. (defvar org-export-latex-not-done-keywords nil)
  56. (defvar org-export-latex-done-keywords nil)
  57. (defvar org-export-latex-display-custom-times nil)
  58. (defvar org-export-latex-all-targets-re nil)
  59. (defvar org-export-latex-add-level 0)
  60. (defvar org-export-latex-sectioning "")
  61. (defvar org-export-latex-sectioning-depth 0)
  62. (defvar org-export-latex-special-keyword-regexp
  63. (concat "\\<\\(" org-scheduled-string "\\|"
  64. org-deadline-string "\\|"
  65. org-closed-string"\\)")
  66. "Regexp matching special time planning keywords plus the time after it.")
  67. (defvar latexp) ; dynamically scoped from org.el
  68. (defvar re-quote) ; dynamically scoped from org.el
  69. (defvar commentsp) ; dynamically scoped from org.el
  70. ;;; User variables:
  71. (defgroup org-export-latex nil
  72. "Options for exporting Org-mode files to LaTeX."
  73. :tag "Org Export LaTeX"
  74. :group 'org-export)
  75. (defcustom org-export-latex-default-class "article"
  76. "The default LaTeX class."
  77. :group 'org-export-latex
  78. :type '(string :tag "LaTeX class"))
  79. (defcustom org-export-latex-classes
  80. '(("article"
  81. "\\documentclass[11pt]{article}
  82. \\usepackage[utf8]{inputenc}
  83. \\usepackage[T1]{fontenc}
  84. \\usepackage{graphicx}
  85. \\usepackage{longtable}
  86. \\usepackage{float}
  87. \\usepackage{wrapfig}
  88. \\usepackage{soul}
  89. \\usepackage{amssymb}
  90. \\usepackage{hyperref}"
  91. ("\\section{%s}" . "\\section*{%s}")
  92. ("\\subsection{%s}" . "\\subsection*{%s}")
  93. ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
  94. ("\\paragraph{%s}" . "\\paragraph*{%s}")
  95. ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
  96. ("report"
  97. "\\documentclass[11pt]{report}
  98. \\usepackage[utf8]{inputenc}
  99. \\usepackage[T1]{fontenc}
  100. \\usepackage{graphicx}
  101. \\usepackage{longtable}
  102. \\usepackage{float}
  103. \\usepackage{wrapfig}
  104. \\usepackage{soul}
  105. \\usepackage{amssymb}
  106. \\usepackage{hyperref}"
  107. ("\\part{%s}" . "\\part*{%s}")
  108. ("\\chapter{%s}" . "\\chapter*{%s}")
  109. ("\\section{%s}" . "\\section*{%s}")
  110. ("\\subsection{%s}" . "\\subsection*{%s}")
  111. ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
  112. ("book"
  113. "\\documentclass[11pt]{book}
  114. \\usepackage[utf8]{inputenc}
  115. \\usepackage[T1]{fontenc}
  116. \\usepackage{graphicx}
  117. \\usepackage{longtable}
  118. \\usepackage{float}
  119. \\usepackage{wrapfig}
  120. \\usepackage{soul}
  121. \\usepackage{amssymb}
  122. \\usepackage{hyperref}"
  123. ("\\part{%s}" . "\\part*{%s}")
  124. ("\\chapter{%s}" . "\\chapter*{%s}")
  125. ("\\section{%s}" . "\\section*{%s}")
  126. ("\\subsection{%s}" . "\\subsection*{%s}")
  127. ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
  128. ("beamer"
  129. "\\documentclass{beamer}
  130. \\usepackage[utf8]{inputenc}
  131. \\usepackage[T1]{fontenc}
  132. \\usepackage{graphicx}
  133. \\usepackage{longtable}
  134. \\usepackage{float}
  135. \\usepackage{wrapfig}
  136. \\usepackage{soul}
  137. \\usepackage{amssymb}
  138. \\usepackage{hyperref}"
  139. org-beamer-sectioning
  140. ))
  141. "Alist of LaTeX classes and associated header and structure.
  142. If #+LaTeX_CLASS is set in the buffer, use its value and the
  143. associated information. Here is the structure of each cell:
  144. \(class-name
  145. header-string
  146. (numbered-section . unnumbered-section\)
  147. ...\)
  148. A %s formatter is mandatory in each section string and will be
  149. replaced by the title of the section.
  150. Instead of a cons cell (numbered . unnumbered), you can also provide a list
  151. of 2-4 elements,
  152. (numbered-open numbered-close)
  153. or
  154. (numbered-open numbered-close unnumbered-open unnumbered-close)
  155. providing opening and closing strings for an environment that should
  156. represent the document section. The opening clause should have a %s
  157. to represent the section title.
  158. Instead of a list of sectioning commands, you can also specify a
  159. function name. that function will be called with two parameters,
  160. the (reduced) level of the headline, and the headline text. The functions
  161. returns a cons cell with the (possibly modified) headline text, and the
  162. sectioning list in the cdr."
  163. :group 'org-export-latex
  164. :type '(repeat
  165. (list (string :tag "LaTeX class")
  166. (string :tag "LaTeX header")
  167. (repeat :tag "Levels" :inline t
  168. (choice
  169. (cons :tag "Heading"
  170. (string :tag " numbered")
  171. (string :tag "unnumbered"))
  172. (list :tag "Environment"
  173. (string :tag "Opening (numbered)")
  174. (string :tag "Closing (numbered)")
  175. (string :tag "Opening (unnumbered)")
  176. (string :tag "Closing (unnumbered)"))
  177. (function :tag "Hook computing sectioning"))))))
  178. (defcustom org-export-latex-emphasis-alist
  179. '(("*" "\\textbf{%s}" nil)
  180. ("/" "\\emph{%s}" nil)
  181. ("_" "\\underline{%s}" nil)
  182. ("+" "\\st{%s}" nil)
  183. ("=" "\\verb" t)
  184. ("~" "\\verb" t))
  185. "Alist of LaTeX expressions to convert emphasis fontifiers.
  186. Each element of the list is a list of three elements.
  187. The first element is the character used as a marker for fontification.
  188. The second element is a formatting string to wrap fontified text with.
  189. If it is \"\\verb\", Org will automatically select a delimiter
  190. character that is not in the string.
  191. The third element decides whether to protect converted text from other
  192. conversions."
  193. :group 'org-export-latex
  194. :type 'alist)
  195. (defcustom org-export-latex-title-command "\\maketitle"
  196. "The command used to insert the title just after \\begin{document}.
  197. If this string contains the formatting specification \"%s\" then
  198. it will be used as a formatting string, passing the title as an
  199. argument."
  200. :group 'org-export-latex
  201. :type 'string)
  202. (defcustom org-export-latex-import-inbuffer-stuff nil
  203. "Non-nil means define TeX macros for Org's inbuffer definitions.
  204. For example \orgTITLE for #+TITLE."
  205. :group 'org-export-latex
  206. :type 'boolean)
  207. (defcustom org-export-latex-date-format
  208. "%d %B %Y"
  209. "Format string for \\date{...}."
  210. :group 'org-export-latex
  211. :type 'string)
  212. (defcustom org-export-latex-todo-keyword-markup "\\textbf{%s}"
  213. "Markup for TODO keywords, as a printf format.
  214. This can be a single format for all keywords, a cons cell with separate
  215. formats for not-done and done states, or an association list with setup
  216. for individual keywords. If a keyword shows up for which there is no
  217. markup defined, the first one in the association list will be used."
  218. :group 'org-export-latex
  219. :type '(choice
  220. (string :tag "Default")
  221. (cons :tag "Distinguish undone and done"
  222. (string :tag "Not-DONE states")
  223. (string :tag "DONE states"))
  224. (repeat :tag "Per keyword markup"
  225. (cons
  226. (string :tag "Keyword")
  227. (string :tag "Markup")))))
  228. (defcustom org-export-latex-timestamp-markup "\\textit{%s}"
  229. "A printf format string to be applied to time stamps."
  230. :group 'org-export-latex
  231. :type 'string)
  232. (defcustom org-export-latex-timestamp-keyword-markup "\\texttt{%s}"
  233. "A printf format string to be applied to time stamps."
  234. :group 'org-export-latex
  235. :type 'string)
  236. (defcustom org-export-latex-tables-verbatim nil
  237. "When non-nil, tables are exported verbatim."
  238. :group 'org-export-latex
  239. :type 'boolean)
  240. (defcustom org-export-latex-tables-centered t
  241. "When non-nil, tables are exported in a center environment."
  242. :group 'org-export-latex
  243. :type 'boolean)
  244. (defcustom org-export-latex-tables-column-borders nil
  245. "When non-nil, grouping columns can cause outer vertical lines in tables.
  246. When nil, grouping causes only separation lines between groups."
  247. :group 'org-export-latex
  248. :type 'boolean)
  249. (defcustom org-export-latex-low-levels 'itemize
  250. "How to convert sections below the current level of sectioning.
  251. This is specified by the `org-export-headline-levels' option or the
  252. value of \"H:\" in Org's #+OPTION line.
  253. This can be either nil (skip the sections), `description', `itemize',
  254. or `enumerate' (convert the sections as the corresponding list type), or
  255. a string to be used instead of \\section{%s}. In this latter case,
  256. the %s stands here for the inserted headline and is mandatory.
  257. It may also be a list of three string to define a user-defined environment
  258. that should be used. The first string should be the like
  259. \"\\begin{itemize}\", the second should be like \"\\item %s %s\" with up
  260. to two occurrences of %s for the title and a label, respectively. The third
  261. string should be like \"\\end{itemize\"."
  262. :group 'org-export-latex
  263. :type '(choice (const :tag "Ignore" nil)
  264. (const :tag "Convert as descriptive list" description)
  265. (const :tag "Convert as itemized list" itemize)
  266. (const :tag "Convert as enumerated list" enumerate)
  267. (list :tag "User-defined environment"
  268. :value ("\\begin{itemize}" "\\end{itemize}" "\\item %s")
  269. (string :tag "Start")
  270. (string :tag "End")
  271. (string :tag "item"))
  272. (string :tag "Use a section string" :value "\\subparagraph{%s}")))
  273. (defcustom org-export-latex-list-parameters
  274. '(:cbon "$\\boxtimes$" :cboff "$\\Box$")
  275. "Parameters for the LaTeX list exporter.
  276. These parameters will be passed on to `org-list-to-latex', which in turn
  277. will pass them (combined with the LaTeX default list parameters) to
  278. `org-list-to-generic'."
  279. :group 'org-export-latex
  280. :type 'plist)
  281. (defcustom org-export-latex-verbatim-wrap
  282. '("\\begin{verbatim}\n" . "\\end{verbatim}\n")
  283. "Environment to be wrapped around a fixed-width section in LaTeX export.
  284. This is a cons with two strings, to be added before and after the
  285. fixed-with text.
  286. Defaults to \\begin{verbatim} and \\end{verbatim}."
  287. :group 'org-export-translation
  288. :group 'org-export-latex
  289. :type '(cons (string :tag "Open")
  290. (string :tag "Close")))
  291. (defcustom org-export-latex-listings nil
  292. "Non-nil means, export source code using the listings package.
  293. This package will fontify source code, possibly even with color.
  294. If you want to use this, you also need to make LaTeX use the
  295. listings package, and if you want to have color, the color
  296. package. Just add these to `org-export-latex-packages-alist',
  297. for example using customize, or with something like
  298. (require 'org-latex)
  299. (add-to-list 'org-export-latex-packages-alist '(\"\" \"listings\"))
  300. (add-to-list 'org-export-latex-packages-alist '(\"\" \"color\"))"
  301. :group 'org-export-latex
  302. :type 'boolean)
  303. (defcustom org-export-latex-listings-langs
  304. '((emacs-lisp "Lisp") (lisp "Lisp")
  305. (c "C") (cc "C++")
  306. (fortran "fortran")
  307. (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
  308. (html "HTML") (xml "XML")
  309. (tex "TeX") (latex "TeX")
  310. (shell-script "bash")
  311. (gnuplot "Gnuplot")
  312. (ocaml "Caml") (caml "Caml")
  313. (sql "SQL"))
  314. "Alist mapping languages to their listing language counterpart.
  315. The key is a symbol, the major mode symbol without the \"-mode\".
  316. The value is the string that should be inserted as the language parameter
  317. for the listings package. If the mode name and the listings name are
  318. the same, the language does not need an entry in this list - but it does not
  319. hurt if it is present."
  320. :group 'org-export-latex
  321. :type '(repeat
  322. (list
  323. (symbol :tag "Major mode ")
  324. (string :tag "Listings language"))))
  325. (defcustom org-export-latex-remove-from-headlines
  326. '(:todo nil :priority nil :tags nil)
  327. "A plist of keywords to remove from headlines. OBSOLETE.
  328. Non-nil means remove this keyword type from the headline.
  329. Don't remove the keys, just change their values.
  330. Obsolete, this variable is no longer used. Use the separate
  331. variables `org-export-with-todo-keywords', `org-export-with-priority',
  332. and `org-export-with-tags' instead."
  333. :type 'plist
  334. :group 'org-export-latex)
  335. (defcustom org-export-latex-image-default-option "width=10em"
  336. "Default option for images."
  337. :group 'org-export-latex
  338. :type 'string)
  339. (defcustom org-export-latex-inline-image-extensions
  340. '("pdf" "jpeg" "jpg" "png" "ps" "eps")
  341. "Extensions of image files that can be inlined into LaTeX.
  342. Note that the image extension *actually* allowed depend on the way the
  343. LaTeX file is processed. When used with pdflatex, pdf, jpg and png images
  344. are OK. When processing through dvi to Postscript, only ps and eps are
  345. allowed. The default we use here encompasses both."
  346. :group 'org-export-latex
  347. :type '(repeat (string :tag "Extension")))
  348. (defcustom org-export-latex-coding-system nil
  349. "Coding system for the exported LaTex file."
  350. :group 'org-export-latex
  351. :type 'coding-system)
  352. (defgroup org-export-pdf nil
  353. "Options for exporting Org-mode files to PDF, via LaTeX."
  354. :tag "Org Export PDF"
  355. :group 'org-export-latex
  356. :group 'org-export)
  357. (defcustom org-latex-to-pdf-process
  358. '("pdflatex -interaction nonstopmode %s"
  359. "pdflatex -interaction nonstopmode %s")
  360. "Commands to process a LaTeX file to a PDF file.
  361. This is a list of strings, each of them will be given to the shell
  362. as a command. %s in the command will be replaced by the full file name, %b
  363. by the file base name (i.e. without extension).
  364. The reason why this is a list is that it usually takes several runs of
  365. pdflatex, maybe mixed with a call to bibtex. Org does not have a clever
  366. mechanism to detect which of these commands have to be run to get to a stable
  367. result, and it also does not do any error checking.
  368. Alternatively, this may be a Lisp function that does the processing, so you
  369. could use this to apply the machinery of AUCTeX or the Emacs LaTeX mode.
  370. This function should accept the file name as its single argument."
  371. :group 'org-export-pdf
  372. :type '(choice (repeat :tag "Shell command sequence"
  373. (string :tag "Shell command"))
  374. (function)))
  375. (defcustom org-export-pdf-logfiles
  376. '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
  377. "The list of file extensions to consider as LaTeX logfiles."
  378. :group 'org-export-pdf
  379. :type '(repeat (string :tag "Extension")))
  380. (defcustom org-export-pdf-remove-logfiles t
  381. "Non-nil means, remove the logfiles produced by PDF production.
  382. These are the .aux, .log, .out, and .toc files."
  383. :group 'org-export-pdf
  384. :type 'boolean)
  385. ;;; Hooks
  386. (defvar org-export-latex-after-initial-vars-hook nil
  387. "Hook run before LaTeX export.
  388. The exact moment is after the initial variables like org-export-latex-class
  389. have been determined from the environment.")
  390. (defvar org-export-latex-after-blockquotes-hook nil
  391. "Hook run during LaTeX export, after blockquote, verse, center are done.")
  392. (defvar org-export-latex-final-hook nil
  393. "Hook run in the finalized LaTeX buffer.")
  394. ;;; Autoload functions:
  395. ;;;###autoload
  396. (defun org-export-as-latex-batch ()
  397. "Call `org-export-as-latex', may be used in batch processing.
  398. For example:
  399. emacs --batch
  400. --load=$HOME/lib/emacs/org.el
  401. --eval \"(setq org-export-headline-levels 2)\"
  402. --visit=MyFile --funcall org-export-as-latex-batch"
  403. (org-export-as-latex org-export-headline-levels 'hidden))
  404. ;;;###autoload
  405. (defun org-export-as-latex-to-buffer (arg)
  406. "Call `org-export-as-latex` with output to a temporary buffer.
  407. No file is created. The prefix ARG is passed through to `org-export-as-latex'."
  408. (interactive "P")
  409. (org-export-as-latex arg nil nil "*Org LaTeX Export*")
  410. (when org-export-show-temporary-export-buffer
  411. (switch-to-buffer-other-window "*Org LaTeX Export*")))
  412. ;;;###autoload
  413. (defun org-replace-region-by-latex (beg end)
  414. "Replace the region from BEG to END with its LaTeX export.
  415. It assumes the region has `org-mode' syntax, and then convert it to
  416. LaTeX. This can be used in any buffer. For example, you could
  417. write an itemized list in `org-mode' syntax in an LaTeX buffer and
  418. then use this command to convert it."
  419. (interactive "r")
  420. (let (reg latex buf)
  421. (save-window-excursion
  422. (if (org-mode-p)
  423. (setq latex (org-export-region-as-latex
  424. beg end t 'string))
  425. (setq reg (buffer-substring beg end)
  426. buf (get-buffer-create "*Org tmp*"))
  427. (with-current-buffer buf
  428. (erase-buffer)
  429. (insert reg)
  430. (org-mode)
  431. (setq latex (org-export-region-as-latex
  432. (point-min) (point-max) t 'string)))
  433. (kill-buffer buf)))
  434. (delete-region beg end)
  435. (insert latex)))
  436. ;;;###autoload
  437. (defun org-export-region-as-latex (beg end &optional body-only buffer)
  438. "Convert region from BEG to END in `org-mode' buffer to LaTeX.
  439. If prefix arg BODY-ONLY is set, omit file header, footer, and table of
  440. contents, and only produce the region of converted text, useful for
  441. cut-and-paste operations.
  442. If BUFFER is a buffer or a string, use/create that buffer as a target
  443. of the converted LaTeX. If BUFFER is the symbol `string', return the
  444. produced LaTeX as a string and leave no buffer behind. For example,
  445. a Lisp program could call this function in the following way:
  446. (setq latex (org-export-region-as-latex beg end t 'string))
  447. When called interactively, the output buffer is selected, and shown
  448. in a window. A non-interactive call will only return the buffer."
  449. (interactive "r\nP")
  450. (when (interactive-p)
  451. (setq buffer "*Org LaTeX Export*"))
  452. (let ((transient-mark-mode t) (zmacs-regions t)
  453. ext-plist rtn)
  454. (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
  455. (goto-char end)
  456. (set-mark (point)) ;; to activate the region
  457. (goto-char beg)
  458. (setq rtn (org-export-as-latex
  459. nil nil ext-plist
  460. buffer body-only))
  461. (if (fboundp 'deactivate-mark) (deactivate-mark))
  462. (if (and (interactive-p) (bufferp rtn))
  463. (switch-to-buffer-other-window rtn)
  464. rtn)))
  465. ;;;###autoload
  466. (defun org-export-as-latex (arg &optional hidden ext-plist
  467. to-buffer body-only pub-dir)
  468. "Export current buffer to a LaTeX file.
  469. If there is an active region, export only the region. The prefix
  470. ARG specifies how many levels of the outline should become
  471. headlines. The default is 3. Lower levels will be exported
  472. depending on `org-export-latex-low-levels'. The default is to
  473. convert them as description lists.
  474. HIDDEN is obsolete and does nothing.
  475. EXT-PLIST is a property list with
  476. external parameters overriding org-mode's default settings, but
  477. still inferior to file-local settings. When TO-BUFFER is
  478. non-nil, create a buffer with that name and export to that
  479. buffer. If TO-BUFFER is the symbol `string', don't leave any
  480. buffer behind but just return the resulting LaTeX as a string.
  481. When BODY-ONLY is set, don't produce the file header and footer,
  482. simply return the content of \begin{document}...\end{document},
  483. without even the \begin{document} and \end{document} commands.
  484. when PUB-DIR is set, use this as the publishing directory."
  485. (interactive "P")
  486. (run-hooks 'org-export-first-hook)
  487. ;; Make sure we have a file name when we need it.
  488. (when (and (not (or to-buffer body-only))
  489. (not buffer-file-name))
  490. (if (buffer-base-buffer)
  491. (org-set-local 'buffer-file-name
  492. (with-current-buffer (buffer-base-buffer)
  493. buffer-file-name))
  494. (error "Need a file name to be able to export")))
  495. (message "Exporting to LaTeX...")
  496. (org-unmodified
  497. (remove-text-properties (point-min) (point-max)
  498. '(:org-license-to-kill nil)))
  499. (org-update-radio-target-regexp)
  500. (org-export-latex-set-initial-vars ext-plist arg)
  501. (run-hooks 'org-export-latex-after-initial-vars-hook)
  502. (let* ((wcf (current-window-configuration))
  503. (opt-plist org-export-latex-options-plist)
  504. (region-p (org-region-active-p))
  505. (rbeg (and region-p (region-beginning)))
  506. (rend (and region-p (region-end)))
  507. (subtree-p
  508. (if (plist-get opt-plist :ignore-subtree-p)
  509. nil
  510. (when region-p
  511. (save-excursion
  512. (goto-char rbeg)
  513. (and (org-at-heading-p)
  514. (>= (org-end-of-subtree t t) rend))))))
  515. (opt-plist (setq org-export-opt-plist
  516. (if subtree-p
  517. (org-export-add-subtree-options opt-plist rbeg)
  518. opt-plist)))
  519. ;; Make sure the variable contains the updated values.
  520. (org-export-latex-options-plist opt-plist)
  521. (title (or (and subtree-p (org-export-get-title-from-subtree))
  522. (plist-get opt-plist :title)
  523. (and (not
  524. (plist-get opt-plist :skip-before-1st-heading))
  525. (org-export-grab-title-from-buffer))
  526. (file-name-sans-extension
  527. (file-name-nondirectory buffer-file-name))))
  528. (filename (concat (file-name-as-directory
  529. (or pub-dir
  530. (org-export-directory :LaTeX ext-plist)))
  531. (file-name-sans-extension
  532. (or (and subtree-p
  533. (org-entry-get rbeg "EXPORT_FILE_NAME" t))
  534. (file-name-nondirectory ;sans-extension
  535. buffer-file-name)))
  536. ".tex"))
  537. (filename (if (equal (file-truename filename)
  538. (file-truename buffer-file-name))
  539. (concat filename ".tex")
  540. filename))
  541. (buffer (if to-buffer
  542. (cond
  543. ((eq to-buffer 'string) (get-buffer-create
  544. "*Org LaTeX Export*"))
  545. (t (get-buffer-create to-buffer)))
  546. (find-file-noselect filename)))
  547. (odd org-odd-levels-only)
  548. (header (org-export-latex-make-header title opt-plist))
  549. (skip (cond (subtree-p nil)
  550. (region-p nil)
  551. (t (plist-get opt-plist :skip-before-1st-heading))))
  552. (text (plist-get opt-plist :text))
  553. (org-export-preprocess-hook
  554. (cons
  555. `(lambda () (org-set-local 'org-complex-heading-regexp
  556. ,org-export-latex-complex-heading-re))
  557. org-export-preprocess-hook))
  558. (first-lines (if skip "" (org-export-latex-first-lines
  559. opt-plist
  560. (if subtree-p
  561. (save-excursion
  562. (goto-char rbeg)
  563. (point-at-bol 2))
  564. rbeg)
  565. (if region-p rend))))
  566. (coding-system (and (boundp 'buffer-file-coding-system)
  567. buffer-file-coding-system))
  568. (coding-system-for-write (or org-export-latex-coding-system
  569. coding-system))
  570. (save-buffer-coding-system (or org-export-latex-coding-system
  571. coding-system))
  572. (region (buffer-substring
  573. (if region-p (region-beginning) (point-min))
  574. (if region-p (region-end) (point-max))))
  575. (string-for-export
  576. (org-export-preprocess-string
  577. region
  578. :emph-multiline t
  579. :for-LaTeX t
  580. :comments nil
  581. :tags (plist-get opt-plist :tags)
  582. :priority (plist-get opt-plist :priority)
  583. :footnotes (plist-get opt-plist :footnotes)
  584. :drawers (plist-get opt-plist :drawers)
  585. :timestamps (plist-get opt-plist :timestamps)
  586. :todo-keywords (plist-get opt-plist :todo-keywords)
  587. :add-text (if (eq to-buffer 'string) nil text)
  588. :skip-before-1st-heading skip
  589. :select-tags (plist-get opt-plist :select-tags)
  590. :exclude-tags (plist-get opt-plist :exclude-tags)
  591. :LaTeX-fragments nil)))
  592. (set-buffer buffer)
  593. (erase-buffer)
  594. (org-install-letbind)
  595. (and (fboundp 'set-buffer-file-coding-system)
  596. (set-buffer-file-coding-system coding-system-for-write))
  597. ;; insert the header and initial document commands
  598. (unless (or (eq to-buffer 'string) body-only)
  599. (insert header))
  600. ;; insert text found in #+TEXT
  601. (when (and text (not (eq to-buffer 'string)))
  602. (insert (org-export-latex-content
  603. text '(lists tables fixed-width keywords))
  604. "\n\n"))
  605. ;; insert lines before the first headline
  606. (unless skip
  607. (insert first-lines))
  608. ;; export the content of headlines
  609. (org-export-latex-global
  610. (with-temp-buffer
  611. (insert string-for-export)
  612. (goto-char (point-min))
  613. (when (re-search-forward "^\\(\\*+\\) " nil t)
  614. (let* ((asters (length (match-string 1)))
  615. (level (if odd (- asters 2) (- asters 1))))
  616. (setq org-export-latex-add-level
  617. (if odd (1- (/ (1+ asters) 2)) (1- asters)))
  618. (org-export-latex-parse-global level odd)))))
  619. ;; finalization
  620. (unless body-only (insert "\n\\end{document}"))
  621. ;; Attach description terms to the \item macro
  622. (goto-char (point-min))
  623. (while (re-search-forward "^[ \t]*\\\\item\\([ \t]+\\)\\[" nil t)
  624. (delete-region (match-beginning 1) (match-end 1)))
  625. ;; Relocate the table of contents
  626. (goto-char (point-min))
  627. (when (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
  628. (goto-char (point-min))
  629. (while (re-search-forward "\\\\tableofcontents\\>[ \t]*\n?" nil t)
  630. (replace-match ""))
  631. (goto-char (point-min))
  632. (and (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
  633. (replace-match "\\tableofcontents" t t)))
  634. ;; Cleanup forced line ends in itmes where they are not needed
  635. (goto-char (point-min))
  636. (while (re-search-forward
  637. "^[ \t]*\\\\item\\>.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)?\n\\\\begin"
  638. nil t)
  639. (delete-region (match-beginning 1) (match-end 1)))
  640. (run-hooks 'org-export-latex-final-hook)
  641. (or to-buffer (save-buffer))
  642. (goto-char (point-min))
  643. (or (org-export-push-to-kill-ring "LaTeX")
  644. (message "Exporting to LaTeX...done"))
  645. (prog1
  646. (if (eq to-buffer 'string)
  647. (prog1 (buffer-substring (point-min) (point-max))
  648. (kill-buffer (current-buffer)))
  649. (current-buffer))
  650. (set-window-configuration wcf))))
  651. ;;;###autoload
  652. (defun org-export-as-pdf (arg &optional hidden ext-plist
  653. to-buffer body-only pub-dir)
  654. "Export as LaTeX, then process through to PDF."
  655. (interactive "P")
  656. (message "Exporting to PDF...")
  657. (let* ((wconfig (current-window-configuration))
  658. (lbuf (org-export-as-latex arg hidden ext-plist
  659. to-buffer body-only pub-dir))
  660. (file (buffer-file-name lbuf))
  661. (base (file-name-sans-extension (buffer-file-name lbuf)))
  662. (pdffile (concat base ".pdf"))
  663. (cmds org-latex-to-pdf-process)
  664. (outbuf (get-buffer-create "*Org PDF LaTeX Output*"))
  665. (bibtex-p (with-current-buffer lbuf
  666. (save-excursion
  667. (goto-char (point-min))
  668. (re-search-forward "\\\\bibliography{" nil t))))
  669. cmd)
  670. (with-current-buffer outbuf (erase-buffer))
  671. (message "Processing LaTeX file...")
  672. (if (and cmds (symbolp cmds))
  673. (funcall cmds file)
  674. (while cmds
  675. (setq cmd (pop cmds))
  676. (while (string-match "%b" cmd)
  677. (setq cmd (replace-match
  678. (save-match-data
  679. (shell-quote-argument base))
  680. t t cmd)))
  681. (while (string-match "%s" cmd)
  682. (setq cmd (replace-match
  683. (save-match-data
  684. (shell-quote-argument file))
  685. t t cmd)))
  686. (shell-command cmd outbuf outbuf)))
  687. (message "Processing LaTeX file...done")
  688. (if (not (file-exists-p pdffile))
  689. (error "PDF file was not produced")
  690. (set-window-configuration wconfig)
  691. (when org-export-pdf-remove-logfiles
  692. (dolist (ext org-export-pdf-logfiles)
  693. (setq file (concat base "." ext))
  694. (and (file-exists-p file) (delete-file file))))
  695. (message "Exporting to PDF...done")
  696. pdffile)))
  697. ;;;###autoload
  698. (defun org-export-as-pdf-and-open (arg)
  699. "Export as LaTeX, then process through to PDF, and open."
  700. (interactive "P")
  701. (let ((pdffile (org-export-as-pdf arg)))
  702. (if pdffile
  703. (org-open-file pdffile)
  704. (error "PDF file was not produced"))))
  705. ;;; Parsing functions:
  706. (defun org-export-latex-parse-global (level odd)
  707. "Parse the current buffer recursively, starting at LEVEL.
  708. If ODD is non-nil, assume the buffer only contains odd sections.
  709. Return a list reflecting the document structure."
  710. (save-excursion
  711. (goto-char (point-min))
  712. (let* ((cnt 0) output
  713. (depth org-export-latex-sectioning-depth))
  714. (while (org-re-search-forward-unprotected
  715. (concat "^\\(\\(?:\\*\\)\\{"
  716. (number-to-string (+ (if odd 2 1) level))
  717. "\\}\\) \\(.*\\)$")
  718. ;; make sure that there is no upper heading
  719. (when (> level 0)
  720. (save-excursion
  721. (save-match-data
  722. (org-re-search-forward-unprotected
  723. (concat "^\\(\\(?:\\*\\)\\{"
  724. (number-to-string level)
  725. "\\}\\) \\(.*\\)$") nil t)))) t)
  726. (setq cnt (1+ cnt))
  727. (let* ((pos (match-beginning 0))
  728. (heading (match-string 2))
  729. (nlevel (if odd (/ (+ 3 level) 2) (1+ level))))
  730. (save-excursion
  731. (narrow-to-region
  732. (point)
  733. (save-match-data
  734. (if (org-re-search-forward-unprotected
  735. (concat "^\\(\\(?:\\*\\)\\{"
  736. (number-to-string (+ (if odd 2 1) level))
  737. "\\}\\) \\(.*\\)$") nil t)
  738. (match-beginning 0)
  739. (point-max))))
  740. (goto-char (point-min))
  741. (setq output
  742. (append output
  743. (list
  744. (list
  745. `(pos . ,pos)
  746. `(level . ,nlevel)
  747. `(occur . ,cnt)
  748. `(heading . ,heading)
  749. `(content . ,(org-export-latex-parse-content))
  750. `(subcontent . ,(org-export-latex-parse-subcontent
  751. level odd)))))))
  752. (widen)))
  753. (list output))))
  754. (defun org-export-latex-parse-content ()
  755. "Extract the content of a section."
  756. (let ((beg (point))
  757. (end (if (org-re-search-forward-unprotected "^\\(\\*\\)+ .*$" nil t)
  758. (progn (beginning-of-line) (point))
  759. (point-max))))
  760. (buffer-substring beg end)))
  761. (defun org-export-latex-parse-subcontent (level odd)
  762. "Extract the subcontent of a section at LEVEL.
  763. If ODD Is non-nil, assume subcontent only contains odd sections."
  764. (if (not (org-re-search-forward-unprotected
  765. (concat "^\\(\\(?:\\*\\)\\{"
  766. (number-to-string (+ (if odd 4 2) level))
  767. "\\}\\) \\(.*\\)$")
  768. nil t))
  769. nil ; subcontent is nil
  770. (org-export-latex-parse-global (+ (if odd 2 1) level) odd)))
  771. ;;; Rendering functions:
  772. (defun org-export-latex-global (content)
  773. "Export CONTENT to LaTeX.
  774. CONTENT is an element of the list produced by
  775. `org-export-latex-parse-global'."
  776. (if (eq (car content) 'subcontent)
  777. (mapc 'org-export-latex-sub (cdr content))
  778. (org-export-latex-sub (car content))))
  779. (defun org-export-latex-sub (subcontent)
  780. "Export the list SUBCONTENT to LaTeX.
  781. SUBCONTENT is an alist containing information about the headline
  782. and its content."
  783. (let ((num (plist-get org-export-latex-options-plist :section-numbers)))
  784. (mapc (lambda(x) (org-export-latex-subcontent x num)) subcontent)))
  785. (defun org-export-latex-subcontent (subcontent num)
  786. "Export each cell of SUBCONTENT to LaTeX.
  787. If NUM, export sections as numerical sections."
  788. (let* ((heading (cdr (assoc 'heading subcontent)))
  789. (level (- (cdr (assoc 'level subcontent))
  790. org-export-latex-add-level))
  791. (occur (number-to-string (cdr (assoc 'occur subcontent))))
  792. (content (cdr (assoc 'content subcontent)))
  793. (subcontent (cadr (assoc 'subcontent subcontent)))
  794. (label (org-get-text-property-any 0 'target heading))
  795. (label-list (cons label (cdr (assoc label
  796. org-export-target-aliases))))
  797. (sectioning org-export-latex-sectioning)
  798. (depth org-export-latex-sectioning-depth)
  799. main-heading sub-heading)
  800. (when (symbolp (car sectioning))
  801. (setq sectioning (funcall (car sectioning) level heading))
  802. (when sectioning
  803. (setq heading (car sectioning)
  804. sectioning (cdr sectioning)))
  805. (if sectioning (setq sectioning (make-list 10 sectioning)))
  806. (setq depth (if sectioning 10000 0)))
  807. (if (string-match "[ \t]*\\\\\\\\[ \t]*" heading)
  808. (setq main-heading (substring heading 0 (match-beginning 0))
  809. sub-heading (substring heading (match-end 0))))
  810. (setq heading (org-export-latex-fontify-headline heading)
  811. sub-heading (and sub-heading
  812. (org-export-latex-fontify-headline sub-heading))
  813. main-heading (and main-heading
  814. (org-export-latex-fontify-headline main-heading)))
  815. (cond
  816. ;; Normal conversion
  817. ((<= level depth)
  818. (let* ((sec (nth (1- level) sectioning))
  819. start end)
  820. (if (consp (cdr sec))
  821. (setq start (nth (if num 0 2) sec)
  822. end (nth (if num 1 3) sec))
  823. (setq start (if num (car sec) (cdr sec))))
  824. (insert (format start (if main-heading main-heading heading)
  825. (or sub-heading "")))
  826. (insert "\n")
  827. (when label
  828. (insert (mapconcat (lambda (l) (format "\\label{%s}" l))
  829. label-list "\n") "\n"))
  830. (insert (org-export-latex-content content))
  831. (cond ((stringp subcontent) (insert subcontent))
  832. ((listp subcontent)
  833. (while (org-looking-back "\n\n") (backward-delete-char 1))
  834. (org-export-latex-sub subcontent)))
  835. (when (and end (string-match "[^ \t]" end))
  836. (let ((hook (org-get-text-property-any 0 'org-insert-hook end)))
  837. (and (functionp hook) (funcall hook)))
  838. (insert end "\n"))))
  839. ;; At a level under the hl option: we can drop this subsection
  840. ((> level depth)
  841. (cond ((eq org-export-latex-low-levels 'description)
  842. (if (string-match "% ends low level$"
  843. (buffer-substring (point-at-bol 0) (point)))
  844. (delete-region (point-at-bol 0) (point))
  845. (insert "\\begin{description}\n"))
  846. (insert (format "\n\\item[%s]%s~\n"
  847. heading
  848. (if label (format "\\label{%s}" label) "")))
  849. (insert (org-export-latex-content content))
  850. (cond ((stringp subcontent) (insert subcontent))
  851. ((listp subcontent) (org-export-latex-sub subcontent)))
  852. (insert "\\end{description} % ends low level\n"))
  853. ((memq org-export-latex-low-levels '(itemize enumerate))
  854. (if (string-match "% ends low level$"
  855. (buffer-substring (point-at-bol 0) (point)))
  856. (delete-region (point-at-bol 0) (point))
  857. (insert (format "\\begin{%s}\n"
  858. (symbol-name org-export-latex-low-levels))))
  859. (insert (format "\n\\item %s\\\\\n%s%%"
  860. heading
  861. (if label (format "\\label{%s}" label) "")))
  862. (insert (org-export-latex-content content))
  863. (cond ((stringp subcontent) (insert subcontent))
  864. ((listp subcontent) (org-export-latex-sub subcontent)))
  865. (insert (format "\\end{%s} %% ends low level\n"
  866. (symbol-name org-export-latex-low-levels))))
  867. ((listp org-export-latex-low-levels)
  868. (if (string-match "% ends low level$"
  869. (buffer-substring (point-at-bol 0) (point)))
  870. (delete-region (point-at-bol 0) (point))
  871. (insert (car org-export-latex-low-levels) "\n"))
  872. (insert (format (nth 2 org-export-latex-low-levels)
  873. heading
  874. (if label (format "\\label{%s}" label) "")))
  875. (insert (org-export-latex-content content))
  876. (cond ((stringp subcontent) (insert subcontent))
  877. ((listp subcontent) (org-export-latex-sub subcontent)))
  878. (insert (nth 1 org-export-latex-low-levels)
  879. " %% ends low level\n"))
  880. ((stringp org-export-latex-low-levels)
  881. (insert (format org-export-latex-low-levels heading) "\n")
  882. (when label (insert (format "\\label{%s}\n" label)))
  883. (insert (org-export-latex-content content))
  884. (cond ((stringp subcontent) (insert subcontent))
  885. ((listp subcontent) (org-export-latex-sub subcontent)))))))))
  886. ;;; Exporting internals:
  887. (defun org-export-latex-set-initial-vars (ext-plist level)
  888. "Store org local variables required for LaTeX export.
  889. EXT-PLIST is an optional additional plist.
  890. LEVEL indicates the default depth for export."
  891. (setq org-export-latex-todo-keywords-1 org-todo-keywords-1
  892. org-export-latex-done-keywords org-done-keywords
  893. org-export-latex-not-done-keywords org-not-done-keywords
  894. org-export-latex-complex-heading-re org-complex-heading-regexp
  895. org-export-latex-display-custom-times org-display-custom-times
  896. org-export-latex-all-targets-re
  897. (org-make-target-link-regexp (org-all-targets))
  898. org-export-latex-options-plist
  899. (org-combine-plists (org-default-export-plist) ext-plist
  900. (org-infile-export-plist))
  901. org-export-latex-class
  902. (or (and (org-region-active-p)
  903. (save-excursion
  904. (goto-char (region-beginning))
  905. (and (looking-at org-complex-heading-regexp)
  906. (org-entry-get nil "LaTeX_CLASS" 'selective))))
  907. (save-excursion
  908. (save-restriction
  909. (widen)
  910. (goto-char (point-min))
  911. (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\([a-zA-Z]+\\)" nil t)
  912. (match-string 1))))
  913. (plist-get org-export-latex-options-plist :latex-class)
  914. org-export-latex-default-class)
  915. org-export-latex-class-options
  916. (or (and (org-region-active-p)
  917. (save-excursion
  918. (goto-char (region-beginning))
  919. (and (looking-at org-complex-heading-regexp)
  920. (org-entry-get nil "LaTeX_CLASS_OPTIONS" 'selective))))
  921. (save-excursion
  922. (save-restriction
  923. (widen)
  924. (goto-char (point-min))
  925. (and (re-search-forward "^#\\+LaTeX_CLASS_OPTIONS:[ \t]*\\(.*?\\)[ \t]*$" nil t)
  926. (match-string 1))))
  927. (plist-get org-export-latex-options-plist :latex-class-options))
  928. org-export-latex-class
  929. (or (car (assoc org-export-latex-class org-export-latex-classes))
  930. (error "No definition for class `%s' in `org-export-latex-classes'"
  931. org-export-latex-class))
  932. org-export-latex-header
  933. (cadr (assoc org-export-latex-class org-export-latex-classes))
  934. org-export-latex-sectioning
  935. (cddr (assoc org-export-latex-class org-export-latex-classes))
  936. org-export-latex-sectioning-depth
  937. (or level
  938. (let ((hl-levels
  939. (plist-get org-export-latex-options-plist :headline-levels))
  940. (sec-depth (length org-export-latex-sectioning)))
  941. (if (> hl-levels sec-depth) sec-depth hl-levels))))
  942. (when (and org-export-latex-class-options
  943. (string-match "\\S-" org-export-latex-class-options)
  944. (string-match "^[ \t]*\\(\\\\documentclass\\)\\(\\[.*?\\]\\)?"
  945. org-export-latex-header))
  946. (setq org-export-latex-header
  947. (concat (substring org-export-latex-header 0 (match-end 1))
  948. org-export-latex-class-options
  949. (substring org-export-latex-header (match-end 0))))))
  950. (defvar org-export-latex-format-toc-function
  951. 'org-export-latex-format-toc-default
  952. "The function formatting returning the string to createthe table of contents.
  953. The function mus take one parameter, the depth of the table of contents.")
  954. (defun org-export-latex-make-header (title opt-plist)
  955. "Make the LaTeX header and return it as a string.
  956. TITLE is the current title from the buffer or region.
  957. OPT-PLIST is the options plist for current buffer."
  958. (let ((toc (plist-get opt-plist :table-of-contents))
  959. (author (plist-get opt-plist :author)))
  960. (concat
  961. (if (plist-get opt-plist :time-stamp-file)
  962. (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  963. ;; insert LaTeX custom header
  964. (org-export-apply-macros-in-string org-export-latex-header)
  965. "\n"
  966. ;; insert information on LaTeX packages
  967. (when org-export-latex-packages-alist
  968. (concat
  969. (mapconcat (lambda(p)
  970. (if (equal "" (car p))
  971. (format "\\usepackage{%s}" (cadr p))
  972. (format "\\usepackage[%s]{%s}"
  973. (car p) (cadr p))))
  974. org-export-latex-packages-alist "\n")
  975. "\n"))
  976. ;; insert additional commands in the header
  977. (org-export-apply-macros-in-string
  978. (plist-get opt-plist :latex-header-extra))
  979. (org-export-apply-macros-in-string org-export-latex-append-header)
  980. ;; insert the title
  981. (format
  982. "\n\n\\title{%s}\n"
  983. ;; convert the title
  984. (org-export-latex-content
  985. title '(lists tables fixed-width keywords)))
  986. ;; insert author info
  987. (if (plist-get opt-plist :author-info)
  988. (format "\\author{%s}\n"
  989. (org-export-latex-fontify-headline (or author user-full-name)))
  990. (format "%%\\author{%s}\n"
  991. (or author user-full-name)))
  992. ;; insert the date
  993. (format "\\date{%s}\n"
  994. (format-time-string
  995. (or (plist-get opt-plist :date)
  996. org-export-latex-date-format)))
  997. ;; beginning of the document
  998. "\n\\begin{document}\n\n"
  999. ;; insert the title command
  1000. (when (string-match "\\S-" title)
  1001. (if (string-match "%s" org-export-latex-title-command)
  1002. (format org-export-latex-title-command title)
  1003. org-export-latex-title-command))
  1004. "\n\n"
  1005. ;; table of contents
  1006. (when (and org-export-with-toc
  1007. (plist-get opt-plist :section-numbers))
  1008. (funcall org-export-latex-format-toc-function
  1009. (cond ((numberp toc)
  1010. (min toc (plist-get opt-plist :headline-levels)))
  1011. (toc (plist-get opt-plist :headline-levels))))))))
  1012. (defun org-export-latex-format-toc-default (depth)
  1013. (when depth
  1014. (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\\vspace*{1cm}\n"
  1015. depth)))
  1016. (defun org-export-latex-first-lines (opt-plist &optional beg end)
  1017. "Export the first lines before first headline.
  1018. If BEG is non-nil, it is the beginning of the region.
  1019. If END is non-nil, it is the end of the region."
  1020. (save-excursion
  1021. (goto-char (or beg (point-min)))
  1022. (let* ((pt (point))
  1023. (end (if (re-search-forward "^\\*+ " end t)
  1024. (goto-char (match-beginning 0))
  1025. (goto-char (or end (point-max))))))
  1026. (prog1
  1027. (org-export-latex-content
  1028. (org-export-preprocess-string
  1029. (buffer-substring pt end)
  1030. :for-LaTeX t
  1031. :emph-multiline t
  1032. :add-text nil
  1033. :comments nil
  1034. :skip-before-1st-heading nil
  1035. :LaTeX-fragments nil
  1036. :timestamps (plist-get opt-plist :timestamps)
  1037. :footnotes (plist-get opt-plist :footnotes)))
  1038. (org-unmodified
  1039. (add-text-properties pt (max pt (1- end))
  1040. '(:org-license-to-kill t)))))))
  1041. (defvar org-export-latex-header-defs nil
  1042. "The header definitions that might be used in the LaTeX body.")
  1043. (defvar org-export-latex-header-defs-re nil
  1044. "The header definitions that might be used in the LaTeX body.")
  1045. (defun org-export-latex-content (content &optional exclude-list)
  1046. "Convert CONTENT string to LaTeX.
  1047. Don't perform conversions that are in EXCLUDE-LIST. Recognized
  1048. conversion types are: quotation-marks, emphasis, sub-superscript,
  1049. links, keywords, lists, tables, fixed-width"
  1050. (with-temp-buffer
  1051. (insert content)
  1052. (unless (memq 'timestamps exclude-list)
  1053. (org-export-latex-time-stamps))
  1054. (unless (memq 'quotation-marks exclude-list)
  1055. (org-export-latex-quotation-marks))
  1056. (unless (memq 'emphasis exclude-list)
  1057. (when (plist-get org-export-latex-options-plist :emphasize)
  1058. (org-export-latex-fontify)))
  1059. (unless (memq 'sub-superscript exclude-list)
  1060. (org-export-latex-special-chars
  1061. (plist-get org-export-latex-options-plist :sub-superscript)))
  1062. (unless (memq 'links exclude-list)
  1063. (org-export-latex-links))
  1064. (unless (memq 'keywords exclude-list)
  1065. (org-export-latex-keywords))
  1066. (unless (memq 'lists exclude-list)
  1067. (org-export-latex-lists))
  1068. (unless (memq 'tables exclude-list)
  1069. (org-export-latex-tables
  1070. (plist-get org-export-latex-options-plist :tables)))
  1071. (unless (memq 'fixed-width exclude-list)
  1072. (org-export-latex-fixed-width
  1073. (plist-get org-export-latex-options-plist :fixed-width)))
  1074. ;; return string
  1075. (buffer-substring (point-min) (point-max))))
  1076. (defun org-export-latex-protect-string (s)
  1077. "Add the org-protected property to string S."
  1078. (add-text-properties 0 (length s) '(org-protected t) s) s)
  1079. (defun org-export-latex-protect-char-in-string (char-list string)
  1080. "Add org-protected text-property to char from CHAR-LIST in STRING."
  1081. (with-temp-buffer
  1082. (save-match-data
  1083. (insert string)
  1084. (goto-char (point-min))
  1085. (while (re-search-forward (regexp-opt char-list) nil t)
  1086. (add-text-properties (match-beginning 0)
  1087. (match-end 0) '(org-protected t)))
  1088. (buffer-string))))
  1089. (defun org-export-latex-keywords-maybe (&optional remove-list)
  1090. "Maybe remove keywords depending on rules in REMOVE-LIST."
  1091. (goto-char (point-min))
  1092. (let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1 "\\|"))
  1093. (case-fold-search nil)
  1094. (todo-markup org-export-latex-todo-keyword-markup)
  1095. fmt)
  1096. ;; convert TODO keywords
  1097. (when (re-search-forward (concat "^\\(" re-todo "\\)") nil t)
  1098. (if (plist-get remove-list :todo)
  1099. (replace-match "")
  1100. (setq fmt (cond
  1101. ((stringp todo-markup) todo-markup)
  1102. ((and (consp todo-markup) (stringp (car todo-markup)))
  1103. (if (member (match-string 1) org-export-latex-done-keywords)
  1104. (cdr todo-markup) (car todo-markup)))
  1105. (t (cdr (or (assoc (match-string 1) todo-markup)
  1106. (car todo-markup))))))
  1107. (replace-match (format fmt (match-string 1)) t t)))
  1108. ;; convert priority string
  1109. (when (re-search-forward "\\[\\\\#.\\]" nil t)
  1110. (if (plist-get remove-list :priority)
  1111. (replace-match "")
  1112. (replace-match (format "\\textbf{%s}" (match-string 0)) t t)))
  1113. ;; convert tags
  1114. (when (re-search-forward "\\(:[a-zA-Z0-9_@]+\\)+:" nil t)
  1115. (if (or (not org-export-with-tags)
  1116. (plist-get remove-list :tags))
  1117. (replace-match "")
  1118. (replace-match
  1119. (org-export-latex-protect-string
  1120. (format "\\textbf{%s}"
  1121. (save-match-data
  1122. (replace-regexp-in-string
  1123. "_" "\\\\_" (match-string 0)))))
  1124. t t)))))
  1125. (defun org-export-latex-fontify-headline (string)
  1126. "Fontify special words in STRING."
  1127. (with-temp-buffer
  1128. ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
  1129. ;; the beginning of the buffer - inserting "\n" is safe here though.
  1130. (insert "\n" string)
  1131. (goto-char (point-min))
  1132. (let ((re (concat "\\\\[a-zA-Z]+\\(?:"
  1133. "\\[.*\\]"
  1134. "\\)?"
  1135. (org-create-multibrace-regexp "{" "}" 3))))
  1136. (while (re-search-forward re nil t)
  1137. (unless (save-excursion (goto-char (match-beginning 0))
  1138. (equal (char-after (point-at-bol)) ?#))
  1139. (add-text-properties (match-beginning 0) (match-end 0)
  1140. '(org-protected t)))))
  1141. (when (plist-get org-export-latex-options-plist :emphasize)
  1142. (org-export-latex-fontify))
  1143. (org-export-latex-keywords-maybe)
  1144. (org-export-latex-special-chars
  1145. (plist-get org-export-latex-options-plist :sub-superscript))
  1146. (org-export-latex-links)
  1147. (org-trim (buffer-string))))
  1148. (defun org-export-latex-time-stamps ()
  1149. "Format time stamps."
  1150. (goto-char (point-min))
  1151. (let ((org-display-custom-times org-export-latex-display-custom-times))
  1152. (while (re-search-forward org-ts-regexp-both nil t)
  1153. (org-if-unprotected-at (1- (point))
  1154. (replace-match
  1155. (org-export-latex-protect-string
  1156. (format org-export-latex-timestamp-markup
  1157. (substring (org-translate-time (match-string 0)) 1 -1)))
  1158. t t)))))
  1159. (defun org-export-latex-quotation-marks ()
  1160. "Export quotation marks depending on language conventions."
  1161. (let* ((lang (plist-get org-export-latex-options-plist :language))
  1162. (quote-rpl (if (equal lang "fr")
  1163. '(("\\(\\s-\\)\"" "«~")
  1164. ("\\(\\S-\\)\"" "~»")
  1165. ("\\(\\s-\\)'" "`"))
  1166. '(("\\(\\s-\\|[[(]\\)\"" "``")
  1167. ("\\(\\S-\\)\"" "''")
  1168. ("\\(\\s-\\|(\\)'" "`")))))
  1169. (mapc (lambda(l) (goto-char (point-min))
  1170. (while (re-search-forward (car l) nil t)
  1171. (let ((rpl (concat (match-string 1)
  1172. (org-export-latex-protect-string
  1173. (copy-sequence (cadr l))))))
  1174. (org-if-unprotected-1
  1175. (replace-match rpl t t))))) quote-rpl)))
  1176. (defun org-export-latex-special-chars (sub-superscript)
  1177. "Export special characters to LaTeX.
  1178. If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
  1179. See the `org-export-latex.el' code for a complete conversion table."
  1180. (goto-char (point-min))
  1181. (mapc (lambda(c)
  1182. (goto-char (point-min))
  1183. (while (re-search-forward c nil t)
  1184. ;; Put the point where to check for org-protected
  1185. (unless (get-text-property (match-beginning 2) 'org-protected)
  1186. (cond ((member (match-string 2) '("\\$" "$"))
  1187. (if (equal (match-string 2) "\\$")
  1188. nil
  1189. (replace-match "\\$" t t)))
  1190. ((member (match-string 2) '("&" "%" "#"))
  1191. (if (equal (match-string 1) "\\")
  1192. (replace-match (match-string 2) t t)
  1193. (replace-match (concat (match-string 1) "\\"
  1194. (match-string 2)) t t)))
  1195. ((equal (match-string 2) "...")
  1196. (replace-match
  1197. (concat (match-string 1)
  1198. (org-export-latex-protect-string "\\ldots{}")) t t))
  1199. ((equal (match-string 2) "~")
  1200. (cond ((equal (match-string 1) "\\") nil)
  1201. ((eq 'org-link (get-text-property 0 'face (match-string 2)))
  1202. (replace-match (concat (match-string 1) "\\~") t t))
  1203. (t (replace-match
  1204. (org-export-latex-protect-string
  1205. (concat (match-string 1) "\\~{}")) t t))))
  1206. ((member (match-string 2) '("{" "}"))
  1207. (unless (save-match-data (org-inside-latex-math-p))
  1208. (if (equal (match-string 1) "\\")
  1209. (replace-match (match-string 2) t t)
  1210. (replace-match (concat (match-string 1) "\\"
  1211. (match-string 2)) t t)))))
  1212. (unless (save-match-data (org-inside-latex-math-p))
  1213. (cond ((equal (match-string 2) "\\")
  1214. (replace-match (or (save-match-data
  1215. (org-export-latex-treat-backslash-char
  1216. (match-string 1)
  1217. (or (match-string 3) "")))
  1218. "") t t))
  1219. ((member (match-string 2) '("_" "^"))
  1220. (replace-match (or (save-match-data
  1221. (org-export-latex-treat-sub-super-char
  1222. sub-superscript
  1223. (match-string 2)
  1224. (match-string 1)
  1225. (match-string 3))) "") t t)
  1226. (backward-char 1)))))))
  1227. '(;"^\\([^\n$]*?\\|^\\)\\(\\\\?\\$\\)\\([^\n$]*\\)$"
  1228. "\\(\\(\\\\?\\$\\)\\)"
  1229. "\\([a-za-z0-9]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\({[^{}]+}\\|[a-za-z0-9]+\\|[ \t\n]\\|[:punct:]\\|)\\|{[a-za-z0-9]+}\\|([a-za-z0-9]+)\\)"
  1230. "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|[a-zA-Z&#%{}\"]+\\)"
  1231. "\\(.\\|^\\)\\(&\\)"
  1232. "\\(.\\|^\\)\\(#\\)"
  1233. "\\(.\\|^\\)\\(%\\)"
  1234. "\\(.\\|^\\)\\({\\)"
  1235. "\\(.\\|^\\)\\(}\\)"
  1236. "\\(.\\|^\\)\\(~\\)"
  1237. "\\(.\\|^\\)\\(\\.\\.\\.\\)"
  1238. ;; (?\< . "\\textless{}")
  1239. ;; (?\> . "\\textgreater{}")
  1240. )))
  1241. (defun org-inside-latex-math-p ()
  1242. (get-text-property (point) 'org-latex-math))
  1243. (defun org-export-latex-treat-sub-super-char
  1244. (subsup char string-before string-after)
  1245. "Convert the \"_\" and \"^\" characters to LaTeX.
  1246. SUBSUP corresponds to the ^: option in the #+OPTIONS line.
  1247. Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
  1248. (cond ((equal string-before "\\")
  1249. (concat string-before char string-after))
  1250. ((and (string-match "\\S-+" string-after))
  1251. ;; this is part of a math formula
  1252. (cond ((eq 'org-link (get-text-property 0 'face char))
  1253. (concat string-before "\\" char string-after))
  1254. ((save-match-data (org-inside-latex-math-p))
  1255. (if subsup
  1256. (cond ((eq 1 (length string-after))
  1257. (concat string-before char string-after))
  1258. ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after)
  1259. (format "%s%s{%s}" string-before char
  1260. (match-string 1 string-after))))))
  1261. ((and (> (length string-after) 1)
  1262. (or (eq subsup t)
  1263. (and (equal subsup '{}) (eq (string-to-char string-after) ?\{)))
  1264. (string-match "[({]?\\([^)}]+\\)[)}]?" string-after))
  1265. (org-export-latex-protect-string
  1266. (format "%s$%s{%s}$" string-before char
  1267. (if (and (> (match-end 1) (1+ (match-beginning 1)))
  1268. (not (equal (substring string-after 0 2) "{\\")))
  1269. (concat "\\mathrm{" (match-string 1 string-after) "}")
  1270. (match-string 1 string-after)))))
  1271. ((eq subsup t) (concat string-before "$" char string-after "$"))
  1272. (t (org-export-latex-protect-string
  1273. (concat string-before "\\" char "{}" string-after)))))
  1274. (t (org-export-latex-protect-string
  1275. (concat string-before "\\" char "{}" string-after)))))
  1276. (defun org-export-latex-treat-backslash-char (string-before string-after)
  1277. "Convert the \"$\" special character to LaTeX.
  1278. The conversion is made depending of STRING-BEFORE and STRING-AFTER."
  1279. (cond ((member (list string-after) org-html-entities)
  1280. ;; backslash is part of a special entity (like "\alpha")
  1281. (concat string-before "$\\"
  1282. (or (cdar (member (list string-after) org-html-entities))
  1283. string-after) "$"))
  1284. ((and (not (string-match "^[ \n\t]" string-after))
  1285. (not (string-match "[ \t]\\'\\|^" string-before)))
  1286. ;; backslash is inside a word
  1287. (org-export-latex-protect-string
  1288. (concat string-before "\\textbackslash{}" string-after)))
  1289. ((not (or (equal string-after "")
  1290. (string-match "^[ \t\n]" string-after)))
  1291. ;; backslash might escape a character (like \#) or a user TeX
  1292. ;; macro (like \setcounter)
  1293. (org-export-latex-protect-string
  1294. (concat string-before "\\" string-after)))
  1295. ((and (string-match "^[ \t\n]" string-after)
  1296. (string-match "[ \t\n]\\'" string-before))
  1297. ;; backslash is alone, convert it to $\backslash$
  1298. (org-export-latex-protect-string
  1299. (concat string-before "\\textbackslash{}" string-after)))
  1300. (t (org-export-latex-protect-string
  1301. (concat string-before "\\textbackslash{}" string-after)))))
  1302. (defun org-export-latex-keywords ()
  1303. "Convert special keywords to LaTeX."
  1304. (goto-char (point-min))
  1305. (while (re-search-forward org-export-latex-special-keyword-regexp nil t)
  1306. (replace-match (format org-export-latex-timestamp-keyword-markup
  1307. (match-string 0)) t t)
  1308. (save-excursion
  1309. (beginning-of-line 1)
  1310. (unless (looking-at ".*\\\\newline[ \t]*$")
  1311. (end-of-line 1)
  1312. (insert "\\newline")))))
  1313. (defun org-export-latex-fixed-width (opt)
  1314. "When OPT is non-nil convert fixed-width sections to LaTeX."
  1315. (goto-char (point-min))
  1316. (while (re-search-forward "^[ \t]*:\\([ \t]\\|$\\)" nil t)
  1317. (if opt
  1318. (progn (goto-char (match-beginning 0))
  1319. (insert "\\begin{verbatim}\n")
  1320. (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
  1321. (replace-match (concat (match-string 1)
  1322. (match-string 2)) t t)
  1323. (forward-line))
  1324. (insert "\\end{verbatim}\n\n"))
  1325. (progn (goto-char (match-beginning 0))
  1326. (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
  1327. (replace-match (concat "%" (match-string 1)
  1328. (match-string 2)) t t)
  1329. (forward-line))))))
  1330. (defvar org-table-last-alignment) ; defined in org-table.el
  1331. (defvar org-table-last-column-widths) ; defined in org-table.el
  1332. (declare-function orgtbl-to-latex "org-table" (table params) t)
  1333. (defun org-export-latex-tables (insert)
  1334. "Convert tables to LaTeX and INSERT it."
  1335. (goto-char (point-min))
  1336. (while (re-search-forward "^\\([ \t]*\\)|" nil t)
  1337. (org-if-unprotected-at (1- (point))
  1338. (org-table-align)
  1339. (let* ((beg (org-table-begin))
  1340. (end (org-table-end))
  1341. (raw-table (buffer-substring beg end))
  1342. (org-table-last-alignment (copy-sequence org-table-last-alignment))
  1343. (org-table-last-column-widths (copy-sequence
  1344. org-table-last-column-widths))
  1345. fnum fields line lines olines gr colgropen line-fmt align
  1346. caption label attr floatp longtblp)
  1347. (if org-export-latex-tables-verbatim
  1348. (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
  1349. "\\end{verbatim}\n")))
  1350. (apply 'delete-region (list beg end))
  1351. (insert (org-export-latex-protect-string tbl)))
  1352. (progn
  1353. (setq caption (org-find-text-property-in-string
  1354. 'org-caption raw-table)
  1355. attr (org-find-text-property-in-string
  1356. 'org-attributes raw-table)
  1357. label (org-find-text-property-in-string
  1358. 'org-label raw-table)
  1359. longtblp (and attr (stringp attr)
  1360. (string-match "\\<longtable\\>" attr))
  1361. align (and attr (stringp attr)
  1362. (string-match "\\<align=\\([^ \t\n\r,]+\\)" attr)
  1363. (match-string 1 attr))
  1364. floatp (or caption label))
  1365. (setq lines (org-split-string raw-table "\n"))
  1366. (apply 'delete-region (list beg end))
  1367. (when org-export-table-remove-special-lines
  1368. (setq lines (org-table-clean-before-export lines 'maybe-quoted)))
  1369. (when org-table-clean-did-remove-column
  1370. (pop org-table-last-alignment)
  1371. (pop org-table-last-column-widths))
  1372. ;; make a formatting string to reflect alignment
  1373. (setq olines lines)
  1374. (while (and (not line-fmt) (setq line (pop olines)))
  1375. (unless (string-match "^[ \t]*|-" line)
  1376. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  1377. (setq fnum (make-vector (length fields) 0))
  1378. (setq line-fmt
  1379. (mapconcat
  1380. (lambda (x)
  1381. (setq gr (pop org-table-colgroup-info))
  1382. (format "%s%%s%s"
  1383. (cond ((eq gr :start)
  1384. (prog1 (if colgropen "|" "|")
  1385. (setq colgropen t)))
  1386. ((eq gr :startend)
  1387. (prog1 (if colgropen "|" "|")
  1388. (setq colgropen nil)))
  1389. (t ""))
  1390. (if (memq gr '(:end :startend))
  1391. (progn (setq colgropen nil) "|")
  1392. "")))
  1393. fnum ""))))
  1394. ;; fix double || in line-fmt
  1395. (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
  1396. ;; maybe remove the first and last "|"
  1397. (when (and (not org-export-latex-tables-column-borders)
  1398. (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
  1399. (setq line-fmt (match-string 2 line-fmt)))
  1400. ;; format alignment
  1401. (unless align
  1402. (setq align (apply 'format
  1403. (cons line-fmt
  1404. (mapcar (lambda (x) (if x "r" "l"))
  1405. org-table-last-alignment)))))
  1406. ;; prepare the table to send to orgtbl-to-latex
  1407. (setq lines
  1408. (mapcar
  1409. (lambda(elem)
  1410. (or (and (string-match "[ \t]*|-+" elem) 'hline)
  1411. (org-split-string (org-trim elem) "|")))
  1412. lines))
  1413. (when insert
  1414. (insert (org-export-latex-protect-string
  1415. (concat
  1416. (if longtblp
  1417. (concat "\\begin{longtable}{" align "}\n")
  1418. (if floatp "\\begin{table}[htb]\n"))
  1419. (if (or floatp longtblp)
  1420. (format
  1421. "\\caption{%s%s}"
  1422. (if label (concat "\\\label{" label "}") "")
  1423. (or caption "")))
  1424. (if longtblp "\\\\\n" "\n")
  1425. (if (and org-export-latex-tables-centered (not longtblp))
  1426. "\\begin{center}\n")
  1427. (if (not longtblp) (concat "\\begin{tabular}{" align "}\n"))
  1428. (orgtbl-to-latex
  1429. lines
  1430. `(:tstart nil :tend nil
  1431. :hlend ,(if longtblp
  1432. (format "\\\\
  1433. \\hline
  1434. \\endhead
  1435. \\hline\\multicolumn{%d}{r}{Continued on next page}\\
  1436. \\endfoot
  1437. \\endlastfoot" (length org-table-last-alignment))
  1438. nil)))
  1439. (if (not longtblp) (concat "\n\\end{tabular}"))
  1440. (if longtblp "\n" (if org-export-latex-tables-centered
  1441. "\n\\end{center}\n" "\n"))
  1442. (if longtblp
  1443. "\\end{longtable}"
  1444. (if floatp "\\end{table}"))))
  1445. "\n\n"))))))))
  1446. (defun org-export-latex-fontify ()
  1447. "Convert fontification to LaTeX."
  1448. (goto-char (point-min))
  1449. (while (re-search-forward org-emph-re nil t)
  1450. ;; The match goes one char after the *string*, except at the end of a line
  1451. (let ((emph (assoc (match-string 3)
  1452. org-export-latex-emphasis-alist))
  1453. (beg (match-beginning 0))
  1454. (end (match-end 0))
  1455. rpl s)
  1456. (unless emph
  1457. (message "`org-export-latex-emphasis-alist' has no entry for formatting triggered by \"%s\""
  1458. (match-string 3)))
  1459. (unless (or (and (get-text-property (- (point) 2) 'org-protected)
  1460. (not (get-text-property
  1461. (- (point) 2) 'org-verbatim-emph)))
  1462. (save-excursion
  1463. (goto-char (match-beginning 1))
  1464. (save-match-data
  1465. (and (org-at-table-p)
  1466. (string-match
  1467. "[|\n]" (buffer-substring beg end))))))
  1468. (setq s (match-string 4))
  1469. (setq rpl (concat (match-string 1)
  1470. (org-export-latex-emph-format (cadr emph)
  1471. (match-string 4))
  1472. (match-string 5)))
  1473. (if (caddr emph)
  1474. (setq rpl (org-export-latex-protect-string rpl))
  1475. (save-match-data
  1476. (if (string-match "\\`.?\\(\\\\[a-z]+{\\)\\(.*\\)\\(}\\).?\\'" rpl)
  1477. (progn
  1478. (add-text-properties (match-beginning 1) (match-end 1)
  1479. '(org-protected t) rpl)
  1480. (add-text-properties (match-beginning 3) (match-end 3)
  1481. '(org-protected t) rpl)))))
  1482. (replace-match rpl t t)))
  1483. (backward-char)))
  1484. (defvar org-export-latex-use-verb nil)
  1485. (defun org-export-latex-emph-format (format string)
  1486. "Format an emphasis string and handle the \\verb special case."
  1487. (when (equal format "\\verb")
  1488. (save-match-data
  1489. (if org-export-latex-use-verb
  1490. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  1491. (catch 'exit
  1492. (loop for i from 0 to (1- (length ll)) do
  1493. (if (not (string-match (regexp-quote (substring ll i (1+ i)))
  1494. string))
  1495. (progn
  1496. (setq format (concat "\\verb" (substring ll i (1+ i))
  1497. "%s" (substring ll i (1+ i))))
  1498. (throw 'exit nil))))))
  1499. (let ((start 0)
  1500. (trans '(("\\" . "\\textbackslash{}")
  1501. ("~" . "\\textasciitilde{}")
  1502. ("^" . "\\textasciicircum{}")))
  1503. (rtn "") char)
  1504. (while (string-match "[\\{}$%&_#~^]" string)
  1505. (setq char (match-string 0 string))
  1506. (if (> (match-beginning 0) 0)
  1507. (setq rtn (concat rtn (substring string
  1508. 0 (match-beginning 0)))))
  1509. (setq string (substring string (1+ (match-beginning 0))))
  1510. (setq char (or (cdr (assoc char trans)) (concat "\\" char))
  1511. rtn (concat rtn char)))
  1512. (setq string (concat rtn string) format "\\texttt{%s}")))))
  1513. (format format string))
  1514. (defun org-export-latex-links ()
  1515. ;; Make sure to use the LaTeX hyperref and graphicx package
  1516. ;; or send some warnings.
  1517. "Convert links to LaTeX."
  1518. (goto-char (point-min))
  1519. (while (re-search-forward org-bracket-link-analytic-regexp++ nil t)
  1520. (org-if-unprotected-1
  1521. (goto-char (match-beginning 0))
  1522. (let* ((re-radio org-export-latex-all-targets-re)
  1523. (remove (list (match-beginning 0) (match-end 0)))
  1524. (raw-path (org-extract-attributes (match-string 3)))
  1525. (full-raw-path (concat (match-string 1) raw-path))
  1526. (desc (match-string 5))
  1527. (type (or (match-string 2)
  1528. (if (or (file-name-absolute-p raw-path)
  1529. (string-match "^\\.\\.?/" raw-path))
  1530. "file")))
  1531. (coderefp (equal type "coderef"))
  1532. (caption (org-find-text-property-in-string 'org-caption raw-path))
  1533. (attr (or (org-find-text-property-in-string 'org-attributes raw-path)
  1534. (plist-get org-export-latex-options-plist :latex-image-options)))
  1535. (label (org-find-text-property-in-string 'org-label raw-path))
  1536. imgp radiop
  1537. ;; define the path of the link
  1538. (path (cond
  1539. ((member type '("coderef"))
  1540. raw-path)
  1541. ((member type '("http" "https" "ftp"))
  1542. (concat type ":" raw-path))
  1543. ((and re-radio (string-match re-radio raw-path))
  1544. (setq radiop t))
  1545. ((equal type "mailto")
  1546. (concat type ":" raw-path))
  1547. ((equal type "file")
  1548. (if (and (org-file-image-p
  1549. (expand-file-name
  1550. raw-path)
  1551. org-export-latex-inline-image-extensions)
  1552. (or (get-text-property 0 'org-no-description
  1553. raw-path)
  1554. (equal desc full-raw-path)))
  1555. (setq imgp t)
  1556. (progn (when (string-match "\\(.+\\)::.+" raw-path)
  1557. (setq raw-path (match-string 1 raw-path)))
  1558. (if (file-exists-p raw-path)
  1559. (concat type "://" (expand-file-name raw-path))
  1560. (concat type "://" (org-export-directory
  1561. :LaTeX org-export-latex-options-plist)
  1562. raw-path))))))))
  1563. ;; process with link inserting
  1564. (apply 'delete-region remove)
  1565. (cond ((and imgp
  1566. (plist-get org-export-latex-options-plist :inline-images))
  1567. ;; OK, we need to inline an image
  1568. (insert
  1569. (org-export-latex-format-image raw-path caption label attr)))
  1570. (coderefp
  1571. (insert (format
  1572. (org-export-get-coderef-format path desc)
  1573. (cdr (assoc path org-export-code-refs)))))
  1574. (radiop (insert (format "\\hyperref[%s]{%s}"
  1575. (org-solidify-link-text raw-path) desc)))
  1576. ((not type)
  1577. (insert (format "\\hyperref[%s]{%s}"
  1578. (org-remove-initial-hash
  1579. (org-solidify-link-text raw-path))
  1580. desc)))
  1581. (path
  1582. (when (org-at-table-p)
  1583. ;; There is a strange problem when we have a link in a table,
  1584. ;; ampersands then cause a problem. I think this must be
  1585. ;; a LaTeX issue, but we here implement a work-around anyway.
  1586. (setq path (org-export-latex-protect-amp path)
  1587. desc (org-export-latex-protect-amp desc)))
  1588. (insert (format "\\href{%s}{%s}" path desc)))
  1589. (t (insert "\\texttt{" desc "}")))))))
  1590. (defun org-export-latex-format-image (path caption label attr)
  1591. "Format the image element, depending on user settings."
  1592. (let (ind floatp wrapp placement figenv)
  1593. (setq floatp (or caption label))
  1594. (setq ind (org-get-text-property-any 0 'original-indentation path))
  1595. (when (and attr (stringp attr))
  1596. (if (string-match "[ \t]*\\<wrap\\>" attr)
  1597. (setq wrapp t floatp nil attr (replace-match "" t t attr)))
  1598. (if (string-match "[ \t]*\\<float\\>" attr)
  1599. (setq wrapp nil floatp t attr (replace-match "" t t attr))))
  1600. (setq placement
  1601. (cond
  1602. (wrapp "{l}{0.5\\textwidth}")
  1603. (floatp "[htb]")
  1604. (t "")))
  1605. (when (and attr (stringp attr)
  1606. (string-match "[ \t]*\\<placement=\\(\\S-+\\)" attr))
  1607. (setq placement (match-string 1 attr)
  1608. attr (replace-match "" t t attr)))
  1609. (setq attr (and attr (org-trim attr)))
  1610. (when (or (not attr) (= (length attr) 0))
  1611. (setq attr (cond (floatp "width=0.7\\textwidth")
  1612. (wrapp "width=0.48\\textwidth")
  1613. (t attr))))
  1614. (setq figenv
  1615. (cond
  1616. (wrapp "\\begin{wrapfigure}%placement
  1617. \\centering
  1618. \\includegraphics[%attr]{%path}
  1619. \\caption{%labelcmd%caption}
  1620. \\end{wrapfigure}")
  1621. (floatp "\\begin{figure}%placement
  1622. \\centering
  1623. \\includegraphics[%attr]{%path}
  1624. \\caption{%labelcmd%caption}
  1625. \\end{figure}")
  1626. (t "\\includegraphics[%attr]{%path}")))
  1627. (setq figenv (mapconcat 'identity (split-string figenv "\n")
  1628. (save-excursion (beginning-of-line 1)
  1629. (looking-at "[ \t]*")
  1630. (concat "\n" (match-string 0)))))
  1631. (if (and (not label) (not caption)
  1632. (string-match "^\\\\caption{.*\n" figenv))
  1633. (setq figenv (replace-match "" t t figenv)))
  1634. (org-add-props
  1635. (org-fill-template
  1636. figenv
  1637. (list (cons "path"
  1638. (if (file-name-absolute-p path)
  1639. (expand-file-name path)
  1640. path))
  1641. (cons "attr" attr)
  1642. (cons "labelcmd" (if label (format "\\label{%s}"
  1643. label)""))
  1644. (cons "caption" (or caption ""))
  1645. (cons "placement" (or placement ""))))
  1646. nil 'original-indentation ind)))
  1647. (defun org-export-latex-protect-amp (s)
  1648. (while (string-match "\\([^\\\\]\\)\\(&\\)" s)
  1649. (setq s (replace-match (concat (match-string 1 s) "\\" (match-string 2 s))
  1650. t t s)))
  1651. s)
  1652. (defun org-remove-initial-hash (s)
  1653. (if (string-match "\\`#" s)
  1654. (substring s 1)
  1655. s))
  1656. (defvar org-latex-entities) ; defined below
  1657. (defvar org-latex-entities-regexp) ; defined below
  1658. (defvar org-latex-entities-exceptions) ; defined below
  1659. (defun org-export-latex-preprocess (parameters)
  1660. "Clean stuff in the LaTeX export."
  1661. ;; Preserve line breaks
  1662. (goto-char (point-min))
  1663. (while (re-search-forward "\\\\\\\\" nil t)
  1664. (add-text-properties (match-beginning 0) (match-end 0)
  1665. '(org-protected t)))
  1666. ;; Preserve latex environments
  1667. (goto-char (point-min))
  1668. (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\*?\\)}" nil t)
  1669. (let* ((start (progn (beginning-of-line) (point)))
  1670. (end (and (re-search-forward
  1671. (concat "^[ \t]*\\\\end{"
  1672. (regexp-quote (match-string 1))
  1673. "}") nil t)
  1674. (point-at-eol))))
  1675. (if end
  1676. (add-text-properties start end '(org-protected t))
  1677. (goto-char (point-at-eol)))))
  1678. ;; Preserve math snippets
  1679. (let* ((matchers (plist-get org-format-latex-options :matchers))
  1680. (re-list org-latex-regexps)
  1681. beg end re e m n block off)
  1682. ;; Check the different regular expressions
  1683. (while (setq e (pop re-list))
  1684. (setq m (car e) re (nth 1 e) n (nth 2 e)
  1685. block (if (nth 3 e) "\n\n" ""))
  1686. (setq off (if (member m '("$" "$1")) 1 0))
  1687. (when (and (member m matchers) (not (equal m "begin")))
  1688. (goto-char (point-min))
  1689. (while (re-search-forward re nil t)
  1690. (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
  1691. (add-text-properties beg end '(org-protected t org-latex-math t))))))
  1692. ;; Convert LaTeX to \LaTeX{}
  1693. (goto-char (point-min))
  1694. (let ((case-fold-search nil))
  1695. (while (re-search-forward "\\([^+_]\\)LaTeX" nil t)
  1696. (org-if-unprotected
  1697. (replace-match (org-export-latex-protect-string
  1698. (concat (match-string 1) "\\LaTeX{}")) t t))))
  1699. ;; Convert blockquotes
  1700. (goto-char (point-min))
  1701. (while (search-forward "ORG-BLOCKQUOTE-START" nil t)
  1702. (org-replace-match-keep-properties "\\begin{quote}" t t))
  1703. (goto-char (point-min))
  1704. (while (search-forward "ORG-BLOCKQUOTE-END" nil t)
  1705. (org-replace-match-keep-properties "\\end{quote}" t t))
  1706. ;; Convert verse
  1707. (goto-char (point-min))
  1708. (while (search-forward "ORG-VERSE-START" nil t)
  1709. (org-replace-match-keep-properties "\\begin{verse}" t t)
  1710. (beginning-of-line 2)
  1711. (while (and (not (looking-at "[ \t]*ORG-VERSE-END.*")) (not (eobp)))
  1712. (when (looking-at "\\([ \t]+\\)\\([^ \t\n]\\)")
  1713. (goto-char (match-end 1))
  1714. (org-replace-match-keep-properties
  1715. (org-export-latex-protect-string
  1716. (concat "\\hspace*{1cm}" (match-string 2))) t t)
  1717. (beginning-of-line 1))
  1718. (if (looking-at "[ \t]*$")
  1719. (insert (org-export-latex-protect-string "\\vspace*{1em}"))
  1720. (unless (looking-at ".*?[^ \t\n].*?\\\\\\\\[ \t]*$")
  1721. (end-of-line 1)
  1722. (insert "\\\\")))
  1723. (beginning-of-line 2))
  1724. (and (looking-at "[ \t]*ORG-VERSE-END.*")
  1725. (org-replace-match-keep-properties "\\end{verse}" t t)))
  1726. ;; Convert center
  1727. (goto-char (point-min))
  1728. (while (search-forward "ORG-CENTER-START" nil t)
  1729. (org-replace-match-keep-properties "\\begin{center}" t t))
  1730. (goto-char (point-min))
  1731. (while (search-forward "ORG-CENTER-END" nil t)
  1732. (org-replace-match-keep-properties "\\end{center}" t t))
  1733. (run-hooks 'org-export-latex-after-blockquotes-hook)
  1734. ;; Convert horizontal rules
  1735. (goto-char (point-min))
  1736. (while (re-search-forward "^----+.$" nil t)
  1737. (org-if-unprotected
  1738. (replace-match (org-export-latex-protect-string "\\hrule") t t)))
  1739. ;; Protect LaTeX commands like \command[...]{...} or \command{...}
  1740. (let ((re (concat "\\\\[a-zA-Z]+\\(?:"
  1741. "\\[.*\\]"
  1742. "\\)?"
  1743. "\\(" (org-create-multibrace-regexp "{" "}" 3)
  1744. "\\)\\{1,3\\}")))
  1745. (while (re-search-forward re nil t)
  1746. (unless (save-excursion (goto-char (match-beginning 0))
  1747. (equal (char-after (point-at-bol)) ?#))
  1748. (add-text-properties (match-beginning 0) (match-end 0)
  1749. '(org-protected t)))))
  1750. ;; Protect LaTeX entities
  1751. (goto-char (point-min))
  1752. (let (a)
  1753. (while (re-search-forward org-latex-entities-regexp nil t)
  1754. (if (setq a (assoc (match-string 0) org-latex-entities-exceptions))
  1755. (replace-match (org-add-props (nth 1 a) nil 'org-protected t)
  1756. t t)
  1757. (add-text-properties (match-beginning 0) (match-end 0)
  1758. '(org-protected t)))))
  1759. ;; Replace radio links
  1760. (goto-char (point-min))
  1761. (while (re-search-forward
  1762. (concat "<<<?" org-export-latex-all-targets-re
  1763. ">>>?\\((INVISIBLE)\\)?") nil t)
  1764. (org-if-unprotected-at (+ (match-beginning 0) 2)
  1765. (replace-match
  1766. (org-export-latex-protect-string
  1767. (format "\\label{%s}%s" (save-match-data (org-solidify-link-text
  1768. (match-string 1)))
  1769. (if (match-string 2) "" (match-string 1)))) t t)))
  1770. ;; Delete @<...> constructs
  1771. ;; Thanks to Daniel Clemente for this regexp
  1772. (goto-char (point-min))
  1773. (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t)
  1774. (org-if-unprotected
  1775. (replace-match "")))
  1776. ;; When converting to LaTeX, replace footnotes
  1777. ;; FIXME: don't protect footnotes from conversion
  1778. (when (plist-get org-export-latex-options-plist :footnotes)
  1779. (goto-char (point-min))
  1780. (while (re-search-forward "\\[\\([0-9]+\\)\\]" nil t)
  1781. (org-if-unprotected
  1782. (when (and (save-match-data
  1783. (save-excursion (beginning-of-line)
  1784. (looking-at "[^:|#]")))
  1785. (not (org-in-verbatim-emphasis)))
  1786. (let ((foot-beg (match-beginning 0))
  1787. (foot-end (match-end 0))
  1788. (foot-prefix (match-string 0))
  1789. footnote footnote-rpl)
  1790. (save-excursion
  1791. (if (not (re-search-forward (concat "^" (regexp-quote foot-prefix))
  1792. nil t))
  1793. (replace-match (org-export-latex-protect-string
  1794. (concat "$^{" (match-string 1) "}$")))
  1795. (replace-match "")
  1796. (let ((end (save-excursion
  1797. (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t)
  1798. (match-beginning 0) (point-max)))))
  1799. (setq footnote (concat (org-trim (buffer-substring (point) end))
  1800. " ")) ; prevent last } being part of a link
  1801. (delete-region (point) end))
  1802. (goto-char foot-beg)
  1803. (delete-region foot-beg foot-end)
  1804. (unless (null footnote)
  1805. (setq footnote-rpl (format "\\footnote{%s}" footnote))
  1806. (add-text-properties 0 10 '(org-protected t) footnote-rpl)
  1807. (add-text-properties (1- (length footnote-rpl))
  1808. (length footnote-rpl)
  1809. '(org-protected t) footnote-rpl)
  1810. (insert footnote-rpl)))
  1811. )))))
  1812. ;; Remove footnote section tag for LaTeX
  1813. (goto-char (point-min))
  1814. (while (re-search-forward
  1815. (concat "^" footnote-section-tag-regexp) nil t)
  1816. (org-if-unprotected
  1817. (replace-match "")))))
  1818. ;;; List handling:
  1819. (defun org-export-latex-lists ()
  1820. "Convert plain text lists in current buffer into LaTeX lists."
  1821. (goto-char (point-min))
  1822. (while (re-search-forward org-list-beginning-re nil t)
  1823. (org-if-unprotected
  1824. (beginning-of-line)
  1825. (insert (org-list-to-latex (org-list-parse-list t)
  1826. org-export-latex-list-parameters))
  1827. "\n")))
  1828. (defconst org-latex-entities
  1829. '("\\!"
  1830. "\\'"
  1831. "\\+"
  1832. "\\,"
  1833. "\\-"
  1834. "\\:"
  1835. "\\;"
  1836. "\\<"
  1837. "\\="
  1838. "\\>"
  1839. "\\Huge"
  1840. "\\LARGE"
  1841. "\\Large"
  1842. "\\Styles"
  1843. "\\\\"
  1844. "\\`"
  1845. "\\addcontentsline"
  1846. "\\address"
  1847. "\\addtocontents"
  1848. "\\addtocounter"
  1849. "\\addtolength"
  1850. "\\addvspace"
  1851. "\\alph"
  1852. "\\appendix"
  1853. "\\arabic"
  1854. "\\author"
  1855. "\\begin{array}"
  1856. "\\begin{center}"
  1857. "\\begin{description}"
  1858. "\\begin{enumerate}"
  1859. "\\begin{eqnarray}"
  1860. "\\begin{equation}"
  1861. "\\begin{figure}"
  1862. "\\begin{flushleft}"
  1863. "\\begin{flushright}"
  1864. "\\begin{itemize}"
  1865. "\\begin{list}"
  1866. "\\begin{minipage}"
  1867. "\\begin{picture}"
  1868. "\\begin{quotation}"
  1869. "\\begin{quote}"
  1870. "\\begin{tabbing}"
  1871. "\\begin{table}"
  1872. "\\begin{tabular}"
  1873. "\\begin{thebibliography}"
  1874. "\\begin{theorem}"
  1875. "\\begin{titlepage}"
  1876. "\\begin{verbatim}"
  1877. "\\begin{verse}"
  1878. "\\bf"
  1879. "\\bf"
  1880. "\\bibitem"
  1881. "\\bigskip"
  1882. "\\cdots"
  1883. "\\centering"
  1884. "\\circle"
  1885. "\\cite"
  1886. "\\cleardoublepage"
  1887. "\\clearpage"
  1888. "\\cline"
  1889. "\\closing"
  1890. "\\dashbox"
  1891. "\\date"
  1892. "\\ddots"
  1893. "\\dotfill"
  1894. "\\em"
  1895. "\\fbox"
  1896. "\\flushbottom"
  1897. "\\fnsymbol"
  1898. "\\footnote"
  1899. "\\footnotemark"
  1900. "\\footnotesize"
  1901. "\\footnotetext"
  1902. "\\frac"
  1903. "\\frame"
  1904. "\\framebox"
  1905. "\\hfill"
  1906. "\\hline"
  1907. "\\hrulespace"
  1908. "\\hspace"
  1909. "\\huge"
  1910. "\\hyphenation"
  1911. "\\include"
  1912. "\\includeonly"
  1913. "\\indent"
  1914. "\\input"
  1915. "\\it"
  1916. "\\kill"
  1917. "\\label"
  1918. "\\large"
  1919. "\\ldots"
  1920. "\\line"
  1921. "\\linebreak"
  1922. "\\linethickness"
  1923. "\\listoffigures"
  1924. "\\listoftables"
  1925. "\\location"
  1926. "\\makebox"
  1927. "\\maketitle"
  1928. "\\mark"
  1929. "\\mbox"
  1930. "\\medskip"
  1931. "\\multicolumn"
  1932. "\\multiput"
  1933. ("\\nbsp" "~")
  1934. "\\newcommand"
  1935. "\\newcounter"
  1936. "\\newenvironment"
  1937. "\\newfont"
  1938. "\\newlength"
  1939. "\\newline"
  1940. "\\newpage"
  1941. "\\newsavebox"
  1942. "\\newtheorem"
  1943. "\\nocite"
  1944. "\\nofiles"
  1945. "\\noindent"
  1946. "\\nolinebreak"
  1947. "\\nopagebreak"
  1948. "\\normalsize"
  1949. "\\onecolumn"
  1950. "\\opening"
  1951. "\\oval"
  1952. "\\overbrace"
  1953. "\\overline"
  1954. "\\pagebreak"
  1955. "\\pagenumbering"
  1956. "\\pageref"
  1957. "\\pagestyle"
  1958. "\\par"
  1959. "\\parbox"
  1960. "\\put"
  1961. "\\raggedbottom"
  1962. "\\raggedleft"
  1963. "\\raggedright"
  1964. "\\raisebox"
  1965. "\\ref"
  1966. "\\rm"
  1967. "\\roman"
  1968. "\\rule"
  1969. "\\savebox"
  1970. "\\sc"
  1971. "\\scriptsize"
  1972. "\\setcounter"
  1973. "\\setlength"
  1974. "\\settowidth"
  1975. "\\sf"
  1976. "\\shortstack"
  1977. "\\signature"
  1978. "\\sl"
  1979. "\\small"
  1980. "\\smallskip"
  1981. "\\sqrt"
  1982. "\\tableofcontents"
  1983. "\\telephone"
  1984. "\\thanks"
  1985. "\\thispagestyle"
  1986. "\\tiny"
  1987. "\\title"
  1988. "\\tt"
  1989. "\\twocolumn"
  1990. "\\typein"
  1991. "\\typeout"
  1992. "\\underbrace"
  1993. "\\underline"
  1994. "\\usebox"
  1995. "\\usecounter"
  1996. "\\value"
  1997. "\\vdots"
  1998. "\\vector"
  1999. "\\verb"
  2000. "\\vfill"
  2001. "\\vline"
  2002. "\\vspace")
  2003. "A list of LaTeX commands to be protected when performing conversion.")
  2004. (defvar org-latex-entities-exceptions nil)
  2005. (defconst org-latex-entities-regexp
  2006. (let (names rest)
  2007. (dolist (x org-latex-entities)
  2008. (when (consp x)
  2009. (add-to-list 'org-latex-entities-exceptions x)
  2010. (setq x (car x)))
  2011. (if (string-match "[a-zA-Z]$" x)
  2012. (push x names)
  2013. (push x rest)))
  2014. (concat "\\(" (regexp-opt (nreverse names)) "\\>\\)"
  2015. "\\|\\(" (regexp-opt (nreverse rest)) "\\)")))
  2016. (provide 'org-export-latex)
  2017. (provide 'org-latex)
  2018. ;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad
  2019. ;;; org-latex.el ends here