merge trunk
[bpt/emacs.git] / lisp / org / org-latex.el
index 3f4c1dc..609bcbe 100644 (file)
@@ -1,11 +1,10 @@
 ;;; org-latex.el --- LaTeX exporter for org-mode
 ;;
-;; Copyright (C) 2007-2011 Free Software Foundation, Inc.
+;; Copyright (C) 2007-2013 Free Software Foundation, Inc.
 ;;
 ;; Emacs Lisp Archive Entry
 ;; Filename: org-latex.el
-;; Version: 7.4
-;; Author: Bastien Guerry <bzg AT altern DOT org>
+;; Author: Bastien Guerry <bzg AT gnu DOT org>
 ;; Maintainer: Carsten Dominik <carsten.dominik AT gmail DOT com>
 ;; Keywords: org, wp, tex
 ;; Description: Converts an org-mode buffer into LaTeX
@@ -65,6 +64,8 @@
 (defvar org-export-latex-display-custom-times nil)
 (defvar org-export-latex-all-targets-re nil)
 (defvar org-export-latex-add-level 0)
+(defvar org-export-latex-footmark-seen nil
+  "List of footnotes markers seen so far by exporter.")
 (defvar org-export-latex-sectioning "")
 (defvar org-export-latex-sectioning-depth 0)
 (defvar org-export-latex-special-keyword-regexp
          org-deadline-string "\\|"
          org-closed-string"\\)")
   "Regexp matching special time planning keywords plus the time after it.")
-
-(defvar latexp)    ; dynamically scoped from org.el
-(defvar re-quote)  ; dynamically scoped from org.el
-(defvar commentsp) ; dynamically scoped from org.el
+(defvar org-re-quote)  ; dynamically scoped from org.el
+(defvar org-commentsp) ; dynamically scoped from org.el
 
 ;;; User variables:
 
@@ -219,6 +218,7 @@ For example, adding an entry
 will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
 are written as utf8 files."
   :group 'org-export-latex
+  :version "24.1"
   :type '(repeat
          (cons
           (string :tag "Derived from buffer")
@@ -230,14 +230,15 @@ are written as utf8 files."
     ("/" "\\emph{%s}" nil)
     ("_" "\\underline{%s}" nil)
     ("+" "\\st{%s}" nil)
-    ("=" "\\verb" t)
+    ("=" "\\protectedtexttt" t)
     ("~" "\\verb" t))
   "Alist of LaTeX expressions to convert emphasis fontifiers.
 Each element of the list is a list of three elements.
 The first element is the character used as a marker for fontification.
-The second element is a formatting string to wrap fontified text with.
+The second element is a format string to wrap fontified text with.
 If it is \"\\verb\", Org will automatically select a delimiter
-character that is not in the string.
+character that is not in the string.  \"\\protectedtexttt\" will use \\texttt
+to typeset and try to protect special characters.
 The third element decides whether to protect converted text from other
 conversions."
   :group 'org-export-latex
@@ -246,7 +247,7 @@ conversions."
 (defcustom org-export-latex-title-command "\\maketitle"
   "The command used to insert the title just after \\begin{document}.
 If this string contains the formatting specification \"%s\" then
-it will be used as a formatting string, passing the title as an
+it will be used as a format string, passing the title as an
 argument."
   :group 'org-export-latex
   :type 'string)
@@ -258,7 +259,7 @@ For example \orgTITLE for #+TITLE."
   :type 'boolean)
 
 (defcustom org-export-latex-date-format
-  "%d %B %Y"
+  "\\today"
   "Format string for \\date{...}."
   :group 'org-export-latex
   :type 'string)
@@ -283,6 +284,7 @@ markup defined, the first one in the association list will be used."
 (defcustom org-export-latex-tag-markup "\\textbf{%s}"
   "Markup for tags, as a printf format."
   :group 'org-export-latex
+  :version "24.1"
   :type 'string)
 
 (defcustom org-export-latex-timestamp-markup "\\textit{%s}"
@@ -290,6 +292,12 @@ markup defined, the first one in the association list will be used."
   :group 'org-export-latex
   :type 'string)
 
+(defcustom org-export-latex-timestamp-inactive-markup "\\textit{%s}"
+  "A printf format string to be applied to inactive time stamps."
+  :group 'org-export-latex
+  :version "24.1"
+  :type 'string)
+
 (defcustom org-export-latex-timestamp-keyword-markup "\\texttt{%s}"
   "A printf format string to be applied to time stamps."
   :group 'org-export-latex
@@ -297,18 +305,67 @@ markup defined, the first one in the association list will be used."
 
 (defcustom org-export-latex-href-format "\\href{%s}{%s}"
   "A printf format string to be applied to href links.
-The format must contain two %s instances.  The first will be filled with
-the link, the second with the link description."
+The format must contain either two %s instances or just one.
+If it contains two %s instances, the first will be filled with
+the link, the second with the link description.  If it contains
+only one, the %s will be filled with the link."
   :group 'org-export-latex
+  :version "24.1"
   :type 'string)
 
 (defcustom org-export-latex-hyperref-format "\\hyperref[%s]{%s}"
   "A printf format string to be applied to hyperref links.
-The format must contain two %s instances.  The first will be filled with
-the link, the second with the link description."
+The format must contain one or two %s instances.  The first one
+will be filled with the link, the second with its description."
   :group 'org-export-latex
+  :version "24.1"
   :type 'string)
 
+(defcustom org-export-latex-hyperref-options-format
+  "\\hypersetup{\n  pdfkeywords={%s},\n  pdfsubject={%s},\n  pdfcreator={Emacs Org-mode version %s}}\n"
+  "A format string for hyperref options.
+When non-nil, it must contain three %s format specifications
+which will respectively be replaced by the document's keywords,
+its description and the Org's version number, as a string.  Set
+this option to the empty string if you don't want to include
+hyperref options altogether."
+  :type 'string
+  :version "24.3"
+  :group 'org-export-latex)
+
+(defcustom org-export-latex-footnote-separator "\\textsuperscript{,}\\,"
+  "Text used to separate footnotes."
+  :group 'org-export-latex
+  :version "24.1"
+  :type 'string)
+
+(defcustom org-export-latex-quotes
+  '(("fr" ("\\(\\s-\\|[[(]\\)\"" . "«~") ("\\(\\S-\\)\"" . "~»") ("\\(\\s-\\|(\\)'" . "'"))
+    ("en" ("\\(\\s-\\|[[(]\\)\"" . "``") ("\\(\\S-\\)\"" . "''") ("\\(\\s-\\|(\\)'" . "`")))
+  "Alist for quotes to use when converting english double-quotes.
+
+The CAR of each item in this alist is the language code.
+The CDR of each item in this alist is a list of three CONS:
+- the first CONS defines the opening quote;
+- the second CONS defines the closing quote;
+- the last CONS defines single quotes.
+
+For each item in a CONS, the first string is a regexp
+for allowed characters before/after the quote, the second
+string defines the replacement string for this quote."
+  :group 'org-export-latex
+  :version "24.1"
+  :type '(list
+         (cons :tag "Opening quote"
+               (string :tag "Regexp for char before")
+               (string :tag "Replacement quote     "))
+         (cons :tag "Closing quote"
+               (string :tag "Regexp for char after ")
+               (string :tag "Replacement quote     "))
+         (cons :tag "Single quote"
+               (string :tag "Regexp for char before")
+               (string :tag "Replacement quote     "))))
+
 (defcustom org-export-latex-tables-verbatim nil
   "When non-nil, tables are exported verbatim."
   :group 'org-export-latex
@@ -319,12 +376,46 @@ the link, the second with the link description."
   :group 'org-export-latex
   :type 'boolean)
 
+(defcustom org-export-latex-table-caption-above t
+  "When non-nil, the caption is set above the table.  When nil,
+the caption is set below the table."
+  :group 'org-export-latex
+  :version "24.1"
+  :type 'boolean)
+
 (defcustom org-export-latex-tables-column-borders nil
   "When non-nil, grouping columns can cause outer vertical lines in tables.
 When nil, grouping causes only separation lines between groups."
   :group 'org-export-latex
   :type 'boolean)
 
+(defcustom org-export-latex-tables-tstart nil
+  "LaTeX command for top rule for tables."
+  :group 'org-export-latex
+  :version "24.1"
+  :type '(choice
+          (const :tag "Nothing" nil)
+          (string :tag "String")
+          (const  :tag "Booktabs default: \\toprule" "\\toprule")))
+
+(defcustom org-export-latex-tables-hline "\\hline"
+  "LaTeX command to use for a rule somewhere in the middle of a table."
+  :group 'org-export-latex
+  :version "24.1"
+  :type '(choice
+          (string :tag "String")
+          (const  :tag "Standard: \\hline" "\\hline")
+          (const  :tag "Booktabs default: \\midrule" "\\midrule")))
+
+(defcustom org-export-latex-tables-tend nil
+  "LaTeX command for bottom rule for tables."
+  :group 'org-export-latex
+  :version "24.1"
+  :type '(choice
+          (const :tag "Nothing" nil)
+          (string :tag "String")
+          (const  :tag "Booktabs default: \\bottomrule" "\\bottomrule")))
+
 (defcustom org-export-latex-low-levels 'itemize
   "How to convert sections below the current level of sectioning.
 This is specified by the `org-export-headline-levels' option or the
@@ -353,7 +444,7 @@ string should be like \"\\end{itemize\"."
                 (string :tag "Use a section string" :value "\\subparagraph{%s}")))
 
 (defcustom org-export-latex-list-parameters
-  '(:cbon "$\\boxtimes$" :cboff "$\\Box$")
+  '(:cbon "$\\boxtimes$" :cboff "$\\Box$" :cbtrans "$\\boxminus$")
   "Parameters for the LaTeX list exporter.
 These parameters will be passed on to `org-list-to-latex', which in turn
 will pass them (combined with the LaTeX default list parameters) to
@@ -362,7 +453,7 @@ will pass them (combined with the LaTeX default list parameters) to
   :type 'plist)
 
 (defcustom org-export-latex-verbatim-wrap
-  '("\\begin{verbatim}\n" . "\\end{verbatim}\n")
+  '("\\begin{verbatim}\n" . "\\end{verbatim}")
   "Environment to be wrapped around a fixed-width section in LaTeX export.
 This is a cons with two strings, to be added before and after the
 fixed-with text.
@@ -390,15 +481,15 @@ Alternatively,
   (setq org-export-latex-listings 'minted)
 
 causes source code to be exported using the minted package as
-opposed to listings. If you want to use minted, you need to add
+opposed to listings.  If you want to use minted, you need to add
 the minted package to `org-export-latex-packages-alist', for
 example using customize, or with
 
   (require 'org-latex)
   (add-to-list 'org-export-latex-packages-alist '(\"\" \"minted\"))
 
-In addition, it is neccessary to install
-pygments (http://pygments.org), and to configure
+In addition, it is necessary to install
+pygments (http://pygments.org), and to configure the variable
 `org-latex-to-pdf-process' so that the -shell-escape option is
 passed to pdflatex.
 "
@@ -434,6 +525,7 @@ Code blocks exported with the listings package (controlled by the
 `org-export-latex-listings' variable) can be named in the style
 of noweb."
   :group 'org-export-latex
+  :version "24.1"
   :type 'boolean)
 
 (defcustom org-export-latex-minted-langs
@@ -455,11 +547,75 @@ with:
 pygmentize -L lexers
 "
   :group 'org-export-latex
+  :version "24.1"
   :type '(repeat
          (list
           (symbol :tag "Major mode       ")
           (string :tag "Listings language"))))
 
+(defcustom org-export-latex-listings-options nil
+  "Association list of options for the latex listings package.
+
+These options are supplied as a comma-separated list to the
+\\lstset command.  Each element of the association list should be
+a list containing two strings: the name of the option, and the
+value.  For example,
+
+  (setq org-export-latex-listings-options
+    '((\"basicstyle\" \"\\small\")
+      (\"keywordstyle\" \"\\color{black}\\bfseries\\underbar\")))
+
+will typeset the code in a small size font with underlined, bold
+black keywords.
+
+Note that the same options will be applied to blocks of all
+languages."
+  :group 'org-export-latex
+  :version "24.1"
+  :type '(repeat
+         (list
+          (string :tag "Listings option name ")
+          (string :tag "Listings option value"))))
+
+(defcustom org-export-latex-minted-options nil
+  "Association list of options for the latex minted package.
+
+These options are supplied within square brackets in
+\\begin{minted} environments.  Each element of the alist should be
+a list containing two strings: the name of the option, and the
+value.  For example,
+
+  (setq org-export-latex-minted-options
+    '((\"bgcolor\" \"bg\") (\"frame\" \"lines\")))
+
+will result in src blocks being exported with
+
+\\begin{minted}[bgcolor=bg,frame=lines]{<LANG>}
+
+as the start of the minted environment.  Note that the same
+options will be applied to blocks of all languages."
+  :group 'org-export-latex
+  :version "24.1"
+  :type '(repeat
+         (list
+          (string :tag "Minted option name ")
+          (string :tag "Minted option value"))))
+
+(defvar org-export-latex-custom-lang-environments nil
+  "Association list mapping languages to language-specific latex
+  environments used during export of src blocks by the listings
+  and minted latex packages.  For example,
+
+  (setq org-export-latex-custom-lang-environments
+     '((python \"pythoncode\")))
+
+  would have the effect that if org encounters begin_src python
+  during latex export it will output
+
+  \\begin{pythoncode}
+  <src block body>
+  \\end{pythoncode}")
+
 (defcustom org-export-latex-remove-from-headlines
   '(:todo nil :priority nil :tags nil)
   "A plist of keywords to remove from headlines.  OBSOLETE.
@@ -473,14 +629,27 @@ and `org-export-with-tags' instead."
   :type 'plist
   :group 'org-export-latex)
 
-(defcustom org-export-latex-image-default-option "width=10em"
+(defcustom org-export-latex-image-default-option "width=.9\\linewidth"
   "Default option for images."
   :group 'org-export-latex
   :type 'string)
 
+(defcustom org-latex-default-figure-position "htb"
+  "Default position for latex figures."
+  :group 'org-export-latex
+  :version "24.1"
+  :type 'string)
+
 (defcustom org-export-latex-tabular-environment "tabular"
   "Default environment used to build tables."
   :group 'org-export-latex
+  :version "24.1"
+  :type 'string)
+
+(defcustom org-export-latex-link-with-unknown-path-format "\\texttt{%s}"
+  "Format string for links with unknown path type."
+  :group 'org-export-latex
+  :version "24.3"
   :type 'string)
 
 (defcustom org-export-latex-inline-image-extensions
@@ -508,11 +677,24 @@ allowed.  The default we use here encompasses both."
   '("pdflatex -interaction nonstopmode -output-directory %o %f"
     "pdflatex -interaction nonstopmode -output-directory %o %f"
     "pdflatex -interaction nonstopmode -output-directory %o %f")
-  "Commands to process a LaTeX file to a PDF file.
-This is a list of strings, each of them will be given to the shell
-as a command.  %f in the command will be replaced by the full file name, %b
-by the file base name (i.e. without extension) and %o by the base directory
-of the file.
+  "Commands to process a LaTeX file to a PDF file and process latex
+fragments to pdf files.By default,this is a list of strings,and each of
+strings will be given to the shell as a command. %f in the command will
+be replaced by the full file name, %b by the file base name (i.e. without
+extension) and %o by the base directory of the file.
+
+If you set `org-create-formula-image-program'
+`org-export-with-LaTeX-fragments' to 'imagemagick, you can add a
+sublist which contains your own command(s) for LaTeX fragments
+previewing, like this:
+
+   '(\"xelatex -interaction nonstopmode -output-directory %o %f\"
+     \"xelatex -interaction nonstopmode -output-directory %o %f\"
+     ;; use below command(s) to convert latex fragments
+     (\"xelatex %f\"))
+
+With no such sublist, the default command used to convert LaTeX
+fragments will be the first string in the list.
 
 The reason why this is a list is that it usually takes several runs of
 `pdflatex', maybe mixed with a call to `bibtex'.  Org does not have a clever
@@ -537,16 +719,28 @@ This function should accept the file name as its single argument."
                  (string :tag "Shell command"))
          (const :tag "2 runs of pdflatex"
                 ("pdflatex -interaction nonstopmode -output-directory %o %f"
-                  "pdflatex -interaction nonstopmode -output-directory %o %f"))
+                 "pdflatex -interaction nonstopmode -output-directory %o %f"))
          (const :tag "3 runs of pdflatex"
                 ("pdflatex -interaction nonstopmode -output-directory %o %f"
-                  "pdflatex -interaction nonstopmode -output-directory %o %f"
-                  "pdflatex -interaction nonstopmode -output-directory %o %f"))
+                 "pdflatex -interaction nonstopmode -output-directory %o %f"
+                 "pdflatex -interaction nonstopmode -output-directory %o %f"))
          (const :tag "pdflatex,bibtex,pdflatex,pdflatex"
                 ("pdflatex -interaction nonstopmode -output-directory %o %f"
-                  "bibtex %b"
-                  "pdflatex -interaction nonstopmode -output-directory %o %f"
-                  "pdflatex -interaction nonstopmode -output-directory %o %f"))
+                 "bibtex %b"
+                 "pdflatex -interaction nonstopmode -output-directory %o %f"
+                 "pdflatex -interaction nonstopmode -output-directory %o %f"))
+         (const :tag "2 runs of xelatex"
+                ("xelatex -interaction nonstopmode -output-directory %o %f"
+                 "xelatex -interaction nonstopmode -output-directory %o %f"))
+         (const :tag "3 runs of xelatex"
+                ("xelatex -interaction nonstopmode -output-directory %o %f"
+                 "xelatex -interaction nonstopmode -output-directory %o %f"
+                 "xelatex -interaction nonstopmode -output-directory %o %f"))
+         (const :tag "xelatex,bibtex,xelatex,xelatex"
+                ("xelatex -interaction nonstopmode -output-directory %o %f"
+                 "bibtex %b"
+                 "xelatex -interaction nonstopmode -output-directory %o %f"
+                 "xelatex -interaction nonstopmode -output-directory %o %f"))
          (const :tag "texi2dvi"
                 ("texi2dvi -p -b -c -V %f"))
          (const :tag "rubber"
@@ -557,6 +751,7 @@ This function should accept the file name as its single argument."
   '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
   "The list of file extensions to consider as LaTeX logfiles."
   :group 'org-export-pdf
+  :version "24.1"
   :type '(repeat (string :tag "Extension")))
 
 (defcustom org-export-pdf-remove-logfiles t
@@ -592,14 +787,14 @@ emacs   --batch
         --load=$HOME/lib/emacs/org.el
         --eval \"(setq org-export-headline-levels 2)\"
         --visit=MyFile --funcall org-export-as-latex-batch"
-  (org-export-as-latex org-export-headline-levels 'hidden))
+  (org-export-as-latex org-export-headline-levels))
 
 ;;;###autoload
 (defun org-export-as-latex-to-buffer (arg)
   "Call `org-export-as-latex` with output to a temporary buffer.
 No file is created.  The prefix ARG is passed through to `org-export-as-latex'."
   (interactive "P")
-  (org-export-as-latex arg nil nil "*Org LaTeX Export*")
+  (org-export-as-latex arg nil "*Org LaTeX Export*")
   (when org-export-show-temporary-export-buffer
     (switch-to-buffer-other-window "*Org LaTeX Export*")))
 
@@ -613,7 +808,7 @@ then use this command to convert it."
   (interactive "r")
   (let (reg latex buf)
     (save-window-excursion
-      (if (org-mode-p)
+      (if (derived-mode-p 'org-mode)
          (setq latex (org-export-region-as-latex
                       beg end t 'string))
        (setq reg (buffer-substring beg end)
@@ -644,7 +839,7 @@ a Lisp program could call this function in the following way:
 When called interactively, the output buffer is selected, and shown
 in a window.  A non-interactive call will only return the buffer."
   (interactive "r\nP")
-  (when (interactive-p)
+  (when (org-called-interactively-p 'any)
     (setq buffer "*Org LaTeX Export*"))
   (let ((transient-mark-mode t) (zmacs-regions t)
        ext-plist rtn)
@@ -653,33 +848,31 @@ in a window.  A non-interactive call will only return the buffer."
     (set-mark (point)) ;; to activate the region
     (goto-char beg)
     (setq rtn (org-export-as-latex
-              nil nil ext-plist
+              nil ext-plist
               buffer body-only))
     (if (fboundp 'deactivate-mark) (deactivate-mark))
-    (if (and (interactive-p) (bufferp rtn))
+    (if (and (org-called-interactively-p 'any) (bufferp rtn))
        (switch-to-buffer-other-window rtn)
       rtn)))
 
 ;;;###autoload
-(defun org-export-as-latex (arg &optional hidden ext-plist
-                               to-buffer body-only pub-dir)
+(defun org-export-as-latex (arg &optional ext-plist to-buffer body-only pub-dir)
   "Export current buffer to a LaTeX file.
 If there is an active region, export only the region.  The prefix
 ARG specifies how many levels of the outline should become
 headlines.  The default is 3.  Lower levels will be exported
 depending on `org-export-latex-low-levels'.  The default is to
 convert them as description lists.
-HIDDEN is obsolete and does nothing.
-EXT-PLIST is a property list with
-external parameters overriding org-mode's default settings, but
-still inferior to file-local settings.  When TO-BUFFER is
-non-nil, create a buffer with that name and export to that
-buffer.  If TO-BUFFER is the symbol `string', don't leave any
-buffer behind but just return the resulting LaTeX as a string.
+EXT-PLIST is a property list with external parameters overriding
+org-mode's default settings, but still inferior to file-local settings.
+When TO-BUFFER is non-nil, create a buffer with that name and export
+to that buffer.  If TO-BUFFER is the symbol `string', don't leave any
+buffer behind and just return the resulting LaTeX as a string, with
+no LaTeX header.
 When BODY-ONLY is set, don't produce the file header and footer,
 simply return the content of \\begin{document}...\\end{document},
 without even the \\begin{document} and \\end{document} commands.
-when PUB-DIR is set, use this as the publishing directory."
+When PUB-DIR is set, use this as the publishing directory."
   (interactive "P")
   (when (and (not body-only) arg (listp arg)) (setq body-only t))
   (run-hooks 'org-export-first-hook)
@@ -700,11 +893,15 @@ when PUB-DIR is set, use this as the publishing directory."
                             '(:org-license-to-kill nil))))
   (org-update-radio-target-regexp)
   (org-export-latex-set-initial-vars ext-plist arg)
-  (setq org-export-opt-plist org-export-latex-options-plist)
+  (setq org-export-opt-plist org-export-latex-options-plist
+       org-export-footnotes-data (org-footnote-all-labels 'with-defs)
+       org-export-footnotes-seen nil
+       org-export-latex-footmark-seen nil)
   (org-install-letbind)
   (run-hooks 'org-export-latex-after-initial-vars-hook)
   (let* ((wcf (current-window-configuration))
-        (opt-plist org-export-latex-options-plist)
+        (opt-plist
+         (org-export-process-option-filters org-export-latex-options-plist))
         (region-p (org-region-active-p))
         (rbeg (and region-p (region-beginning)))
         (rend (and region-p (region-end)))
@@ -741,7 +938,7 @@ when PUB-DIR is set, use this as the publishing directory."
               (concat
                (file-name-as-directory
                 (or pub-dir
-                    (org-export-directory :LaTeX ext-plist)))
+                    (org-export-directory :LaTeX org-export-latex-options-plist)))
                (file-name-sans-extension
                 (or (and subtree-p
                          (org-entry-get rbeg "EXPORT_FILE_NAME" t))
@@ -755,11 +952,12 @@ when PUB-DIR is set, use this as the publishing directory."
                          (file-truename (or buffer-file-name "dummy.org")))
                   (concat filename ".tex")
                 filename)))
+        (auto-insert nil); Avoid any auto-insert stuff for the new file
+        (TeX-master (boundp 'TeX-master))
         (buffer (if to-buffer
-                    (cond
-                     ((eq to-buffer 'string) (get-buffer-create
-                                              "*Org LaTeX Export*"))
-                     (t (get-buffer-create to-buffer)))
+                    (if (eq to-buffer 'string)
+                        (get-buffer-create "*Org LaTeX Export*")
+                      (get-buffer-create to-buffer))
                   (find-file-noselect filename)))
         (odd org-odd-levels-only)
         (header (org-export-latex-make-header title opt-plist))
@@ -794,7 +992,7 @@ when PUB-DIR is set, use this as the publishing directory."
               (org-export-preprocess-string
                text
                :emph-multiline t
-               :for-LaTeX t
+               :for-backend 'latex
                :comments nil
                :tags (plist-get opt-plist :tags)
                :priority (plist-get opt-plist :priority)
@@ -802,6 +1000,7 @@ when PUB-DIR is set, use this as the publishing directory."
                :drawers (plist-get opt-plist :drawers)
                :timestamps (plist-get opt-plist :timestamps)
                :todo-keywords (plist-get opt-plist :todo-keywords)
+               :tasks (plist-get opt-plist :tasks)
                :add-text nil
                :skip-before-1st-heading skip
                :select-tags nil
@@ -811,7 +1010,7 @@ when PUB-DIR is set, use this as the publishing directory."
          (org-export-preprocess-string
           region
           :emph-multiline t
-          :for-LaTeX t
+          :for-backend 'latex
           :comments nil
           :tags (plist-get opt-plist :tags)
           :priority (plist-get opt-plist :priority)
@@ -819,6 +1018,7 @@ when PUB-DIR is set, use this as the publishing directory."
           :drawers (plist-get opt-plist :drawers)
           :timestamps (plist-get opt-plist :timestamps)
           :todo-keywords (plist-get opt-plist :todo-keywords)
+          :tasks (plist-get opt-plist :tasks)
           :add-text (if (eq to-buffer 'string) nil text)
           :skip-before-1st-heading skip
           :select-tags (plist-get opt-plist :select-tags)
@@ -840,10 +1040,10 @@ when PUB-DIR is set, use this as the publishing directory."
     (when (and text (not (eq to-buffer 'string)))
       (insert (org-export-latex-content
               text '(lists tables fixed-width keywords))
-              "\n\n"))
+             "\n\n"))
 
     ;; insert lines before the first headline
-    (unless skip
+    (unless (or skip (string-match "^\\*" first-lines))
       (insert first-lines))
 
     ;; export the content of headlines
@@ -889,6 +1089,11 @@ when PUB-DIR is set, use this as the publishing directory."
       (if (looking-at "[\n \t]+")
          (replace-match "\n")))
 
+    ;; Ensure we have a final newline
+    (goto-char (point-max))
+    (or (eq (char-before) ?\n)
+       (insert ?\n))
+
     (run-hooks 'org-export-latex-final-hook)
     (if to-buffer
        (unless (eq major-mode 'latex-mode) (latex-mode))
@@ -912,12 +1117,17 @@ when PUB-DIR is set, use this as the publishing directory."
   (interactive "P")
   (message "Exporting to PDF...")
   (let* ((wconfig (current-window-configuration))
-        (lbuf (org-export-as-latex arg hidden ext-plist
-                                   to-buffer body-only pub-dir))
+        (lbuf (org-export-as-latex arg ext-plist to-buffer body-only pub-dir))
         (file (buffer-file-name lbuf))
         (base (file-name-sans-extension (buffer-file-name lbuf)))
         (pdffile (concat base ".pdf"))
-        (cmds org-latex-to-pdf-process)
+        (cmds (if (eq org-export-latex-listings 'minted)
+                  ;; automatically add -shell-escape when needed
+                  (mapcar (lambda (cmd)
+                            (replace-regexp-in-string
+                             "pdflatex " "pdflatex -shell-escape " cmd))
+                          org-latex-to-pdf-process)
+                org-latex-to-pdf-process))
         (outbuf (get-buffer-create "*Org PDF LaTeX Output*"))
         (bibtex-p (with-current-buffer lbuf
                     (save-excursion
@@ -927,26 +1137,30 @@ when PUB-DIR is set, use this as the publishing directory."
     (with-current-buffer outbuf (erase-buffer))
     (message (concat "Processing LaTeX file " file "..."))
     (setq output-dir (file-name-directory file))
-    (if (and cmds (symbolp cmds))
-       (funcall cmds (shell-quote-argument file))
-      (while cmds
-       (setq cmd (pop cmds))
-       (while (string-match "%b" cmd)
-         (setq cmd (replace-match
-                    (save-match-data
-                      (shell-quote-argument base))
-                    t t cmd)))
-       (while (string-match "%f" cmd)
-         (setq cmd (replace-match
-                    (save-match-data
-                      (shell-quote-argument file))
-                    t t cmd)))
-       (while (string-match "%o" cmd)
-         (setq cmd (replace-match
-                    (save-match-data
-                      (shell-quote-argument output-dir))
-                    t t cmd)))
-       (shell-command cmd outbuf)))
+    (with-current-buffer lbuf
+      (save-excursion
+       (if (and cmds (symbolp cmds))
+           (funcall cmds (shell-quote-argument file))
+         (while cmds
+           (setq cmd (pop cmds))
+           (cond
+            ((not (listp cmd))
+             (while (string-match "%b" cmd)
+               (setq cmd (replace-match
+                          (save-match-data
+                            (shell-quote-argument base))
+                          t t cmd)))
+             (while (string-match "%f" cmd)
+               (setq cmd (replace-match
+                          (save-match-data
+                            (shell-quote-argument file))
+                          t t cmd)))
+             (while (string-match "%o" cmd)
+               (setq cmd (replace-match
+                          (save-match-data
+                            (shell-quote-argument output-dir))
+                          t t cmd)))
+             (shell-command cmd outbuf)))))))
     (message (concat "Processing LaTeX file " file "...done"))
     (setq errors (org-export-latex-get-error outbuf))
     (if (not (file-exists-p pdffile))
@@ -1084,7 +1298,9 @@ and its content."
 
 (defun org-export-latex-subcontent (subcontent num)
   "Export each cell of SUBCONTENT to LaTeX.
-If NUM, export sections as numerical sections."
+If NUM is non-nil export numbered sections, otherwise use unnumbered
+sections.  If NUM is an integer, export the highest NUM levels as
+numbered sections and lower levels as unnumbered sections."
   (let* ((heading (cdr (assoc 'heading subcontent)))
         (level (- (cdr (assoc 'level subcontent))
                   org-export-latex-add-level))
@@ -1096,7 +1312,7 @@ If NUM, export sections as numerical sections."
                                             org-export-target-aliases))))
         (sectioning org-export-latex-sectioning)
         (depth org-export-latex-sectioning-depth)
-        main-heading sub-heading)
+        main-heading sub-heading ctnt)
     (when (symbolp (car sectioning))
       (setq sectioning (funcall (car sectioning) level heading))
       (when sectioning
@@ -1120,6 +1336,9 @@ If NUM, export sections as numerical sections."
      ;; Normal conversion
      ((<= level depth)
       (let* ((sec (nth (1- level) sectioning))
+            (num (if (integerp num)
+                     (>= num level)
+                   num))
             start end)
        (if (consp (cdr sec))
            (setq start (nth (if num 0 2) sec)
@@ -1160,16 +1379,20 @@ If NUM, export sections as numerical sections."
                 (delete-region (point-at-bol 0) (point))
               (insert (format "\\begin{%s}\n"
                               (symbol-name org-export-latex-low-levels))))
-            (insert (format "\n\\item %s\\\\\n%s%%"
-                            heading
-                            (if label (format "\\label{%s}" label) "")))
-            (insert (org-export-latex-content content))
+            (let ((ctnt (org-export-latex-content content)))
+              (insert (format (if (not (equal (replace-regexp-in-string "\n" "" ctnt) ""))
+                                  "\n\\item %s\\\\\n%s%%"
+                                "\n\\item %s\n%s%%")
+                              heading
+                              (if label (format "\\label{%s}" label) "")))
+              (insert ctnt))
             (cond ((stringp subcontent) (insert subcontent))
                   ((listp subcontent) (org-export-latex-sub subcontent)))
             (insert (format "\\end{%s} %% ends low level\n"
                             (symbol-name org-export-latex-low-levels))))
 
-           ((listp org-export-latex-low-levels)
+           ((and (listp org-export-latex-low-levels)
+                 org-export-latex-low-levels)
             (if (string-match "% ends low level$"
                               (buffer-substring (point-at-bol 0) (point)))
                 (delete-region (point-at-bol 0) (point))
@@ -1215,7 +1438,7 @@ LEVEL indicates the default depth for export."
              (save-restriction
                (widen)
                (goto-char (point-min))
-               (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\(-[a-zA-Z]+\\)" nil t)
+               (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\([-/a-zA-Z]+\\)" nil t)
                     (match-string 1))))
            (plist-get org-export-latex-options-plist :latex-class)
            org-export-latex-default-class)
@@ -1266,7 +1489,15 @@ TITLE is the current title from the buffer or region.
 OPT-PLIST is the options plist for current buffer."
   (let ((toc (plist-get opt-plist :table-of-contents))
        (author (org-export-apply-macros-in-string
-                (plist-get opt-plist :author))))
+                (plist-get opt-plist :author)))
+       (email (replace-regexp-in-string
+               "_" "\\\\_"
+               (org-export-apply-macros-in-string
+                (plist-get opt-plist :email))))
+       (description (org-export-apply-macros-in-string
+                     (plist-get opt-plist :description)))
+       (keywords (org-export-apply-macros-in-string
+                  (plist-get opt-plist :keywords))))
     (concat
      (if (plist-get opt-plist :time-stamp-file)
         (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
@@ -1281,17 +1512,18 @@ OPT-PLIST is the options plist for current buffer."
      (org-export-apply-macros-in-string org-export-latex-append-header)
      ;; define alert if not yet defined
      "\n\\providecommand{\\alert}[1]{\\textbf{#1}}"
-     ;; beginning of the document
-     "\n\\begin{document}\n\n"
      ;; insert the title
      (format
       "\n\n\\title{%s}\n"
-      ;; convert the title
       (org-export-latex-fontify-headline title))
      ;; insert author info
      (if (plist-get opt-plist :author-info)
-        (format "\\author{%s}\n"
-                (org-export-latex-fontify-headline (or author user-full-name)))
+        (format "\\author{%s%s}\n"
+                (org-export-latex-fontify-headline (or author user-full-name))
+                (if (and (plist-get opt-plist :email-info) email
+                         (string-match "\\S-" email))
+                    (format "\\thanks{%s}" email)
+                  ""))
        (format "%%\\author{%s}\n"
               (org-export-latex-fontify-headline (or author user-full-name))))
      ;; insert the date
@@ -1299,6 +1531,13 @@ OPT-PLIST is the options plist for current buffer."
             (format-time-string
              (or (plist-get opt-plist :date)
                  org-export-latex-date-format)))
+     ;; add some hyperref options
+     (format org-export-latex-hyperref-options-format
+            (org-export-latex-fontify-headline keywords)
+            (org-export-latex-fontify-headline description)
+            (org-version))
+     ;; beginning of the document
+     "\n\\begin{document}\n\n"
      ;; insert the title command
      (when (string-match "\\S-" title)
        (if (string-match "%s" org-export-latex-title-command)
@@ -1325,14 +1564,15 @@ If END is non-nil, it is the end of the region."
   (save-excursion
     (goto-char (or beg (point-min)))
     (let* ((pt (point))
-          (end (if (re-search-forward (org-get-limited-outline-regexp) end t)
+          (end (if (re-search-forward
+                    (concat "^" (org-get-limited-outline-regexp)) end t)
                    (goto-char (match-beginning 0))
                  (goto-char (or end (point-max))))))
       (prog1
          (org-export-latex-content
           (org-export-preprocess-string
            (buffer-substring pt end)
-           :for-LaTeX t
+           :for-backend 'latex
            :emph-multiline t
            :add-text nil
            :comments nil
@@ -1354,12 +1594,10 @@ If END is non-nil, it is the end of the region."
                          (match-string 0))
                   (remove-text-properties (match-beginning 0) (match-end 0)
                                           '(:org-license-to-kill t))))))))))))
-              
+
 
 (defvar org-export-latex-header-defs nil
   "The header definitions that might be used in the LaTeX body.")
-(defvar org-export-latex-header-defs-re nil
-  "The header definitions that might be used in the LaTeX body.")
 
 (defun org-export-latex-content (content &optional exclude-list)
   "Convert CONTENT string to LaTeX.
@@ -1367,31 +1605,32 @@ Don't perform conversions that are in EXCLUDE-LIST.  Recognized
 conversion types are: quotation-marks, emphasis, sub-superscript,
 links, keywords, lists, tables, fixed-width"
   (with-temp-buffer
-   (insert content)
-   (unless (memq 'timestamps exclude-list)
-     (org-export-latex-time-stamps))
-   (unless (memq 'quotation-marks exclude-list)
-     (org-export-latex-quotation-marks))
-   (unless (memq 'emphasis exclude-list)
-     (when (plist-get org-export-latex-options-plist :emphasize)
-       (org-export-latex-fontify)))
-   (unless (memq 'sub-superscript exclude-list)
-     (org-export-latex-special-chars
-      (plist-get org-export-latex-options-plist :sub-superscript)))
-   (unless (memq 'links exclude-list)
-     (org-export-latex-links))
-   (unless (memq 'keywords exclude-list)
-     (org-export-latex-keywords))
-   (unless (memq 'lists exclude-list)
-     (org-export-latex-lists))
-   (unless (memq 'tables exclude-list)
-     (org-export-latex-tables
-      (plist-get org-export-latex-options-plist :tables)))
-   (unless (memq 'fixed-width exclude-list)
-     (org-export-latex-fixed-width
-      (plist-get org-export-latex-options-plist :fixed-width)))
-   ;; return string
-   (buffer-substring (point-min) (point-max))))
+    (org-install-letbind)
+    (insert content)
+    (unless (memq 'timestamps exclude-list)
+      (org-export-latex-time-stamps))
+    (unless (memq 'quotation-marks exclude-list)
+      (org-export-latex-quotation-marks))
+    (unless (memq 'emphasis exclude-list)
+      (when (plist-get org-export-latex-options-plist :emphasize)
+       (org-export-latex-fontify)))
+    (unless (memq 'sub-superscript exclude-list)
+      (org-export-latex-special-chars
+       (plist-get org-export-latex-options-plist :sub-superscript)))
+    (unless (memq 'links exclude-list)
+      (org-export-latex-links))
+    (unless (memq 'keywords exclude-list)
+      (org-export-latex-keywords))
+    (unless (memq 'lists exclude-list)
+      (org-export-latex-lists))
+    (unless (memq 'tables exclude-list)
+      (org-export-latex-tables
+       (plist-get org-export-latex-options-plist :tables)))
+    (unless (memq 'fixed-width exclude-list)
+      (org-export-latex-fixed-width
+       (plist-get org-export-latex-options-plist :fixed-width)))
+    ;; return string
+    (buffer-substring (point-min) (point-max))))
 
 (defun org-export-latex-protect-string (s)
   "Add the org-protected property to string S."
@@ -1443,7 +1682,7 @@ links, keywords, lists, tables, fixed-width"
          (format org-export-latex-tag-markup
                  (save-match-data
                    (replace-regexp-in-string
-                    "_" "\\\\_" (match-string 0)))))
+                    "\\([_#]\\)" "\\\\\\1" (match-string 0)))))
         t t)))))
 
 (defun org-export-latex-fontify-headline (string)
@@ -1454,7 +1693,7 @@ links, keywords, lists, tables, fixed-width"
     (insert "\n" string)
 
     ;; Preserve math snippets
-    
+
     (let* ((matchers (plist-get org-format-latex-options :matchers))
           (re-list org-latex-regexps)
           beg end re e m n block off)
@@ -1498,6 +1737,8 @@ links, keywords, lists, tables, fixed-width"
                               '(org-protected t)))))
     (when (plist-get org-export-latex-options-plist :emphasize)
       (org-export-latex-fontify))
+    (org-export-latex-time-stamps)
+    (org-export-latex-quotation-marks)
     (org-export-latex-keywords-maybe)
     (org-export-latex-special-chars
      (plist-get org-export-latex-options-plist :sub-superscript))
@@ -1510,29 +1751,28 @@ links, keywords, lists, tables, fixed-width"
   (let ((org-display-custom-times org-export-latex-display-custom-times))
     (while (re-search-forward org-ts-regexp-both nil t)
       (org-if-unprotected-at (1- (point))
-       (replace-match
-       (org-export-latex-protect-string
-        (format org-export-latex-timestamp-markup
-                (substring (org-translate-time (match-string 0)) 1 -1)))
-       t t)))))
+       (replace-match
+        (org-export-latex-protect-string
+         (format (if (string= "<" (substring (match-string 0) 0 1))
+                     org-export-latex-timestamp-markup
+                   org-export-latex-timestamp-inactive-markup)
+                 (substring (org-translate-time (match-string 0)) 1 -1)))
+        t t)))))
 
 (defun org-export-latex-quotation-marks ()
   "Export quotation marks depending on language conventions."
-  (let* ((lang (plist-get org-export-latex-options-plist :language))
-        (quote-rpl (if (equal lang "fr")
-                       '(("\\(\\s-\\)\"" "«~")
-                         ("\\(\\S-\\)\"" "~»")
-                         ("\\(\\s-\\)'" "`"))
-                     '(("\\(\\s-\\|[[(]\\)\"" "``")
-                       ("\\(\\S-\\)\"" "''")
-                       ("\\(\\s-\\|(\\)'" "`")))))
-    (mapc (lambda(l) (goto-char (point-min))
-           (while (re-search-forward (car l) nil t)
-             (let ((rpl (concat (match-string 1)
-                                (org-export-latex-protect-string
-                                 (copy-sequence (cadr l))))))
-               (org-if-unprotected-1
-                (replace-match rpl t t))))) quote-rpl)))
+  (mapc (lambda(l)
+         (goto-char (point-min))
+         (while (re-search-forward (car l) nil t)
+           (let ((rpl (concat (match-string 1)
+                              (org-export-latex-protect-string
+                               (copy-sequence (cdr l))))))
+             (org-if-unprotected-1
+              (replace-match rpl t t)))))
+       (cdr (or (assoc (plist-get org-export-latex-options-plist :language)
+                       org-export-latex-quotes)
+                ;; falls back on english
+                (assoc "en" org-export-latex-quotes)))))
 
 (defun org-export-latex-special-chars (sub-superscript)
   "Export special characters to LaTeX.
@@ -1571,7 +1811,7 @@ See the `org-export-latex.el' code for a complete conversion table."
                           (replace-match (match-string 2) t t)
                         (replace-match (concat (match-string 1) "\\"
                                                (match-string 2)) t t)))))
-             (unless (save-match-data (org-inside-latex-math-p))
+             (unless (save-match-data (or (org-inside-latex-math-p) (org-at-table-p)))
                (cond ((equal (match-string 2) "\\")
                       (replace-match (or (save-match-data
                                            (org-export-latex-treat-backslash-char
@@ -1602,13 +1842,7 @@ See the `org-export-latex.el' code for a complete conversion table."
          "\\(\\(\\\\?\\$\\)\\)"
          "\\([a-zA-Z0-9()]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\({[^{}]+}\\|[a-zA-Z0-9]+\\|[ \t\n]\\|[:punct:]\\|)\\|{[a-zA-Z0-9]+}\\|([a-zA-Z0-9]+)\\)"
          "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|\\([&#%{}\"]\\|[a-zA-Z][a-zA-Z0-9]*\\)\\)"
-         "\\(.\\|^\\)\\(&\\)"
-         "\\(.\\|^\\)\\(#\\)"
-         "\\(.\\|^\\)\\(%\\)"
-         "\\(.\\|^\\)\\({\\)"
-         "\\(.\\|^\\)\\(}\\)"
-         "\\(.\\|^\\)\\(~\\)"
-         "\\(.\\|^\\)\\(\\.\\.\\.\\)"
+         "\\(^\\|.\\)\\([&#%{}~]\\|\\.\\.\\.\\)"
          ;; (?\< . "\\textless{}")
          ;; (?\> . "\\textgreater{}")
          )))
@@ -1702,19 +1936,19 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
   (goto-char (point-min))
   (while (re-search-forward "^[ \t]*:\\([ \t]\\|$\\)" nil t)
     (unless (get-text-property (point) 'org-example)
-     (if opt
-        (progn (goto-char (match-beginning 0))
-               (insert "\\begin{verbatim}\n")
-               (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
-                 (replace-match (concat (match-string 1)
-                                        (match-string 2)) t t)
-                 (forward-line))
-               (insert "\\end{verbatim}\n\n"))
-       (progn (goto-char (match-beginning 0))
-             (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
-               (replace-match (concat "%" (match-string 1)
-                                      (match-string 2)) t t)
-               (forward-line)))))))
+      (if opt
+         (progn (goto-char (match-beginning 0))
+                (insert "\\begin{verbatim}\n")
+                (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
+                  (replace-match (concat (match-string 1)
+                                         (match-string 2)) t t)
+                  (forward-line))
+                (insert "\\end{verbatim}\n"))
+       (progn (goto-char (match-beginning 0))
+              (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
+                (replace-match (concat "%" (match-string 1)
+                                       (match-string 2)) t t)
+                (forward-line)))))))
 
 (defvar org-table-last-alignment) ; defined in org-table.el
 (defvar org-table-last-column-widths) ; defined in org-table.el
@@ -1740,7 +1974,8 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
              (org-table-last-column-widths (copy-sequence
                                             org-table-last-column-widths))
              fnum fields line lines olines gr colgropen line-fmt align
-             caption shortn label attr floatp placement longtblp)
+             caption width shortn label attr hfmt floatp placement
+            longtblp tblenv tabular-env)
         (if org-export-latex-tables-verbatim
             (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
                                 "\\end{verbatim}\n")))
@@ -1757,15 +1992,35 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
                          'org-label raw-table)
                   longtblp (and attr (stringp attr)
                                 (string-match "\\<longtable\\>" attr))
+                 tblenv (if (and attr (stringp attr))
+                            (cond ((string-match "\\<sidewaystable\\>" attr)
+                                   "sidewaystable")
+                                  ((or (string-match (regexp-quote "table*") attr)
+                                       (string-match "\\<multicolumn\\>" attr))
+                                   "table*")
+                                  (t "table"))
+                          "table")
+                 tabular-env
+                 (if (and attr (stringp attr)
+                          (string-match "\\(tabular.\\)" attr))
+                     (match-string 1 attr)
+                   org-export-latex-tabular-environment)
+                 width (and attr (stringp attr)
+                             (string-match "\\<width=\\([^ \t\n\r]+\\)" attr)
+                             (match-string 1 attr))
                   align (and attr (stringp attr)
                              (string-match "\\<align=\\([^ \t\n\r]+\\)" attr)
                              (match-string 1 attr))
-                  floatp (or caption label)
-                 placement     (if (and attr 
+                 hfmt (and attr (stringp attr)
+                           (string-match "\\<hfmt=\\(\\S-+\\)" attr)
+                           (match-string 1 attr))
+                  floatp (or caption label (string= "table*" tblenv))
+                 placement     (if (and attr
                                         (stringp attr)
                                         (string-match "[ \t]*\\<placement=\\(\\S-+\\)" attr))
                                    (match-string 1 attr)
-                                 "[htb]"))
+                                 (concat
+                                  "[" org-latex-default-figure-position "]")))
            (setq caption (and caption (org-export-latex-fontify-headline caption)))
             (setq lines (org-split-string raw-table "\n"))
             (apply 'delete-region (list beg end))
@@ -1774,7 +2029,7 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
             (when org-table-clean-did-remove-column
              (pop org-table-last-alignment)
              (pop org-table-last-column-widths))
-            ;; make a formatting string to reflect alignment
+            ;; make a format string to reflect alignment
             (setq olines lines)
             (while (and (not line-fmt) (setq line (pop olines)))
               (unless (string-match "^[ \t]*|-" line)
@@ -1813,45 +2068,62 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
                   (mapcar
                    (lambda(elem)
                      (or (and (string-match "[ \t]*|-+" elem) 'hline)
-                         (org-split-string (org-trim elem) "|")))
+                         (org-split-string
+                         (progn (set-text-properties 0 (length elem) nil elem)
+                                (org-trim elem)) "|")))
                    lines))
             (when insert
               (insert (org-export-latex-protect-string
                        (concat
                         (if longtblp
                             (concat "\\begin{longtable}{" align "}\n")
-                          (if floatp (format "\\begin{table}%s\n" placement)))
-                        (if floatp
+                          (if floatp
+                             (format "\\begin{%s}%s\n" tblenv placement)))
+                        (if (and floatp org-export-latex-table-caption-above)
                             (format
                              "\\caption%s{%s} %s"
                              (if shortn (concat "[" shortn "]") "")
                              (or caption "")
                             (if label (format "\\label{%s}" label) "")))
-                        (if (and longtblp caption) "\\\\\n" "\n")
+                       (if (and longtblp caption org-export-latex-table-caption-above)
+                           "\\\\\n" "\n")
                         (if (and org-export-latex-tables-centered (not longtblp))
                             "\\begin{center}\n")
                         (if (not longtblp)
-                           (format "\\begin{%s}{%s}\n"
-                                   org-export-latex-tabular-environment align))
+                           (format "\\begin{%s}%s{%s}\n"
+                                   tabular-env
+                                   (if width (format "{%s}" width) "")
+                                   align))
                         (orgtbl-to-latex
                          lines
-                         `(:tstart nil :tend nil
+                         `(:tstart ,org-export-latex-tables-tstart
+                                  :tend ,org-export-latex-tables-tend
+                                  :hline ,org-export-latex-tables-hline
+                                   :skipheadrule ,longtblp
+                                  :hfmt ,hfmt
                                    :hlend ,(if longtblp
                                                (format "\\\\
-\\hline
+%s
 \\endhead
-\\hline\\multicolumn{%d}{r}{Continued on next page}\\
+%s\\multicolumn{%d}{r}{Continued on next page}\\
 \\endfoot
-\\endlastfoot" (length org-table-last-alignment))
+\\endlastfoot"
+                                                      org-export-latex-tables-hline
+                                                      org-export-latex-tables-hline
+                                                      (length org-table-last-alignment))
                                              nil)))
-                        (if (not longtblp)
-                           (format "\n\\end{%s}"
-                                   org-export-latex-tabular-environment))
+                        (if (not longtblp) (format "\n\\end{%s}" tabular-env))
                         (if longtblp "\n" (if org-export-latex-tables-centered
                                               "\n\\end{center}\n" "\n"))
+                        (if (and floatp (not org-export-latex-table-caption-above))
+                            (format
+                             "\\caption%s{%s} %s"
+                             (if shortn (concat "[" shortn "]") "")
+                             (or caption "")
+                            (if label (format "\\label{%s}" label) "")))
                         (if longtblp
                             "\\end{longtable}"
-                          (if floatp "\\end{table}"))))
+                          (if floatp (format "\\end{%s}" tblenv)))))
                       "\n\n"))))))))
 
 (defun org-export-latex-convert-table.el-table ()
@@ -1898,11 +2170,12 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
       (setq tbl (concat "\\begin{center}\n" tbl "\\end{center}")))
     (when floatp
       (setq tbl (concat "\\begin{table}\n"
-                       (format "\\caption%s{%s}%s\n"
+                       (if (not org-export-latex-table-caption-above) tbl)
+                       (format "\\caption%s{%s%s}\n"
                                (if shortn (format "[%s]" shortn) "")
                                (if label (format "\\label{%s}" label) "")
                                (or caption ""))
-                       tbl
+                       (if org-export-latex-table-caption-above tbl)
                        "\n\\end{table}\n")))
     (insert (org-export-latex-protect-string tbl))))
 
@@ -1950,12 +2223,11 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
        (replace-match rpl t t)))
     (backward-char)))
 
-(defvar org-export-latex-use-verb nil)
 (defun org-export-latex-emph-format (format string)
   "Format an emphasis string and handle the \\verb special case."
-  (when (equal format "\\verb")
+  (when (member format '("\\verb" "\\protectedtexttt"))
     (save-match-data
-      (if org-export-latex-use-verb
+      (if (equal format "\\verb")
          (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
            (catch 'exit
              (loop for i from 0 to (1- (length ll)) do
@@ -1978,7 +2250,9 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
            (setq string (substring string (1+ (match-beginning 0))))
            (setq char (or (cdr (assoc char trans)) (concat "\\" char))
                  rtn (concat rtn char)))
-         (setq string (concat rtn string) format "\\texttt{%s}")))))
+         (setq string (concat rtn string) format "\\texttt{%s}")
+         (while (string-match "--" string)
+           (setq string (replace-match "-{}-" t t string)))))))
   (format format string))
 
 (defun org-export-latex-links ()
@@ -2017,14 +2291,13 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
                    (concat type ":" raw-path))
                   ((equal type "file")
                    (if (and (org-file-image-p
-                             (expand-file-name
-                              raw-path)
+                             (expand-file-name (org-link-unescape raw-path))
                              org-export-latex-inline-image-extensions)
-                            (or (get-text-property 0 'org-no-description
-                                                   raw-path)
+                            (or (get-text-property 0 'org-no-description raw-path)
                                 (equal desc full-raw-path)))
                        (setq imgp t)
-                     (progn (when (string-match "\\(.+\\)::.+" raw-path)
+                     (progn (setq raw-path (org-link-unescape raw-path))
+                            (when (string-match "\\(.+\\)::.+" raw-path)
                               (setq raw-path (match-string 1 raw-path)))
                             (if (file-exists-p raw-path)
                                 (concat type "://" (expand-file-name raw-path))
@@ -2057,15 +2330,18 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
                ;; a LaTeX issue, but we here implement a work-around anyway.
                (setq path (org-export-latex-protect-amp path)
                      desc (org-export-latex-protect-amp desc)))
-             (insert (format org-export-latex-href-format path desc)))
+             (insert
+              (if (string-match "%s.*%s" org-export-latex-href-format)
+                  (format org-export-latex-href-format path desc)
+                (format org-export-latex-href-format path))))
 
             ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
              ;; The link protocol has a function for formatting the link
              (insert
               (save-match-data
                 (funcall fnc (org-link-unescape raw-path) desc 'latex))))
-
-            (t (insert "\\texttt{" desc "}")))))))
+            ;; Unrecognized path type
+            (t (insert (format org-export-latex-link-with-unknown-path-format desc))))))))
 
 
 (defun org-export-latex-format-image (path caption label attr &optional shortn)
@@ -2084,7 +2360,7 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
     (setq placement
          (cond
           (wrapp "{l}{0.5\\textwidth}")
-          (floatp "[htb]")
+          (floatp (concat "[" org-latex-default-figure-position "]"))
           (t "")))
 
     (when (and attr (stringp attr)
@@ -2106,12 +2382,12 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
           (multicolumnp "\\begin{figure*}%placement
 \\centering
 \\includegraphics[%attr]{%path}
-\\caption{%labelcmd%caption}
+\\caption%shortn{%labelcmd%caption}
 \\end{figure*}")
           (floatp "\\begin{figure}%placement
 \\centering
 \\includegraphics[%attr]{%path}
-\\caption{%labelcmd%caption}
+\\caption%shortn{%labelcmd%caption}
 \\end{figure}")
           (t "\\includegraphics[%attr]{%path}")))
 
@@ -2154,6 +2430,68 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 
 (defun org-export-latex-preprocess (parameters)
   "Clean stuff in the LaTeX export."
+  ;; Replace footnotes.
+  (when (plist-get parameters :footnotes)
+    (goto-char (point-min))
+    (let (ref)
+      (while (setq ref (org-footnote-get-next-reference))
+       (let* ((beg (nth 1 ref))
+              (lbl (car ref))
+              (def (nth 1 (assoc (string-to-number lbl)
+                                 (mapcar (lambda (e) (cdr e))
+                                         org-export-footnotes-seen)))))
+         ;; Fix body for footnotes ending on a link or a list and
+         ;; remove definition from buffer.
+         (setq def
+               (concat def
+                       (if (string-match "ORG-LIST-END-MARKER\\'" def)
+                           "\n" " ")))
+         (org-footnote-delete-definitions lbl)
+         ;; Compute string to insert (FNOTE), and protect the outside
+         ;; macro from further transformation.  When footnote at
+         ;; point is referring to a previously defined footnote, use
+         ;; \footnotemark.  Otherwise, use \footnote.
+         (let ((fnote (if (member lbl org-export-latex-footmark-seen)
+                          (org-export-latex-protect-string
+                           (format "\\footnotemark[%s]" lbl))
+                        (push lbl org-export-latex-footmark-seen)
+                        (concat (org-export-latex-protect-string "\\footnote{")
+                                def
+                                (org-export-latex-protect-string "}"))))
+               ;; Check if another footnote is immediately following.
+               ;; If so, add a separator in-between.
+               (sep (org-export-latex-protect-string
+                     (if (save-excursion (goto-char (1- (nth 2 ref)))
+                                         (let ((next (org-footnote-get-next-reference)))
+                                           (and next (= (nth 1 next) (nth 2 ref)))))
+                         org-export-latex-footnote-separator ""))))
+           (when (org-at-heading-p)
+             (setq fnote (concat (org-export-latex-protect-string "\\protect")
+                                 fnote)))
+           ;; Ensure a footnote at column 0 cannot end a list
+           ;; containing it.
+           (put-text-property 0 (length fnote) 'original-indentation 1000 fnote)
+           ;; Replace footnote reference with FNOTE and, maybe, SEP.
+           ;; `save-excursion' is required if there are two footnotes
+           ;; in a row.  In that case, point would be left at the
+           ;; beginning of the second one, and
+           ;; `org-footnote-get-next-reference' would then skip it.
+           (goto-char beg)
+           (delete-region beg (nth 2 ref))
+           (save-excursion (insert fnote sep)))))))
+
+  ;; Remove footnote section tag for LaTeX
+  (goto-char (point-min))
+  (while (re-search-forward
+         (concat "^" footnote-section-tag-regexp) nil t)
+    (org-if-unprotected
+     (replace-match "")))
+  ;; Remove any left-over footnote definition.
+  (mapc (lambda (fn) (org-footnote-delete-definitions (car fn)))
+       org-export-footnotes-data)
+  (mapc (lambda (fn) (org-footnote-delete-definitions fn))
+       org-export-latex-footmark-seen)
+
   ;; Preserve line breaks
   (goto-char (point-min))
   (while (re-search-forward "\\\\\\\\" nil t)
@@ -2165,17 +2503,16 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
   (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\*?\\)}" nil t)
     (org-if-unprotected
      (let* ((start (progn (beginning-of-line) (point)))
-          (end (and (re-search-forward
-                     (concat "^[ \t]*\\\\end{"
-                             (regexp-quote (match-string 1))
-                             "}") nil t)
-                    (point-at-eol))))
-      (if end
-         (add-text-properties start end '(org-protected t))
-       (goto-char (point-at-eol))))))
+           (end (and (re-search-forward
+                      (concat "^[ \t]*\\\\end{"
+                              (regexp-quote (match-string 1))
+                              "}") nil t)
+                     (point-at-eol))))
+       (if end
+          (add-text-properties start end '(org-protected t))
+        (goto-char (point-at-eol))))))
 
   ;; Preserve math snippets
-
   (let* ((matchers (plist-get org-format-latex-options :matchers))
         (re-list org-latex-regexps)
         beg end re e m n block off)
@@ -2229,6 +2566,18 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
     (and (looking-at "[ \t]*ORG-VERSE-END.*")
         (org-replace-match-keep-properties "\\end{verse}" t t)))
 
+  ;; Convert #+INDEX to LaTeX \\index.
+  (goto-char (point-min))
+  (let ((case-fold-search t) entry)
+    (while (re-search-forward
+           "^[ \t]*#\\+index:[ \t]*\\([^ \t\r\n].*?\\)[ \t]*$"
+           nil t)
+      (setq entry
+           (save-match-data
+             (org-export-latex-protect-string
+              (org-export-latex-fontify-headline (match-string 1)))))
+      (replace-match (format "\\index{%s}" entry) t t)))
+
   ;; Convert center
   (goto-char (point-min))
   (while (search-forward "ORG-CENTER-START" nil t)
@@ -2241,26 +2590,31 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 
   ;; Convert horizontal rules
   (goto-char (point-min))
-  (while (re-search-forward "^----+.$" nil t)
+  (while (re-search-forward "^[ \t]*-\\{5,\\}[ \t]*$" nil t)
     (org-if-unprotected
      (replace-match (org-export-latex-protect-string "\\hrule") t t)))
 
   ;; Protect LaTeX commands like \command[...]{...} or \command{...}
   (goto-char (point-min))
   (let ((re (concat
-            "\\\\\\([a-zA-Z]+\\)"
+            "\\\\\\([a-zA-Z]+\\*?\\)"
             "\\(?:<[^<>\n]*>\\)*"
             "\\(?:\\[[^][\n]*?\\]\\)*"
             "\\(?:<[^<>\n]*>\\)*"
             "\\(" (org-create-multibrace-regexp "{" "}" 3) "\\)\\{1,3\\}")))
     (while (re-search-forward re nil t)
       (unless (or
-              ;; check for comment line
+              ;; Check for comment line.
               (save-excursion (goto-char (match-beginning 0))
                               (org-in-indented-comment-line))
-              ;; Check if this is a defined entity, so that is may need conversion
+              ;; Check if this is a defined entity, so that is may
+              ;; need conversion.
               (org-entity-get (match-string 1))
-              )
+              ;; Do not protect interior of footnotes.  Those have
+              ;; already been taken care of earlier in the function.
+              ;; Yet, keep looking inside them for more commands.
+              (and (equal (match-string 1) "footnote")
+                   (goto-char (match-end 1))))
        (add-text-properties (match-beginning 0) (match-end 0)
                             '(org-protected t)))))
 
@@ -2283,68 +2637,20 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
          (concat "<<<?" org-export-latex-all-targets-re
                  ">>>?\\((INVISIBLE)\\)?") nil t)
     (org-if-unprotected-at (+ (match-beginning 0) 2)
-     (replace-match
-      (concat
-       (org-export-latex-protect-string
-       (format "\\label{%s}" (save-match-data (org-solidify-link-text
-                                               (match-string 1)))))
-       (if (match-string 2) "" (match-string 1)))
-      t t)))
+      (replace-match
+       (concat
+       (org-export-latex-protect-string
+        (format "\\label{%s}" (save-match-data (org-solidify-link-text
+                                                (match-string 1)))))
+       (if (match-string 2) "" (match-string 1)))
+       t t)))
 
   ;; Delete @<...> constructs
   ;; Thanks to Daniel Clemente for this regexp
   (goto-char (point-min))
   (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t)
     (org-if-unprotected
-     (replace-match "")))
-
-  ;; When converting to LaTeX, replace footnotes
-  ;; FIXME: don't protect footnotes from conversion
-  (when (plist-get org-export-latex-options-plist :footnotes)
-    (goto-char (point-min))
-    (while (re-search-forward "\\[\\([0-9]+\\)\\]" nil t)
-      (org-if-unprotected
-       (when (and (save-match-data
-                   (save-excursion (beginning-of-line)
-                                   (looking-at "[^:|#]")))
-                 (not (org-in-verbatim-emphasis)))
-        (let ((foot-beg (match-beginning 0))
-              (foot-end (match-end 0))
-              (foot-prefix (match-string 0))
-              footnote footnote-rpl)
-          (save-excursion
-            (if (not (re-search-forward (concat "^" (regexp-quote foot-prefix))
-                                        nil t))
-                (replace-match (org-export-latex-protect-string
-                                (concat "$^{" (match-string 1) "}$")))
-              (replace-match "")
-              (let ((end (save-excursion
-                           (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t)
-                               (match-beginning 0) (point-max)))))
-                (setq footnote (concat (org-trim (buffer-substring (point) end))
-                                       " ")) ; prevent last } being part of a link
-                (delete-region (point) end))
-              (goto-char foot-beg)
-              (delete-region foot-beg foot-end)
-              (unless (null footnote)
-                (setq footnote-rpl (format "\\footnote{%s}" footnote))
-                (add-text-properties 0 10 '(org-protected t) footnote-rpl)
-                (add-text-properties (1- (length footnote-rpl))
-                                     (length footnote-rpl)
-                                     '(org-protected t) footnote-rpl)
-                (if (org-on-heading-p)
-                     (setq footnote-rpl
-                           (concat (org-export-latex-protect-string "\\protect")
-                                   footnote-rpl)))
-                (insert footnote-rpl)))
-            )))))
-
-    ;; Remove footnote section tag for LaTeX
-    (goto-char (point-min))
-    (while (re-search-forward
-           (concat "^" footnote-section-tag-regexp) nil t)
-      (org-if-unprotected
-       (replace-match "")))))
+     (replace-match ""))))
 
 (defun org-export-latex-fix-inputenc ()
   "Set the coding system in inputenc to what the buffer is."
@@ -2368,198 +2674,213 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 
 (defun org-export-latex-lists ()
   "Convert plain text lists in current buffer into LaTeX lists."
-  (let (res)
-    (goto-char (point-min))
-    (while (org-search-forward-unenclosed org-item-beginning-re nil t)
-      (beginning-of-line)
-      (setq res (org-list-to-latex (org-list-parse-list t)
-                                  org-export-latex-list-parameters))
-      (while (string-match "^\\(\\\\item[ \t]+\\)\\[@\\(?:start:\\)?\\([0-9]+\\)\\]"
-                          res)
-       (setq res (replace-match
-                  (concat (format "\\setcounter{enumi}{%d}"
-                                  (1- (string-to-number
-                                       (match-string 2 res))))
-                          "\n"
-                          (match-string 1 res))
-                  t t res)))
-      (insert res))))
+  ;; `org-list-end-re' output has changed since preprocess from
+  ;; org-exp.el.  Make sure it is taken into account.
+  (let ((org-list-end-re "^ORG-LIST-END-MARKER\n"))
+    (mapc
+     (lambda (e)
+       ;; For each type of context allowed for list export (E), find
+       ;; every list, parse it, delete it and insert resulting
+       ;; conversion to latex (RES), while keeping the same
+       ;; `original-indentation' property.
+       (let (res)
+        (goto-char (point-min))
+        (while (re-search-forward (org-item-beginning-re) nil t)
+          (when (and (eq (get-text-property (point) 'list-context) e)
+                     (not (get-text-property (point) 'org-example)))
+            (beginning-of-line)
+            (setq res
+                  (org-list-to-latex
+                   ;; Narrowing is needed because we're converting
+                   ;; from inner functions to outer ones.
+                   (save-restriction
+                     (narrow-to-region (point) (point-max))
+                     (org-list-parse-list t))
+                   org-export-latex-list-parameters))
+            ;; Extend previous value of original-indentation to the
+            ;; whole string
+            (insert (org-add-props res nil 'original-indentation
+                                   (org-find-text-property-in-string
+                                    'original-indentation res)))))))
+     ;; List of allowed contexts for export, and the default one.
+     (append org-list-export-context '(nil)))))
 
 (defconst org-latex-entities
- '("\\!"
-   "\\'"
-   "\\+"
-   "\\,"
-   "\\-"
-   "\\:"
-   "\\;"
-   "\\<"
-   "\\="
-   "\\>"
-   "\\Huge"
-   "\\LARGE"
-   "\\Large"
-   "\\Styles"
-   "\\\\"
-   "\\`"
-   "\\addcontentsline"
-   "\\address"
-   "\\addtocontents"
-   "\\addtocounter"
-   "\\addtolength"
-   "\\addvspace"
-   "\\alph"
-   "\\appendix"
-   "\\arabic"
-   "\\author"
-   "\\begin{array}"
-   "\\begin{center}"
-   "\\begin{description}"
-   "\\begin{enumerate}"
-   "\\begin{eqnarray}"
-   "\\begin{equation}"
-   "\\begin{figure}"
-   "\\begin{flushleft}"
-   "\\begin{flushright}"
-   "\\begin{itemize}"
-   "\\begin{list}"
-   "\\begin{minipage}"
-   "\\begin{picture}"
-   "\\begin{quotation}"
-   "\\begin{quote}"
-   "\\begin{tabbing}"
-   "\\begin{table}"
-   "\\begin{tabular}"
-   "\\begin{thebibliography}"
-   "\\begin{theorem}"
-   "\\begin{titlepage}"
-   "\\begin{verbatim}"
-   "\\begin{verse}"
-   "\\bf"
-   "\\bf"
-   "\\bibitem"
-   "\\bigskip"
-   "\\cdots"
-   "\\centering"
-   "\\circle"
-   "\\cite"
-   "\\cleardoublepage"
-   "\\clearpage"
-   "\\cline"
-   "\\closing"
-   "\\dashbox"
-   "\\date"
-   "\\ddots"
-   "\\dotfill"
-   "\\em"
-   "\\fbox"
-   "\\flushbottom"
-   "\\fnsymbol"
-   "\\footnote"
-   "\\footnotemark"
-   "\\footnotesize"
-   "\\footnotetext"
-   "\\frac"
-   "\\frame"
-   "\\framebox"
-   "\\hfill"
-   "\\hline"
-   "\\hrulespace"
-   "\\hspace"
-   "\\huge"
-   "\\hyphenation"
-   "\\include"
-   "\\includeonly"
-   "\\indent"
-   "\\input"
-   "\\it"
-   "\\kill"
-   "\\label"
-   "\\large"
-   "\\ldots"
-   "\\line"
-   "\\linebreak"
-   "\\linethickness"
-   "\\listoffigures"
-   "\\listoftables"
-   "\\location"
-   "\\makebox"
-   "\\maketitle"
-   "\\mark"
-   "\\mbox"
-   "\\medskip"
-   "\\multicolumn"
-   "\\multiput"
-   "\\newcommand"
-   "\\newcounter"
-   "\\newenvironment"
-   "\\newfont"
-   "\\newlength"
-   "\\newline"
-   "\\newpage"
-   "\\newsavebox"
-   "\\newtheorem"
-   "\\nocite"
-   "\\nofiles"
-   "\\noindent"
-   "\\nolinebreak"
-   "\\nopagebreak"
-   "\\normalsize"
-   "\\onecolumn"
-   "\\opening"
-   "\\oval"
-   "\\overbrace"
-   "\\overline"
-   "\\pagebreak"
-   "\\pagenumbering"
-   "\\pageref"
-   "\\pagestyle"
-   "\\par"
-   "\\parbox"
-   "\\put"
-   "\\raggedbottom"
-   "\\raggedleft"
-   "\\raggedright"
-   "\\raisebox"
-   "\\ref"
-   "\\rm"
-   "\\roman"
-   "\\rule"
-   "\\savebox"
-   "\\sc"
-   "\\scriptsize"
-   "\\setcounter"
-   "\\setlength"
-   "\\settowidth"
-   "\\sf"
-   "\\shortstack"
-   "\\signature"
-   "\\sl"
-   "\\small"
-   "\\smallskip"
-   "\\sqrt"
-   "\\tableofcontents"
-   "\\telephone"
-   "\\thanks"
-   "\\thispagestyle"
-   "\\tiny"
-   "\\title"
-   "\\tt"
-   "\\twocolumn"
-   "\\typein"
-   "\\typeout"
-   "\\underbrace"
-   "\\underline"
-   "\\usebox"
-   "\\usecounter"
-   "\\value"
-   "\\vdots"
-   "\\vector"
-   "\\verb"
-   "\\vfill"
-   "\\vline"
-   "\\vspace")
- "A list of LaTeX commands to be protected when performing conversion.")
+  '("\\!"
+    "\\'"
+    "\\+"
+    "\\,"
+    "\\-"
+    "\\:"
+    "\\;"
+    "\\<"
+    "\\="
+    "\\>"
+    "\\Huge"
+    "\\LARGE"
+    "\\Large"
+    "\\Styles"
+    "\\\\"
+    "\\`"
+    "\\\""
+    "\\addcontentsline"
+    "\\address"
+    "\\addtocontents"
+    "\\addtocounter"
+    "\\addtolength"
+    "\\addvspace"
+    "\\alph"
+    "\\appendix"
+    "\\arabic"
+    "\\author"
+    "\\begin{array}"
+    "\\begin{center}"
+    "\\begin{description}"
+    "\\begin{enumerate}"
+    "\\begin{eqnarray}"
+    "\\begin{equation}"
+    "\\begin{figure}"
+    "\\begin{flushleft}"
+    "\\begin{flushright}"
+    "\\begin{itemize}"
+    "\\begin{list}"
+    "\\begin{minipage}"
+    "\\begin{picture}"
+    "\\begin{quotation}"
+    "\\begin{quote}"
+    "\\begin{tabbing}"
+    "\\begin{table}"
+    "\\begin{tabular}"
+    "\\begin{thebibliography}"
+    "\\begin{theorem}"
+    "\\begin{titlepage}"
+    "\\begin{verbatim}"
+    "\\begin{verse}"
+    "\\bf"
+    "\\bf"
+    "\\bibitem"
+    "\\bigskip"
+    "\\cdots"
+    "\\centering"
+    "\\circle"
+    "\\cite"
+    "\\cleardoublepage"
+    "\\clearpage"
+    "\\cline"
+    "\\closing"
+    "\\dashbox"
+    "\\date"
+    "\\ddots"
+    "\\dotfill"
+    "\\em"
+    "\\fbox"
+    "\\flushbottom"
+    "\\fnsymbol"
+    "\\footnote"
+    "\\footnotemark"
+    "\\footnotesize"
+    "\\footnotetext"
+    "\\frac"
+    "\\frame"
+    "\\framebox"
+    "\\hfill"
+    "\\hline"
+    "\\hrulespace"
+    "\\hspace"
+    "\\huge"
+    "\\hyphenation"
+    "\\include"
+    "\\includeonly"
+    "\\indent"
+    "\\input"
+    "\\it"
+    "\\kill"
+    "\\label"
+    "\\large"
+    "\\ldots"
+    "\\line"
+    "\\linebreak"
+    "\\linethickness"
+    "\\listoffigures"
+    "\\listoftables"
+    "\\location"
+    "\\makebox"
+    "\\maketitle"
+    "\\mark"
+    "\\mbox"
+    "\\medskip"
+    "\\multicolumn"
+    "\\multiput"
+    "\\newcommand"
+    "\\newcounter"
+    "\\newenvironment"
+    "\\newfont"
+    "\\newlength"
+    "\\newline"
+    "\\newpage"
+    "\\newsavebox"
+    "\\newtheorem"
+    "\\nocite"
+    "\\nofiles"
+    "\\noindent"
+    "\\nolinebreak"
+    "\\nopagebreak"
+    "\\normalsize"
+    "\\onecolumn"
+    "\\opening"
+    "\\oval"
+    "\\overbrace"
+    "\\overline"
+    "\\pagebreak"
+    "\\pagenumbering"
+    "\\pageref"
+    "\\pagestyle"
+    "\\par"
+    "\\parbox"
+    "\\put"
+    "\\raggedbottom"
+    "\\raggedleft"
+    "\\raggedright"
+    "\\raisebox"
+    "\\ref"
+    "\\rm"
+    "\\roman"
+    "\\rule"
+    "\\savebox"
+    "\\sc"
+    "\\scriptsize"
+    "\\setcounter"
+    "\\setlength"
+    "\\settowidth"
+    "\\sf"
+    "\\shortstack"
+    "\\signature"
+    "\\sl"
+    "\\small"
+    "\\smallskip"
+    "\\sqrt"
+    "\\tableofcontents"
+    "\\telephone"
+    "\\thanks"
+    "\\thispagestyle"
+    "\\tiny"
+    "\\title"
+    "\\tt"
+    "\\twocolumn"
+    "\\typein"
+    "\\typeout"
+    "\\underbrace"
+    "\\underline"
+    "\\usebox"
+    "\\usecounter"
+    "\\value"
+    "\\vdots"
+    "\\vector"
+    "\\verb"
+    "\\vfill"
+    "\\vline"
+    "\\vspace")
+  "A list of LaTeX commands to be protected when performing conversion.")
 
 (defconst org-latex-entities-regexp
   (let (names rest)
@@ -2573,5 +2894,8 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 (provide 'org-export-latex)
 (provide 'org-latex)
 
+;; Local variables:
+;; generated-autoload-file: "org-loaddefs.el"
+;; End:
 
 ;;; org-latex.el ends here