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
332 to-buffer body-only pub-dir
)
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.
348 when PUB-DIR is set, use this as the publishing directory."
350 ;; Make sure we have a file name when we need it.
351 (when (and (not (or to-buffer body-only
))
352 (not buffer-file-name
))
353 (if (buffer-base-buffer)
354 (org-set-local 'buffer-file-name
355 (with-current-buffer (buffer-base-buffer)
357 (error "Need a file name to be able to export")))
359 (message "Exporting to LaTeX...")
360 (org-update-radio-target-regexp)
361 (org-export-latex-set-initial-vars ext-plist arg
)
362 (let* ((wcf (current-window-configuration))
363 (opt-plist org-export-latex-options-plist
)
364 (region-p (org-region-active-p))
368 (goto-char (region-beginning))
369 (and (org-at-heading-p)
370 (>= (org-end-of-subtree t t
) (region-end))))))
371 (title (or (and subtree-p
(org-export-get-title-from-subtree))
372 (plist-get opt-plist
:title
)
374 (plist-get opt-plist
:skip-before-1st-heading
))
375 (org-export-grab-title-from-buffer))
376 (file-name-sans-extension
377 (file-name-nondirectory buffer-file-name
))))
378 (filename (concat (file-name-as-directory
380 (org-export-directory :LaTeX ext-plist
)))
381 (file-name-sans-extension
382 (file-name-nondirectory ;sans-extension
383 buffer-file-name
)) ".tex"))
384 (filename (if (equal (file-truename filename
)
385 (file-truename buffer-file-name
))
386 (concat filename
".tex")
388 (buffer (if to-buffer
390 ((eq to-buffer
'string
) (get-buffer-create
391 "*Org LaTeX Export*"))
392 (t (get-buffer-create to-buffer
)))
393 (find-file-noselect filename
)))
394 (odd org-odd-levels-only
)
395 (header (org-export-latex-make-header title opt-plist
))
396 (skip (cond (subtree-p nil
)
398 ;; never skip first lines when exporting a subtree
399 (t (plist-get opt-plist
:skip-before-1st-heading
))))
400 (text (plist-get opt-plist
:text
))
401 (first-lines (if skip
"" (org-export-latex-first-lines)))
402 (coding-system (and (boundp 'buffer-file-coding-system
)
403 buffer-file-coding-system
))
404 (coding-system-for-write (or org-export-latex-coding-system
406 (save-buffer-coding-system (or org-export-latex-coding-system
408 (region (buffer-substring
409 (if region-p
(region-beginning) (point-min))
410 (if region-p
(region-end) (point-max))))
412 (org-cleaned-string-for-export
413 region
:emph-multiline t
416 :add-text
(if (eq to-buffer
'string
) nil text
)
417 :skip-before-1st-heading skip
418 :LaTeX-fragments nil
)))
423 (and (fboundp 'set-buffer-file-coding-system
)
424 (set-buffer-file-coding-system coding-system-for-write
))
426 ;; insert the header and initial document commands
427 (unless (or (eq to-buffer
'string
) body-only
)
430 ;; insert text found in #+TEXT
431 (when (and text
(not (eq to-buffer
'string
)))
432 (insert (org-export-latex-content
433 text
'(lists tables fixed-width keywords
))
436 ;; insert lines before the first headline
437 (unless (or skip
(eq to-buffer
'string
))
438 (insert first-lines
))
440 ;; handle the case where the region does not begin with a section
442 (insert (with-temp-buffer
443 (insert string-for-export
)
444 (org-export-latex-first-lines))))
446 ;; export the content of headlines
447 (org-export-latex-global
449 (insert string-for-export
)
450 (goto-char (point-min))
451 (when (re-search-forward "^\\(\\*+\\) " nil t
)
452 (let* ((asters (length (match-string 1)))
453 (level (if odd
(- asters
2) (- asters
1))))
454 (setq org-export-latex-add-level
455 (if odd
(1- (/ (1+ asters
) 2)) (1- asters
)))
456 (org-export-latex-parse-global level odd
)))))
459 (unless body-only
(insert "\n\\end{document}"))
460 (or to-buffer
(save-buffer))
461 (goto-char (point-min))
462 (message "Exporting to LaTeX...done")
464 (if (eq to-buffer
'string
)
465 (prog1 (buffer-substring (point-min) (point-max))
466 (kill-buffer (current-buffer)))
468 (set-window-configuration wcf
))))
470 ;;; Parsing functions:
472 (defun org-export-latex-parse-global (level odd
)
473 "Parse the current buffer recursively, starting at LEVEL.
474 If ODD is non-nil, assume the buffer only contains odd sections.
475 Return a list reflecting the document structure."
477 (goto-char (point-min))
478 (let* ((cnt 0) output
479 (depth org-export-latex-sectioning-depth
))
480 (while (re-search-forward
481 (concat "^\\(\\(?:\\*\\)\\{"
482 (number-to-string (+ (if odd
2 1) level
))
484 ;; make sure that there is no upper heading
489 (concat "^\\(\\(?:\\*\\)\\{"
490 (number-to-string level
)
491 "\\}\\) \\(.*\\)$") nil t
)))) t
)
493 (let* ((pos (match-beginning 0))
494 (heading (match-string 2))
495 (nlevel (if odd
(/ (+ 3 level
) 2) (1+ level
))))
500 (if (re-search-forward
501 (concat "^\\(\\(?:\\*\\)\\{"
502 (number-to-string (+ (if odd
2 1) level
))
503 "\\}\\) \\(.*\\)$") nil t
)
506 (goto-char (point-min))
514 `(heading .
,heading
)
515 `(content .
,(org-export-latex-parse-content))
516 `(subcontent .
,(org-export-latex-parse-subcontent
521 (defun org-export-latex-parse-content ()
522 "Extract the content of a section."
524 (end (if (re-search-forward "^\\(\\*\\)+ .*$" nil t
)
525 (progn (beginning-of-line) (point))
527 (buffer-substring beg end
)))
529 (defun org-export-latex-parse-subcontent (level odd
)
530 "Extract the subcontent of a section at LEVEL.
531 If ODD Is non-nil, assume subcontent only contains odd sections."
532 (if (not (re-search-forward
533 (concat "^\\(\\(?:\\*\\)\\{"
534 (number-to-string (+ (if odd
4 2) level
))
537 nil
; subcontent is nil
538 (org-export-latex-parse-global (+ (if odd
2 1) level
) odd
)))
540 ;;; Rendering functions:
541 (defun org-export-latex-global (content)
542 "Export CONTENT to LaTeX.
543 CONTENT is an element of the list produced by
544 `org-export-latex-parse-global'."
545 (if (eq (car content
) 'subcontent
)
546 (mapc 'org-export-latex-sub
(cdr content
))
547 (org-export-latex-sub (car content
))))
549 (defun org-export-latex-sub (subcontent)
550 "Export the list SUBCONTENT to LaTeX.
551 SUBCONTENT is an alist containing information about the headline
553 (let ((num (plist-get org-export-latex-options-plist
:section-numbers
)))
554 (mapc (lambda(x) (org-export-latex-subcontent x num
)) subcontent
)))
556 (defun org-export-latex-subcontent (subcontent num
)
557 "Export each cell of SUBCONTENT to LaTeX."
558 (let ((heading (org-export-latex-fontify-headline
559 (cdr (assoc 'heading subcontent
))))
560 (level (- (cdr (assoc 'level subcontent
))
561 org-export-latex-add-level
))
562 (occur (number-to-string (cdr (assoc 'occur subcontent
))))
563 (content (cdr (assoc 'content subcontent
)))
564 (subcontent (cadr (assoc 'subcontent subcontent
))))
567 ((<= level org-export-latex-sectioning-depth
)
568 (let ((sec (nth (1- level
) org-export-latex-sectioning
)))
569 (insert (format (if num
(car sec
) (cdr sec
)) heading
) "\n"))
570 (insert (org-export-latex-content content
))
571 (cond ((stringp subcontent
) (insert subcontent
))
572 ((listp subcontent
) (org-export-latex-sub subcontent
))))
573 ;; At a level under the hl option: we can drop this subsection
574 ((> level org-export-latex-sectioning-depth
)
575 (cond ((eq org-export-latex-low-levels
'description
)
576 (insert (format "\\begin{description}\n\n\\item[%s]\n\n" heading
))
577 (insert (org-export-latex-content content
))
578 (cond ((stringp subcontent
) (insert subcontent
))
579 ((listp subcontent
) (org-export-latex-sub subcontent
)))
580 (insert "\\end{description}\n"))
581 ((stringp org-export-latex-low-levels
)
582 (insert (format org-export-latex-low-levels heading
) "\n")
583 (insert (org-export-latex-content content
))
584 (cond ((stringp subcontent
) (insert subcontent
))
585 ((listp subcontent
) (org-export-latex-sub subcontent
)))))))))
587 ;;; Exporting internals:
588 (defun org-export-latex-set-initial-vars (ext-plist level
)
589 "Store org local variables required for LaTeX export.
590 EXT-PLIST is an optional additional plist.
591 LEVEL indicates the default depth for export."
592 (setq org-export-latex-todo-keywords-1 org-todo-keywords-1
593 org-export-latex-all-targets-re
594 (org-make-target-link-regexp (org-all-targets))
595 org-export-latex-options-plist
596 (org-combine-plists (org-default-export-plist) ext-plist
597 (org-infile-export-plist))
598 org-export-latex-class
600 (goto-char (point-min))
601 (if (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\([a-zA-Z]+\\)" nil t
)
602 (assoc (match-string 1) org-export-latex-classes
))
604 org-export-latex-default-class
))
605 org-export-latex-header
606 (cadr (assoc org-export-latex-class org-export-latex-classes
))
607 org-export-latex-sectioning
608 (cddr (assoc org-export-latex-class org-export-latex-classes
))
609 org-export-latex-sectioning-depth
612 (plist-get org-export-latex-options-plist
:headline-levels
))
613 (sec-depth (length org-export-latex-sectioning
)))
614 (if (> hl-levels sec-depth
) sec-depth hl-levels
)))))
616 (defun org-export-latex-make-header (title opt-plist
)
617 "Make the LaTeX header and return it as a string.
618 TITLE is the current title from the buffer or region.
619 OPT-PLIST is the options plist for current buffer."
620 (let ((toc (plist-get opt-plist
:table-of-contents
))
621 (author (plist-get opt-plist
:author
)))
623 (if (plist-get opt-plist
:time-stamp-file
)
624 (format-time-string "% Created %Y-%m-%d %a %H:%M\n"))
625 ;; insert LaTeX custom header
626 org-export-latex-header
628 ;; insert information on LaTeX packages
629 (when org-export-latex-packages-alist
630 (mapconcat (lambda(p)
631 (if (equal "" (car p
))
632 (format "\\usepackage{%s}" (cadr p
))
633 (format "\\usepackage[%s]{%s}"
635 org-export-latex-packages-alist
"\n"))
636 ;; insert additional commands in the header
637 org-export-latex-append-header
642 (org-export-latex-content
643 title
'(lists tables fixed-width keywords
)))
644 ;; insert author info
645 (if (plist-get opt-plist
:author-info
)
646 (format "\\author{%s}\n"
647 (or author user-full-name
))
648 (format "%%\\author{%s}\n"
649 (or author user-full-name
)))
651 (format "\\date{%s}\n"
653 (or (plist-get opt-plist
:date
)
654 org-export-latex-date-format
)))
655 ;; beginning of the document
656 "\n\\begin{document}\n\n"
657 ;; insert the title command
658 (if (string-match "%s" org-export-latex-title-command
)
659 (format org-export-latex-title-command title
)
660 org-export-latex-title-command
)
663 (when (and org-export-with-toc
664 (plist-get opt-plist
:section-numbers
))
666 (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\n"
667 (min toc
(plist-get opt-plist
:headline-levels
))))
668 (toc (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\n"
669 (plist-get opt-plist
:headline-levels
))))))))
671 (defun org-export-latex-first-lines (&optional comments
)
672 "Export the first lines before first headline.
673 COMMENTS is either nil to replace them with the empty string or a
674 formatting string like %%%%s if we want to comment them out."
676 (goto-char (point-min))
677 (if (org-at-heading-p) (beginning-of-line 2))
679 (end (if (and (re-search-forward "^\\* " nil t
)
680 (not (eq pt
(match-beginning 0))))
681 (goto-char (match-beginning 0))
682 (goto-char (point-max)))))
683 (org-export-latex-content
684 (org-cleaned-string-for-export
685 (buffer-substring (point-min) end
)
690 :skip-before-1st-heading nil
691 :LaTeX-fragments nil
)))))
693 (defun org-export-latex-content (content &optional exclude-list
)
694 "Convert CONTENT string to LaTeX.
695 Don't perform conversions that are in EXCLUDE-LIST. Recognized
696 conversion types are: quotation-marks, emphasis, sub-superscript,
697 links, keywords, lists, tables, fixed-width"
700 (unless (memq 'quotation-marks exclude-list
)
701 (org-export-latex-quotation-marks))
702 (unless (memq 'emphasis exclude-list
)
703 (when (plist-get org-export-latex-options-plist
:emphasize
)
704 (org-export-latex-fontify)))
705 (unless (memq 'sub-superscript exclude-list
)
706 (org-export-latex-special-chars
707 (plist-get org-export-latex-options-plist
:sub-superscript
)))
708 (unless (memq 'links exclude-list
)
709 (org-export-latex-links))
710 (unless (memq 'keywords exclude-list
)
711 (org-export-latex-keywords
712 (plist-get org-export-latex-options-plist
:timestamps
)))
713 (unless (memq 'lists exclude-list
)
714 (org-export-latex-lists))
715 (unless (memq 'tables exclude-list
)
716 (org-export-latex-tables
717 (plist-get org-export-latex-options-plist
:tables
)))
718 (unless (memq 'fixed-width exclude-list
)
719 (org-export-latex-fixed-width
720 (plist-get org-export-latex-options-plist
:fixed-width
)))
722 (buffer-substring (point-min) (point-max))))
724 (defun org-export-latex-protect-string (s)
725 "Prevent further conversion for string S by adding the
726 org-protect property."
727 (add-text-properties 0 (length s
) '(org-protected t
) s
) s
)
729 (defun org-export-latex-protect-char-in-string (char-list string
)
730 "Add org-protected text-property to char from CHAR-LIST in STRING."
734 (goto-char (point-min))
735 (while (re-search-forward (regexp-opt char-list
) nil t
)
736 (add-text-properties (match-beginning 0)
737 (match-end 0) '(org-protected t
)))
740 (defun org-export-latex-keywords-maybe (remove-list)
741 "Maybe remove keywords depending on rules in REMOVE-LIST."
742 (goto-char (point-min))
743 (let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1
"\\|"))
744 (case-fold-search nil
))
745 ;; convert TODO keywords
746 (when (re-search-forward (concat "^\\(" re-todo
"\\)") nil t
)
747 (if (plist-get remove-list
:todo
)
749 (replace-match (format "\\texttt{%s}" (match-string 1)) t t
)))
750 ;; convert priority string
751 (when (re-search-forward "\\[\\\\#.\\]" nil t
)
752 (if (plist-get remove-list
:priority
)
754 (replace-match (format "\\texttt{%s}" (match-string 0)) t t
)))
756 (when (re-search-forward "\\(:[a-zA-Z0-9]+\\)+:" nil t
)
757 (if (or (not org-export-with-tags
)
758 (plist-get remove-list
:tags
))
760 (replace-match (format "\\texttt{%s}" (match-string 0)) t t
)))))
762 (defun org-export-latex-fontify-headline (string)
763 "Fontify special words in string."
765 ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
766 ;; the beginning of the buffer - inserting "\n" is safe here though.
768 (goto-char (point-min))
769 (when (plist-get org-export-latex-options-plist
:emphasize
)
770 (org-export-latex-fontify))
771 (org-export-latex-special-chars
772 (plist-get org-export-latex-options-plist
:sub-superscript
))
773 (org-export-latex-keywords-maybe
774 org-export-latex-remove-from-headlines
)
775 (org-export-latex-links)
776 (org-trim (buffer-substring-no-properties (point-min) (point-max)))))
778 (defun org-export-latex-quotation-marks ()
779 "Export question marks depending on language conventions."
780 (let* ((lang (plist-get org-export-latex-options-plist
:language
))
781 (quote-rpl (if (equal lang
"fr")
782 '(("\\(\\s-\\)\"" "«~")
783 ("\\(\\S-\\)\"" "~»")
785 '(("\\(\\s-\\)\"" "``")
786 ("\\(\\S-\\)\"" "''")
787 ("\\(\\s-\\)'" "`")))))
788 (mapc (lambda(l) (goto-char (point-min))
789 (while (re-search-forward (car l
) nil t
)
790 (let ((rpl (concat (match-string 1) (cadr l
))))
791 (org-export-latex-protect-string rpl
)
793 (replace-match rpl t t
))))) quote-rpl
)))
795 (defun org-export-latex-special-chars (sub-superscript)
796 "Export special characters to LaTeX.
797 If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
798 See the `org-export-latex.el' code for a complete conversion table."
799 (goto-char (point-min))
801 (goto-char (point-min))
802 (while (re-search-forward c nil t
)
803 ;; Put the point where to check for org-protected
804 (unless (or (get-text-property (match-beginning 2) 'org-protected
)
806 (cond ((member (match-string 2) '("\\$" "$"))
807 (if (equal (match-string 2) "\\$")
808 (replace-match (concat (match-string 1) "$"
809 (match-string 3)) t t
)
810 (replace-match (concat (match-string 1) "\\$"
811 (match-string 3)) t t
)))
812 ((member (match-string 2) '("&" "%" "#"))
813 (if (equal (match-string 1) "\\")
814 (replace-match (match-string 2) t t
)
815 (replace-match (concat (match-string 1) "\\"
816 (match-string 2)) t t
)))
817 ((equal (match-string 2) "...")
819 (concat (match-string 1)
820 (org-export-latex-protect-string "\\ldots{}")) t t
))
821 ((equal (match-string 2) "~")
822 (cond ((equal (match-string 1) "\\") nil
)
823 ((eq 'org-link
(get-text-property 0 'face
(match-string 2)))
824 (replace-match (concat (match-string 1) "\\~") t t
))
826 (org-export-latex-protect-string
827 (concat (match-string 1) "\\~{}")) t t
))))
828 ((member (match-string 2) '("{" "}"))
829 (unless (save-match-data (org-inside-LaTeX-fragment-p))
830 (if (equal (match-string 1) "\\")
831 (replace-match (match-string 2) t t
)
832 (replace-match (concat (match-string 1) "\\"
833 (match-string 2)) t t
)))))
834 (unless (save-match-data (org-inside-LaTeX-fragment-p))
835 (cond ((equal (match-string 2) "\\")
836 (replace-match (or (save-match-data
837 (org-export-latex-treat-backslash-char
839 (match-string 3))) "") t t
))
840 ((member (match-string 2) '("_" "^"))
841 (replace-match (or (save-match-data
842 (org-export-latex-treat-sub-super-char
846 (match-string 3))) "") t t
)))))))
847 '("^\\([^\n$]*?\\|^\\)\\(\\\\?\\$\\)\\([^\n$]*\\)$"
848 "\\([a-za-z0-9]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\([a-za-z0-9]+\\|[ \t\n]\\|[:punct:]\\|{[a-za-z0-9]+}\\|([a-za-z0-9]+)\\)"
849 "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|[a-zA-Z&#%{}\"]+\\)"
856 "\\(.\\|^\\)\\(\\.\\.\\.\\)"
857 ;; (?\< . "\\textless{}")
858 ;; (?\> . "\\textgreater{}")
861 (defun org-export-latex-treat-sub-super-char
862 (subsup string-before char string-after
)
863 "Convert the \"_\" and \"^\" characters to LaTeX.
864 SUBSUP corresponds to the ^: option in the #+OPTIONS line.
865 Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
866 (cond ((equal string-before
"\\")
867 (concat string-before char string-after
))
868 ;; this is part of a math formula
869 ((and (string-match "\\S-+" string-before
)
870 (string-match "\\S-+" string-after
))
871 (cond ((eq 'org-link
(get-text-property 0 'face char
))
872 (concat string-before
"\\" char string-after
))
873 ((save-match-data (org-inside-LaTeX-fragment-p))
875 (cond ((eq 1 (length string-after
))
876 (concat string-before char string-after
))
877 ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after
)
878 (format "%s%s{%s}" string-before char
879 (match-string 1 string-after
))))))
881 (> (length string-after
) 1)
882 (string-match "[({]?\\([^)}]+\\)[)}]?" string-after
))
883 (format "$%s%s{%s}$" string-before char
884 (match-string 1 string-after
)))
885 (subsup (concat "$" string-before char string-after
"$"))
886 (t (org-export-latex-protect-string
887 (concat string-before
"\\" char
"{}" string-after
)))))
888 (t (org-export-latex-protect-string
889 (concat string-before
"\\" char
"{}" string-after
)))))
891 (defun org-export-latex-treat-backslash-char (string-before string-after
)
892 "Convert the \"$\" special character to LaTeX.
893 The conversion is made depending of STRING-BEFORE and STRING-AFTER."
894 (cond ((member (list string-after
) org-html-entities
)
895 ;; backslash is part of a special entity (like "\alpha")
896 (concat string-before
"$\\"
897 (or (cdar (member (list string-after
) org-html-entities
))
899 ((and (not (string-match "^[ \n\t]" string-after
))
900 (not (string-match "[ \t]\\'\\|^" string-before
)))
901 ;; backslash is inside a word
902 (org-export-latex-protect-string
903 (concat string-before
"\\textbackslash{}" string-after
)))
904 ((not (or (equal string-after
"")
905 (string-match "^[ \t\n]" string-after
)))
906 ;; backslash might escape a character (like \#) or a user TeX
907 ;; macro (like \setcounter)
908 (org-export-latex-protect-string
909 (concat string-before
"\\" string-after
)))
910 ((and (string-match "^[ \t\n]" string-after
)
911 (string-match "[ \t\n]\\'" string-before
))
912 ;; backslash is alone, convert it to $\backslash$
913 (org-export-latex-protect-string
914 (concat string-before
"\\textbackslash{}" string-after
)))
915 (t (org-export-latex-protect-string
916 (concat string-before
"\\textbackslash{}" string-after
)))))
918 (defun org-export-latex-keywords (timestamps)
919 "Convert special keywords to LaTeX.
920 Regexps are those from `org-export-latex-special-string-regexps'."
921 (let ((rg org-export-latex-special-string-regexps
) r
)
922 (while (setq r
(pop rg
))
923 (goto-char (point-min))
924 (while (re-search-forward (eval r
) nil t
)
926 (replace-match (format "\\\\texttt{%s}" (match-string 0)) t
)
927 (replace-match ""))))))
929 (defun org-export-latex-fixed-width (opt)
930 "When OPT is non-nil convert fixed-width sections to LaTeX."
931 (goto-char (point-min))
932 (while (re-search-forward "^[ \t]*:" nil t
)
934 (progn (goto-char (match-beginning 0))
935 (insert "\\begin{verbatim}\n")
936 (while (looking-at "^\\([ \t]*\\):\\(.*\\)$")
937 (replace-match (concat (match-string 1)
938 (match-string 2)) t t
)
940 (insert "\\end{verbatim}\n\n"))
941 (progn (goto-char (match-beginning 0))
942 (while (looking-at "^\\([ \t]*\\):\\(.*\\)$")
943 (replace-match (concat "%" (match-string 1)
944 (match-string 2)) t t
)
947 (defun org-export-latex-tables (insert)
948 "Convert tables to LaTeX and INSERT it."
949 (goto-char (point-min))
950 (while (re-search-forward "^\\([ \t]*\\)|" nil t
)
951 ;; FIXME really need to save-excursion?
952 (save-excursion (org-table-align))
953 (let* ((beg (org-table-begin))
954 (end (org-table-end))
955 (raw-table (buffer-substring-no-properties beg end
))
956 fnum fields line lines olines gr colgropen line-fmt align
)
957 (if org-export-latex-tables-verbatim
958 (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
959 "\\end{verbatim}\n")))
960 (apply 'delete-region
(list beg end
))
963 (setq lines
(split-string raw-table
"\n" t
))
964 (apply 'delete-region
(list beg end
))
965 (when org-export-table-remove-special-lines
966 (setq lines
(org-table-clean-before-export lines
)))
967 ;; make a formatting string to reflect aligment
969 (while (and (not line-fmt
) (setq line
(pop olines
)))
970 (unless (string-match "^[ \t]*|-" line
)
971 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
972 (setq fnum
(make-vector (length fields
) 0))
976 (setq gr
(pop org-table-colgroup-info
))
978 (cond ((eq gr
':start
)
979 (prog1 (if colgropen
"|" "")
982 (prog1 (if colgropen
"|" "|")
983 (setq colgropen nil
)))
985 (if (memq gr
'(:end
:startend
))
986 (progn (setq colgropen nil
) "|")
989 ;; fix double || in line-fmt
990 (setq line-fmt
(replace-regexp-in-string "||" "|" line-fmt
))
991 ;; maybe remove the first and last "|"
992 (when (and (not org-export-latex-tables-column-borders
)
993 (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt
))
994 (setq line-fmt
(match-string 2 line-fmt
)))
996 (setq align
(apply 'format
998 (mapcar (lambda (x) (if x
"r" "l"))
999 org-table-last-alignment
))))
1000 ;; prepare the table to send to orgtbl-to-latex
1004 (or (and (string-match "[ \t]*|-+" elem
) 'hline
)
1005 (split-string (org-trim elem
) "|" t
)))
1008 (insert (orgtbl-to-latex
1009 lines
`(:tstart
,(concat "\\begin{tabular}{" align
"}")))
1012 (defun org-export-latex-fontify ()
1013 "Convert fontification to LaTeX."
1014 (goto-char (point-min))
1015 (while (re-search-forward org-emph-re nil t
)
1016 ;; The match goes one char after the *string*
1017 (let ((emph (assoc (match-string 3)
1018 org-export-latex-emphasis-alist
))
1020 (unless (get-text-property (1- (point)) 'org-protected
)
1021 (setq rpl
(concat (match-string 1)
1022 (format (org-export-latex-protect-char-in-string
1023 '("\\" "{" "}") (cadr emph
))
1027 (setq rpl
(org-export-latex-protect-string rpl
)))
1028 (replace-match rpl t t
)))
1031 (defun org-export-latex-links ()
1032 ;; Make sure to use the LaTeX hyperref and graphicx package
1033 ;; or send some warnings.
1034 "Convert links to LaTeX."
1035 (goto-char (point-min))
1036 (while (re-search-forward org-bracket-link-analytic-regexp nil t
)
1038 (goto-char (match-beginning 0))
1039 (let* ((re-radio org-export-latex-all-targets-re
)
1040 (remove (list (match-beginning 0) (match-end 0)))
1041 (type (match-string 2))
1042 (raw-path (match-string 3))
1043 (full-raw-path (concat (match-string 1) raw-path
))
1044 (desc (match-string 5))
1046 ;; define the path of the link
1048 ((member type
'("http" "https" "ftp"))
1049 (concat type
":" raw-path
))
1050 ((and re-radio
(string-match re-radio raw-path
))
1052 ((equal type
"mailto")
1053 (concat type
":" raw-path
))
1054 ((equal type
"file")
1055 (if (and (or (org-file-image-p (expand-file-name raw-path
))
1056 (string-match "\\.eps$" raw-path
))
1057 (equal desc full-raw-path
))
1059 (progn (when (string-match "\\(.+\\)::.+" raw-path
)
1060 (setq raw-path
(match-string 1 raw-path
)))
1061 (if (file-exists-p raw-path
)
1062 (concat type
"://" (expand-file-name raw-path
))
1063 (concat type
"://" (org-export-directory
1064 :LaTeX org-export-latex-options-plist
)
1066 ;; process with link inserting
1067 (apply 'delete-region remove
)
1068 (cond ((and imgp
(plist-get org-export-latex-options-plist
:inline-images
))
1069 (insert (format "\\includegraphics[%s]{%s}"
1070 ;; image option should be set be a comment line
1071 org-export-latex-image-default-option
1072 (expand-file-name raw-path
))))
1073 (radiop (insert (format "\\hyperref[%s]{%s}" raw-path desc
)))
1074 (path (insert (format "\\href{%s}{%s}" path desc
)))
1075 (t (insert "\\texttt{" desc
"}")))))))
1077 (defvar org-latex-entities
) ; defined below
1079 (defun org-export-latex-cleaned-string ()
1080 "Clean stuff in the LaTeX export."
1082 ;; Preserve line breaks
1083 (goto-char (point-min))
1084 (while (re-search-forward "\\\\\\\\" nil t
)
1085 (add-text-properties (match-beginning 0) (match-end 0)
1086 '(org-protected t
)))
1088 ;; Convert LaTeX to \LaTeX{}
1089 (goto-char (point-min))
1090 (let ((case-fold-search nil
) rpl
)
1091 (while (re-search-forward "\\([^+_]\\)LaTeX" nil t
)
1092 (replace-match (org-export-latex-protect-string
1093 (concat (match-string 1) "\\LaTeX{}")) t t
)))
1095 ;; Convert horizontal rules
1096 (goto-char (point-min))
1097 (while (re-search-forward "^----+.$" nil t
)
1098 (replace-match (org-export-latex-protect-string "\\hrule") t t
))
1100 ;; Protect LaTeX commands like \commad[...]{...} or \command{...}
1101 (goto-char (point-min))
1102 (while (re-search-forward "\\\\[a-zA-Z]+\\(?:\\[.*\\]\\)?{.*}" nil t
)
1103 (add-text-properties (match-beginning 0) (match-end 0)
1104 '(org-protected t
)))
1106 ;; Protect LaTeX entities
1107 (goto-char (point-min))
1108 (while (re-search-forward (regexp-opt org-latex-entities
) nil t
)
1109 (add-text-properties (match-beginning 0) (match-end 0)
1110 '(org-protected t
)))
1112 ;; Replace radio links
1113 (goto-char (point-min))
1114 (while (re-search-forward
1115 (concat "<<<?" org-export-latex-all-targets-re
1116 ">>>?\\((INVISIBLE)\\)?") nil t
)
1118 (org-export-latex-protect-string
1119 (format "\\label{%s}%s"(match-string 1)
1120 (if (match-string 2) "" (match-string 1)))) t t
))
1122 ;; Delete @<...> constructs
1123 ;; Thanks to Daniel Clemente for this regexp
1124 (goto-char (point-min))
1125 (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t
)
1128 ;; When converting to LaTeX, replace footnotes
1129 ;; FIXME: don't protect footnotes from conversion
1130 (when (plist-get org-export-latex-options-plist
:footnotes
)
1131 (goto-char (point-min))
1132 (while (re-search-forward "\\[[0-9]+\\]" nil t
)
1133 (when (save-match-data
1134 (save-excursion (beginning-of-line)
1135 (looking-at "[^:|#]")))
1136 (let ((foot-beg (match-beginning 0))
1137 (foot-end (match-end 0))
1138 (foot-prefix (match-string 0))
1139 footnote footnote-rpl
)
1141 (when (search-forward foot-prefix nil t
)
1143 (let ((end (save-excursion
1144 (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t
)
1145 (match-beginning 0) (point-max)))))
1146 (setq footnote
(concat (org-trim (buffer-substring (point) end
))
1147 " ")) ; prevent last } being part of a link
1148 (delete-region (point) end
))
1149 (goto-char foot-beg
)
1150 (delete-region foot-beg foot-end
)
1151 (unless (null footnote
)
1152 (setq footnote-rpl
(format "\\footnote{%s}" footnote
))
1153 (add-text-properties 0 10 '(org-protected t
) footnote-rpl
)
1154 (add-text-properties (1- (length footnote-rpl
))
1155 (length footnote-rpl
)
1156 '(org-protected t
) footnote-rpl
)
1157 (insert footnote-rpl
)))))))
1159 ;; Replace footnote section tag for LaTeX
1160 (goto-char (point-min))
1161 (while (re-search-forward
1162 (concat "^" footnote-section-tag-regexp
) nil t
)
1163 (replace-match ""))))
1167 (defun org-export-latex-lists ()
1168 "Replace plain text lists in current buffer into LaTeX lists."
1169 "Convert lists to LaTeX."
1170 (goto-char (point-min))
1171 (while (re-search-forward org-export-latex-list-beginning-re nil t
)
1173 (insert (org-list-to-latex (org-list-parse-list t
)) "\n")))
1175 (defun org-list-parse-list (&optional delete
)
1176 "Parse the list at point.
1177 Return a list containing first level items as strings and
1178 sublevels as a list of strings."
1179 (let ((start (org-list-item-begin))
1180 (end (org-list-end))
1182 (while (re-search-forward org-export-latex-list-beginning-re end t
)
1183 (setq itemsep
(if (save-match-data
1184 (string-match "^[0-9]" (match-string 2)))
1185 "[0-9]+\\(?:\\.\\|)\\)" "[-+]"))
1186 (let* ((indent1 (match-string 1))
1187 (nextitem (save-excursion
1189 (or (and (re-search-forward
1190 (concat "^" indent1 itemsep
" *?") end t
)
1191 (match-beginning 0)) end
))))
1192 (item (buffer-substring
1194 (or (and (re-search-forward
1195 org-export-latex-list-beginning-re end t
)
1196 (goto-char (match-beginning 0)))
1198 (nextindent (match-string 1))
1199 (item (org-trim item
))
1200 (item (if (string-match "^\\[.+\\]" item
)
1201 (replace-match "\\\\texttt{\\&}"
1204 (when (> (length nextindent
)
1206 (narrow-to-region (point) nextitem
)
1207 (push (org-list-parse-list) output
)
1209 (when delete
(delete-region start end
))
1210 (setq output
(nreverse output
))
1211 (push (if (string-match "^\\[0" itemsep
)
1212 'ordered
'unordered
) output
)))
1214 (defun org-list-item-begin ()
1215 "Find the beginning of the list item and return its position."
1217 (if (not (or (looking-at org-export-latex-list-beginning-re
)
1219 org-export-latex-list-beginning-re nil t
)))
1220 (progn (goto-char (point-min)) (point))
1221 (match-beginning 0))))
1223 (defun org-list-end ()
1224 "Find the end of the list and return its position."
1227 (while (or (looking-at org-export-latex-list-beginning-re
)
1228 (looking-at "^[ \t]+\\|^$"))
1229 (if (eq (point) (point-max))
1230 (throw 'exit
(point-max)))
1231 (forward-line 1))) (point)))
1233 (defun org-list-insert-radio-list ()
1234 "Insert a radio list template appropriate for this major mode."
1236 (let* ((e (assq major-mode org-list-radio-list-templates
))
1239 (unless e
(error "No radio list setup defined for %s" major-mode
))
1240 (setq name
(read-string "List name: "))
1241 (while (string-match "%n" txt
)
1242 (setq txt
(replace-match name t t txt
)))
1243 (or (bolp) (insert "\n"))
1248 (defun org-list-send-list (&optional maybe
)
1249 "Send a tranformed version of this list to the receiver position.
1250 With argument MAYBE, fail quietly if no transformation is defined for
1254 (unless (org-at-item-p) (error "Not at a list"))
1256 (goto-char (org-list-item-begin))
1257 (beginning-of-line 0)
1258 (unless (looking-at "#\\+ORGLST: *SEND +\\([a-zA-Z0-9_]+\\) +\\([^ \t\r\n]+\\)\\( +.*\\)?")
1261 (error "Don't know how to transform this list"))))
1262 (let* ((name (match-string 1))
1264 (transform (intern (match-string 2)))
1265 (txt (buffer-substring-no-properties
1266 (org-list-item-begin)
1268 (list (org-list-parse-list)))
1269 (unless (fboundp transform
)
1270 (error "No such transformation function %s" transform
))
1271 (setq txt
(funcall transform list
))
1272 ;; Find the insertion place
1274 (goto-char (point-min))
1275 (unless (re-search-forward
1276 (concat "BEGIN RECEIVE ORGLST +" name
"\\([ \t]\\|$\\)") nil t
)
1277 (error "Don't know where to insert translated list"))
1278 (goto-char (match-beginning 0))
1279 (beginning-of-line 2)
1281 (unless (re-search-forward (concat "END RECEIVE ORGLST +" name
) nil t
)
1282 (error "Cannot find end of insertion region"))
1283 (beginning-of-line 1)
1284 (delete-region beg
(point))
1287 (message "List converted and installed at receiver location"))))
1289 (defun org-list-to-generic (list params
)
1290 "Convert a LIST parsed through `org-list-parse-list' to other formats.
1292 Valid parameters are
1294 :ustart String to start an unordered list
1295 :uend String to end an unordered list
1297 :ostart String to start an ordered list
1298 :oend String to end an ordered list
1300 :splice When set to t, return only list body lines, don't wrap
1301 them into :[u/o]start and :[u/o]end. Default is nil.
1303 :istart String to start a list item
1304 :iend String to end a list item
1305 :isep String to separate items
1306 :lsep String to separate sublists"
1308 (let* ((p params
) sublist
1309 (splicep (plist-get p
:splice
))
1310 (ostart (plist-get p
:ostart
))
1311 (oend (plist-get p
:oend
))
1312 (ustart (plist-get p
:ustart
))
1313 (uend (plist-get p
:uend
))
1314 (istart (plist-get p
:istart
))
1315 (iend (plist-get p
:iend
))
1316 (isep (plist-get p
:isep
))
1317 (lsep (plist-get p
:lsep
)))
1319 (cond ((eq (car list
) 'ordered
)
1320 (concat ostart
"\n%s" oend
"\n"))
1321 ((eq (car list
) 'unordered
)
1322 (concat ustart
"\n%s" uend
"\n"))))
1324 (while (setq sublist
(pop list
))
1325 (cond ((symbolp sublist
) nil
)
1327 (setq rtn
(concat rtn istart sublist iend isep
)))
1329 (setq rtn
(concat rtn
;; previous list
1330 lsep
;; list separator
1331 (org-list-to-generic sublist p
)
1332 lsep
;; list separator
1334 (format wrapper rtn
))))
1336 (defun org-list-to-latex (list)
1337 "Convert LIST into a LaTeX list."
1338 (org-list-to-generic
1339 list
'(:splicep nil
:ostart
"\\begin{enumerate}" :oend
"\\end{enumerate}"
1340 :ustart
"\\begin{itemize}" :uend
"\\end{itemize}"
1341 :istart
"\\item " :iend
""
1342 :isep
"\n" :lsep
"\n")))
1344 (defun org-list-to-html (list)
1345 "Convert LIST into a HTML list."
1346 (org-list-to-generic
1347 list
'(:splicep nil
:ostart
"<ol>" :oend
"</ol>"
1348 :ustart
"<ul>" :uend
"</ul>"
1349 :istart
"<li>" :iend
"</li>"
1350 :isep
"\n" :lsep
"\n")))
1352 (defun org-list-to-texinfo (list)
1353 "Convert LIST into a Texinfo list."
1354 (org-list-to-generic
1355 list
'(:splicep nil
:ostart
"@itemize @minus" :oend
"@end itemize"
1356 :ustart
"@enumerate" :uend
"@end enumerate"
1357 :istart
"@item\n" :iend
""
1358 :isep
"\n" :lsep
"\n")))
1360 (defconst org-latex-entities
1389 "\\begin{description}"
1390 "\\begin{enumerate}"
1394 "\\begin{flushleft}"
1395 "\\begin{flushright}"
1400 "\\begin{quotation}"
1405 "\\begin{thebibliography}"
1407 "\\begin{titlepage}"
1534 "A list of LaTeX commands to be protected when performing conversion.")
1536 (provide 'org-export-latex
)
1538 ;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad
1539 ;;; org-export-latex.el ends here