Browse Source

LaTeX export: Automatically choose \verb delimiter

Carsten Dominik 16 years ago
parent
commit
8461b96e79
2 changed files with 27 additions and 5 deletions
  1. 5 0
      lisp/ChangeLog
  2. 22 5
      lisp/org-export-latex.el

+ 5 - 0
lisp/ChangeLog

@@ -1,5 +1,10 @@
 2009-03-14  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-03-14  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
+	* org-export-latex.el (org-export-latex-emphasis-alist): Better
+	defaults for verbose emphasis.
+	(org-export-latex-emph-format): New function.
+	(org-export-latex-fontify): Call `org-export-latex-emph-format'.
+
 	* org-agenda.el (org-agenda-menu): Add new commands to menu.
 	* org-agenda.el (org-agenda-menu): Add new commands to menu.
 	(org-agenda-do-date-later, org-agenda-do-date-earlier)
 	(org-agenda-do-date-later, org-agenda-do-date-earlier)
 	(org-agenda-date-later-minutes, org-agenda-date-earlier-minutes)
 	(org-agenda-date-later-minutes, org-agenda-date-earlier-minutes)

+ 22 - 5
lisp/org-export-latex.el

@@ -165,12 +165,14 @@ to represent the section title."
     ("/" "\\emph{%s}" nil)
     ("/" "\\emph{%s}" nil)
     ("_" "\\underline{%s}" nil)
     ("_" "\\underline{%s}" nil)
     ("+" "\\texttt{%s}" nil)
     ("+" "\\texttt{%s}" nil)
-    ("=" "\\verb=%s=" nil)
-    ("~" "\\verb~%s~" t))
+    ("=" "\\verb" t)
+    ("~" "\\verb" t))
   "Alist of LaTeX expressions to convert emphasis fontifiers.
   "Alist of LaTeX expressions to convert emphasis fontifiers.
 Each element of the list is a list of three elements.
 Each element of the list is a list of three elements.
 The first element is the character used as a marker for fontification.
 The first element is the character used as a marker for fontification.
 The second element is a formatting string to wrap fontified text with.
 The second element is a formatting string to wrap fontified text with.
+If it is \"\\verb\", Org will automatically select a deimiter
+character that is not in the string.
 The third element decides whether to protect converted text from other
 The third element decides whether to protect converted text from other
 conversions."
 conversions."
   :group 'org-export-latex
   :group 'org-export-latex
@@ -1203,15 +1205,30 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 			   (string-match
 			   (string-match
 			    "[|\n]" (buffer-substring beg end))))))
 			    "[|\n]" (buffer-substring beg end))))))
 	(setq rpl (concat (match-string 1)
 	(setq rpl (concat (match-string 1)
-			  (format (org-export-latex-protect-char-in-string
-				   '("\\" "{" "}") (cadr emph))
-				  (match-string 4))
+			  (org-export-latex-emph-format (cadr emph)
+							(match-string 4))
 			  (match-string 5)))
 			  (match-string 5)))
 	(if (caddr emph)
 	(if (caddr emph)
 	    (setq rpl (org-export-latex-protect-string rpl)))
 	    (setq rpl (org-export-latex-protect-string rpl)))
 	(replace-match rpl t t)))
 	(replace-match rpl t t)))
     (backward-char)))
     (backward-char)))
 
 
+(defun org-export-latex-emph-format (format string)
+  "Format an emphasis string and handle the \\verb special case."
+  (when (equal format "\\verb")
+    (save-match-data
+      (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
+	(catch 'exit
+	  (loop for i from 0 to (1- (length ll)) do
+		(if (not (string-match (regexp-quote (substring ll i (1+ i)))
+				       string))
+		    (progn
+		      (setq format (concat "\\verb" (substring ll i (1+ i))
+					   "%s" (substring ll i (1+ i))))
+		      (throw 'exit nil))))))))
+  (setq string (org-export-latex-protect-string
+		(format format string))))
+
 (defun org-export-latex-links ()
 (defun org-export-latex-links ()
   ;; Make sure to use the LaTeX hyperref and graphicx package
   ;; Make sure to use the LaTeX hyperref and graphicx package
   ;; or send some warnings.
   ;; or send some warnings.