org-latex.el 97 KB

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