org-latex.el 98 KB

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