org-export: Handle "\-" as a special string

* contrib/lisp/org-export.el (org-export-with-special-strings): Fix
  docstring.
* contrib/lisp/org-e-ascii.el (org-e-ascii-plain-text): Remove soft
  hyphens.
* contrib/lisp/org-e-latex.el (org-e-latex-plain-text): Handle soft
  hyphens.
This commit is contained in:
Nicolas Goaziou 2012-08-27 14:17:27 +02:00
parent 4d789f4c30
commit 86b1be57b9
3 changed files with 46 additions and 43 deletions

View File

@ -1361,15 +1361,15 @@ contextual information."
(defun org-e-ascii-plain-text (text info)
"Transcode a TEXT string from Org to ASCII.
INFO is a plist used as a communication channel."
(if (not (and (eq (plist-get info :ascii-charset) 'utf-8)
(plist-get info :with-special-strings)))
text
;; Usual replacements in utf-8 with proper option set.
(replace-regexp-in-string
"\\.\\.\\." ""
(replace-regexp-in-string
"--" ""
(replace-regexp-in-string "---" "" text)))))
(if (not (plist-get info :with-special-strings)) text
(setq text (replace-regexp-in-string "\\\\-" "" text))
(if (not (eq (plist-get info :ascii-charset) 'utf-8)) text
;; Usual replacements in utf-8 with proper option set.
(replace-regexp-in-string
"\\.\\.\\." ""
(replace-regexp-in-string
"--" ""
(replace-regexp-in-string "---" "" text))))))
;;;; Planning

View File

@ -1885,33 +1885,36 @@ contextual information."
"Transcode a TEXT string from Org to LaTeX.
TEXT is the string to transcode. INFO is a plist holding
contextual information."
;; Protect %, #, &, $, ~, ^, _, { and }.
(while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
(setq text
(replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
;; Protect \
(setq text (replace-regexp-in-string
"\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
"$\\backslash$" text nil t 1))
;; LaTeX into \LaTeX{} and TeX into \TeX{}.
(let ((case-fold-search nil)
(start 0))
(while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
(setq text (replace-match
(format "\\%s{}" (match-string 1 text)) nil t text)
start (match-end 0))))
;; Handle quotation marks
(setq text (org-e-latex--quotation-marks text info))
;; Convert special strings.
(when (plist-get info :with-special-strings)
(while (string-match (regexp-quote "...") text)
(setq text (replace-match "\\ldots{}" nil t text))))
;; Handle break preservation if required.
(when (plist-get info :preserve-breaks)
(setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
text)))
;; Return value.
text)
(let ((specialp (plist-get info :with-special-strings)))
;; Protect %, #, &, $, ~, ^, _, { and }.
(while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
(setq text
(replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
;; Protect \. If special strings are used, be careful not to
;; protect "\" in "\-" constructs.
(let ((symbols (if specialp "-%$#&{}~^_\\" "%$#&{}~^_\\")))
(setq text
(replace-regexp-in-string
(format "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%s]\\|$\\)" symbols)
"$\\backslash$" text nil t 1)))
;; LaTeX into \LaTeX{} and TeX into \TeX{}.
(let ((case-fold-search nil)
(start 0))
(while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
(setq text (replace-match
(format "\\%s{}" (match-string 1 text)) nil t text)
start (match-end 0))))
;; Handle quotation marks.
(setq text (org-e-latex--quotation-marks text info))
;; Convert special strings.
(when specialp
(setq text (replace-regexp-in-string "\\.\\.\\." "\\ldots{}" text nil t)))
;; Handle break preservation if required.
(when (plist-get info :preserve-breaks)
(setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
text)))
;; Return value.
text))
;;;; Planning

View File

@ -488,16 +488,16 @@ This option can also be set with the #+SELECT_TAGS: keyword."
:type '(repeat (string :tag "Tag")))
(defcustom org-export-with-special-strings t
"Non-nil means interpret \"\-\", \"--\" and \"---\" for export.
"Non-nil means interpret \"\\-\", \"--\" and \"---\" for export.
When this option is turned on, these strings will be exported as:
Org HTML LaTeX
-----+----------+--------
\\- &shy; \\-
-- &ndash; --
--- &mdash; ---
... &hellip; \ldots
Org HTML LaTeX UTF-8
-----+----------+--------+-------
\\- &shy; \\-
-- &ndash; --
--- &mdash; ---
... &hellip; \\ldots
This option can also be set with the #+OPTIONS line,
e.g. \"-:nil\"."