Author: rgheck
Date: Mon Nov 8 18:50:02 2010
New Revision: 36211
URL: http://www.lyx.org/trac/changeset/36211
Log:
Fix bug in fallback reference output with refstyle. Based on idea by
Jean-Pierre Chretien.
Modified:
lyx-devel/trunk/src/insets/InsetRef.cpp
lyx-devel/trunk/src/insets/InsetRef.h
Modified: lyx-devel/trunk/src/insets/InsetRef.cpp
==============================================================================
--- lyx-devel/trunk/src/insets/InsetRef.cpp Mon Nov 8 16:15:42 2010
(r36210)
+++ lyx-devel/trunk/src/insets/InsetRef.cpp Mon Nov 8 18:50:02 2010
(r36211)
@@ -70,16 +70,25 @@
}
-// for refstyle, given pfx:suffix, we want to return "\\pfxcmd"
-// and put "suffix" into label.
-// otherwise, we put the reference into label.
-docstring InsetRef::getFormattedCmd(
- docstring const & ref, docstring & label) const
+// the ref argument is the label name we are referencing.
+// we expect ref to be in the form: pfx:suffix.
+//
+// if it isn't, then we can't produce a formatted reference,
+// so we return "\ref" and put ref into label.
+//
+// for refstyle, we return "\pfxcmd", and put suffix into
+// label and pfx into prefix. this is because refstyle expects
+// the command: \pfxcmd{suffix}.
+//
+// for prettyref, we return "\prettyref" and put ref into label
+// and pfx into prefix. this is because prettyref
+//
+docstring InsetRef::getFormattedCmd(docstring const & ref,
+ docstring & label, docstring & prefix) const
{
static docstring const defcmd = from_ascii("\\ref");
static docstring const prtcmd = from_ascii("\\prettyref");
- docstring prefix;
label = split(ref, prefix, ':');
// we have to have xxx:xxxxx...
@@ -134,7 +143,8 @@
// so we're doing a formatted reference.
docstring const data = getEscapedLabel(rp);
docstring label;
- docstring const fcmd = getFormattedCmd(data, label);
+ docstring prefix;
+ docstring const fcmd = getFormattedCmd(data, label, prefix);
os << fcmd << '{' << label << '}';
return 0;
}
@@ -277,9 +287,11 @@
features.require("refstyle");
docstring const data =
getEscapedLabel(features.runparams());
docstring label;
- string const fcmd = to_utf8(getFormattedCmd(data,
label));
- if (fcmd != "\\ref") {
- string lcmd =
"\\AtBeginDocument{\\providecommand" + fcmd + "[1]{\\ref{#1}}}";
+ docstring prefix;
+ string const fcmd = to_utf8(getFormattedCmd(data,
label, prefix));
+ if (!prefix.empty()) {
+ string lcmd =
"\\AtBeginDocument{\\providecommand" +
+ fcmd + "[1]{\\ref{" +
to_utf8(prefix) + ":#1}}}";
features.addPreambleSnippet(lcmd);
}
} else
Modified: lyx-devel/trunk/src/insets/InsetRef.h
==============================================================================
--- lyx-devel/trunk/src/insets/InsetRef.h Mon Nov 8 16:15:42 2010
(r36210)
+++ lyx-devel/trunk/src/insets/InsetRef.h Mon Nov 8 18:50:02 2010
(r36211)
@@ -101,8 +101,11 @@
/// \return the label with things that need to be escaped escaped
docstring getEscapedLabel(OutputParams const &) const;
/// \return the command for a formatted reference to ref
- /// \param label gets what follows the prefix, for refstyle
- docstring getFormattedCmd(docstring const & ref, docstring & label)
const;
+ /// \param label we're cross-referencing
+ /// \param argument for reference command
+ /// \param prefix of the label (before :)
+ docstring getFormattedCmd(docstring const & ref, docstring & label,
+ docstring & prefix) const;
///
mutable docstring screen_label_;