org-latex.el 96 KB

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