]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetRef.cpp
Merge branch 'master' of git.lyx.org:lyx
[lyx.git] / src / insets / InsetRef.cpp
index 17184e51f6333291430073a9ddd586a2aa37556f..bae4992f66f156cb22cf9126ec652698adf30bca 100644 (file)
@@ -140,34 +140,35 @@ docstring InsetRef::getEscapedLabel(OutputParams const & rp) const
 void InsetRef::latex(otexstream & os, OutputParams const & rp) const
 {
        string const cmd = getCmdName();
+       docstring const data = getEscapedLabel(rp);
+
+       if (rp.inulemcmd)
+               os << "\\mbox{";
 
-       // refstyle defines its own version of \eqref
-       if (cmd != "formatted" &&
-           !(cmd == "eqref" && buffer().params().use_refstyle)
-          ) {
+       if (cmd == "eqref" && buffer().params().use_refstyle) {
+               // we advertise this as printing "(n)", so we'll do that, at least
+               // for refstyle, since refstlye's own \eqref prints, by default,
+               // "equation n". if one wants \eqref, one can get it by using a
+               // formatted label in this case.
+               os << '(' << from_ascii("\\ref{") << data << from_ascii("})");
+       } 
+       else if (cmd == "formatted") {
+               docstring label;
+               docstring prefix;
+               docstring const fcmd = getFormattedCmd(data, label, prefix);
+               os << fcmd << '{' << label << '}';
+       }
+       else {
                // We don't want to output p_["name"], since that is only used 
                // in docbook. So we construct new params, without it, and use that.
                InsetCommandParams p(REF_CODE, cmd);
                docstring const ref = getParam("reference");
                p["reference"] = ref;
                os << p.getCommand(rp);
-               return;
        }
 
-       // so we're doing a formatted reference of some kind.
-       docstring const data = getEscapedLabel(rp);
-
-       // what we say in the UI is that an "eqref" is supposed to surround the
-       // reference with parentheses, so let's do that.
-       if (cmd == "eqref" /* && buffer().params().use_refstyle */) {
-               os << '(' << from_ascii("\\ref{") << data << from_ascii("})");
-               return;
-       }
-
-       docstring label;
-       docstring prefix;
-       docstring const fcmd = getFormattedCmd(data, label, prefix);
-       os << fcmd << '{' << label << '}';
+       if (rp.inulemcmd)
+               os << "}";
 }
 
 
@@ -224,7 +225,7 @@ docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const &) const
                        display_string = _("elsewhere");
                else if (cmd == "eqref")
                        display_string = bformat(from_ascii("equation (%1$s)"), value);
-               else if (cmd == "prettyref" 
+               else if (cmd == "formatted"
                         // we don't really have the ability to handle these 
                         // properly in XHTML output
                         || cmd == "nameref")
@@ -272,7 +273,7 @@ void InsetRef::updateBuffer(ParIterator const & it, UpdateType)
        }
        label += ref;
        
-       if (!buffer().isLatex() && !getParam("name").empty()) {
+       if (!buffer().params().isLatex() && !getParam("name").empty()) {
                label += "||";
                label += getParam("name");
        }
@@ -311,13 +312,13 @@ void InsetRef::validate(LaTeXFeatures & features) const
        string const cmd = getCmdName();
        if (cmd == "vref" || cmd == "vpageref")
                features.require("varioref");
-       else if (getCmdName() == "formatted") {
+       else if (cmd == "formatted") {
                docstring const data = getEscapedLabel(features.runparams());
                docstring label;
                docstring prefix;
+               string const fcmd = to_utf8(getFormattedCmd(data, label, prefix));
                if (buffer().params().use_refstyle) {
                        features.require("refstyle");
-                       string const fcmd = to_utf8(getFormattedCmd(data, label, prefix));
                        if (!prefix.empty()) {
                                string lcmd = "\\AtBeginDocument{\\providecommand" + 
                                                fcmd + "[1]{\\ref{" + to_utf8(prefix) + ":#1}}}";
@@ -331,8 +332,8 @@ void InsetRef::validate(LaTeXFeatures & features) const
                        if (prefix == "chap")
                                features.addPreambleSnippet("\\let\\pr@chap=\\pr@cha");
                }
-       } else if (getCmdName() == "eqref" && !buffer().params().use_refstyle)
-               // refstyle defines its own version
+       } else if (cmd == "eqref" && !buffer().params().use_refstyle)
+               // with refstyle, we simply output "(\ref{label})"
                features.require("amsmath");
        else if (cmd == "nameref")
                features.require("nameref");