LaTeX Export: More standardization

This commit removes some of the stuff that was specific for the LaTeX
exporter, and falls back to the default configuration that works for
all backends.

Here is what the commit does:

- The variable `org-export-latex-remove-from-headlines' is now
  obsolete.  Instead, also LaTeX export now responds to the settings
  in the variables org-export-with-todo-keywords',
  `org-export-with-priority', and `org-export-with-tags' and in the
  corresponding OPTION settings.

- Removal of time stamps and related keywords now already happens in
  the preprocessor, so that it will be perfectly the same for all
  backends.

- The list functions have been extended to accept an additional
  parameter list, to overrule the default setting for a particular
  list function.  This is used to make the checkbox appearance in
  LaTeX configurable, through the new variable
  `org-export-latex-list-parameters'.
This commit is contained in:
Carsten Dominik 2009-01-06 17:23:36 +01:00
parent d31eb4cce9
commit 9dc65e4811
4 changed files with 164 additions and 69 deletions

View File

@ -1,5 +1,42 @@
2009-01-06 Carsten Dominik <carsten.dominik@gmail.com>
* org-exp.el (org-html-handle-time-stamps): No longer check for
the `org-export-with-timestamps' option, because the preprocesser
has taken care of this already.
* org.el (org-entry-properties): Catch the case when this is
called in a non-org-mode file.
* org-export-latex.el (org-export-latex-remove-from-headlines):
Variable made obsolete, also LaTeX export now uses the standard
variables.
(org-export-as-latex): Add the timestamps parameter to the
preprocessor parameter list.
(org-export-latex-content): Export the remaining keywords without
considering to remove them.
(org-export-latex-keywords-maybe): Make the REMOVE-LIST optional.
Use bold font instead of tt font for the keywords.
(org-export-latex-fontify-headline): Format headlines, assuming
that all keywords still present should be published.
(org-export-latex-keywords): Remove argument TIMESTAMPS and just
publish what ever remains of the time stamps.
(org-export-latex-list-parameters): New option.
(org-export-latex-lists): Pass additional parameters to the list
converter.
* org-exp.el (org-export-preprocess-string): Remove clock lines
and timestamps already in the preprocesor.
(org-export-remove-timestamps, org-export-remove-clock-lines): New
functions.
(org-export-as-ascii, org-export-as-html): Add the timestamps
parameter to the preprocessor parameter list.
* org-list.el (org-list-parse-list): Parse for checkboxes.
(org-list-to-generic): Introduce and handle new parameters :cbon
and :cboff.
(org-list-to-latex, org-list-to-html, org-list-to-texinfo): Add
optional parameter PARAMS.
* org-export-latex.el (org-export-latex-special-chars): Fix
problems with interpreting dollar signs.
(org-inside-latex-math-p): New function.

View File

@ -1552,6 +1552,11 @@ on this string to produce the exported version."
;; Remove todo-keywords before exporting, if the user has requested so
(org-export-remove-headline-metadata parameters)
;; Remove timestamps, if the user has requested so
(org-export-remove-clock-lines)
(unless (plist-get parameters :timestamps)
(org-export-remove-timestamps))
;; Find targets in comments and move them out of comments,
;; but mark them as targets that should be invisible
(setq target-alist (org-export-handle-invisible-targets target-alist))
@ -1837,6 +1842,22 @@ from the buffer."
elts " "))
(replace-match rpl t t))))))
(defun org-export-remove-timestamps ()
"Remove timestamps and keywords for export."
(while (re-search-forward org-maybe-keyword-time-regexp nil t)
(org-if-unprotected
(replace-match "")
(beginning-of-line 1)
(if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
(replace-match "")))))
(defun org-export-remove-clock-lines ()
"Remove timestamps and keywords for export."
(let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
(while (re-search-forward re nil t)
(org-if-unprotected
(replace-match "")))))
(defun org-export-protect-quoted-subtrees ()
"Mark quoted subtrees with the protection property."
(let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
@ -2524,6 +2545,7 @@ underlined headlines. The default is 3."
:tags (plist-get opt-plist :tags)
:priority (plist-get opt-plist :priority)
:footnotes (plist-get opt-plist :footnotes)
:timestamps (plist-get opt-plist :timestamps)
:todo-keywords (plist-get opt-plist :todo-keywords)
:verbatim-multiline t
:select-tags (plist-get opt-plist :select-tags)
@ -3217,6 +3239,7 @@ PUB-DIR is set, use this as the publishing directory."
:tags (plist-get opt-plist :tags)
:priority (plist-get opt-plist :priority)
:footnotes (plist-get opt-plist :footnotes)
:timestamps (plist-get opt-plist :timestamps)
:archived-trees
(plist-get opt-plist :archived-trees)
:select-tags (plist-get opt-plist :select-tags)
@ -4213,22 +4236,16 @@ But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
(catch 'exit
(let (r b)
(while (string-match org-maybe-keyword-time-regexp s)
(if (and (match-end 1) (equal (match-string 1 s) org-clock-string))
;; never export CLOCK
(throw 'exit ""))
(or b (setq b (substring s 0 (match-beginning 0))))
(if (not org-export-with-timestamps)
(setq r (concat r (substring s 0 (match-beginning 0)))
s (substring s (match-end 0)))
(setq r (concat
r (substring s 0 (match-beginning 0))
(if (match-end 1)
(format "@<span class=\"timestamp-kwd\">%s @</span>"
(match-string 1 s)))
(format " @<span class=\"timestamp\">%s@</span>"
(substring
(org-translate-time (match-string 3 s)) 1 -1)))
s (substring s (match-end 0)))))
(setq r (concat
r (substring s 0 (match-beginning 0))
(if (match-end 1)
(format "@<span class=\"timestamp-kwd\">%s @</span>"
(match-string 1 s)))
(format " @<span class=\"timestamp\">%s@</span>"
(substring
(org-translate-time (match-string 3 s)) 1 -1)))
s (substring s (match-end 0))))
;; Line break if line started and ended with time stamp stuff
(if (not r)
s

View File

@ -221,12 +221,25 @@ inserted headline and is mandatory."
(symbol :tag "Convert as descriptive list" description)
(string :tag "Use a section string" :value "\\subparagraph{%s}")))
(defcustom org-export-latex-list-parameters
'(:cbon "\\texttt{[ ]}" :cboff "\\texttt{[ ]}")
"Parameters for the LaTeX list exporter.
These parameters will be passed on to `org-list-to-latex', which in turn
will pass them (combined with the LaTeX default list parameters) to
`org-list-to-generic'."
:group 'org-export-latex
:type 'plist)
(defcustom org-export-latex-remove-from-headlines
'(:todo t :priority t :tags t)
"A plist of keywords to remove from headlines.
'(:todo nil :priority nil :tags nil)
"A plist of keywords to remove from headlines. OBSOLETE.
Non-nil means remove this keyword type from the headline.
Don't remove the keys, just change their values."
Don't remove the keys, just change their values.
Obsolete, this variable is no longer used. Use the separate
variables `org-export-with-todo-keywords', `org-export-with-priority',
and `org-export-with-tags' instead."
:type 'plist
:group 'org-export-latex)
@ -431,6 +444,7 @@ when PUB-DIR is set, use this as the publishing directory."
:tags (plist-get opt-plist :tags)
:priority (plist-get opt-plist :priority)
:footnotes (plist-get opt-plist :footnotes)
:timestamps (plist-get opt-plist :timestamps)
:todo-keywords (plist-get opt-plist :todo-keywords)
:add-text (if (eq to-buffer 'string) nil text)
:skip-before-1st-heading skip
@ -779,8 +793,7 @@ links, keywords, lists, tables, fixed-width"
(unless (memq 'links exclude-list)
(org-export-latex-links))
(unless (memq 'keywords exclude-list)
(org-export-latex-keywords
(plist-get org-export-latex-options-plist :timestamps)))
(org-export-latex-keywords))
(unless (memq 'lists exclude-list)
(org-export-latex-lists))
(unless (memq 'tables exclude-list)
@ -807,7 +820,7 @@ links, keywords, lists, tables, fixed-width"
(match-end 0) '(org-protected t)))
(buffer-string))))
(defun org-export-latex-keywords-maybe (remove-list)
(defun org-export-latex-keywords-maybe (&optional remove-list)
"Maybe remove keywords depending on rules in REMOVE-LIST."
(goto-char (point-min))
(let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1 "\\|"))
@ -816,12 +829,12 @@ links, keywords, lists, tables, fixed-width"
(when (re-search-forward (concat "^\\(" re-todo "\\)") nil t)
(if (plist-get remove-list :todo)
(replace-match "")
(replace-match (format "\\texttt{%s}" (match-string 1)) t t)))
(replace-match (format "\\textbf{%s}" (match-string 1)) t t)))
;; convert priority string
(when (re-search-forward "\\[\\\\#.\\]" nil t)
(if (plist-get remove-list :priority)
(replace-match "")
(replace-match (format "\\texttt{%s}" (match-string 0)) t t)))
(replace-match (format "\\textbf{%s}" (match-string 0)) t t)))
;; convert tags
(when (re-search-forward "\\(:[a-zA-Z0-9_@]+\\)+:" nil t)
(if (or (not org-export-with-tags)
@ -829,7 +842,7 @@ links, keywords, lists, tables, fixed-width"
(replace-match "")
(replace-match
(org-export-latex-protect-string
(format "\\texttt{%s}"
(format "\\textbf{%s}"
(save-match-data
(replace-regexp-in-string
"_" "\\\\_" (match-string 0)))))
@ -844,8 +857,7 @@ links, keywords, lists, tables, fixed-width"
(goto-char (point-min))
(when (plist-get org-export-latex-options-plist :emphasize)
(org-export-latex-fontify))
(org-export-latex-keywords-maybe
org-export-latex-remove-from-headlines)
(org-export-latex-keywords-maybe)
(org-export-latex-special-chars
(plist-get org-export-latex-options-plist :sub-superscript))
(org-export-latex-links)
@ -999,17 +1011,14 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
(t (org-export-latex-protect-string
(concat string-before "\\textbackslash{}" string-after)))))
(defun org-export-latex-keywords (timestamps)
(defun org-export-latex-keywords ()
"Convert special keywords to LaTeX.
Regexps are those from `org-export-latex-special-string-regexps'.
If TIMESTAMPS, convert timestamps, otherwise delete them."
(let ((rg org-export-latex-special-string-regexps) r)
(while (setq r (pop rg))
(goto-char (point-min))
(while (re-search-forward (eval r) nil t)
(if (not timestamps)
(replace-match (format "\\\\texttt{%s}" (match-string 0)) t)
(replace-match ""))))))
(goto-char (point-min))
(let ((re (concat org-maybe-keyword-time-regexp ".*")))
(while (re-search-forward re nil t)
(replace-match (format "\\\\texttt{%s}" (match-string 0)) t))))
(defun org-export-latex-fixed-width (opt)
"When OPT is non-nil convert fixed-width sections to LaTeX."
@ -1366,13 +1375,14 @@ If TIMESTAMPS, convert timestamps, otherwise delete them."
;;; List handling:
(defun org-export-latex-lists ()
"Replace plain text lists in current buffer into LaTeX lists."
"Convert lists to LaTeX."
"Convert plain text lists in current buffer into LaTeX lists."
(goto-char (point-min))
(while (re-search-forward org-list-beginning-re nil t)
(org-if-unprotected
(beginning-of-line)
(insert (org-list-to-latex (org-list-parse-list t)) "\n"))))
(insert (org-list-to-latex (org-list-parse-list t)
org-export-latex-list-parameters))
"\n")))
(defconst org-latex-entities
'("\\!"

View File

@ -46,6 +46,7 @@
(declare-function org-trim "org" (s))
(declare-function org-get-indentation "org" (&optional line))
(declare-function org-timer-item "org-timer" (&optional arg))
(declare-function org-combine-plists "org" (&rest plists))
(defgroup org-plain-lists nil
"Options concerning plain lists in Org-mode."
@ -894,9 +895,12 @@ sublevels as a list of strings."
(goto-char end))))
(nextindent (match-string 1))
(item (org-trim item))
(item (if (string-match "^\\[.+\\]" item)
(replace-match "\\\\texttt{\\&}"
t nil item) item)))
(item (if (string-match "^\\[\\([xX ]\\)\\]" item)
(replace-match (if (equal (match-string 1 item) " ")
"[CBOFF]"
"[CBON]")
t nil item)
item)))
(push item output)
(when (> (length nextindent)
(length indent1))
@ -1010,7 +1014,10 @@ Valid parameters PARAMS are
:istart String to start a list item
:iend String to end a list item
:isep String to separate items
:lsep String to separate sublists"
:lsep String to separate sublists
:cboff String to insert for an unchecked checkbox
:cbon String to insert for a checked checkbox"
(interactive)
(let* ((p params) sublist
(splicep (plist-get p :splice))
@ -1027,7 +1034,9 @@ Valid parameters PARAMS are
(istart (plist-get p :istart))
(iend (plist-get p :iend))
(isep (plist-get p :isep))
(lsep (plist-get p :lsep)))
(lsep (plist-get p :lsep))
(cbon (plist-get p :cbon))
(cboff (plist-get p :cboff)))
(let ((wrapper
(cond ((eq (car list) 'ordered)
(concat ostart "\n%s" oend "\n"))
@ -1043,6 +1052,10 @@ Valid parameters PARAMS are
(setq term (org-trim (format (concat dtstart "%s" dtend)
(match-string 1 sublist))))
(setq sublist (substring sublist (1+ (length term)))))
(if (string-match "\\[CBON\\]" sublist)
(setq sublist (replace-match cbon t t sublist)))
(if (string-match "\\[CBOFF\\]" sublist)
(setq sublist (replace-match cboff t t sublist)))
(setq rtn (concat rtn istart term ddstart
sublist ddend iend isep)))
(t (setq rtn (concat rtn ;; previous list
@ -1052,38 +1065,56 @@ Valid parameters PARAMS are
)))))
(format wrapper rtn))))
(defun org-list-to-latex (list)
"Convert LIST into a LaTeX list."
(defun org-list-to-latex (list &optional params)
"Convert LIST into a LaTeX list.
LIST is as returnd by `org-list-parse-list'. PARAMS is a property list
with overruling parameters for `org-list-to-generic'."
(org-list-to-generic
list '(:splicep nil :ostart "\\begin{enumerate}" :oend "\\end{enumerate}"
:ustart "\\begin{itemize}" :uend "\\end{itemize}"
:dstart "\\begin{description}" :dend "\\end{description}"
:dtstart "[" :dtend "]"
:ddstart "" :ddend ""
:istart "\\item " :iend ""
:isep "\n" :lsep "\n")))
list
(org-combine-plists
'(:splicep nil :ostart "\\begin{enumerate}" :oend "\\end{enumerate}"
:ustart "\\begin{itemize}" :uend "\\end{itemize}"
:dstart "\\begin{description}" :dend "\\end{description}"
:dtstart "[" :dtend "]"
:ddstart "" :ddend ""
:istart "\\item " :iend ""
:isep "\n" :lsep "\n"
:cbon "\\texttt{[X]}" :cboff "\\texttt{[ ]}")
params)))
(defun org-list-to-html (list)
"Convert LIST into a HTML list."
(defun org-list-to-html (list &optional params)
"Convert LIST into a HTML list.
LIST is as returnd by `org-list-parse-list'. PARAMS is a property list
with overruling parameters for `org-list-to-generic'."
(org-list-to-generic
list '(:splicep nil :ostart "<ol>" :oend "</ol>"
:ustart "<ul>" :uend "</ul>"
:dstart "<dl>" :dend "</dl>"
:dtstart "<dt>" :dtend "</dt>"
:ddstart "<dd>" :ddend "</dd>"
:istart "<li>" :iend "</li>"
:isep "\n" :lsep "\n")))
list
(org-combine-plists
'(:splicep nil :ostart "<ol>" :oend "</ol>"
:ustart "<ul>" :uend "</ul>"
:dstart "<dl>" :dend "</dl>"
:dtstart "<dt>" :dtend "</dt>"
:ddstart "<dd>" :ddend "</dd>"
:istart "<li>" :iend "</li>"
:isep "\n" :lsep "\n"
:cbon "<code>[X]</code>" :cboff "<code>[ ]</code>")
params)))
(defun org-list-to-texinfo (list)
"Convert LIST into a Texinfo list."
(defun org-list-to-texinfo (list &optional params)
"Convert LIST into a Texinfo list.
LIST is as returnd by `org-list-parse-list'. PARAMS is a property list
with overruling parameters for `org-list-to-generic'."
(org-list-to-generic
list '(:splicep nil :ostart "@itemize @minus" :oend "@end itemize"
:ustart "@enumerate" :uend "@end enumerate"
:dstart "@table" :dend "@end table"
:dtstart "@item " :dtend "\n"
:ddstart "" :ddend ""
:istart "@item\n" :iend ""
:isep "\n" :lsep "\n")))
list
(org-combine-plists
'(:splicep nil :ostart "@itemize @minus" :oend "@end itemize"
:ustart "@enumerate" :uend "@end enumerate"
:dstart "@table" :dend "@end table"
:dtstart "@item " :dtend "\n"
:ddstart "" :ddend ""
:istart "@item\n" :iend ""
:isep "\n" :lsep "\n"
:cbon "@code{[X]}" :cboff "@code{[ ]}")
params)))
(provide 'org-list)