Here's a patch updated to current trunk, since I incremented the format for another reason.

There are a couple conceptual issues.

(1) refstyle does not know about theorems and lemmas by default. What mechanism should we use for declaring the reference styles? One possibility is to include the \newref commands in the Preamble section of the layout. Either we would then have to load refstyle no matter what, or else we'd have to wrap it in a check for whether it is loaded, probably the latter. Alternatively, we could have a new layout command, RefCommand or whatever, that would declare those commands:
    RefPreamble
        \newref{thm}{%
            name = \RSthmtxt,
            names = \RSthmstxt,
        % etc
        }
        \def\RSthmtxt{theorem~}
        % etc
    EndPreamble
And then this would be included whenever refstyle is loaded. (A more subtle check could be done, but perhaps isn't necessary.)

(2) Part of the attraction of refstyle is that it doesn't have to use ":" as a separator, which is bad in French, since the colon is active. Should we just use something else? If so, what? Should we allow it to be customized? The disadvantage in either case is that refstyle by default assumes ":", and so either we or the user has to take appropriate steps to tell refstyle about the difference. Unfortunately, there is no easy way to do that. It has to be done for each and every reference style you declare.

rh

Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(revision 33794)
+++ src/Buffer.cpp	(working copy)
@@ -126,7 +126,7 @@
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 379; // rgh: xhtml math output type
+int const LYX_FORMAT = 380; // rgh: refstyle
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
Index: src/insets/InsetRef.cpp
===================================================================
--- src/insets/InsetRef.cpp	(revision 33794)
+++ src/insets/InsetRef.cpp	(working copy)
@@ -24,6 +24,7 @@
 #include "sgml.h"
 #include "TocBackend.h"
 
+#include "support/debug.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
@@ -51,7 +52,7 @@
 		|| s == "pageref"
 		|| s == "vref" 
 		|| s == "vpageref"
-		|| s == "prettyref"
+		|| s == "refstyle"
 		|| s == "eqref";
 }
 
@@ -74,6 +75,25 @@
 	// in docbook. So we construct new params, without it, and use that.
 	InsetCommandParams p(REF_CODE, getCmdName());
 	p["reference"] = getParam("reference");
+	string const cmd = p.getCmdName();
+	if (cmd != "refstyle") {
+		os << p.getCommand(runparams);
+		return 0;
+	}
+	// refstyle isn't really a command. rather, it signals that
+	// we need to create the command needed.
+	docstring prefix;
+	docstring const rest = split(p["reference"], prefix, ':');
+	// if rest is empty, then there's no ":", so we'll treat
+	// it simply as a normal reference.
+	if (rest.empty()) {
+		LYXERR0("Couldn't determine reference type for label `" << 
+				prefix << "'");
+		p.setCmdName("ref");
+	} else {
+		p.setCmdName(to_utf8(prefix) + "ref");
+		p["reference"] = rest;
+	}
 	os << p.getCommand(runparams);
 	return 0;
 }
@@ -208,8 +228,8 @@
 {
 	if (getCmdName() == "vref" || getCmdName() == "vpageref")
 		features.require("varioref");
-	else if (getCmdName() == "prettyref")
-		features.require("prettyref");
+	else if (getCmdName() == "refstyle")
+		features.require("refstyle");
 	else if (getCmdName() == "eqref")
 		features.require("amsmath");
 }
@@ -221,7 +241,7 @@
 	{ "pageref",   N_("Page Number"),           N_("Page: ")},
 	{ "vpageref",  N_("Textual Page Number"),   N_("TextPage: ")},
 	{ "vref",      N_("Standard+Textual Page"), N_("Ref+Text: ")},
-	{ "prettyref", N_("PrettyRef"),             N_("FrmtRef: ")},
+	{ "refstyle",  N_("RefStyle"),              N_("RefStyle: ")},
 	{ "", "", "" }
 };
 
Index: src/LaTeXFeatures.cpp
===================================================================
--- src/LaTeXFeatures.cpp	(revision 33794)
+++ src/LaTeXFeatures.cpp	(working copy)
@@ -510,7 +510,7 @@
 	"pifont",
 	// subfig is handled in BufferParams.cpp
 	"varioref",
-	"prettyref",
+	"refstyle",
 	/*For a successful cooperation of the `wrapfig' package with the
 	  `float' package you should load the `wrapfig' package *after*
 	  the `float' package. See the caption package documentation
Index: src/LyXAction.cpp
===================================================================
--- src/LyXAction.cpp	(revision 33794)
+++ src/LyXAction.cpp	(working copy)
@@ -2305,7 +2305,7 @@
                pageref -- <page> \n
                vpageref -- on <page> \n
                vref -- <reference> on <page> \n
-               prettyref -- Formatted reference
+               refstyle -- Formatted reference
  * \endvar
  */
 		{ LFUN_INSET_INSERT, "inset-insert", Noop, Edit },
Index: lib/lyx2lyx/lyx_2_0.py
===================================================================
--- lib/lyx2lyx/lyx_2_0.py	(revision 33794)
+++ lib/lyx2lyx/lyx_2_0.py	(working copy)
@@ -602,6 +602,76 @@
         i = i + 1
 
 
+def convert_prettyref(document):
+    " Converts prettyref commands to refstyle commands "
+    re_ref = re.compile("^reference\s+\"(\w+):(\S+)\"")
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset CommandInset ref", i)
+        if i == -1:
+            break
+        j = find_end_of_inset(document.body, i)
+        if j == -1:
+            document.warning("Malformed LyX document: No end of InsetRef")
+            i += 1
+            continue
+        k = find_token(document.body, "LatexCommand prettyref", i)
+        if k == -1 or k > j:
+            i = j + 1
+            continue
+        document.body[k] = "LatexCommand refstyle"
+        k = find_token(document.body, "reference", i)
+        if k == -1 or k > j:
+            i = j + 1
+            continue
+        m = re_ref.match(document.body[k])
+        if m:
+            # Note: We could switch from ":" to something else here, though
+            # that would mean doing a lot of \newref somewhere.
+            prefix = m.group(1)
+            suffix = m.group(2)
+            if prefix == "cha":
+                prefix = "chap"
+            elif prefix == "par":
+                prefix = "part"
+            document.body[k] = "reference \"" + prefix + ":" + suffix + "\""
+        i = j + 1
+
+
+def revert_refstyle(document):
+    " Converts resfstyle commands to pretty commands "
+    re_ref = re.compile("^reference\s+\"(\w+):(\S+)\"")
+    i = 0
+    while True:
+        i = find_token(document.body, "\\begin_inset CommandInset ref", i)
+        if i == -1:
+            break
+        j = find_end_of_inset(document.body, i)
+        if j == -1:
+            document.warning("Malformed LyX document: No end of InsetRef")
+            i += 1
+            continue
+        k = find_token(document.body, "LatexCommand refstyle", i)
+        if k == -1 or k > j:
+            i = j + 1
+            continue
+        document.body[k] = "LatexCommand prettyref"
+        k = find_token(document.body, "reference", i)
+        if k == -1 or k > j:
+            i = j + 1
+            continue
+        m = re_ref.match(document.body[k])
+        if m:
+            prefix = m.group(1)
+            suffix = m.group(2)
+            if prefix == "chap":
+                prefix = "cha"
+            elif prefix == "part":
+                prefix = "par"
+            document.body[k] = "reference \"" + prefix + ":" + suffix + "\""
+        i = j + 1
+
+
 def convert_splitindex(document):
     " Converts index and printindex insets to splitindex-aware format "
     i = 0
@@ -1273,10 +1343,12 @@
            [376, []],
            [377, []],
            [378, []],
-           [379, [convert_math_output]]
+           [379, [convert_math_output]],
+           [380, [convert_prettyref]]
           ]
 
-revert =  [[378, [revert_math_output]],
+revert =  [[379, [revert_refstyle]],
+           [378, [revert_math_output]],
            [377, []],
            [376, [revert_multirow]],
            [375, [revert_includeall]],
Index: lib/symbols
===================================================================
--- lib/symbols	(revision 33794)
+++ lib/symbols	(working copy)
@@ -131,7 +131,7 @@
 
 # references
 pageref           ref         none
-prettyref         ref         none
+refstyle          ref         none
 ref               ref         none
 vpageref          ref         none
 vref              ref         none
Index: lib/ui/stdcontext.inc
===================================================================
--- lib/ui/stdcontext.inc	(revision 33794)
+++ lib/ui/stdcontext.inc	(working copy)
@@ -90,7 +90,7 @@
 		Item "<Page>|P" "inset-modify changetype pageref"
 		Item "On Page <Page>|O" "inset-modify changetype vpageref"
 		Item "<Reference> on Page <Page>|f" "inset-modify changetype vref"
-		Item "Formatted Reference|t" "inset-modify changetype prettyref"
+		Item "Formatted Reference|t" "inset-modify changetype refstyle"
 		Separator
 		Item "Settings...|S" "inset-settings"
 	End
Index: lib/chkconfig.ltx
===================================================================
--- lib/chkconfig.ltx	(revision 33794)
+++ lib/chkconfig.ltx	(working copy)
@@ -265,8 +265,8 @@
 \TestPackage{nomencl}
 \TestPackage{pdfcolmk}
 \TestPackage{pdfpages}
-\TestPackage{prettyref}
 \TestPackage{preview}
+\TestPackage{refstyle}
 \TestPackage{rotating}
 \TestPackage{rotfloat}
 \TestPackage{setspace}
Index: development/FORMAT
===================================================================
--- development/FORMAT	(revision 33794)
+++ development/FORMAT	(working copy)
@@ -1,6 +1,9 @@
 LyX file-format changes
 -----------------------
 
+2010-03-21: Richard Heck <rgh...@comcast.net>
+  * Format incremented to 380: convert from prettyref to refstyle
+
 2010-03-18: Richard Heck <rgh...@comcast.net>
   * Format incremented to 379: revise format 374
 	  Replace boolean \html_use_mathml with \html_math_output,

Reply via email to