Implement export of descriptive lists.

Prevent special chars from being converted when in a LaTeX
environment.  Fix a bug about conversion of "&" conversion
in tables.
This commit is contained in:
Bastien Guerry 2008-09-19 21:48:47 +02:00
parent b777e88fd6
commit 57d80846b3
1 changed files with 61 additions and 19 deletions

View File

@ -61,7 +61,7 @@
(defvar org-export-latex-sectioning "") (defvar org-export-latex-sectioning "")
(defvar org-export-latex-sectioning-depth 0) (defvar org-export-latex-sectioning-depth 0)
(defvar org-export-latex-list-beginning-re (defvar org-export-latex-list-beginning-re
"^\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) +?") "^\\([ \t]*\\)\\([-+*]\\|[0-9]+[.)]\\) +\\(.*\\)$")
(defvar org-export-latex-special-string-regexps (defvar org-export-latex-special-string-regexps
'(org-ts-regexp '(org-ts-regexp
@ -988,7 +988,7 @@ Regexps are those from `org-export-latex-special-string-regexps'."
(let* ((tbl (concat "\\begin{verbatim}\n" raw-table (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
"\\end{verbatim}\n"))) "\\end{verbatim}\n")))
(apply 'delete-region (list beg end)) (apply 'delete-region (list beg end))
(insert tbl)) (insert (org-export-latex-protect-string tbl)))
(progn (progn
(setq lines (split-string raw-table "\n" t)) (setq lines (split-string raw-table "\n" t))
(apply 'delete-region (list beg end)) (apply 'delete-region (list beg end))
@ -1035,8 +1035,9 @@ Regexps are those from `org-export-latex-special-string-regexps'."
(split-string (org-trim elem) "|" t))) (split-string (org-trim elem) "|" t)))
lines)) lines))
(when insert (when insert
(insert (orgtbl-to-latex (insert (org-export-latex-protect-string
lines `(:tstart ,(concat "\\begin{tabular}{" align "}"))) (orgtbl-to-latex
lines `(:tstart ,(concat "\\begin{tabular}{" align "}"))))
"\n\n"))))))) "\n\n")))))))
(defun org-export-latex-fontify () (defun org-export-latex-fontify ()
@ -1115,6 +1116,15 @@ Regexps are those from `org-export-latex-special-string-regexps'."
(add-text-properties (match-beginning 0) (match-end 0) (add-text-properties (match-beginning 0) (match-end 0)
'(org-protected t))) '(org-protected t)))
;; Preserve latex environments
(goto-char (point-min))
(while (search-forward "\\begin{" nil t)
(let ((start (progn (beginning-of-line) (point)))
(end (or (and (search-forward "\\end{" nil t)
(end-of-line) (point))
(point-max))))
(add-text-properties start end '(org-protected t))))
;; Convert LaTeX to \LaTeX{} ;; Convert LaTeX to \LaTeX{}
(goto-char (point-min)) (goto-char (point-min))
(let ((case-fold-search nil) rpl) (let ((case-fold-search nil) rpl)
@ -1224,11 +1234,16 @@ Return a list containing first level items as strings and
sublevels as a list of strings." sublevels as a list of strings."
(let ((start (org-list-item-begin)) (let ((start (org-list-item-begin))
(end (org-list-end)) (end (org-list-end))
output itemsep) output itemsep ltype)
(while (re-search-forward org-export-latex-list-beginning-re end t) (while (re-search-forward org-export-latex-list-beginning-re end t)
(setq itemsep (if (save-match-data (goto-char (match-beginning 3))
(string-match "^[0-9]" (match-string 2))) (save-match-data
"[0-9]+\\(?:\\.\\|)\\)" "[-+]")) (cond ((string-match "[0-9]" (match-string 2))
(setq itemsep "[0-9]+\\(?:\\.\\|)\\)"
ltype 'ordered))
((string-match "^.*::" (match-string 0))
(setq itemsep "[-+]" ltype 'descriptive))
(t (setq itemsep "[-+]" ltype 'unordered))))
(let* ((indent1 (match-string 1)) (let* ((indent1 (match-string 1))
(nextitem (save-excursion (nextitem (save-excursion
(save-match-data (save-match-data
@ -1254,8 +1269,7 @@ sublevels as a list of strings."
(widen)))) (widen))))
(when delete (delete-region start end)) (when delete (delete-region start end))
(setq output (nreverse output)) (setq output (nreverse output))
(push (if (string-match "^\\[0" itemsep) (push ltype output)))
'ordered 'unordered) output)))
(defun org-list-item-begin () (defun org-list-item-begin ()
"Find the beginning of the list item and return its position." "Find the beginning of the list item and return its position."
@ -1343,6 +1357,13 @@ Valid parameters are
:ostart String to start an ordered list :ostart String to start an ordered list
:oend String to end an ordered list :oend String to end an ordered list
:dstart String to start a descriptive list
:dend String to end a descriptive list
:dtstart String to start a descriptive term
:dtend String to end a descriptive term
:ddstart String to start a description
:ddend String to end a description
:splice When set to t, return only list body lines, don't wrap :splice When set to t, return only list body lines, don't wrap
them into :[u/o]start and :[u/o]end. Default is nil. them into :[u/o]start and :[u/o]end. Default is nil.
@ -1357,6 +1378,12 @@ Valid parameters are
(oend (plist-get p :oend)) (oend (plist-get p :oend))
(ustart (plist-get p :ustart)) (ustart (plist-get p :ustart))
(uend (plist-get p :uend)) (uend (plist-get p :uend))
(dstart (plist-get p :dstart))
(dend (plist-get p :dend))
(dtstart (plist-get p :dtstart))
(dtend (plist-get p :dtend))
(ddstart (plist-get p :ddstart))
(ddend (plist-get p :ddend))
(istart (plist-get p :istart)) (istart (plist-get p :istart))
(iend (plist-get p :iend)) (iend (plist-get p :iend))
(isep (plist-get p :isep)) (isep (plist-get p :isep))
@ -1365,18 +1392,24 @@ Valid parameters are
(cond ((eq (car list) 'ordered) (cond ((eq (car list) 'ordered)
(concat ostart "\n%s" oend "\n")) (concat ostart "\n%s" oend "\n"))
((eq (car list) 'unordered) ((eq (car list) 'unordered)
(concat ustart "\n%s" uend "\n")))) (concat ustart "\n%s" uend "\n"))
rtn) ((eq (car list) 'descriptive)
(concat dstart "\n%s" dend "\n"))))
rtn term defstart defend)
(while (setq sublist (pop list)) (while (setq sublist (pop list))
(cond ((symbolp sublist) nil) (cond ((symbolp sublist) nil)
((stringp sublist) ((stringp sublist)
(setq rtn (concat rtn istart sublist iend isep))) (when (string-match "^\\(.*\\) ::" sublist)
(t (setq term (org-trim (format (concat dtstart "%s" dtend)
(setq rtn (concat rtn ;; previous list (match-string 1 sublist))))
lsep ;; list separator (setq sublist (substring sublist (1+ (length term)))))
(org-list-to-generic sublist p) (setq rtn (concat rtn istart term ddstart
lsep ;; list separator sublist ddend iend isep)))
))))) (t (setq rtn (concat rtn ;; previous list
lsep ;; list separator
(org-list-to-generic sublist p)
lsep ;; list separator
)))))
(format wrapper rtn)))) (format wrapper rtn))))
(defun org-list-to-latex (list) (defun org-list-to-latex (list)
@ -1384,6 +1417,9 @@ Valid parameters are
(org-list-to-generic (org-list-to-generic
list '(:splicep nil :ostart "\\begin{enumerate}" :oend "\\end{enumerate}" list '(:splicep nil :ostart "\\begin{enumerate}" :oend "\\end{enumerate}"
:ustart "\\begin{itemize}" :uend "\\end{itemize}" :ustart "\\begin{itemize}" :uend "\\end{itemize}"
:dstart "\\begin{description}" :dend "\\end{description}"
:dtstart "[" :dtend "]"
:ddstart "" :ddend ""
:istart "\\item " :iend "" :istart "\\item " :iend ""
:isep "\n" :lsep "\n"))) :isep "\n" :lsep "\n")))
@ -1392,6 +1428,9 @@ Valid parameters are
(org-list-to-generic (org-list-to-generic
list '(:splicep nil :ostart "<ol>" :oend "</ol>" list '(:splicep nil :ostart "<ol>" :oend "</ol>"
:ustart "<ul>" :uend "</ul>" :ustart "<ul>" :uend "</ul>"
:dstart "<dl>" :dend "</dl>"
:dtstart "<dt>" :dtend "</dt>"
:ddstart "<dd>" :ddend "</dd>"
:istart "<li>" :iend "</li>" :istart "<li>" :iend "</li>"
:isep "\n" :lsep "\n"))) :isep "\n" :lsep "\n")))
@ -1400,6 +1439,9 @@ Valid parameters are
(org-list-to-generic (org-list-to-generic
list '(:splicep nil :ostart "@itemize @minus" :oend "@end itemize" list '(:splicep nil :ostart "@itemize @minus" :oend "@end itemize"
:ustart "@enumerate" :uend "@end enumerate" :ustart "@enumerate" :uend "@end enumerate"
:dstart "@table" :dend "@end table"
:dtstart "@item " :dtend "\n"
:ddstart "" :ddend ""
:istart "@item\n" :iend "" :istart "@item\n" :iend ""
:isep "\n" :lsep "\n"))) :isep "\n" :lsep "\n")))