org-latex.el 94 KB

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