]> git.lyx.org Git - features.git/commitdiff
Fix bug in fallback reference output with refstyle. Based on idea by
authorRichard Heck <rgheck@comcast.net>
Mon, 8 Nov 2010 17:50:02 +0000 (17:50 +0000)
committerRichard Heck <rgheck@comcast.net>
Mon, 8 Nov 2010 17:50:02 +0000 (17:50 +0000)
Jean-Pierre Chretien.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36211 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetRef.cpp
src/insets/InsetRef.h

index 73ee8cbbcb8c4cadd3ad3f0d04fc5cd4d1c76990..b67c512cf1d43ad1ec7e3cf9cd2b194866df56f9 100644 (file)
@@ -70,16 +70,25 @@ ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
 }
 
 
-// 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 @@ int InsetRef::latex(odocstream & os, OutputParams const & rp) const
        // 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 @@ void InsetRef::validate(LaTeXFeatures & features) const
                        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
index 5d2483fe0f3d76251f488db6d81eba1835e15776..61620d3f25a604a59fdba903f9d0f795bb5f22d7 100644 (file)
@@ -101,8 +101,11 @@ private:
        /// \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_;