From d27d3e5fa6ba2de93e9cc9068cc481a22fb9d5ce Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Tue, 9 Jun 2009 06:26:59 +0200 Subject: [PATCH] LaTeX export: Fix problems with use of \verb in headlines See http://article.gmane.org/gmane.emacs.orgmode/14257 --- lisp/ChangeLog | 6 ++++++ lisp/org-latex.el | 36 +++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2cdc5b02e..faffcb36f 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2009-06-09 Carsten Dominik + + * 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 * org-docbook.el (org-export-docbook-close-lists-maybe): Also look diff --git a/lisp/org-latex.el b/lisp/org-latex.el index bdb4479ce..2bffa6dcf 100644 --- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -1367,19 +1367,37 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (replace-match rpl t t))) (backward-char))) +(defvar org-export-latex-use-verb nil) (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)))))))) + (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 (format format string)))) -- 2.11.4.GIT