org-latex.el 99 KB

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