1 ;;; org-export-latex.el --- LaTeX exporter for org-mode
3 ;; Copyright (c) 2007, 2008 Free Software Foundation, Inc.
5 ;; Emacs Lisp Archive Entry
6 ;; Filename: org-export-latex.el
8 ;; Author: Bastien Guerry <bzg AT altern DOT org>
9 ;; Maintainer: Bastien Guerry <bzg AT altern DOT org>
10 ;; Keywords: org, wp, tex
11 ;; Description: Converts an org-mode buffer into LaTeX
12 ;; URL: http://www.cognition.ens.fr/~guerry/u/org-export-latex.el
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify it
17 ;; under the terms of the GNU General Public License as published by the
18 ;; Free Software Foundation; either version 3, or (at your option) any
21 ;; GNU Emacs is distributed in the hope that it will be useful, but
22 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 ;; General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the Free
28 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
29 ;; MA 02110-1301, USA.
33 ;; This library implements a LaTeX exporter for org-mode.
35 ;; Put this file into your load-path and the following into your ~/.emacs:
36 ;; (require 'org-export-latex)
38 ;; The interactive functions are similar to those of the HTML exporter:
40 ;; M-x `org-export-as-latex'
41 ;; M-x `org-export-as-latex-batch'
42 ;; M-x `org-export-as-latex-to-buffer'
43 ;; M-x `org-export-region-as-latex'
44 ;; M-x `org-replace-region-by-latex'
55 (defvar org-export-latex-class nil
)
56 (defvar org-export-latex-header nil
)
57 (defvar org-export-latex-append-header nil
)
58 (defvar org-export-latex-options-plist nil
)
59 (defvar org-export-latex-todo-keywords-1 nil
)
60 (defvar org-export-latex-all-targets-re nil
)
61 (defvar org-export-latex-add-level
0)
62 (defvar org-export-latex-sectioning
"")
63 (defvar org-export-latex-sectioning-depth
0)
64 (defvar org-export-latex-list-beginning-re
65 "^\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) +?")
67 (defvar org-export-latex-special-string-regexps
72 "A list of regexps to convert as special keywords.")
74 (defvar latexp
) ; dynamically scoped from org.el
75 (defvar re-quote
) ; dynamically scoped from org.el
76 (defvar commentsp
) ; dynamically scoped from org.el
80 (defcustom org-export-latex-default-class
"article"
81 "The default LaTeX class."
82 :group
'org-export-latex
83 :type
'(string :tag
"LaTeX class"))
85 (defcustom org-export-latex-classes
87 "\\documentclass[11pt,a4paper]{article}
88 \\usepackage[utf8]{inputenc}
89 \\usepackage[T1]{fontenc}
90 \\usepackage{hyperref}"
91 ("\\section{%s}" .
"\\section*{%s}")
92 ("\\subsection{%s}" .
"\\subsection*{%s}")
93 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}")
94 ("\\paragraph{%s}" .
"\\paragraph*{%s}")
95 ("\\subparagraph{%s}" .
"\\subparagraph*{%s}"))
97 "\\documentclass[11pt,a4paper]{report}
98 \\usepackage[utf8]{inputenc}
99 \\usepackage[T1]{fontenc}
100 \\usepackage{hyperref}"
101 ("\\part{%s}" .
"\\part*{%s}")
102 ("\\chapter{%s}" .
"\\chapter*{%s}")
103 ("\\section{%s}" .
"\\section*{%s}")
104 ("\\subsection{%s}" .
"\\subsection*{%s}")
105 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}"))
107 "\\documentclass[11pt,a4paper]{book}
108 \\usepackage[utf8]{inputenc}
109 \\usepackage[T1]{fontenc}
110 \\usepackage{hyperref}"
111 ("\\part{%s}" .
"\\part*{%s}")
112 ("\\chapter{%s}" .
"\\chapter*{%s}")
113 ("\\section{%s}" .
"\\section*{%s}")
114 ("\\subsection{%s}" .
"\\subsection*{%s}")
115 ("\\subsubsection{%s}" .
"\\subsubsection*{%s}")))
116 "Alist of LaTeX classes and associated header and structure.
117 If #+LaTeX_CLASS is set in the buffer, use its value and the
118 associated information. Here is the structure of each cell:
122 (unnumbered-section numbered-section\)
125 A %s formatter is mandatory in each section string and will be
126 replaced by the title of the section."
127 :group
'org-export-latex
129 (list (string :tag
"LaTeX class")
130 (string :tag
"LaTeX header")
132 (string :tag
"Numbered")
133 (string :tag
"Unnumbered"))
135 (string :tag
"Numbered")
136 (string :tag
"Unnumbered"))
138 (string :tag
"Numbered")
139 (string :tag
"Unnumbered"))
141 (string :tag
"Numbered")
142 (string :tag
"Unnumbered"))
144 (string :tag
"Numbered")
145 (string :tag
"Unnumbered")))))
147 (defcustom org-export-latex-emphasis-alist
148 '(("*" "\\textbf{%s}" nil
)
149 ("/" "\\emph{%s}" nil
)
150 ("_" "\\underline{%s}" nil
)
151 ("+" "\\texttt{%s}" nil
)
152 ("=" "\\texttt{%s}" nil
)
153 ("~" "\\texttt{%s}" t
))
154 "Alist of LaTeX expressions to convert emphasis fontifiers.
155 Each element of the list is a list of three elements.
156 The first element is the character used as a marker for fontification.
157 The second element is a formatting string to wrap fontified text with.
158 The third element decides whether to protect converted text from other
160 :group
'org-export-latex
163 (defcustom org-export-latex-title-command
"\\maketitle"
164 "The command used to insert the title just after \\begin{document}.
165 If this string contains the formatting specification \"%s\" then
166 it will be used as a formatting string, passing the title as an
168 :group
'org-export-latex
171 (defcustom org-export-latex-date-format
173 "Format string for \\date{...}."
174 :group
'org-export-latex
177 (defcustom org-export-latex-tables-verbatim nil
178 "When non-nil, export tables as verbatim."
179 :group
'org-export-latex
182 (defcustom org-export-latex-tables-column-borders nil
183 "When non-nil, group of columns are surrounded with borders,
184 XSeven if these borders are the outside borders of the table."
185 :group
'org-export-latex
188 (defcustom org-export-latex-packages-alist nil
189 "Alist of packages to be inserted in the header.
190 Each cell is of the forma \( \"option\" . \"package\" \)."
191 :group
'org-export-latex
194 (defcustom org-export-latex-low-levels
'description
195 "How to convert sections below the current level of sectioning,
196 as specified by `org-export-headline-levels' or the value of \"H:\"
197 in Org's #+OPTION line.
199 This can be either nil (skip the sections), 'description (convert
200 the sections as descriptive lists) or a string to be used instead
201 of \\section{%s}. In this latter case, the %s stands here for the
202 inserted headline and is mandatory."
203 :group
'org-export-latex
204 :type
'(choice (const :tag
"Ignore" nil
)
205 (symbol :tag
"Convert as descriptive list" description
)
206 (string :tag
"Use a section string" :value
"\\subparagraph{%s}")))
208 (defcustom org-export-latex-remove-from-headlines
209 '(:todo t
:priority t
:tags t
)
210 "A plist of keywords to remove from headlines.
211 Non-nil means remove this keyword type from the headline.
213 Don't remove the keys, just change their values."
215 :group
'org-export-latex
)
217 (defcustom org-export-latex-image-default-option
"width=10em"
218 "Default option for images."
219 :group
'org-export-latex
222 (defcustom org-export-latex-coding-system nil
223 "Coding system for the exported LaTex file."
224 :group
'org-export-latex
225 :type
'coding-system
)
227 (defcustom org-list-radio-list-templates
228 '((latex-mode "% BEGIN RECEIVE ORGLST %n
229 % END RECEIVE ORGLST %n
231 #+ORGLST: SEND %n org-list-to-latex
234 (texinfo-mode "@c BEGIN RECEIVE ORGLST %n
235 @c END RECEIVE ORGLST %n
237 #+ORGLST: SEND %n org-list-to-texinfo
240 (html-mode "<!-- BEGIN RECEIVE ORGLST %n -->
241 <!-- END RECEIVE ORGLST %n -->
243 #+ORGLST: SEND %n org-list-to-html
246 "Templates for radio lists in different major modes.
247 All occurrences of %n in a template will be replaced with the name of the
248 list, obtained by prompting the user."
249 :group
'org-plain-lists
251 (list (symbol :tag
"Major mode")
252 (string :tag
"Format"))))
254 ;;; Autoload functions:
257 (defun org-export-as-latex-batch ()
258 "Call `org-export-as-latex', may be used in batch processing as
260 --load=$HOME/lib/emacs/org.el
261 --eval \"(setq org-export-headline-levels 2)\"
262 --visit=MyFile --funcall org-export-as-latex-batch"
263 (org-export-as-latex org-export-headline-levels
'hidden
))
266 (defun org-export-as-latex-to-buffer (arg)
267 "Call `org-exort-as-latex` with output to a temporary buffer.
268 No file is created. The prefix ARG is passed through to `org-export-as-latex'."
270 (org-export-as-latex arg nil nil
"*Org LaTeX Export*")
271 (switch-to-buffer-other-window "*Org LaTeX Export*"))
274 (defun org-replace-region-by-latex (beg end
)
275 "Replace the region from BEG to END with its LaTeX export.
276 It assumes the region has `org-mode' syntax, and then convert it to
277 LaTeX. This can be used in any buffer. For example, you could
278 write an itemized list in `org-mode' syntax in an LaTeX buffer and
279 then use this command to convert it."
282 (save-window-excursion
284 (setq latex
(org-export-region-as-latex
286 (setq reg
(buffer-substring beg end
)
287 buf
(get-buffer-create "*Org tmp*"))
293 (setq latex
(org-export-region-as-latex
294 (point-min) (point-max) t
'string
)))
296 (delete-region beg end
)
300 (defun org-export-region-as-latex (beg end
&optional body-only buffer
)
301 "Convert region from BEG to END in `org-mode' buffer to LaTeX.
302 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
303 contents, and only produce the region of converted text, useful for
304 cut-and-paste operations.
305 If BUFFER is a buffer or a string, use/create that buffer as a target
306 of the converted LaTeX. If BUFFER is the symbol `string', return the
307 produced LaTeX as a string and leave not buffer behind. For example,
308 a Lisp program could call this function in the following way:
310 (setq latex (org-export-region-as-latex beg end t 'string))
312 When called interactively, the output buffer is selected, and shown
313 in a window. A non-interactive call will only retunr the buffer."
315 (when (interactive-p)
316 (setq buffer
"*Org LaTeX Export*"))
317 (let ((transient-mark-mode t
) (zmacs-regions t
)
320 (set-mark (point)) ;; to activate the region
322 (setq rtn
(org-export-as-latex
325 (if (fboundp 'deactivate-mark
) (deactivate-mark))
326 (if (and (interactive-p) (bufferp rtn
))
327 (switch-to-buffer-other-window rtn
)
331 (defun org-export-as-latex (arg &optional hidden ext-plist
333 "Export current buffer to a LaTeX file.
334 If there is an active region, export only the region. The prefix
335 ARG specifies how many levels of the outline should become
336 headlines. The default is 3. Lower levels will be exported
337 depending on `org-export-latex-low-levels'. The default is to
338 convert them as description lists. When HIDDEN is non-nil, don't
339 display the LaTeX buffer. EXT-PLIST is a property list with
340 external parameters overriding org-mode's default settings, but
341 still inferior to file-local settings. When TO-BUFFER is
342 non-nil, create a buffer with that name and export to that
343 buffer. If TO-BUFFER is the symbol `string', don't leave any
344 buffer behind but just return the resulting LaTeX as a string.
345 When BODY-ONLY is set, don't produce the file header and footer,
346 simply return the content of \begin{document}...\end{document},
347 without even the \begin{document} and \end{document} commands."
349 ;; Make sure we have a file name when we need it.
350 (when (and (not (or to-buffer body-only
))
351 (not buffer-file-name
))
352 (if (buffer-base-buffer)
353 (org-set-local 'buffer-file-name
354 (with-current-buffer (buffer-base-buffer)
356 (error "Need a file name to be able to export")))
358 (message "Exporting to LaTeX...")
359 (org-update-radio-target-regexp)
360 (org-export-latex-set-initial-vars ext-plist arg
)
361 (let* ((wcf (current-window-configuration))
362 (opt-plist org-export-latex-options-plist
)
363 (region-p (org-region-active-p))
367 (goto-char (region-beginning))
368 (and (org-at-heading-p)
369 (>= (org-end-of-subtree t t
) (region-end))))))
370 (title (or (and subtree-p
(org-export-get-title-from-subtree))
371 (plist-get opt-plist
:title
)
373 (plist-get opt-plist
:skip-before-1st-heading
))
374 (org-export-grab-title-from-buffer))
375 (file-name-sans-extension
376 (file-name-nondirectory buffer-file-name
))))
377 (filename (concat (file-name-as-directory
378 (org-export-directory :LaTeX ext-plist
))
379 (file-name-sans-extension
380 (file-name-nondirectory ;sans-extension
381 buffer-file-name
)) ".tex"))
382 (filename (if (equal (file-truename filename
)
383 (file-truename buffer-file-name
))
384 (concat filename
".tex")
386 (buffer (if to-buffer
388 ((eq to-buffer
'string
) (get-buffer-create
389 "*Org LaTeX Export*"))
390 (t (get-buffer-create to-buffer
)))
391 (find-file-noselect filename
)))
392 (odd org-odd-levels-only
)
393 (header (org-export-latex-make-header title opt-plist
))
394 (skip (cond (subtree-p nil
)
396 ;; never skip first lines when exporting a subtree
397 (t (plist-get opt-plist
:skip-before-1st-heading
))))
398 (text (plist-get opt-plist
:text
))
399 (first-lines (if skip
"" (org-export-latex-first-lines)))
400 (coding-system (and (boundp 'buffer-file-coding-system
)
401 buffer-file-coding-system
))
402 (coding-system-for-write (or org-export-latex-coding-system
404 (save-buffer-coding-system (or org-export-latex-coding-system
406 (region (buffer-substring
407 (if region-p
(region-beginning) (point-min))
408 (if region-p
(region-end) (point-max))))
410 (org-cleaned-string-for-export
411 region
:emph-multiline t
414 :add-text
(if (eq to-buffer
'string
) nil text
)
415 :skip-before-1st-heading skip
416 :LaTeX-fragments nil
)))
421 (and (fboundp 'set-buffer-file-coding-system
)
422 (set-buffer-file-coding-system coding-system-for-write
))
424 ;; insert the header and initial document commands
425 (unless (or (eq to-buffer
'string
) body-only
)
428 ;; insert text found in #+TEXT
429 (when (and text
(not (eq to-buffer
'string
)))
430 (insert (org-export-latex-content
431 text
'(lists tables fixed-width keywords
))
434 ;; insert lines before the first headline
435 (unless (or skip
(eq to-buffer
'string
))
436 (insert first-lines
))
438 ;; handle the case where the region does not begin with a section
440 (insert (with-temp-buffer
441 (insert string-for-export
)
442 (org-export-latex-first-lines))))
444 ;; export the content of headlines
445 (org-export-latex-global
447 (insert string-for-export
)
448 (goto-char (point-min))
449 (when (re-search-forward "^\\(\\*+\\) " nil t
)
450 (let* ((asters (length (match-string 1)))
451 (level (if odd
(- asters
2) (- asters
1))))
452 (setq org-export-latex-add-level
453 (if odd
(1- (/ (1+ asters
) 2)) (1- asters
)))
454 (org-export-latex-parse-global level odd
)))))
457 (unless body-only
(insert "\n\\end{document}"))
458 (or to-buffer
(save-buffer))
459 (goto-char (point-min))
460 (message "Exporting to LaTeX...done")
462 (if (eq to-buffer
'string
)
463 (prog1 (buffer-substring (point-min) (point-max))
464 (kill-buffer (current-buffer)))
466 (set-window-configuration wcf
))))
468 ;;; Parsing functions:
470 (defun org-export-latex-parse-global (level odd
)
471 "Parse the current buffer recursively, starting at LEVEL.
472 If ODD is non-nil, assume the buffer only contains odd sections.
473 Return a list reflecting the document structure."
475 (goto-char (point-min))
476 (let* ((cnt 0) output
477 (depth org-export-latex-sectioning-depth
))
478 (while (re-search-forward
479 (concat "^\\(\\(?:\\*\\)\\{"
480 (number-to-string (+ (if odd
2 1) level
))
482 ;; make sure that there is no upper heading
487 (concat "^\\(\\(?:\\*\\)\\{"
488 (number-to-string level
)
489 "\\}\\) \\(.*\\)$") nil t
)))) t
)
491 (let* ((pos (match-beginning 0))
492 (heading (match-string 2))
493 (nlevel (if odd
(/ (+ 3 level
) 2) (1+ level
))))
498 (if (re-search-forward
499 (concat "^\\(\\(?:\\*\\)\\{"
500 (number-to-string (+ (if odd
2 1) level
))
501 "\\}\\) \\(.*\\)$") nil t
)
504 (goto-char (point-min))
512 `(heading .
,heading
)
513 `(content .
,(org-export-latex-parse-content))
514 `(subcontent .
,(org-export-latex-parse-subcontent
519 (defun org-export-latex-parse-content ()
520 "Extract the content of a section."
522 (end (if (re-search-forward "^\\(\\*\\)+ .*$" nil t
)
523 (progn (beginning-of-line) (point))
525 (buffer-substring beg end
)))
527 (defun org-export-latex-parse-subcontent (level odd
)
528 "Extract the subcontent of a section at LEVEL.
529 If ODD Is non-nil, assume subcontent only contains odd sections."
530 (if (not (re-search-forward
531 (concat "^\\(\\(?:\\*\\)\\{"
532 (number-to-string (+ (if odd
4 2) level
))
535 nil
; subcontent is nil
536 (org-export-latex-parse-global (+ (if odd
2 1) level
) odd
)))
538 ;;; Rendering functions:
539 (defun org-export-latex-global (content)
540 "Export CONTENT to LaTeX.
541 CONTENT is an element of the list produced by
542 `org-export-latex-parse-global'."
543 (if (eq (car content
) 'subcontent
)
544 (mapc 'org-export-latex-sub
(cdr content
))
545 (org-export-latex-sub (car content
))))
547 (defun org-export-latex-sub (subcontent)
548 "Export the list SUBCONTENT to LaTeX.
549 SUBCONTENT is an alist containing information about the headline
551 (let ((num (plist-get org-export-latex-options-plist
:section-numbers
)))
552 (mapc (lambda(x) (org-export-latex-subcontent x num
)) subcontent
)))
554 (defun org-export-latex-subcontent (subcontent num
)
555 "Export each cell of SUBCONTENT to LaTeX."
556 (let ((heading (org-export-latex-fontify-headline
557 (cdr (assoc 'heading subcontent
))))
558 (level (- (cdr (assoc 'level subcontent
))
559 org-export-latex-add-level
))
560 (occur (number-to-string (cdr (assoc 'occur subcontent
))))
561 (content (cdr (assoc 'content subcontent
)))
562 (subcontent (cadr (assoc 'subcontent subcontent
))))
565 ((<= level org-export-latex-sectioning-depth
)
566 (let ((sec (nth (1- level
) org-export-latex-sectioning
)))
567 (insert (format (if num
(car sec
) (cdr sec
)) heading
) "\n"))
568 (insert (org-export-latex-content content
))
569 (cond ((stringp subcontent
) (insert subcontent
))
570 ((listp subcontent
) (org-export-latex-sub subcontent
))))
571 ;; At a level under the hl option: we can drop this subsection
572 ((> level org-export-latex-sectioning-depth
)
573 (cond ((eq org-export-latex-low-levels
'description
)
574 (insert (format "\\begin{description}\n\n\\item[%s]\n\n" heading
))
575 (insert (org-export-latex-content content
))
576 (cond ((stringp subcontent
) (insert subcontent
))
577 ((listp subcontent
) (org-export-latex-sub subcontent
)))
578 (insert "\\end{description}\n"))
579 ((stringp org-export-latex-low-levels
)
580 (insert (format org-export-latex-low-levels heading
) "\n")
581 (insert (org-export-latex-content content
))
582 (cond ((stringp subcontent
) (insert subcontent
))
583 ((listp subcontent
) (org-export-latex-sub subcontent
)))))))))
585 ;;; Exporting internals:
586 (defun org-export-latex-set-initial-vars (ext-plist level
)
587 "Store org local variables required for LaTeX export.
588 EXT-PLIST is an optional additional plist.
589 LEVEL indicates the default depth for export."
590 (setq org-export-latex-todo-keywords-1 org-todo-keywords-1
591 org-export-latex-all-targets-re
592 (org-make-target-link-regexp (org-all-targets))
593 org-export-latex-options-plist
594 (org-combine-plists (org-default-export-plist) ext-plist
595 (org-infile-export-plist))
596 org-export-latex-class
598 (goto-char (point-min))
599 (if (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\([a-zA-Z]+\\)" nil t
)
600 (assoc (match-string 1) org-export-latex-classes
))
602 org-export-latex-default-class
))
603 org-export-latex-header
604 (cadr (assoc org-export-latex-class org-export-latex-classes
))
605 org-export-latex-sectioning
606 (cddr (assoc org-export-latex-class org-export-latex-classes
))
607 org-export-latex-sectioning-depth
610 (plist-get org-export-latex-options-plist
:headline-levels
))
611 (sec-depth (length org-export-latex-sectioning
)))
612 (if (> hl-levels sec-depth
) sec-depth hl-levels
)))))
614 (defun org-export-latex-make-header (title opt-plist
)
615 "Make the LaTeX header and return it as a string.
616 TITLE is the current title from the buffer or region.
617 OPT-PLIST is the options plist for current buffer."
618 (let ((toc (plist-get opt-plist
:table-of-contents
))
619 (author (plist-get opt-plist
:author
)))
621 (if (plist-get opt-plist
:time-stamp-file
)
622 (format-time-string "% Created %Y-%m-%d %a %H:%M\n"))
623 ;; insert LaTeX custom header
624 org-export-latex-header
626 ;; insert information on LaTeX packages
627 (when org-export-latex-packages-alist
628 (mapconcat (lambda(p)
629 (if (equal "" (car p
))
630 (format "\\usepackage{%s}" (cadr p
))
631 (format "\\usepackage[%s]{%s}"
633 org-export-latex-packages-alist
"\n"))
634 ;; insert additional commands in the header
635 org-export-latex-append-header
640 (org-export-latex-content
641 title
'(lists tables fixed-width keywords
)))
642 ;; insert author info
643 (if (plist-get opt-plist
:author-info
)
644 (format "\\author{%s}\n"
645 (or author user-full-name
))
646 (format "%%\\author{%s}\n"
647 (or author user-full-name
)))
649 (format "\\date{%s}\n"
651 (or (plist-get opt-plist
:date
)
652 org-export-latex-date-format
)))
653 ;; beginning of the document
654 "\n\\begin{document}\n\n"
655 ;; insert the title command
656 (if (string-match "%s" org-export-latex-title-command
)
657 (format org-export-latex-title-command title
)
658 org-export-latex-title-command
)
661 (when (and org-export-with-toc
662 (plist-get opt-plist
:section-numbers
))
664 (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\n"
665 (min toc
(plist-get opt-plist
:headline-levels
))))
666 (toc (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\n"
667 (plist-get opt-plist
:headline-levels
))))))))
669 (defun org-export-latex-first-lines (&optional comments
)
670 "Export the first lines before first headline.
671 COMMENTS is either nil to replace them with the empty string or a
672 formatting string like %%%%s if we want to comment them out."
674 (goto-char (point-min))
675 (if (org-at-heading-p) (beginning-of-line 2))
677 (end (if (and (re-search-forward "^\\* " nil t
)
678 (not (eq pt
(match-beginning 0))))
679 (goto-char (match-beginning 0))
680 (goto-char (point-max)))))
681 (org-export-latex-content
682 (org-cleaned-string-for-export
683 (buffer-substring (point-min) end
)
688 :skip-before-1st-heading nil
689 :LaTeX-fragments nil
)))))
691 (defun org-export-latex-content (content &optional exclude-list
)
692 "Convert CONTENT string to LaTeX.
693 Don't perform conversions that are in EXCLUDE-LIST. Recognized
694 conversion types are: quotation-marks, emphasis, sub-superscript,
695 links, keywords, lists, tables, fixed-width"
698 (unless (memq 'quotation-marks exclude-list
)
699 (org-export-latex-quotation-marks))
700 (unless (memq 'emphasis exclude-list
)
701 (when (plist-get org-export-latex-options-plist
:emphasize
)
702 (org-export-latex-fontify)))
703 (unless (memq 'sub-superscript exclude-list
)
704 (org-export-latex-special-chars
705 (plist-get org-export-latex-options-plist
:sub-superscript
)))
706 (unless (memq 'links exclude-list
)
707 (org-export-latex-links))
708 (unless (memq 'keywords exclude-list
)
709 (org-export-latex-keywords
710 (plist-get org-export-latex-options-plist
:timestamps
)))
711 (unless (memq 'lists exclude-list
)
712 (org-export-latex-lists))
713 (unless (memq 'tables exclude-list
)
714 (org-export-latex-tables
715 (plist-get org-export-latex-options-plist
:tables
)))
716 (unless (memq 'fixed-width exclude-list
)
717 (org-export-latex-fixed-width
718 (plist-get org-export-latex-options-plist
:fixed-width
)))
720 (buffer-substring (point-min) (point-max))))
722 (defun org-export-latex-protect-string (s)
723 "Prevent further conversion for string S by adding the
724 org-protect property."
725 (add-text-properties 0 (length s
) '(org-protected t
) s
) s
)
727 (defun org-export-latex-protect-char-in-string (char-list string
)
728 "Add org-protected text-property to char from CHAR-LIST in STRING."
732 (goto-char (point-min))
733 (while (re-search-forward (regexp-opt char-list
) nil t
)
734 (add-text-properties (match-beginning 0)
735 (match-end 0) '(org-protected t
)))
738 (defun org-export-latex-keywords-maybe (remove-list)
739 "Maybe remove keywords depending on rules in REMOVE-LIST."
740 (goto-char (point-min))
741 (let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1
"\\|"))
742 (case-fold-search nil
))
743 ;; convert TODO keywords
744 (when (re-search-forward (concat "^\\(" re-todo
"\\)") nil t
)
745 (if (plist-get remove-list
:todo
)
747 (replace-match (format "\\texttt{%s}" (match-string 1)) t t
)))
748 ;; convert priority string
749 (when (re-search-forward "\\[\\\\#.\\]" nil t
)
750 (if (plist-get remove-list
:priority
)
752 (replace-match (format "\\texttt{%s}" (match-string 0)) t t
)))
754 (when (re-search-forward "\\(:[a-zA-Z0-9]+\\)+:" nil t
)
755 (if (or (not org-export-with-tags
)
756 (plist-get remove-list
:tags
))
758 (replace-match (format "\\texttt{%s}" (match-string 0)) t t
)))))
760 (defun org-export-latex-fontify-headline (string)
761 "Fontify special words in string."
763 ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
764 ;; the beginning of the buffer - inserting "\n" is safe here though.
766 (goto-char (point-min))
767 (when (plist-get org-export-latex-options-plist
:emphasize
)
768 (org-export-latex-fontify))
769 (org-export-latex-special-chars
770 (plist-get org-export-latex-options-plist
:sub-superscript
))
771 (org-export-latex-keywords-maybe
772 org-export-latex-remove-from-headlines
)
773 (org-export-latex-links)
774 (org-trim (buffer-substring-no-properties (point-min) (point-max)))))
776 (defun org-export-latex-quotation-marks ()
777 "Export question marks depending on language conventions."
778 (let* ((lang (plist-get org-export-latex-options-plist
:language
))
779 (quote-rpl (if (equal lang
"fr")
780 '(("\\(\\s-\\)\"" "«~")
781 ("\\(\\S-\\)\"" "~»")
783 '(("\\(\\s-\\)\"" "``")
784 ("\\(\\S-\\)\"" "''")
785 ("\\(\\s-\\)'" "`")))))
786 (mapc (lambda(l) (goto-char (point-min))
787 (while (re-search-forward (car l
) nil t
)
788 (let ((rpl (concat (match-string 1) (cadr l
))))
789 (org-export-latex-protect-string rpl
)
791 (replace-match rpl t t
))))) quote-rpl
)))
793 (defun org-export-latex-special-chars (sub-superscript)
794 "Export special characters to LaTeX.
795 If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
796 See the `org-export-latex.el' code for a complete conversion table."
797 (goto-char (point-min))
799 (goto-char (point-min))
800 (while (re-search-forward c nil t
)
801 ;; Put the point where to check for org-protected
802 (unless (or (get-text-property (match-beginning 2) 'org-protected
)
804 (cond ((member (match-string 2) '("\\$" "$"))
805 (if (equal (match-string 2) "\\$")
806 (replace-match (concat (match-string 1) "$"
807 (match-string 3)) t t
)
808 (replace-match (concat (match-string 1) "\\$"
809 (match-string 3)) t t
)))
810 ((member (match-string 2) '("&" "%" "#"))
811 (if (equal (match-string 1) "\\")
812 (replace-match (match-string 2) t t
)
813 (replace-match (concat (match-string 1) "\\"
814 (match-string 2)) t t
)))
815 ((equal (match-string 2) "...")
817 (concat (match-string 1)
818 (org-export-latex-protect-string "\\ldots{}")) t t
))
819 ((equal (match-string 2) "~")
820 (cond ((equal (match-string 1) "\\") nil
)
821 ((eq 'org-link
(get-text-property 0 'face
(match-string 2)))
822 (replace-match (concat (match-string 1) "\\~") t t
))
824 (org-export-latex-protect-string
825 (concat (match-string 1) "\\~{}")) t t
))))
826 ((member (match-string 2) '("{" "}"))
827 (unless (save-match-data (org-inside-LaTeX-fragment-p))
828 (if (equal (match-string 1) "\\")
829 (replace-match (match-string 2) t t
)
830 (replace-match (concat (match-string 1) "\\"
831 (match-string 2)) t t
)))))
832 (unless (save-match-data (org-inside-LaTeX-fragment-p))
833 (cond ((equal (match-string 2) "\\")
834 (replace-match (or (save-match-data
835 (org-export-latex-treat-backslash-char
837 (match-string 3))) "") t t
))
838 ((member (match-string 2) '("_" "^"))
839 (replace-match (or (save-match-data
840 (org-export-latex-treat-sub-super-char
844 (match-string 3))) "") t t
)))))))
845 '("^\\([^\n$]*?\\|^\\)\\(\\\\?\\$\\)\\([^\n$]*\\)$"
846 "\\([a-za-z0-9]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\([a-za-z0-9]+\\|[ \t\n]\\|[:punct:]\\|{[a-za-z0-9]+}\\|([a-za-z0-9]+)\\)"
847 "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|[a-zA-Z&#%{}\"]+\\)"
854 "\\(.\\|^\\)\\(\\.\\.\\.\\)"
855 ;; (?\< . "\\textless{}")
856 ;; (?\> . "\\textgreater{}")
859 (defun org-export-latex-treat-sub-super-char
860 (subsup string-before char string-after
)
861 "Convert the \"_\" and \"^\" characters to LaTeX.
862 SUBSUP corresponds to the ^: option in the #+OPTIONS line.
863 Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
864 (cond ((equal string-before
"\\")
865 (concat string-before char string-after
))
866 ;; this is part of a math formula
867 ((and (string-match "\\S-+" string-before
)
868 (string-match "\\S-+" string-after
))
869 (cond ((eq 'org-link
(get-text-property 0 'face char
))
870 (concat string-before
"\\" char string-after
))
871 ((save-match-data (org-inside-LaTeX-fragment-p))
873 (cond ((eq 1 (length string-after
))
874 (concat string-before char string-after
))
875 ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after
)
876 (format "%s%s{%s}" string-before char
877 (match-string 1 string-after
))))))
879 (> (length string-after
) 1)
880 (string-match "[({]?\\([^)}]+\\)[)}]?" string-after
))
881 (format "$%s%s{%s}$" string-before char
882 (match-string 1 string-after
)))
883 (subsup (concat "$" string-before char string-after
"$"))
884 (t (org-export-latex-protect-string
885 (concat string-before
"\\" char
"{}" string-after
)))))
886 (t (org-export-latex-protect-string
887 (concat string-before
"\\" char
"{}" string-after
)))))
889 (defun org-export-latex-treat-backslash-char (string-before string-after
)
890 "Convert the \"$\" special character to LaTeX.
891 The conversion is made depending of STRING-BEFORE and STRING-AFTER."
892 (cond ((member (list string-after
) org-html-entities
)
893 ;; backslash is part of a special entity (like "\alpha")
894 (concat string-before
"$\\"
895 (or (cdar (member (list string-after
) org-html-entities
))
897 ((and (not (string-match "^[ \n\t]" string-after
))
898 (not (string-match "[ \t]\\'\\|^" string-before
)))
899 ;; backslash is inside a word
900 (org-export-latex-protect-string
901 (concat string-before
"\\textbackslash{}" string-after
)))
902 ((not (or (equal string-after
"")
903 (string-match "^[ \t\n]" string-after
)))
904 ;; backslash might escape a character (like \#) or a user TeX
905 ;; macro (like \setcounter)
906 (org-export-latex-protect-string
907 (concat string-before
"\\" string-after
)))
908 ((and (string-match "^[ \t\n]" string-after
)
909 (string-match "[ \t\n]\\'" string-before
))
910 ;; backslash is alone, convert it to $\backslash$
911 (org-export-latex-protect-string
912 (concat string-before
"\\textbackslash{}" string-after
)))
913 (t (org-export-latex-protect-string
914 (concat string-before
"\\textbackslash{}" string-after
)))))
916 (defun org-export-latex-keywords (timestamps)
917 "Convert special keywords to LaTeX.
918 Regexps are those from `org-export-latex-special-string-regexps'."
919 (let ((rg org-export-latex-special-string-regexps
) r
)
920 (while (setq r
(pop rg
))
921 (goto-char (point-min))
922 (while (re-search-forward (eval r
) nil t
)
924 (replace-match (format "\\\\texttt{%s}" (match-string 0)) t
)
925 (replace-match ""))))))
927 (defun org-export-latex-fixed-width (opt)
928 "When OPT is non-nil convert fixed-width sections to LaTeX."
929 (goto-char (point-min))
930 (while (re-search-forward "^[ \t]*:" nil t
)
932 (progn (goto-char (match-beginning 0))
933 (insert "\\begin{verbatim}\n")
934 (while (looking-at "^\\([ \t]*\\):\\(.*\\)$")
935 (replace-match (concat (match-string 1)
936 (match-string 2)) t t
)
938 (insert "\\end{verbatim}\n\n"))
939 (progn (goto-char (match-beginning 0))
940 (while (looking-at "^\\([ \t]*\\):\\(.*\\)$")
941 (replace-match (concat "%" (match-string 1)
942 (match-string 2)) t t
)
945 (defun org-export-latex-tables (insert)
946 "Convert tables to LaTeX and INSERT it."
947 (goto-char (point-min))
948 (while (re-search-forward "^\\([ \t]*\\)|" nil t
)
949 ;; FIXME really need to save-excursion?
950 (save-excursion (org-table-align))
951 (let* ((beg (org-table-begin))
952 (end (org-table-end))
953 (raw-table (buffer-substring-no-properties beg end
))
954 fnum fields line lines olines gr colgropen line-fmt align
)
955 (if org-export-latex-tables-verbatim
956 (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
957 "\\end{verbatim}\n")))
958 (apply 'delete-region
(list beg end
))
961 (setq lines
(split-string raw-table
"\n" t
))
962 (apply 'delete-region
(list beg end
))
963 (when org-export-table-remove-special-lines
964 (setq lines
(org-table-clean-before-export lines
)))
965 ;; make a formatting string to reflect aligment
967 (while (and (not line-fmt
) (setq line
(pop olines
)))
968 (unless (string-match "^[ \t]*|-" line
)
969 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
970 (setq fnum
(make-vector (length fields
) 0))
974 (setq gr
(pop org-table-colgroup-info
))
976 (cond ((eq gr
':start
)
977 (prog1 (if colgropen
"|" "")
980 (prog1 (if colgropen
"|" "|")
981 (setq colgropen nil
)))
983 (if (memq gr
'(:end
:startend
))
984 (progn (setq colgropen nil
) "|")
987 ;; fix double || in line-fmt
988 (setq line-fmt
(replace-regexp-in-string "||" "|" line-fmt
))
989 ;; maybe remove the first and last "|"
990 (when (and (not org-export-latex-tables-column-borders
)
991 (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt
))
992 (setq line-fmt
(match-string 2 line-fmt
)))
994 (setq align
(apply 'format
996 (mapcar (lambda (x) (if x
"r" "l"))
997 org-table-last-alignment
))))
998 ;; prepare the table to send to orgtbl-to-latex
1002 (or (and (string-match "[ \t]*|-+" elem
) 'hline
)
1003 (split-string (org-trim elem
) "|" t
)))
1006 (insert (orgtbl-to-latex
1007 lines
`(:tstart
,(concat "\\begin{tabular}{" align
"}")))
1010 (defun org-export-latex-fontify ()
1011 "Convert fontification to LaTeX."
1012 (goto-char (point-min))
1013 (while (re-search-forward org-emph-re nil t
)
1014 ;; The match goes one char after the *string*
1015 (let ((emph (assoc (match-string 3)
1016 org-export-latex-emphasis-alist
))
1018 (unless (get-text-property (1- (point)) 'org-protected
)
1019 (setq rpl
(concat (match-string 1)
1020 (format (org-export-latex-protect-char-in-string
1021 '("\\" "{" "}") (cadr emph
))
1025 (setq rpl
(org-export-latex-protect-string rpl
)))
1026 (replace-match rpl t t
)))
1029 (defun org-export-latex-links ()
1030 ;; Make sure to use the LaTeX hyperref and graphicx package
1031 ;; or send some warnings.
1032 "Convert links to LaTeX."
1033 (goto-char (point-min))
1034 (while (re-search-forward org-bracket-link-analytic-regexp nil t
)
1036 (goto-char (match-beginning 0))
1037 (let* ((re-radio org-export-latex-all-targets-re
)
1038 (remove (list (match-beginning 0) (match-end 0)))
1039 (type (match-string 2))
1040 (raw-path (match-string 3))
1041 (full-raw-path (concat (match-string 1) raw-path
))
1042 (desc (match-string 5))
1044 ;; define the path of the link
1046 ((member type
'("http" "https" "ftp"))
1047 (concat type
":" raw-path
))
1048 ((and re-radio
(string-match re-radio raw-path
))
1050 ((equal type
"mailto")
1051 (concat type
":" raw-path
))
1052 ((equal type
"file")
1053 (if (and (or (org-file-image-p (expand-file-name raw-path
))
1054 (string-match "\\.eps$" raw-path
))
1055 (equal desc full-raw-path
))
1057 (progn (when (string-match "\\(.+\\)::.+" raw-path
)
1058 (setq raw-path
(match-string 1 raw-path
)))
1059 (if (file-exists-p raw-path
)
1060 (concat type
"://" (expand-file-name raw-path
))
1061 (concat type
"://" (org-export-directory
1062 :LaTeX org-export-latex-options-plist
)
1064 ;; process with link inserting
1065 (apply 'delete-region remove
)
1066 (cond ((and imgp
(plist-get org-export-latex-options-plist
:inline-images
))
1067 (insert (format "\\includegraphics[%s]{%s}"
1068 ;; image option should be set be a comment line
1069 org-export-latex-image-default-option
1070 (expand-file-name raw-path
))))
1071 (radiop (insert (format "\\hyperref[%s]{%s}" raw-path desc
)))
1072 (path (insert (format "\\href{%s}{%s}" path desc
)))
1073 (t (insert "\\texttt{" desc
"}")))))))
1075 (defvar org-latex-entities
) ; defined below
1077 (defun org-export-latex-cleaned-string ()
1078 "Clean stuff in the LaTeX export."
1080 ;; Preserve line breaks
1081 (goto-char (point-min))
1082 (while (re-search-forward "\\\\\\\\" nil t
)
1083 (add-text-properties (match-beginning 0) (match-end 0)
1084 '(org-protected t
)))
1086 ;; Convert LaTeX to \LaTeX{}
1087 (goto-char (point-min))
1088 (let ((case-fold-search nil
) rpl
)
1089 (while (re-search-forward "\\([^+_]\\)LaTeX" nil t
)
1090 (replace-match (org-export-latex-protect-string
1091 (concat (match-string 1) "\\LaTeX{}")) t t
)))
1093 ;; Convert horizontal rules
1094 (goto-char (point-min))
1095 (while (re-search-forward "^----+.$" nil t
)
1096 (replace-match (org-export-latex-protect-string "\\hrule") t t
))
1098 ;; Protect LaTeX commands like \commad[...]{...} or \command{...}
1099 (goto-char (point-min))
1100 (while (re-search-forward "\\\\[a-zA-Z]+\\(?:\\[.*\\]\\)?{.*}" nil t
)
1101 (add-text-properties (match-beginning 0) (match-end 0)
1102 '(org-protected t
)))
1104 ;; Protect LaTeX entities
1105 (goto-char (point-min))
1106 (while (re-search-forward (regexp-opt org-latex-entities
) nil t
)
1107 (add-text-properties (match-beginning 0) (match-end 0)
1108 '(org-protected t
)))
1110 ;; Replace radio links
1111 (goto-char (point-min))
1112 (while (re-search-forward
1113 (concat "<<<?" org-export-latex-all-targets-re
1114 ">>>?\\((INVISIBLE)\\)?") nil t
)
1116 (org-export-latex-protect-string
1117 (format "\\label{%s}%s"(match-string 1)
1118 (if (match-string 2) "" (match-string 1)))) t t
))
1120 ;; Delete @<...> constructs
1121 ;; Thanks to Daniel Clemente for this regexp
1122 (goto-char (point-min))
1123 (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t
)
1126 ;; When converting to LaTeX, replace footnotes
1127 ;; FIXME: don't protect footnotes from conversion
1128 (when (plist-get org-export-latex-options-plist
:footnotes
)
1129 (goto-char (point-min))
1130 (while (re-search-forward "\\[[0-9]+\\]" nil t
)
1131 (when (save-match-data
1132 (save-excursion (beginning-of-line)
1133 (looking-at "[^:|#]")))
1134 (let ((foot-beg (match-beginning 0))
1135 (foot-end (match-end 0))
1136 (foot-prefix (match-string 0))
1137 footnote footnote-rpl
)
1139 (when (search-forward foot-prefix nil t
)
1141 (let ((end (save-excursion
1142 (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t
)
1143 (match-beginning 0) (point-max)))))
1144 (setq footnote
(concat (org-trim (buffer-substring (point) end
))
1145 " ")) ; prevent last } being part of a link
1146 (delete-region (point) end
))
1147 (goto-char foot-beg
)
1148 (delete-region foot-beg foot-end
)
1149 (unless (null footnote
)
1150 (setq footnote-rpl
(format "\\footnote{%s}" footnote
))
1151 (add-text-properties 0 10 '(org-protected t
) footnote-rpl
)
1152 (add-text-properties (1- (length footnote-rpl
))
1153 (length footnote-rpl
)
1154 '(org-protected t
) footnote-rpl
)
1155 (insert footnote-rpl
)))))))
1157 ;; Replace footnote section tag for LaTeX
1158 (goto-char (point-min))
1159 (while (re-search-forward
1160 (concat "^" footnote-section-tag-regexp
) nil t
)
1161 (replace-match ""))))
1165 (defun org-export-latex-lists ()
1166 "Replace plain text lists in current buffer into LaTeX lists."
1167 "Convert lists to LaTeX."
1168 (goto-char (point-min))
1169 (while (re-search-forward org-export-latex-list-beginning-re nil t
)
1171 (insert (org-list-to-latex (org-list-parse-list t
)) "\n")))
1173 (defun org-list-parse-list (&optional delete
)
1174 "Parse the list at point.
1175 Return a list containing first level items as strings and
1176 sublevels as a list of strings."
1177 (let ((start (org-list-item-begin))
1178 (end (org-list-end))
1180 (while (re-search-forward org-export-latex-list-beginning-re end t
)
1181 (setq itemsep
(if (save-match-data
1182 (string-match "^[0-9]" (match-string 2)))
1183 "[0-9]+\\(?:\\.\\|)\\)" "[-+]"))
1184 (let* ((indent1 (match-string 1))
1185 (nextitem (save-excursion
1187 (or (and (re-search-forward
1188 (concat "^" indent1 itemsep
" *?") end t
)
1189 (match-beginning 0)) end
))))
1190 (item (buffer-substring
1192 (or (and (re-search-forward
1193 org-export-latex-list-beginning-re end t
)
1194 (goto-char (match-beginning 0)))
1196 (nextindent (match-string 1))
1197 (item (org-trim item
))
1198 (item (if (string-match "^\\[.+\\]" item
)
1199 (replace-match "\\\\texttt{\\&}"
1202 (when (> (length nextindent
)
1204 (narrow-to-region (point) nextitem
)
1205 (push (org-list-parse-list) output
)
1207 (when delete
(delete-region start end
))
1208 (setq output
(nreverse output
))
1209 (push (if (string-match "^\\[0" itemsep
)
1210 'ordered
'unordered
) output
)))
1212 (defun org-list-item-begin ()
1213 "Find the beginning of the list item and return its position."
1215 (if (not (or (looking-at org-export-latex-list-beginning-re
)
1217 org-export-latex-list-beginning-re nil t
)))
1218 (progn (goto-char (point-min)) (point))
1219 (match-beginning 0))))
1221 (defun org-list-end ()
1222 "Find the end of the list and return its position."
1225 (while (or (looking-at org-export-latex-list-beginning-re
)
1226 (looking-at "^[ \t]+\\|^$"))
1227 (if (eq (point) (point-max))
1228 (throw 'exit
(point-max)))
1229 (forward-line 1))) (point)))
1231 (defun org-list-insert-radio-list ()
1232 "Insert a radio list template appropriate for this major mode."
1234 (let* ((e (assq major-mode org-list-radio-list-templates
))
1237 (unless e
(error "No radio list setup defined for %s" major-mode
))
1238 (setq name
(read-string "List name: "))
1239 (while (string-match "%n" txt
)
1240 (setq txt
(replace-match name t t txt
)))
1241 (or (bolp) (insert "\n"))
1246 (defun org-list-send-list (&optional maybe
)
1247 "Send a tranformed version of this list to the receiver position.
1248 With argument MAYBE, fail quietly if no transformation is defined for
1252 (unless (org-at-item-p) (error "Not at a list"))
1254 (goto-char (org-list-item-begin))
1255 (beginning-of-line 0)
1256 (unless (looking-at "#\\+ORGLST: *SEND +\\([a-zA-Z0-9_]+\\) +\\([^ \t\r\n]+\\)\\( +.*\\)?")
1259 (error "Don't know how to transform this list"))))
1260 (let* ((name (match-string 1))
1262 (transform (intern (match-string 2)))
1263 (txt (buffer-substring-no-properties
1264 (org-list-item-begin)
1266 (list (org-list-parse-list)))
1267 (unless (fboundp transform
)
1268 (error "No such transformation function %s" transform
))
1269 (setq txt
(funcall transform list
))
1270 ;; Find the insertion place
1272 (goto-char (point-min))
1273 (unless (re-search-forward
1274 (concat "BEGIN RECEIVE ORGLST +" name
"\\([ \t]\\|$\\)") nil t
)
1275 (error "Don't know where to insert translated list"))
1276 (goto-char (match-beginning 0))
1277 (beginning-of-line 2)
1279 (unless (re-search-forward (concat "END RECEIVE ORGLST +" name
) nil t
)
1280 (error "Cannot find end of insertion region"))
1281 (beginning-of-line 1)
1282 (delete-region beg
(point))
1285 (message "List converted and installed at receiver location"))))
1287 (defun org-list-to-generic (list params
)
1288 "Convert a LIST parsed through `org-list-parse-list' to other formats.
1290 Valid parameters are
1292 :ustart String to start an unordered list
1293 :uend String to end an unordered list
1295 :ostart String to start an ordered list
1296 :oend String to end an ordered list
1298 :splice When set to t, return only list body lines, don't wrap
1299 them into :[u/o]start and :[u/o]end. Default is nil.
1301 :istart String to start a list item
1302 :iend String to end a list item
1303 :isep String to separate items
1304 :lsep String to separate sublists"
1306 (let* ((p params
) sublist
1307 (splicep (plist-get p
:splice
))
1308 (ostart (plist-get p
:ostart
))
1309 (oend (plist-get p
:oend
))
1310 (ustart (plist-get p
:ustart
))
1311 (uend (plist-get p
:uend
))
1312 (istart (plist-get p
:istart
))
1313 (iend (plist-get p
:iend
))
1314 (isep (plist-get p
:isep
))
1315 (lsep (plist-get p
:lsep
)))
1317 (cond ((eq (car list
) 'ordered
)
1318 (concat ostart
"\n%s" oend
"\n"))
1319 ((eq (car list
) 'unordered
)
1320 (concat ustart
"\n%s" uend
"\n"))))
1322 (while (setq sublist
(pop list
))
1323 (cond ((symbolp sublist
) nil
)
1325 (setq rtn
(concat rtn istart sublist iend isep
)))
1327 (setq rtn
(concat rtn
;; previous list
1328 lsep
;; list separator
1329 (org-list-to-generic sublist p
)
1330 lsep
;; list separator
1332 (format wrapper rtn
))))
1334 (defun org-list-to-latex (list)
1335 "Convert LIST into a LaTeX list."
1336 (org-list-to-generic
1337 list
'(:splicep nil
:ostart
"\\begin{enumerate}" :oend
"\\end{enumerate}"
1338 :ustart
"\\begin{itemize}" :uend
"\\end{itemize}"
1339 :istart
"\\item " :iend
""
1340 :isep
"\n" :lsep
"\n")))
1342 (defun org-list-to-html (list)
1343 "Convert LIST into a HTML list."
1344 (org-list-to-generic
1345 list
'(:splicep nil
:ostart
"<ol>" :oend
"</ol>"
1346 :ustart
"<ul>" :uend
"</ul>"
1347 :istart
"<li>" :iend
"</li>"
1348 :isep
"\n" :lsep
"\n")))
1350 (defun org-list-to-texinfo (list)
1351 "Convert LIST into a Texinfo list."
1352 (org-list-to-generic
1353 list
'(:splicep nil
:ostart
"@itemize @minus" :oend
"@end itemize"
1354 :ustart
"@enumerate" :uend
"@end enumerate"
1355 :istart
"@item\n" :iend
""
1356 :isep
"\n" :lsep
"\n")))
1358 (defconst org-latex-entities
1387 "\\begin{description}"
1388 "\\begin{enumerate}"
1392 "\\begin{flushleft}"
1393 "\\begin{flushright}"
1398 "\\begin{quotation}"
1403 "\\begin{thebibliography}"
1405 "\\begin{titlepage}"
1532 "A list of LaTeX commands to be protected when performing conversion.")
1534 (provide 'org-export-latex
)
1536 ;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad
1537 ;;; org-export-latex.el ends here