org-latex.el 78 KB

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