org-latex.el 94 KB

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