org-latex.el 98 KB

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