org-latex.el 94 KB

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