org-latex.el 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194
  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. (let ((inhibit-read-only t))
  498. (remove-text-properties (point-min) (point-max)
  499. '(:org-license-to-kill nil))))
  500. (org-update-radio-target-regexp)
  501. (org-export-latex-set-initial-vars ext-plist arg)
  502. (setq org-export-opt-plist org-export-latex-options-plist)
  503. (org-install-letbind)
  504. (run-hooks 'org-export-latex-after-initial-vars-hook)
  505. (let* ((wcf (current-window-configuration))
  506. (opt-plist org-export-latex-options-plist)
  507. (region-p (org-region-active-p))
  508. (rbeg (and region-p (region-beginning)))
  509. (rend (and region-p (region-end)))
  510. (subtree-p
  511. (if (plist-get opt-plist :ignore-subtree-p)
  512. nil
  513. (when region-p
  514. (save-excursion
  515. (goto-char rbeg)
  516. (and (org-at-heading-p)
  517. (>= (org-end-of-subtree t t) rend))))))
  518. (opt-plist (setq org-export-opt-plist
  519. (if subtree-p
  520. (org-export-add-subtree-options opt-plist rbeg)
  521. opt-plist)))
  522. ;; Make sure the variable contains the updated values.
  523. (org-export-latex-options-plist (setq org-export-opt-plist opt-plist))
  524. (title (or (and subtree-p (org-export-get-title-from-subtree))
  525. (plist-get opt-plist :title)
  526. (and (not
  527. (plist-get opt-plist :skip-before-1st-heading))
  528. (org-export-grab-title-from-buffer))
  529. (file-name-sans-extension
  530. (file-name-nondirectory buffer-file-name))))
  531. (filename (concat (file-name-as-directory
  532. (or pub-dir
  533. (org-export-directory :LaTeX ext-plist)))
  534. (file-name-sans-extension
  535. (or (and subtree-p
  536. (org-entry-get rbeg "EXPORT_FILE_NAME" t))
  537. (file-name-nondirectory ;sans-extension
  538. buffer-file-name)))
  539. ".tex"))
  540. (filename (if (equal (file-truename filename)
  541. (file-truename buffer-file-name))
  542. (concat filename ".tex")
  543. filename))
  544. (buffer (if to-buffer
  545. (cond
  546. ((eq to-buffer 'string) (get-buffer-create
  547. "*Org LaTeX Export*"))
  548. (t (get-buffer-create to-buffer)))
  549. (find-file-noselect filename)))
  550. (odd org-odd-levels-only)
  551. (header (org-export-latex-make-header title opt-plist))
  552. (skip (cond (subtree-p nil)
  553. (region-p nil)
  554. (t (plist-get opt-plist :skip-before-1st-heading))))
  555. (text (plist-get opt-plist :text))
  556. (org-export-preprocess-hook
  557. (cons
  558. `(lambda () (org-set-local 'org-complex-heading-regexp
  559. ,org-export-latex-complex-heading-re))
  560. org-export-preprocess-hook))
  561. (first-lines (if skip "" (org-export-latex-first-lines
  562. opt-plist
  563. (if subtree-p
  564. (save-excursion
  565. (goto-char rbeg)
  566. (point-at-bol 2))
  567. rbeg)
  568. (if region-p rend))))
  569. (coding-system (and (boundp 'buffer-file-coding-system)
  570. buffer-file-coding-system))
  571. (coding-system-for-write (or org-export-latex-coding-system
  572. coding-system))
  573. (save-buffer-coding-system (or org-export-latex-coding-system
  574. coding-system))
  575. (region (buffer-substring
  576. (if region-p (region-beginning) (point-min))
  577. (if region-p (region-end) (point-max))))
  578. (text
  579. (and text (string-match "\\S-" text)
  580. (org-export-preprocess-string
  581. text
  582. :emph-multiline t
  583. :for-LaTeX t
  584. :comments nil
  585. :tags (plist-get opt-plist :tags)
  586. :priority (plist-get opt-plist :priority)
  587. :footnotes (plist-get opt-plist :footnotes)
  588. :drawers (plist-get opt-plist :drawers)
  589. :timestamps (plist-get opt-plist :timestamps)
  590. :todo-keywords (plist-get opt-plist :todo-keywords)
  591. :add-text nil
  592. :skip-before-1st-heading skip
  593. :select-tags nil
  594. :exclude-tags nil
  595. :LaTeX-fragments nil)))
  596. (string-for-export
  597. (org-export-preprocess-string
  598. region
  599. :emph-multiline t
  600. :for-LaTeX t
  601. :comments nil
  602. :tags (plist-get opt-plist :tags)
  603. :priority (plist-get opt-plist :priority)
  604. :footnotes (plist-get opt-plist :footnotes)
  605. :drawers (plist-get opt-plist :drawers)
  606. :timestamps (plist-get opt-plist :timestamps)
  607. :todo-keywords (plist-get opt-plist :todo-keywords)
  608. :add-text (if (eq to-buffer 'string) nil text)
  609. :skip-before-1st-heading skip
  610. :select-tags (plist-get opt-plist :select-tags)
  611. :exclude-tags (plist-get opt-plist :exclude-tags)
  612. :LaTeX-fragments nil)))
  613. (set-buffer buffer)
  614. (erase-buffer)
  615. (org-install-letbind)
  616. (and (fboundp 'set-buffer-file-coding-system)
  617. (set-buffer-file-coding-system coding-system-for-write))
  618. ;; insert the header and initial document commands
  619. (unless (or (eq to-buffer 'string) body-only)
  620. (insert header))
  621. ;; insert text found in #+TEXT
  622. (when (and text (not (eq to-buffer 'string)))
  623. (insert (org-export-latex-content
  624. text '(lists tables fixed-width keywords))
  625. "\n\n"))
  626. ;; insert lines before the first headline
  627. (unless skip
  628. (insert first-lines))
  629. ;; export the content of headlines
  630. (org-export-latex-global
  631. (with-temp-buffer
  632. (insert string-for-export)
  633. (goto-char (point-min))
  634. (when (re-search-forward "^\\(\\*+\\) " nil t)
  635. (let* ((asters (length (match-string 1)))
  636. (level (if odd (- asters 2) (- asters 1))))
  637. (setq org-export-latex-add-level
  638. (if odd (1- (/ (1+ asters) 2)) (1- asters)))
  639. (org-export-latex-parse-global level odd)))))
  640. ;; finalization
  641. (unless body-only (insert "\n\\end{document}"))
  642. ;; Attach description terms to the \item macro
  643. (goto-char (point-min))
  644. (while (re-search-forward "^[ \t]*\\\\item\\([ \t]+\\)\\[" nil t)
  645. (delete-region (match-beginning 1) (match-end 1)))
  646. ;; Relocate the table of contents
  647. (goto-char (point-min))
  648. (when (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
  649. (goto-char (point-min))
  650. (while (re-search-forward "\\\\tableofcontents\\>[ \t]*\n?" nil t)
  651. (replace-match ""))
  652. (goto-char (point-min))
  653. (and (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
  654. (replace-match "\\tableofcontents" t t)))
  655. ;; Cleanup forced line ends in items where they are not needed
  656. (goto-char (point-min))
  657. (while (re-search-forward
  658. "^[ \t]*\\\\item\\>.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)*\n\\\\begin"
  659. nil t)
  660. (delete-region (match-beginning 1) (match-end 1)))
  661. (goto-char (point-min))
  662. (while (re-search-forward
  663. "^[ \t]*\\\\item\\>.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)*"
  664. nil t)
  665. (if (looking-at "[\n \t]+")
  666. (replace-match "\n")))
  667. (run-hooks 'org-export-latex-final-hook)
  668. (or to-buffer (save-buffer))
  669. (goto-char (point-min))
  670. (or (org-export-push-to-kill-ring "LaTeX")
  671. (message "Exporting to LaTeX...done"))
  672. (prog1
  673. (if (eq to-buffer 'string)
  674. (prog1 (buffer-substring (point-min) (point-max))
  675. (kill-buffer (current-buffer)))
  676. (current-buffer))
  677. (set-window-configuration wcf))))
  678. ;;;###autoload
  679. (defun org-export-as-pdf (arg &optional hidden ext-plist
  680. to-buffer body-only pub-dir)
  681. "Export as LaTeX, then process through to PDF."
  682. (interactive "P")
  683. (message "Exporting to PDF...")
  684. (let* ((wconfig (current-window-configuration))
  685. (lbuf (org-export-as-latex arg hidden ext-plist
  686. to-buffer body-only pub-dir))
  687. (file (buffer-file-name lbuf))
  688. (base (file-name-sans-extension (buffer-file-name lbuf)))
  689. (pdffile (concat base ".pdf"))
  690. (cmds org-latex-to-pdf-process)
  691. (outbuf (get-buffer-create "*Org PDF LaTeX Output*"))
  692. (bibtex-p (with-current-buffer lbuf
  693. (save-excursion
  694. (goto-char (point-min))
  695. (re-search-forward "\\\\bibliography{" nil t))))
  696. cmd)
  697. (with-current-buffer outbuf (erase-buffer))
  698. (message "Processing LaTeX file...")
  699. (if (and cmds (symbolp cmds))
  700. (funcall cmds file)
  701. (while cmds
  702. (setq cmd (pop cmds))
  703. (while (string-match "%b" cmd)
  704. (setq cmd (replace-match
  705. (save-match-data
  706. (shell-quote-argument base))
  707. t t cmd)))
  708. (while (string-match "%s" cmd)
  709. (setq cmd (replace-match
  710. (save-match-data
  711. (shell-quote-argument file))
  712. t t cmd)))
  713. (shell-command cmd outbuf outbuf)))
  714. (message "Processing LaTeX file...done")
  715. (if (not (file-exists-p pdffile))
  716. (error "PDF file was not produced")
  717. (set-window-configuration wconfig)
  718. (when org-export-pdf-remove-logfiles
  719. (dolist (ext org-export-pdf-logfiles)
  720. (setq file (concat base "." ext))
  721. (and (file-exists-p file) (delete-file file))))
  722. (message "Exporting to PDF...done")
  723. pdffile)))
  724. ;;;###autoload
  725. (defun org-export-as-pdf-and-open (arg)
  726. "Export as LaTeX, then process through to PDF, and open."
  727. (interactive "P")
  728. (let ((pdffile (org-export-as-pdf arg)))
  729. (if pdffile
  730. (org-open-file pdffile)
  731. (error "PDF file was not produced"))))
  732. ;;; Parsing functions:
  733. (defun org-export-latex-parse-global (level odd)
  734. "Parse the current buffer recursively, starting at LEVEL.
  735. If ODD is non-nil, assume the buffer only contains odd sections.
  736. Return a list reflecting the document structure."
  737. (save-excursion
  738. (goto-char (point-min))
  739. (let* ((cnt 0) output
  740. (depth org-export-latex-sectioning-depth))
  741. (while (org-re-search-forward-unprotected
  742. (concat "^\\(\\(?:\\*\\)\\{"
  743. (number-to-string (+ (if odd 2 1) level))
  744. "\\}\\) \\(.*\\)$")
  745. ;; make sure that there is no upper heading
  746. (when (> level 0)
  747. (save-excursion
  748. (save-match-data
  749. (org-re-search-forward-unprotected
  750. (concat "^\\(\\(?:\\*\\)\\{"
  751. (number-to-string level)
  752. "\\}\\) \\(.*\\)$") nil t)))) t)
  753. (setq cnt (1+ cnt))
  754. (let* ((pos (match-beginning 0))
  755. (heading (match-string 2))
  756. (nlevel (if odd (/ (+ 3 level) 2) (1+ level))))
  757. (save-excursion
  758. (narrow-to-region
  759. (point)
  760. (save-match-data
  761. (if (org-re-search-forward-unprotected
  762. (concat "^\\(\\(?:\\*\\)\\{"
  763. (number-to-string (+ (if odd 2 1) level))
  764. "\\}\\) \\(.*\\)$") nil t)
  765. (match-beginning 0)
  766. (point-max))))
  767. (goto-char (point-min))
  768. (setq output
  769. (append output
  770. (list
  771. (list
  772. `(pos . ,pos)
  773. `(level . ,nlevel)
  774. `(occur . ,cnt)
  775. `(heading . ,heading)
  776. `(content . ,(org-export-latex-parse-content))
  777. `(subcontent . ,(org-export-latex-parse-subcontent
  778. level odd)))))))
  779. (widen)))
  780. (list output))))
  781. (defun org-export-latex-parse-content ()
  782. "Extract the content of a section."
  783. (let ((beg (point))
  784. (end (if (org-re-search-forward-unprotected "^\\(\\*\\)+ .*$" nil t)
  785. (progn (beginning-of-line) (point))
  786. (point-max))))
  787. (buffer-substring beg end)))
  788. (defun org-export-latex-parse-subcontent (level odd)
  789. "Extract the subcontent of a section at LEVEL.
  790. If ODD Is non-nil, assume subcontent only contains odd sections."
  791. (if (not (org-re-search-forward-unprotected
  792. (concat "^\\(\\(?:\\*\\)\\{"
  793. (number-to-string (+ (if odd 4 2) level))
  794. "\\}\\) \\(.*\\)$")
  795. nil t))
  796. nil ; subcontent is nil
  797. (org-export-latex-parse-global (+ (if odd 2 1) level) odd)))
  798. ;;; Rendering functions:
  799. (defun org-export-latex-global (content)
  800. "Export CONTENT to LaTeX.
  801. CONTENT is an element of the list produced by
  802. `org-export-latex-parse-global'."
  803. (if (eq (car content) 'subcontent)
  804. (mapc 'org-export-latex-sub (cdr content))
  805. (org-export-latex-sub (car content))))
  806. (defun org-export-latex-sub (subcontent)
  807. "Export the list SUBCONTENT to LaTeX.
  808. SUBCONTENT is an alist containing information about the headline
  809. and its content."
  810. (let ((num (plist-get org-export-latex-options-plist :section-numbers)))
  811. (mapc (lambda(x) (org-export-latex-subcontent x num)) subcontent)))
  812. (defun org-export-latex-subcontent (subcontent num)
  813. "Export each cell of SUBCONTENT to LaTeX.
  814. If NUM, export sections as numerical sections."
  815. (let* ((heading (cdr (assoc 'heading subcontent)))
  816. (level (- (cdr (assoc 'level subcontent))
  817. org-export-latex-add-level))
  818. (occur (number-to-string (cdr (assoc 'occur subcontent))))
  819. (content (cdr (assoc 'content subcontent)))
  820. (subcontent (cadr (assoc 'subcontent subcontent)))
  821. (label (org-get-text-property-any 0 'target heading))
  822. (label-list (cons label (cdr (assoc label
  823. org-export-target-aliases))))
  824. (sectioning org-export-latex-sectioning)
  825. (depth org-export-latex-sectioning-depth)
  826. main-heading sub-heading)
  827. (when (symbolp (car sectioning))
  828. (setq sectioning (funcall (car sectioning) level heading))
  829. (when sectioning
  830. (setq heading (car sectioning)
  831. sectioning (cdr sectioning)))
  832. (if sectioning (setq sectioning (make-list 10 sectioning)))
  833. (setq depth (if sectioning 10000 0)))
  834. (if (string-match "[ \t]*\\\\\\\\[ \t]*" heading)
  835. (setq main-heading (substring heading 0 (match-beginning 0))
  836. sub-heading (substring heading (match-end 0))))
  837. (setq heading (org-export-latex-fontify-headline heading)
  838. sub-heading (and sub-heading
  839. (org-export-latex-fontify-headline sub-heading))
  840. main-heading (and main-heading
  841. (org-export-latex-fontify-headline main-heading)))
  842. (cond
  843. ;; Normal conversion
  844. ((<= level depth)
  845. (let* ((sec (nth (1- level) sectioning))
  846. start end)
  847. (if (consp (cdr sec))
  848. (setq start (nth (if num 0 2) sec)
  849. end (nth (if num 1 3) sec))
  850. (setq start (if num (car sec) (cdr sec))))
  851. (insert (format start (if main-heading main-heading heading)
  852. (or sub-heading "")))
  853. (insert "\n")
  854. (when label
  855. (insert (mapconcat (lambda (l) (format "\\label{%s}" l))
  856. label-list "\n") "\n"))
  857. (insert (org-export-latex-content content))
  858. (cond ((stringp subcontent) (insert subcontent))
  859. ((listp subcontent)
  860. (while (org-looking-back "\n\n") (backward-delete-char 1))
  861. (org-export-latex-sub subcontent)))
  862. (when (and end (string-match "[^ \t]" end))
  863. (let ((hook (org-get-text-property-any 0 'org-insert-hook end)))
  864. (and (functionp hook) (funcall hook)))
  865. (insert end "\n"))))
  866. ;; At a level under the hl option: we can drop this subsection
  867. ((> level depth)
  868. (cond ((eq org-export-latex-low-levels 'description)
  869. (if (string-match "% ends low level$"
  870. (buffer-substring (point-at-bol 0) (point)))
  871. (delete-region (point-at-bol 0) (point))
  872. (insert "\\begin{description}\n"))
  873. (insert (format "\n\\item[%s]%s~\n"
  874. heading
  875. (if label (format "\\label{%s}" label) "")))
  876. (insert (org-export-latex-content content))
  877. (cond ((stringp subcontent) (insert subcontent))
  878. ((listp subcontent) (org-export-latex-sub subcontent)))
  879. (insert "\\end{description} % ends low level\n"))
  880. ((memq org-export-latex-low-levels '(itemize enumerate))
  881. (if (string-match "% ends low level$"
  882. (buffer-substring (point-at-bol 0) (point)))
  883. (delete-region (point-at-bol 0) (point))
  884. (insert (format "\\begin{%s}\n"
  885. (symbol-name org-export-latex-low-levels))))
  886. (insert (format "\n\\item %s\\\\\n%s%%"
  887. heading
  888. (if label (format "\\label{%s}" label) "")))
  889. (insert (org-export-latex-content content))
  890. (cond ((stringp subcontent) (insert subcontent))
  891. ((listp subcontent) (org-export-latex-sub subcontent)))
  892. (insert (format "\\end{%s} %% ends low level\n"
  893. (symbol-name org-export-latex-low-levels))))
  894. ((listp org-export-latex-low-levels)
  895. (if (string-match "% ends low level$"
  896. (buffer-substring (point-at-bol 0) (point)))
  897. (delete-region (point-at-bol 0) (point))
  898. (insert (car org-export-latex-low-levels) "\n"))
  899. (insert (format (nth 2 org-export-latex-low-levels)
  900. heading
  901. (if label (format "\\label{%s}" label) "")))
  902. (insert (org-export-latex-content content))
  903. (cond ((stringp subcontent) (insert subcontent))
  904. ((listp subcontent) (org-export-latex-sub subcontent)))
  905. (insert (nth 1 org-export-latex-low-levels)
  906. " %% ends low level\n"))
  907. ((stringp org-export-latex-low-levels)
  908. (insert (format org-export-latex-low-levels heading) "\n")
  909. (when label (insert (format "\\label{%s}\n" label)))
  910. (insert (org-export-latex-content content))
  911. (cond ((stringp subcontent) (insert subcontent))
  912. ((listp subcontent) (org-export-latex-sub subcontent)))))))))
  913. ;;; Exporting internals:
  914. (defun org-export-latex-set-initial-vars (ext-plist level)
  915. "Store org local variables required for LaTeX export.
  916. EXT-PLIST is an optional additional plist.
  917. LEVEL indicates the default depth for export."
  918. (setq org-export-latex-todo-keywords-1 org-todo-keywords-1
  919. org-export-latex-done-keywords org-done-keywords
  920. org-export-latex-not-done-keywords org-not-done-keywords
  921. org-export-latex-complex-heading-re org-complex-heading-regexp
  922. org-export-latex-display-custom-times org-display-custom-times
  923. org-export-latex-all-targets-re
  924. (org-make-target-link-regexp (org-all-targets))
  925. org-export-latex-options-plist
  926. (org-combine-plists (org-default-export-plist) ext-plist
  927. (org-infile-export-plist))
  928. org-export-latex-class
  929. (or (and (org-region-active-p)
  930. (save-excursion
  931. (goto-char (region-beginning))
  932. (and (looking-at org-complex-heading-regexp)
  933. (org-entry-get nil "LaTeX_CLASS" 'selective))))
  934. (save-excursion
  935. (save-restriction
  936. (widen)
  937. (goto-char (point-min))
  938. (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\([a-zA-Z]+\\)" nil t)
  939. (match-string 1))))
  940. (plist-get org-export-latex-options-plist :latex-class)
  941. org-export-latex-default-class)
  942. org-export-latex-class-options
  943. (or (and (org-region-active-p)
  944. (save-excursion
  945. (goto-char (region-beginning))
  946. (and (looking-at org-complex-heading-regexp)
  947. (org-entry-get nil "LaTeX_CLASS_OPTIONS" 'selective))))
  948. (save-excursion
  949. (save-restriction
  950. (widen)
  951. (goto-char (point-min))
  952. (and (re-search-forward "^#\\+LaTeX_CLASS_OPTIONS:[ \t]*\\(.*?\\)[ \t]*$" nil t)
  953. (match-string 1))))
  954. (plist-get org-export-latex-options-plist :latex-class-options))
  955. org-export-latex-class
  956. (or (car (assoc org-export-latex-class org-export-latex-classes))
  957. (error "No definition for class `%s' in `org-export-latex-classes'"
  958. org-export-latex-class))
  959. org-export-latex-header
  960. (cadr (assoc org-export-latex-class org-export-latex-classes))
  961. org-export-latex-sectioning
  962. (cddr (assoc org-export-latex-class org-export-latex-classes))
  963. org-export-latex-sectioning-depth
  964. (or level
  965. (let ((hl-levels
  966. (plist-get org-export-latex-options-plist :headline-levels))
  967. (sec-depth (length org-export-latex-sectioning)))
  968. (if (> hl-levels sec-depth) sec-depth hl-levels))))
  969. (when (and org-export-latex-class-options
  970. (string-match "\\S-" org-export-latex-class-options)
  971. (string-match "^[ \t]*\\(\\\\documentclass\\)\\(\\[.*?\\]\\)?"
  972. org-export-latex-header))
  973. (setq org-export-latex-header
  974. (concat (substring org-export-latex-header 0 (match-end 1))
  975. org-export-latex-class-options
  976. (substring org-export-latex-header (match-end 0))))))
  977. (defvar org-export-latex-format-toc-function
  978. 'org-export-latex-format-toc-default
  979. "The function formatting returning the string to createthe table of contents.
  980. The function mus take one parameter, the depth of the table of contents.")
  981. (defun org-export-latex-make-header (title opt-plist)
  982. "Make the LaTeX header and return it as a string.
  983. TITLE is the current title from the buffer or region.
  984. OPT-PLIST is the options plist for current buffer."
  985. (let ((toc (plist-get opt-plist :table-of-contents))
  986. (author (plist-get opt-plist :author)))
  987. (concat
  988. (if (plist-get opt-plist :time-stamp-file)
  989. (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
  990. ;; insert LaTeX custom header
  991. (org-export-apply-macros-in-string org-export-latex-header)
  992. "\n"
  993. ;; insert information on LaTeX packages
  994. (when org-export-latex-packages-alist
  995. (concat
  996. (mapconcat (lambda(p)
  997. (if (equal "" (car p))
  998. (format "\\usepackage{%s}" (cadr p))
  999. (format "\\usepackage[%s]{%s}"
  1000. (car p) (cadr p))))
  1001. org-export-latex-packages-alist "\n")
  1002. "\n"))
  1003. ;; insert additional commands in the header
  1004. (org-export-apply-macros-in-string
  1005. (plist-get opt-plist :latex-header-extra))
  1006. (org-export-apply-macros-in-string org-export-latex-append-header)
  1007. ;; insert the title
  1008. (format
  1009. "\n\n\\title{%s}\n"
  1010. ;; convert the title
  1011. (org-export-latex-content
  1012. title '(lists tables fixed-width keywords)))
  1013. ;; insert author info
  1014. (if (plist-get opt-plist :author-info)
  1015. (format "\\author{%s}\n"
  1016. (org-export-latex-fontify-headline (or author user-full-name)))
  1017. (format "%%\\author{%s}\n"
  1018. (or author user-full-name)))
  1019. ;; insert the date
  1020. (format "\\date{%s}\n"
  1021. (format-time-string
  1022. (or (plist-get opt-plist :date)
  1023. org-export-latex-date-format)))
  1024. ;; beginning of the document
  1025. "\n\\begin{document}\n\n"
  1026. ;; insert the title command
  1027. (when (string-match "\\S-" title)
  1028. (if (string-match "%s" org-export-latex-title-command)
  1029. (format org-export-latex-title-command title)
  1030. org-export-latex-title-command))
  1031. "\n\n"
  1032. ;; table of contents
  1033. (when (and org-export-with-toc
  1034. (plist-get opt-plist :section-numbers))
  1035. (funcall org-export-latex-format-toc-function
  1036. (cond ((numberp toc)
  1037. (min toc (plist-get opt-plist :headline-levels)))
  1038. (toc (plist-get opt-plist :headline-levels))))))))
  1039. (defun org-export-latex-format-toc-default (depth)
  1040. (when depth
  1041. (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\\vspace*{1cm}\n"
  1042. depth)))
  1043. (defun org-export-latex-first-lines (opt-plist &optional beg end)
  1044. "Export the first lines before first headline.
  1045. If BEG is non-nil, it is the beginning of the region.
  1046. If END is non-nil, it is the end of the region."
  1047. (save-excursion
  1048. (goto-char (or beg (point-min)))
  1049. (let* ((pt (point))
  1050. (end (if (re-search-forward "^\\*+ " end t)
  1051. (goto-char (match-beginning 0))
  1052. (goto-char (or end (point-max))))))
  1053. (prog1
  1054. (org-export-latex-content
  1055. (org-export-preprocess-string
  1056. (buffer-substring pt end)
  1057. :for-LaTeX t
  1058. :emph-multiline t
  1059. :add-text nil
  1060. :comments nil
  1061. :skip-before-1st-heading nil
  1062. :LaTeX-fragments nil
  1063. :timestamps (plist-get opt-plist :timestamps)
  1064. :footnotes (plist-get opt-plist :footnotes)))
  1065. (org-unmodified
  1066. (let ((inhibit-read-only t))
  1067. (add-text-properties pt (max pt (1- end))
  1068. '(:org-license-to-kill t))))))))
  1069. (defvar org-export-latex-header-defs nil
  1070. "The header definitions that might be used in the LaTeX body.")
  1071. (defvar org-export-latex-header-defs-re nil
  1072. "The header definitions that might be used in the LaTeX body.")
  1073. (defun org-export-latex-content (content &optional exclude-list)
  1074. "Convert CONTENT string to LaTeX.
  1075. Don't perform conversions that are in EXCLUDE-LIST. Recognized
  1076. conversion types are: quotation-marks, emphasis, sub-superscript,
  1077. links, keywords, lists, tables, fixed-width"
  1078. (with-temp-buffer
  1079. (insert content)
  1080. (unless (memq 'timestamps exclude-list)
  1081. (org-export-latex-time-stamps))
  1082. (unless (memq 'quotation-marks exclude-list)
  1083. (org-export-latex-quotation-marks))
  1084. (unless (memq 'emphasis exclude-list)
  1085. (when (plist-get org-export-latex-options-plist :emphasize)
  1086. (org-export-latex-fontify)))
  1087. (unless (memq 'sub-superscript exclude-list)
  1088. (org-export-latex-special-chars
  1089. (plist-get org-export-latex-options-plist :sub-superscript)))
  1090. (unless (memq 'links exclude-list)
  1091. (org-export-latex-links))
  1092. (unless (memq 'keywords exclude-list)
  1093. (org-export-latex-keywords))
  1094. (unless (memq 'lists exclude-list)
  1095. (org-export-latex-lists))
  1096. (unless (memq 'tables exclude-list)
  1097. (org-export-latex-tables
  1098. (plist-get org-export-latex-options-plist :tables)))
  1099. (unless (memq 'fixed-width exclude-list)
  1100. (org-export-latex-fixed-width
  1101. (plist-get org-export-latex-options-plist :fixed-width)))
  1102. ;; return string
  1103. (buffer-substring (point-min) (point-max))))
  1104. (defun org-export-latex-protect-string (s)
  1105. "Add the org-protected property to string S."
  1106. (add-text-properties 0 (length s) '(org-protected t) s) s)
  1107. (defun org-export-latex-protect-char-in-string (char-list string)
  1108. "Add org-protected text-property to char from CHAR-LIST in STRING."
  1109. (with-temp-buffer
  1110. (save-match-data
  1111. (insert string)
  1112. (goto-char (point-min))
  1113. (while (re-search-forward (regexp-opt char-list) nil t)
  1114. (add-text-properties (match-beginning 0)
  1115. (match-end 0) '(org-protected t)))
  1116. (buffer-string))))
  1117. (defun org-export-latex-keywords-maybe (&optional remove-list)
  1118. "Maybe remove keywords depending on rules in REMOVE-LIST."
  1119. (goto-char (point-min))
  1120. (let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1 "\\|"))
  1121. (case-fold-search nil)
  1122. (todo-markup org-export-latex-todo-keyword-markup)
  1123. fmt)
  1124. ;; convert TODO keywords
  1125. (when (re-search-forward (concat "^\\(" re-todo "\\)") nil t)
  1126. (if (plist-get remove-list :todo)
  1127. (replace-match "")
  1128. (setq fmt (cond
  1129. ((stringp todo-markup) todo-markup)
  1130. ((and (consp todo-markup) (stringp (car todo-markup)))
  1131. (if (member (match-string 1) org-export-latex-done-keywords)
  1132. (cdr todo-markup) (car todo-markup)))
  1133. (t (cdr (or (assoc (match-string 1) todo-markup)
  1134. (car todo-markup))))))
  1135. (replace-match (format fmt (match-string 1)) t t)))
  1136. ;; convert priority string
  1137. (when (re-search-forward "\\[\\\\#.\\]" nil t)
  1138. (if (plist-get remove-list :priority)
  1139. (replace-match "")
  1140. (replace-match (format "\\textbf{%s}" (match-string 0)) t t)))
  1141. ;; convert tags
  1142. (when (re-search-forward "\\(:[a-zA-Z0-9_@]+\\)+:" nil t)
  1143. (if (or (not org-export-with-tags)
  1144. (plist-get remove-list :tags))
  1145. (replace-match "")
  1146. (replace-match
  1147. (org-export-latex-protect-string
  1148. (format "\\textbf{%s}"
  1149. (save-match-data
  1150. (replace-regexp-in-string
  1151. "_" "\\\\_" (match-string 0)))))
  1152. t t)))))
  1153. (defun org-export-latex-fontify-headline (string)
  1154. "Fontify special words in STRING."
  1155. (with-temp-buffer
  1156. ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
  1157. ;; the beginning of the buffer - inserting "\n" is safe here though.
  1158. (insert "\n" string)
  1159. (goto-char (point-min))
  1160. (let ((re (concat "\\\\[a-zA-Z]+\\(?:"
  1161. "\\[.*\\]"
  1162. "\\)?"
  1163. (org-create-multibrace-regexp "{" "}" 3))))
  1164. (while (re-search-forward re nil t)
  1165. (unless (save-excursion (goto-char (match-beginning 0))
  1166. (equal (char-after (point-at-bol)) ?#))
  1167. (add-text-properties (match-beginning 0) (match-end 0)
  1168. '(org-protected t)))))
  1169. (when (plist-get org-export-latex-options-plist :emphasize)
  1170. (org-export-latex-fontify))
  1171. (org-export-latex-keywords-maybe)
  1172. (org-export-latex-special-chars
  1173. (plist-get org-export-latex-options-plist :sub-superscript))
  1174. (org-export-latex-links)
  1175. (org-trim (buffer-string))))
  1176. (defun org-export-latex-time-stamps ()
  1177. "Format time stamps."
  1178. (goto-char (point-min))
  1179. (let ((org-display-custom-times org-export-latex-display-custom-times))
  1180. (while (re-search-forward org-ts-regexp-both nil t)
  1181. (org-if-unprotected-at (1- (point))
  1182. (replace-match
  1183. (org-export-latex-protect-string
  1184. (format org-export-latex-timestamp-markup
  1185. (substring (org-translate-time (match-string 0)) 1 -1)))
  1186. t t)))))
  1187. (defun org-export-latex-quotation-marks ()
  1188. "Export quotation marks depending on language conventions."
  1189. (let* ((lang (plist-get org-export-latex-options-plist :language))
  1190. (quote-rpl (if (equal lang "fr")
  1191. '(("\\(\\s-\\)\"" "«~")
  1192. ("\\(\\S-\\)\"" "~»")
  1193. ("\\(\\s-\\)'" "`"))
  1194. '(("\\(\\s-\\|[[(]\\)\"" "``")
  1195. ("\\(\\S-\\)\"" "''")
  1196. ("\\(\\s-\\|(\\)'" "`")))))
  1197. (mapc (lambda(l) (goto-char (point-min))
  1198. (while (re-search-forward (car l) nil t)
  1199. (let ((rpl (concat (match-string 1)
  1200. (org-export-latex-protect-string
  1201. (copy-sequence (cadr l))))))
  1202. (org-if-unprotected-1
  1203. (replace-match rpl t t))))) quote-rpl)))
  1204. (defun org-export-latex-special-chars (sub-superscript)
  1205. "Export special characters to LaTeX.
  1206. If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
  1207. See the `org-export-latex.el' code for a complete conversion table."
  1208. (goto-char (point-min))
  1209. (mapc (lambda(c)
  1210. (goto-char (point-min))
  1211. (while (re-search-forward c nil t)
  1212. ;; Put the point where to check for org-protected
  1213. (unless (get-text-property (match-beginning 2) 'org-protected)
  1214. (cond ((member (match-string 2) '("\\$" "$"))
  1215. (if (equal (match-string 2) "\\$")
  1216. nil
  1217. (replace-match "\\$" t t)))
  1218. ((member (match-string 2) '("&" "%" "#"))
  1219. (if (equal (match-string 1) "\\")
  1220. (replace-match (match-string 2) t t)
  1221. (replace-match (concat (match-string 1) "\\"
  1222. (match-string 2)) t t)))
  1223. ((equal (match-string 2) "...")
  1224. (replace-match
  1225. (concat (match-string 1)
  1226. (org-export-latex-protect-string "\\ldots{}")) t t))
  1227. ((equal (match-string 2) "~")
  1228. (cond ((equal (match-string 1) "\\") nil)
  1229. ((eq 'org-link (get-text-property 0 'face (match-string 2)))
  1230. (replace-match (concat (match-string 1) "\\~") t t))
  1231. (t (replace-match
  1232. (org-export-latex-protect-string
  1233. (concat (match-string 1) "\\~{}")) t t))))
  1234. ((member (match-string 2) '("{" "}"))
  1235. (unless (save-match-data (org-inside-latex-math-p))
  1236. (if (equal (match-string 1) "\\")
  1237. (replace-match (match-string 2) t t)
  1238. (replace-match (concat (match-string 1) "\\"
  1239. (match-string 2)) t t)))))
  1240. (unless (save-match-data (org-inside-latex-math-p))
  1241. (cond ((equal (match-string 2) "\\")
  1242. (replace-match (or (save-match-data
  1243. (org-export-latex-treat-backslash-char
  1244. (match-string 1)
  1245. (or (match-string 3) "")))
  1246. "") t t))
  1247. ((member (match-string 2) '("_" "^"))
  1248. (replace-match (or (save-match-data
  1249. (org-export-latex-treat-sub-super-char
  1250. sub-superscript
  1251. (match-string 2)
  1252. (match-string 1)
  1253. (match-string 3))) "") t t)
  1254. (backward-char 1)))))))
  1255. '(;"^\\([^\n$]*?\\|^\\)\\(\\\\?\\$\\)\\([^\n$]*\\)$"
  1256. "\\(\\(\\\\?\\$\\)\\)"
  1257. "\\([a-za-z0-9]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\({[^{}]+}\\|[a-za-z0-9]+\\|[ \t\n]\\|[:punct:]\\|)\\|{[a-za-z0-9]+}\\|([a-za-z0-9]+)\\)"
  1258. "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|[a-zA-Z&#%{}\"]+\\)"
  1259. "\\(.\\|^\\)\\(&\\)"
  1260. "\\(.\\|^\\)\\(#\\)"
  1261. "\\(.\\|^\\)\\(%\\)"
  1262. "\\(.\\|^\\)\\({\\)"
  1263. "\\(.\\|^\\)\\(}\\)"
  1264. "\\(.\\|^\\)\\(~\\)"
  1265. "\\(.\\|^\\)\\(\\.\\.\\.\\)"
  1266. ;; (?\< . "\\textless{}")
  1267. ;; (?\> . "\\textgreater{}")
  1268. )))
  1269. (defun org-inside-latex-math-p ()
  1270. (get-text-property (point) 'org-latex-math))
  1271. (defun org-export-latex-treat-sub-super-char
  1272. (subsup char string-before string-after)
  1273. "Convert the \"_\" and \"^\" characters to LaTeX.
  1274. SUBSUP corresponds to the ^: option in the #+OPTIONS line.
  1275. Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
  1276. (cond ((equal string-before "\\")
  1277. (concat string-before char string-after))
  1278. ((and (string-match "\\S-+" string-after))
  1279. ;; this is part of a math formula
  1280. (cond ((eq 'org-link (get-text-property 0 'face char))
  1281. (concat string-before "\\" char string-after))
  1282. ((save-match-data (org-inside-latex-math-p))
  1283. (if subsup
  1284. (cond ((eq 1 (length string-after))
  1285. (concat string-before char string-after))
  1286. ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after)
  1287. (format "%s%s{%s}" string-before char
  1288. (match-string 1 string-after))))))
  1289. ((and (> (length string-after) 1)
  1290. (or (eq subsup t)
  1291. (and (equal subsup '{}) (eq (string-to-char string-after) ?\{)))
  1292. (string-match "[({]?\\([^)}]+\\)[)}]?" string-after))
  1293. (org-export-latex-protect-string
  1294. (format "%s$%s{%s}$" string-before char
  1295. (if (and (> (match-end 1) (1+ (match-beginning 1)))
  1296. (not (equal (substring string-after 0 2) "{\\")))
  1297. (concat "\\mathrm{" (match-string 1 string-after) "}")
  1298. (match-string 1 string-after)))))
  1299. ((eq subsup t) (concat string-before "$" char string-after "$"))
  1300. (t (org-export-latex-protect-string
  1301. (concat string-before "\\" char "{}" string-after)))))
  1302. (t (org-export-latex-protect-string
  1303. (concat string-before "\\" char "{}" string-after)))))
  1304. (defun org-export-latex-treat-backslash-char (string-before string-after)
  1305. "Convert the \"$\" special character to LaTeX.
  1306. The conversion is made depending of STRING-BEFORE and STRING-AFTER."
  1307. (cond ((member (list string-after) org-html-entities)
  1308. ;; backslash is part of a special entity (like "\alpha")
  1309. (concat string-before "$\\"
  1310. (or (cdar (member (list string-after) org-html-entities))
  1311. string-after) "$"))
  1312. ((and (not (string-match "^[ \n\t]" string-after))
  1313. (not (string-match "[ \t]\\'\\|^" string-before)))
  1314. ;; backslash is inside a word
  1315. (org-export-latex-protect-string
  1316. (concat string-before "\\textbackslash{}" string-after)))
  1317. ((not (or (equal string-after "")
  1318. (string-match "^[ \t\n]" string-after)))
  1319. ;; backslash might escape a character (like \#) or a user TeX
  1320. ;; macro (like \setcounter)
  1321. (org-export-latex-protect-string
  1322. (concat string-before "\\" string-after)))
  1323. ((and (string-match "^[ \t\n]" string-after)
  1324. (string-match "[ \t\n]\\'" string-before))
  1325. ;; backslash is alone, convert it to $\backslash$
  1326. (org-export-latex-protect-string
  1327. (concat string-before "\\textbackslash{}" string-after)))
  1328. (t (org-export-latex-protect-string
  1329. (concat string-before "\\textbackslash{}" string-after)))))
  1330. (defun org-export-latex-keywords ()
  1331. "Convert special keywords to LaTeX."
  1332. (goto-char (point-min))
  1333. (while (re-search-forward org-export-latex-special-keyword-regexp nil t)
  1334. (replace-match (format org-export-latex-timestamp-keyword-markup
  1335. (match-string 0)) t t)
  1336. (save-excursion
  1337. (beginning-of-line 1)
  1338. (unless (looking-at ".*\\\\newline[ \t]*$")
  1339. (end-of-line 1)
  1340. (insert "\\newline")))))
  1341. (defun org-export-latex-fixed-width (opt)
  1342. "When OPT is non-nil convert fixed-width sections to LaTeX."
  1343. (goto-char (point-min))
  1344. (while (re-search-forward "^[ \t]*:\\([ \t]\\|$\\)" nil t)
  1345. (if opt
  1346. (progn (goto-char (match-beginning 0))
  1347. (insert "\\begin{verbatim}\n")
  1348. (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
  1349. (replace-match (concat (match-string 1)
  1350. (match-string 2)) t t)
  1351. (forward-line))
  1352. (insert "\\end{verbatim}\n\n"))
  1353. (progn (goto-char (match-beginning 0))
  1354. (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
  1355. (replace-match (concat "%" (match-string 1)
  1356. (match-string 2)) t t)
  1357. (forward-line))))))
  1358. (defvar org-table-last-alignment) ; defined in org-table.el
  1359. (defvar org-table-last-column-widths) ; defined in org-table.el
  1360. (declare-function orgtbl-to-latex "org-table" (table params) t)
  1361. (defun org-export-latex-tables (insert)
  1362. "Convert tables to LaTeX and INSERT it."
  1363. (goto-char (point-min))
  1364. (while (re-search-forward "^\\([ \t]*\\)|" nil t)
  1365. (org-if-unprotected-at (1- (point))
  1366. (org-table-align)
  1367. (let* ((beg (org-table-begin))
  1368. (end (org-table-end))
  1369. (raw-table (buffer-substring beg end))
  1370. (org-table-last-alignment (copy-sequence org-table-last-alignment))
  1371. (org-table-last-column-widths (copy-sequence
  1372. org-table-last-column-widths))
  1373. fnum fields line lines olines gr colgropen line-fmt align
  1374. caption label attr floatp longtblp)
  1375. (if org-export-latex-tables-verbatim
  1376. (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
  1377. "\\end{verbatim}\n")))
  1378. (apply 'delete-region (list beg end))
  1379. (insert (org-export-latex-protect-string tbl)))
  1380. (progn
  1381. (setq caption (org-find-text-property-in-string
  1382. 'org-caption raw-table)
  1383. attr (org-find-text-property-in-string
  1384. 'org-attributes raw-table)
  1385. label (org-find-text-property-in-string
  1386. 'org-label raw-table)
  1387. longtblp (and attr (stringp attr)
  1388. (string-match "\\<longtable\\>" attr))
  1389. align (and attr (stringp attr)
  1390. (string-match "\\<align=\\([^ \t\n\r,]+\\)" attr)
  1391. (match-string 1 attr))
  1392. floatp (or caption label))
  1393. (setq lines (org-split-string raw-table "\n"))
  1394. (apply 'delete-region (list beg end))
  1395. (when org-export-table-remove-special-lines
  1396. (setq lines (org-table-clean-before-export lines 'maybe-quoted)))
  1397. (when org-table-clean-did-remove-column
  1398. (pop org-table-last-alignment)
  1399. (pop org-table-last-column-widths))
  1400. ;; make a formatting string to reflect alignment
  1401. (setq olines lines)
  1402. (while (and (not line-fmt) (setq line (pop olines)))
  1403. (unless (string-match "^[ \t]*|-" line)
  1404. (setq fields (org-split-string line "[ \t]*|[ \t]*"))
  1405. (setq fnum (make-vector (length fields) 0))
  1406. (setq line-fmt
  1407. (mapconcat
  1408. (lambda (x)
  1409. (setq gr (pop org-table-colgroup-info))
  1410. (format "%s%%s%s"
  1411. (cond ((eq gr :start)
  1412. (prog1 (if colgropen "|" "|")
  1413. (setq colgropen t)))
  1414. ((eq gr :startend)
  1415. (prog1 (if colgropen "|" "|")
  1416. (setq colgropen nil)))
  1417. (t ""))
  1418. (if (memq gr '(:end :startend))
  1419. (progn (setq colgropen nil) "|")
  1420. "")))
  1421. fnum ""))))
  1422. ;; fix double || in line-fmt
  1423. (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
  1424. ;; maybe remove the first and last "|"
  1425. (when (and (not org-export-latex-tables-column-borders)
  1426. (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
  1427. (setq line-fmt (match-string 2 line-fmt)))
  1428. ;; format alignment
  1429. (unless align
  1430. (setq align (apply 'format
  1431. (cons line-fmt
  1432. (mapcar (lambda (x) (if x "r" "l"))
  1433. org-table-last-alignment)))))
  1434. ;; prepare the table to send to orgtbl-to-latex
  1435. (setq lines
  1436. (mapcar
  1437. (lambda(elem)
  1438. (or (and (string-match "[ \t]*|-+" elem) 'hline)
  1439. (org-split-string (org-trim elem) "|")))
  1440. lines))
  1441. (when insert
  1442. (insert (org-export-latex-protect-string
  1443. (concat
  1444. (if longtblp
  1445. (concat "\\begin{longtable}{" align "}\n")
  1446. (if floatp "\\begin{table}[htb]\n"))
  1447. (if floatp
  1448. (format
  1449. "\\caption{%s%s}"
  1450. (if label (concat "\\\label{" label "}") "")
  1451. (or caption "")))
  1452. (if (and longtblp caption) "\\\\\n" "\n")
  1453. (if (and org-export-latex-tables-centered (not longtblp))
  1454. "\\begin{center}\n")
  1455. (if (not longtblp) (concat "\\begin{tabular}{" align "}\n"))
  1456. (orgtbl-to-latex
  1457. lines
  1458. `(:tstart nil :tend nil
  1459. :hlend ,(if longtblp
  1460. (format "\\\\
  1461. \\hline
  1462. \\endhead
  1463. \\hline\\multicolumn{%d}{r}{Continued on next page}\\
  1464. \\endfoot
  1465. \\endlastfoot" (length org-table-last-alignment))
  1466. nil)))
  1467. (if (not longtblp) (concat "\n\\end{tabular}"))
  1468. (if longtblp "\n" (if org-export-latex-tables-centered
  1469. "\n\\end{center}\n" "\n"))
  1470. (if longtblp
  1471. "\\end{longtable}"
  1472. (if floatp "\\end{table}"))))
  1473. "\n\n"))))))))
  1474. (defun org-export-latex-fontify ()
  1475. "Convert fontification to LaTeX."
  1476. (goto-char (point-min))
  1477. (while (re-search-forward org-emph-re nil t)
  1478. ;; The match goes one char after the *string*, except at the end of a line
  1479. (let ((emph (assoc (match-string 3)
  1480. org-export-latex-emphasis-alist))
  1481. (beg (match-beginning 0))
  1482. (end (match-end 0))
  1483. rpl s)
  1484. (unless emph
  1485. (message "`org-export-latex-emphasis-alist' has no entry for formatting triggered by \"%s\""
  1486. (match-string 3)))
  1487. (unless (or (and (get-text-property (- (point) 2) 'org-protected)
  1488. (not (get-text-property
  1489. (- (point) 2) 'org-verbatim-emph)))
  1490. (save-excursion
  1491. (goto-char (match-beginning 1))
  1492. (save-match-data
  1493. (and (org-at-table-p)
  1494. (string-match
  1495. "[|\n]" (buffer-substring beg end))))))
  1496. (setq s (match-string 4))
  1497. (setq rpl (concat (match-string 1)
  1498. (org-export-latex-emph-format (cadr emph)
  1499. (match-string 4))
  1500. (match-string 5)))
  1501. (if (caddr emph)
  1502. (setq rpl (org-export-latex-protect-string rpl))
  1503. (save-match-data
  1504. (if (string-match "\\`.?\\(\\\\[a-z]+{\\)\\(.*\\)\\(}\\).?\\'" rpl)
  1505. (progn
  1506. (add-text-properties (match-beginning 1) (match-end 1)
  1507. '(org-protected t) rpl)
  1508. (add-text-properties (match-beginning 3) (match-end 3)
  1509. '(org-protected t) rpl)))))
  1510. (replace-match rpl t t)))
  1511. (backward-char)))
  1512. (defvar org-export-latex-use-verb nil)
  1513. (defun org-export-latex-emph-format (format string)
  1514. "Format an emphasis string and handle the \\verb special case."
  1515. (when (equal format "\\verb")
  1516. (save-match-data
  1517. (if org-export-latex-use-verb
  1518. (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
  1519. (catch 'exit
  1520. (loop for i from 0 to (1- (length ll)) do
  1521. (if (not (string-match (regexp-quote (substring ll i (1+ i)))
  1522. string))
  1523. (progn
  1524. (setq format (concat "\\verb" (substring ll i (1+ i))
  1525. "%s" (substring ll i (1+ i))))
  1526. (throw 'exit nil))))))
  1527. (let ((start 0)
  1528. (trans '(("\\" . "\\textbackslash{}")
  1529. ("~" . "\\textasciitilde{}")
  1530. ("^" . "\\textasciicircum{}")))
  1531. (rtn "") char)
  1532. (while (string-match "[\\{}$%&_#~^]" string)
  1533. (setq char (match-string 0 string))
  1534. (if (> (match-beginning 0) 0)
  1535. (setq rtn (concat rtn (substring string
  1536. 0 (match-beginning 0)))))
  1537. (setq string (substring string (1+ (match-beginning 0))))
  1538. (setq char (or (cdr (assoc char trans)) (concat "\\" char))
  1539. rtn (concat rtn char)))
  1540. (setq string (concat rtn string) format "\\texttt{%s}")))))
  1541. (format format string))
  1542. (defun org-export-latex-links ()
  1543. ;; Make sure to use the LaTeX hyperref and graphicx package
  1544. ;; or send some warnings.
  1545. "Convert links to LaTeX."
  1546. (goto-char (point-min))
  1547. (while (re-search-forward org-bracket-link-analytic-regexp++ nil t)
  1548. (org-if-unprotected-1
  1549. (goto-char (match-beginning 0))
  1550. (let* ((re-radio org-export-latex-all-targets-re)
  1551. (remove (list (match-beginning 0) (match-end 0)))
  1552. (raw-path (org-extract-attributes (match-string 3)))
  1553. (full-raw-path (concat (match-string 1) raw-path))
  1554. (desc (match-string 5))
  1555. (type (or (match-string 2)
  1556. (if (or (file-name-absolute-p raw-path)
  1557. (string-match "^\\.\\.?/" raw-path))
  1558. "file")))
  1559. (coderefp (equal type "coderef"))
  1560. (caption (org-find-text-property-in-string 'org-caption raw-path))
  1561. (attr (or (org-find-text-property-in-string 'org-attributes raw-path)
  1562. (plist-get org-export-latex-options-plist :latex-image-options)))
  1563. (label (org-find-text-property-in-string 'org-label raw-path))
  1564. imgp radiop
  1565. ;; define the path of the link
  1566. (path (cond
  1567. ((member type '("coderef"))
  1568. raw-path)
  1569. ((member type '("http" "https" "ftp"))
  1570. (concat type ":" raw-path))
  1571. ((and re-radio (string-match re-radio raw-path))
  1572. (setq radiop t))
  1573. ((equal type "mailto")
  1574. (concat type ":" raw-path))
  1575. ((equal type "file")
  1576. (if (and (org-file-image-p
  1577. (expand-file-name
  1578. raw-path)
  1579. org-export-latex-inline-image-extensions)
  1580. (or (get-text-property 0 'org-no-description
  1581. raw-path)
  1582. (equal desc full-raw-path)))
  1583. (setq imgp t)
  1584. (progn (when (string-match "\\(.+\\)::.+" raw-path)
  1585. (setq raw-path (match-string 1 raw-path)))
  1586. (if (file-exists-p raw-path)
  1587. (concat type "://" (expand-file-name raw-path))
  1588. (concat type "://" (org-export-directory
  1589. :LaTeX org-export-latex-options-plist)
  1590. raw-path))))))))
  1591. ;; process with link inserting
  1592. (apply 'delete-region remove)
  1593. (cond ((and imgp
  1594. (plist-get org-export-latex-options-plist :inline-images))
  1595. ;; OK, we need to inline an image
  1596. (insert
  1597. (org-export-latex-format-image raw-path caption label attr)))
  1598. (coderefp
  1599. (insert (format
  1600. (org-export-get-coderef-format path desc)
  1601. (cdr (assoc path org-export-code-refs)))))
  1602. (radiop (insert (format "\\hyperref[%s]{%s}"
  1603. (org-solidify-link-text raw-path) desc)))
  1604. ((not type)
  1605. (insert (format "\\hyperref[%s]{%s}"
  1606. (org-remove-initial-hash
  1607. (org-solidify-link-text raw-path))
  1608. desc)))
  1609. (path
  1610. (when (org-at-table-p)
  1611. ;; There is a strange problem when we have a link in a table,
  1612. ;; ampersands then cause a problem. I think this must be
  1613. ;; a LaTeX issue, but we here implement a work-around anyway.
  1614. (setq path (org-export-latex-protect-amp path)
  1615. desc (org-export-latex-protect-amp desc)))
  1616. (insert (format "\\href{%s}{%s}" path desc)))
  1617. (t (insert "\\texttt{" desc "}")))))))
  1618. (defun org-export-latex-format-image (path caption label attr)
  1619. "Format the image element, depending on user settings."
  1620. (let (ind floatp wrapp placement figenv)
  1621. (setq floatp (or caption label))
  1622. (setq ind (org-get-text-property-any 0 'original-indentation path))
  1623. (when (and attr (stringp attr))
  1624. (if (string-match "[ \t]*\\<wrap\\>" attr)
  1625. (setq wrapp t floatp nil attr (replace-match "" t t attr)))
  1626. (if (string-match "[ \t]*\\<float\\>" attr)
  1627. (setq wrapp nil floatp t attr (replace-match "" t t attr))))
  1628. (setq placement
  1629. (cond
  1630. (wrapp "{l}{0.5\\textwidth}")
  1631. (floatp "[htb]")
  1632. (t "")))
  1633. (when (and attr (stringp attr)
  1634. (string-match "[ \t]*\\<placement=\\(\\S-+\\)" attr))
  1635. (setq placement (match-string 1 attr)
  1636. attr (replace-match "" t t attr)))
  1637. (setq attr (and attr (org-trim attr)))
  1638. (when (or (not attr) (= (length attr) 0))
  1639. (setq attr (cond (floatp "width=0.7\\textwidth")
  1640. (wrapp "width=0.48\\textwidth")
  1641. (t attr))))
  1642. (setq figenv
  1643. (cond
  1644. (wrapp "\\begin{wrapfigure}%placement
  1645. \\centering
  1646. \\includegraphics[%attr]{%path}
  1647. \\caption{%labelcmd%caption}
  1648. \\end{wrapfigure}")
  1649. (floatp "\\begin{figure}%placement
  1650. \\centering
  1651. \\includegraphics[%attr]{%path}
  1652. \\caption{%labelcmd%caption}
  1653. \\end{figure}")
  1654. (t "\\includegraphics[%attr]{%path}")))
  1655. (setq figenv (mapconcat 'identity (split-string figenv "\n")
  1656. (save-excursion (beginning-of-line 1)
  1657. (looking-at "[ \t]*")
  1658. (concat "\n" (match-string 0)))))
  1659. (if (and (not label) (not caption)
  1660. (string-match "^\\\\caption{.*\n" figenv))
  1661. (setq figenv (replace-match "" t t figenv)))
  1662. (org-add-props
  1663. (org-fill-template
  1664. figenv
  1665. (list (cons "path"
  1666. (if (file-name-absolute-p path)
  1667. (expand-file-name path)
  1668. path))
  1669. (cons "attr" attr)
  1670. (cons "labelcmd" (if label (format "\\label{%s}"
  1671. label)""))
  1672. (cons "caption" (or caption ""))
  1673. (cons "placement" (or placement ""))))
  1674. nil 'original-indentation ind)))
  1675. (defun org-export-latex-protect-amp (s)
  1676. (while (string-match "\\([^\\\\]\\)\\(&\\)" s)
  1677. (setq s (replace-match (concat (match-string 1 s) "\\" (match-string 2 s))
  1678. t t s)))
  1679. s)
  1680. (defun org-remove-initial-hash (s)
  1681. (if (string-match "\\`#" s)
  1682. (substring s 1)
  1683. s))
  1684. (defvar org-latex-entities) ; defined below
  1685. (defvar org-latex-entities-regexp) ; defined below
  1686. (defvar org-latex-entities-exceptions) ; defined below
  1687. (defun org-export-latex-preprocess (parameters)
  1688. "Clean stuff in the LaTeX export."
  1689. ;; Preserve line breaks
  1690. (goto-char (point-min))
  1691. (while (re-search-forward "\\\\\\\\" nil t)
  1692. (add-text-properties (match-beginning 0) (match-end 0)
  1693. '(org-protected t)))
  1694. ;; Preserve latex environments
  1695. (goto-char (point-min))
  1696. (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\*?\\)}" nil t)
  1697. (let* ((start (progn (beginning-of-line) (point)))
  1698. (end (and (re-search-forward
  1699. (concat "^[ \t]*\\\\end{"
  1700. (regexp-quote (match-string 1))
  1701. "}") nil t)
  1702. (point-at-eol))))
  1703. (if end
  1704. (add-text-properties start end '(org-protected t))
  1705. (goto-char (point-at-eol)))))
  1706. ;; Preserve math snippets
  1707. (let* ((matchers (plist-get org-format-latex-options :matchers))
  1708. (re-list org-latex-regexps)
  1709. beg end re e m n block off)
  1710. ;; Check the different regular expressions
  1711. (while (setq e (pop re-list))
  1712. (setq m (car e) re (nth 1 e) n (nth 2 e)
  1713. block (if (nth 3 e) "\n\n" ""))
  1714. (setq off (if (member m '("$" "$1")) 1 0))
  1715. (when (and (member m matchers) (not (equal m "begin")))
  1716. (goto-char (point-min))
  1717. (while (re-search-forward re nil t)
  1718. (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
  1719. (add-text-properties beg end '(org-protected t org-latex-math t))))))
  1720. ;; Convert LaTeX to \LaTeX{}
  1721. (goto-char (point-min))
  1722. (let ((case-fold-search nil))
  1723. (while (re-search-forward "\\([^+_]\\)LaTeX" nil t)
  1724. (org-if-unprotected
  1725. (replace-match (org-export-latex-protect-string
  1726. (concat (match-string 1) "\\LaTeX{}")) t t))))
  1727. ;; Convert blockquotes
  1728. (goto-char (point-min))
  1729. (while (search-forward "ORG-BLOCKQUOTE-START" nil t)
  1730. (org-replace-match-keep-properties "\\begin{quote}" t t))
  1731. (goto-char (point-min))
  1732. (while (search-forward "ORG-BLOCKQUOTE-END" nil t)
  1733. (org-replace-match-keep-properties "\\end{quote}" t t))
  1734. ;; Convert verse
  1735. (goto-char (point-min))
  1736. (while (search-forward "ORG-VERSE-START" nil t)
  1737. (org-replace-match-keep-properties "\\begin{verse}" t t)
  1738. (beginning-of-line 2)
  1739. (while (and (not (looking-at "[ \t]*ORG-VERSE-END.*")) (not (eobp)))
  1740. (when (looking-at "\\([ \t]+\\)\\([^ \t\n]\\)")
  1741. (goto-char (match-end 1))
  1742. (org-replace-match-keep-properties
  1743. (org-export-latex-protect-string
  1744. (concat "\\hspace*{1cm}" (match-string 2))) t t)
  1745. (beginning-of-line 1))
  1746. (if (looking-at "[ \t]*$")
  1747. (insert (org-export-latex-protect-string "\\vspace*{1em}"))
  1748. (unless (looking-at ".*?[^ \t\n].*?\\\\\\\\[ \t]*$")
  1749. (end-of-line 1)
  1750. (insert "\\\\")))
  1751. (beginning-of-line 2))
  1752. (and (looking-at "[ \t]*ORG-VERSE-END.*")
  1753. (org-replace-match-keep-properties "\\end{verse}" t t)))
  1754. ;; Convert center
  1755. (goto-char (point-min))
  1756. (while (search-forward "ORG-CENTER-START" nil t)
  1757. (org-replace-match-keep-properties "\\begin{center}" t t))
  1758. (goto-char (point-min))
  1759. (while (search-forward "ORG-CENTER-END" nil t)
  1760. (org-replace-match-keep-properties "\\end{center}" t t))
  1761. (run-hooks 'org-export-latex-after-blockquotes-hook)
  1762. ;; Convert horizontal rules
  1763. (goto-char (point-min))
  1764. (while (re-search-forward "^----+.$" nil t)
  1765. (org-if-unprotected
  1766. (replace-match (org-export-latex-protect-string "\\hrule") t t)))
  1767. ;; Protect LaTeX commands like \command[...]{...} or \command{...}
  1768. (goto-char (point-min))
  1769. (let ((re (concat
  1770. "\\\\[a-zA-Z]+"
  1771. "\\(?:\\[[^][\n]*?\\]\\)*"
  1772. "\\(" (org-create-multibrace-regexp "{" "}" 3) "\\)\\{1,3\\}")))
  1773. (while (re-search-forward re nil t)
  1774. (unless (save-excursion (goto-char (match-beginning 0))
  1775. (equal (char-after (point-at-bol)) ?#))
  1776. (add-text-properties (match-beginning 0) (match-end 0)
  1777. '(org-protected t)))))
  1778. ;; Protect LaTeX entities
  1779. (goto-char (point-min))
  1780. (let (a)
  1781. (while (re-search-forward org-latex-entities-regexp nil t)
  1782. (if (setq a (assoc (match-string 0) org-latex-entities-exceptions))
  1783. (replace-match (org-add-props (nth 1 a) nil 'org-protected t)
  1784. t t)
  1785. (add-text-properties (match-beginning 0) (match-end 0)
  1786. '(org-protected t)))))
  1787. ;; Replace radio links
  1788. (goto-char (point-min))
  1789. (while (re-search-forward
  1790. (concat "<<<?" org-export-latex-all-targets-re
  1791. ">>>?\\((INVISIBLE)\\)?") nil t)
  1792. (org-if-unprotected-at (+ (match-beginning 0) 2)
  1793. (replace-match
  1794. (concat
  1795. (org-export-latex-protect-string
  1796. (format "\\label{%s}" (save-match-data (org-solidify-link-text
  1797. (match-string 1)))))
  1798. (if (match-string 2) "" (match-string 1)))
  1799. t t)))
  1800. ;; Delete @<...> constructs
  1801. ;; Thanks to Daniel Clemente for this regexp
  1802. (goto-char (point-min))
  1803. (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t)
  1804. (org-if-unprotected
  1805. (replace-match "")))
  1806. ;; When converting to LaTeX, replace footnotes
  1807. ;; FIXME: don't protect footnotes from conversion
  1808. (when (plist-get org-export-latex-options-plist :footnotes)
  1809. (goto-char (point-min))
  1810. (while (re-search-forward "\\[\\([0-9]+\\)\\]" nil t)
  1811. (org-if-unprotected
  1812. (when (and (save-match-data
  1813. (save-excursion (beginning-of-line)
  1814. (looking-at "[^:|#]")))
  1815. (not (org-in-verbatim-emphasis)))
  1816. (let ((foot-beg (match-beginning 0))
  1817. (foot-end (match-end 0))
  1818. (foot-prefix (match-string 0))
  1819. footnote footnote-rpl)
  1820. (save-excursion
  1821. (if (not (re-search-forward (concat "^" (regexp-quote foot-prefix))
  1822. nil t))
  1823. (replace-match (org-export-latex-protect-string
  1824. (concat "$^{" (match-string 1) "}$")))
  1825. (replace-match "")
  1826. (let ((end (save-excursion
  1827. (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t)
  1828. (match-beginning 0) (point-max)))))
  1829. (setq footnote (concat (org-trim (buffer-substring (point) end))
  1830. " ")) ; prevent last } being part of a link
  1831. (delete-region (point) end))
  1832. (goto-char foot-beg)
  1833. (delete-region foot-beg foot-end)
  1834. (unless (null footnote)
  1835. (setq footnote-rpl (format "\\footnote{%s}" footnote))
  1836. (add-text-properties 0 10 '(org-protected t) footnote-rpl)
  1837. (add-text-properties (1- (length footnote-rpl))
  1838. (length footnote-rpl)
  1839. '(org-protected t) footnote-rpl)
  1840. (insert footnote-rpl)))
  1841. )))))
  1842. ;; Remove footnote section tag for LaTeX
  1843. (goto-char (point-min))
  1844. (while (re-search-forward
  1845. (concat "^" footnote-section-tag-regexp) nil t)
  1846. (org-if-unprotected
  1847. (replace-match "")))))
  1848. ;;; List handling:
  1849. (defun org-export-latex-lists ()
  1850. "Convert plain text lists in current buffer into LaTeX lists."
  1851. (goto-char (point-min))
  1852. (while (re-search-forward org-list-beginning-re nil t)
  1853. (org-if-unprotected
  1854. (beginning-of-line)
  1855. (insert (org-list-to-latex (org-list-parse-list t)
  1856. org-export-latex-list-parameters))
  1857. "\n")))
  1858. (defconst org-latex-entities
  1859. '("\\!"
  1860. "\\'"
  1861. "\\+"
  1862. "\\,"
  1863. "\\-"
  1864. "\\:"
  1865. "\\;"
  1866. "\\<"
  1867. "\\="
  1868. "\\>"
  1869. "\\Huge"
  1870. "\\LARGE"
  1871. "\\Large"
  1872. "\\Styles"
  1873. "\\\\"
  1874. "\\`"
  1875. "\\addcontentsline"
  1876. "\\address"
  1877. "\\addtocontents"
  1878. "\\addtocounter"
  1879. "\\addtolength"
  1880. "\\addvspace"
  1881. "\\alph"
  1882. "\\appendix"
  1883. "\\arabic"
  1884. "\\author"
  1885. "\\begin{array}"
  1886. "\\begin{center}"
  1887. "\\begin{description}"
  1888. "\\begin{enumerate}"
  1889. "\\begin{eqnarray}"
  1890. "\\begin{equation}"
  1891. "\\begin{figure}"
  1892. "\\begin{flushleft}"
  1893. "\\begin{flushright}"
  1894. "\\begin{itemize}"
  1895. "\\begin{list}"
  1896. "\\begin{minipage}"
  1897. "\\begin{picture}"
  1898. "\\begin{quotation}"
  1899. "\\begin{quote}"
  1900. "\\begin{tabbing}"
  1901. "\\begin{table}"
  1902. "\\begin{tabular}"
  1903. "\\begin{thebibliography}"
  1904. "\\begin{theorem}"
  1905. "\\begin{titlepage}"
  1906. "\\begin{verbatim}"
  1907. "\\begin{verse}"
  1908. "\\bf"
  1909. "\\bf"
  1910. "\\bibitem"
  1911. "\\bigskip"
  1912. "\\cdots"
  1913. "\\centering"
  1914. "\\circle"
  1915. "\\cite"
  1916. "\\cleardoublepage"
  1917. "\\clearpage"
  1918. "\\cline"
  1919. "\\closing"
  1920. "\\dashbox"
  1921. "\\date"
  1922. "\\ddots"
  1923. "\\dotfill"
  1924. "\\em"
  1925. "\\fbox"
  1926. "\\flushbottom"
  1927. "\\fnsymbol"
  1928. "\\footnote"
  1929. "\\footnotemark"
  1930. "\\footnotesize"
  1931. "\\footnotetext"
  1932. "\\frac"
  1933. "\\frame"
  1934. "\\framebox"
  1935. "\\hfill"
  1936. "\\hline"
  1937. "\\hrulespace"
  1938. "\\hspace"
  1939. "\\huge"
  1940. "\\hyphenation"
  1941. "\\include"
  1942. "\\includeonly"
  1943. "\\indent"
  1944. "\\input"
  1945. "\\it"
  1946. "\\kill"
  1947. "\\label"
  1948. "\\large"
  1949. "\\ldots"
  1950. "\\line"
  1951. "\\linebreak"
  1952. "\\linethickness"
  1953. "\\listoffigures"
  1954. "\\listoftables"
  1955. "\\location"
  1956. "\\makebox"
  1957. "\\maketitle"
  1958. "\\mark"
  1959. "\\mbox"
  1960. "\\medskip"
  1961. "\\multicolumn"
  1962. "\\multiput"
  1963. ("\\nbsp" "~")
  1964. "\\newcommand"
  1965. "\\newcounter"
  1966. "\\newenvironment"
  1967. "\\newfont"
  1968. "\\newlength"
  1969. "\\newline"
  1970. "\\newpage"
  1971. "\\newsavebox"
  1972. "\\newtheorem"
  1973. "\\nocite"
  1974. "\\nofiles"
  1975. "\\noindent"
  1976. "\\nolinebreak"
  1977. "\\nopagebreak"
  1978. "\\normalsize"
  1979. "\\onecolumn"
  1980. "\\opening"
  1981. "\\oval"
  1982. "\\overbrace"
  1983. "\\overline"
  1984. "\\pagebreak"
  1985. "\\pagenumbering"
  1986. "\\pageref"
  1987. "\\pagestyle"
  1988. "\\par"
  1989. "\\parbox"
  1990. "\\put"
  1991. "\\raggedbottom"
  1992. "\\raggedleft"
  1993. "\\raggedright"
  1994. "\\raisebox"
  1995. "\\ref"
  1996. "\\rm"
  1997. "\\roman"
  1998. "\\rule"
  1999. "\\savebox"
  2000. "\\sc"
  2001. "\\scriptsize"
  2002. "\\setcounter"
  2003. "\\setlength"
  2004. "\\settowidth"
  2005. "\\sf"
  2006. "\\shortstack"
  2007. "\\signature"
  2008. "\\sl"
  2009. "\\small"
  2010. "\\smallskip"
  2011. "\\sqrt"
  2012. "\\tableofcontents"
  2013. "\\telephone"
  2014. "\\thanks"
  2015. "\\thispagestyle"
  2016. "\\tiny"
  2017. "\\title"
  2018. "\\tt"
  2019. "\\twocolumn"
  2020. "\\typein"
  2021. "\\typeout"
  2022. "\\underbrace"
  2023. "\\underline"
  2024. "\\usebox"
  2025. "\\usecounter"
  2026. "\\value"
  2027. "\\vdots"
  2028. "\\vector"
  2029. "\\verb"
  2030. "\\vfill"
  2031. "\\vline"
  2032. "\\vspace")
  2033. "A list of LaTeX commands to be protected when performing conversion.")
  2034. (defvar org-latex-entities-exceptions nil)
  2035. (defconst org-latex-entities-regexp
  2036. (let (names rest)
  2037. (dolist (x org-latex-entities)
  2038. (when (consp x)
  2039. (add-to-list 'org-latex-entities-exceptions x)
  2040. (setq x (car x)))
  2041. (if (string-match "[a-zA-Z]$" x)
  2042. (push x names)
  2043. (push x rest)))
  2044. (concat "\\(" (regexp-opt (nreverse names)) "\\>\\)"
  2045. "\\|\\(" (regexp-opt (nreverse rest)) "\\)")))
  2046. (provide 'org-export-latex)
  2047. (provide 'org-latex)
  2048. ;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad
  2049. ;;; org-latex.el ends here