Browse Source

LaTeX export: Fix problems with use of \verb in headlines

See http://article.gmane.org/gmane.emacs.orgmode/14257
Carsten Dominik 16 years ago
parent
commit
d27d3e5fa6
2 changed files with 33 additions and 9 deletions
  1. 6 0
      lisp/ChangeLog
  2. 27 9
      lisp/org-latex.el

+ 6 - 0
lisp/ChangeLog

@@ -1,3 +1,9 @@
+2009-06-09  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org-latex.el (org-export-latex-use-verb): New variable.
+	(org-export-latex-emph-format): Prefer \texttt over \verb when
+	org-export-latex-use-verb is set.
+
 2009-06-08  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-06-08  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
 	* org-docbook.el (org-export-docbook-close-lists-maybe): Also look
 	* org-docbook.el (org-export-docbook-close-lists-maybe): Also look

+ 27 - 9
lisp/org-latex.el

@@ -1367,19 +1367,37 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 	(replace-match rpl t t)))
 	(replace-match rpl t t)))
     (backward-char)))
     (backward-char)))
 
 
+(defvar org-export-latex-use-verb nil)
 (defun org-export-latex-emph-format (format string)
 (defun org-export-latex-emph-format (format string)
   "Format an emphasis string and handle the \\verb special case."
   "Format an emphasis string and handle the \\verb special case."
   (when (equal format "\\verb")
   (when (equal format "\\verb")
     (save-match-data
     (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))))))))
+      (if org-export-latex-use-verb
+	  (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))))))
+	(let ((start 0)
+	      (trans '(("\\" . "\\backslash")
+		       ("~" . "\\ensuremath{\\sim}")
+		       ("^" . "\\ensuremath{\\wedge}")
+		       ("<" . "\\ensuremath{<}")
+		       (">" . "\\ensuremath{>}")))
+	      (rtn ""))
+	  (while (string-match "[\\{}$%&_#~^<>]" string)
+	    (setq char (match-string 0 string))
+	    (if (> (match-beginning 0) 0)
+		(setq rtn (concat rtn (substring string
+						 0 (match-beginning 0)))))
+	    (setq string (substring string (1+ (match-beginning 0))))
+	    (setq char (or (cdr (assoc char trans)) (concat "\\" char))
+		  rtn (concat rtn char)))
+	  (setq string (concat rtn string) format "\\texttt{%s}")))))
   (setq string (org-export-latex-protect-string
   (setq string (org-export-latex-protect-string
 		(format format string))))
 		(format format string))))