Nicolas Goaziou <m...@nicolasgoaziou.fr> writes:

>> Yeah, I though of that, but that require us to maintain a list of latex
>> math environments, which may or may not be annoying.
>
> Well, if an environment is not recognized as a math one, it still gets
> a label. So, that's not a big deal to miss some of them.
>
>> If we add such a variable where should it live? org.el or ox-latex.el?
>
> ox-latex.el. This is a hack. There's no need to leak it elsewhere.

Here's an updated patch.

—Rasmus

-- 
Need more coffee. . .
>From 5442c61a0ab793d0a0cb3507d4355a5d1fb2f623 Mon Sep 17 00:00:00 2001
From: Rasmus <ras...@gmx.us>
Date: Mon, 20 Apr 2015 15:06:55 +0200
Subject: [PATCH] ox-latex: Use standard LaTeX label prefixes

* ox-latex.el (org-latex--label): Use standard LaTeX prefixes.
  (org-latex-math-environments-re): New defconst.
---
 lisp/ox-latex.el | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 2727f1c..2d7ffe5 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -209,6 +209,17 @@
 					  ("kbordermatrix" . "\\\\"))
   "Alist between matrix macros and their row ending.")
 
+(defconst org-latex-math-environments-re
+  (concat (regexp-opt
+	   '("equation" "eqnarray" "math" "displaymath"
+	     "align"  "gather" "multline" "flalign"  "alignat"
+	     "xalignat" "xxalignat"
+	     "subequations"
+	     ;; breqn
+	     "dmath" "dseries" "dgroup" "darray"
+	     ;; empheq
+	     "empheq")) "*?")
+  "Regexp of LaTeX math environments.")
 
 
 ;;; User Configurable Variables
@@ -1067,7 +1078,23 @@ Eventually, if FULL is non-nil, wrap label within \"\\label{}\"."
 	  (and (or user-label force)
 	       (if (and user-label (plist-get info :latex-prefer-user-labels))
 		   user-label
-		 (org-export-get-reference datum info)))))
+		 (concat (case type
+			   (headline "sec:")
+			   (table "tab:")
+			   (latex-environment
+			    (save-match-data
+			      (let ((string (org-element-property :value datum)))
+				(string-match
+				 (nth 1 (assoc "begin" org-latex-regexps))
+				 string)
+				(and (org-string-match-p
+				      org-latex-math-environments-re
+				      (match-string 2 string))
+				     "eq:"))))
+			   (paragraph
+			    (and (org-element-property :caption datum)
+				 "fig:")))
+			 (org-export-get-reference datum info))))))
     (cond ((not full) label)
 	  (label (format "\\label{%s}%s"
 			 label
-- 
2.3.6

Reply via email to