Browse Source

LaTeX export: Protect ampersands in tables

Carsten Dominik 15 năm trước cách đây
mục cha
commit
aedef8c804
2 tập tin đã thay đổi với 20 bổ sung2 xóa
  1. 3 0
      lisp/ChangeLog
  2. 17 2
      lisp/org-latex.el

+ 3 - 0
lisp/ChangeLog

@@ -1,5 +1,8 @@
 2009-08-31  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-latex.el (org-export-latex-protect-amp): New function.
+	(org-export-latex-links): Protect link ampersands in tables.
+
 	* org-exp.el (org-export-select-backend-specific-text): Match in 2
 	steps, to avoid regexp problems.
 

+ 17 - 2
lisp/org-latex.el

@@ -1571,10 +1571,25 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 	     ((not type)
 	      (insert (format "\\hyperref[%s]{%s}"
 			      (org-remove-initial-hash
-			       (org-solidify-link-text raw-path)) desc)))
-	     (path (insert (format "\\href{%s}{%s}" path desc)))
+			       (org-solidify-link-text raw-path))
+			      (org-export-latex-protect-special desc))))
+	     (path 
+	      (when (org-at-table-p)
+		;; There is a strange problem when we have a link in a table,
+		;; ampersands then cause a problem.  I think this must be
+		;; a LaTeX issue, but we here implement a work-around anyway.
+		(setq path (org-export-latex-protect-amp path)
+		      desc (org-export-latex-protect-amp desc)))
+	      (insert (format "\\href{%s}{%s}" path
+			      (org-export-latex-protect-special desc))))
 	     (t (insert "\\texttt{" desc "}")))))))
 
+(defun org-export-latex-protect-amp (s)
+  (while (string-match "\\([^\\\\]\\)\\(&\\)" s)
+    (setq s (replace-match (concat (match-string 1 s) "\\" (match-string 2 s))
+			   t t s)))
+  s)
+
 (defun org-remove-initial-hash (s)
   (if (string-match "\\`#" s)
       (substring s 1)