Переглянути джерело

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.
Nicolas Goaziou 12 роки тому
батько
коміт
86b1be57b9
3 змінених файлів з 46 додано та 43 видалено
  1. 9 9
      contrib/lisp/org-e-ascii.el
  2. 30 27
      contrib/lisp/org-e-latex.el
  3. 7 7
      contrib/lisp/org-export.el

+ 9 - 9
contrib/lisp/org-e-ascii.el

@@ -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

+ 30 - 27
contrib/lisp/org-e-latex.el

@@ -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

+ 7 - 7
contrib/lisp/org-export.el

@@ -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\"."