org-latex.el 78 KB

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