+ static docstring const defcmd = from_ascii("\\ref");
+ static docstring const prtcmd = from_ascii("\\prettyref");
+
+ label = split(ref, prefix, ':');
+
+ // we have to have xxx:xxxxx...
+ if (label.empty()) {
+ LYXERR0("Label `" << ref << "' contains no prefix.");
+ label = ref;
+ prefix = from_ascii("");
+ return defcmd;
+ }
+
+ if (prefix.empty()) {
+ // we have ":xxxx"
+ label = ref;
+ return defcmd;
+ }
+
+ if (!buffer().params().use_refstyle) {
+ // \prettyref uses the whole label
+ label = ref;
+ return prtcmd;
+ }
+
+ // make sure the prefix is legal for a latex command
+ int const len = prefix.size();
+ for (int i = 0; i < len; i++) {
+ char_type const c = prefix[i];
+ if (!isAlphaASCII(c)) {
+ LYXERR0("Prefix `" << prefix << "' is invalid for LaTeX.");
+ // restore the label
+ label = ref;
+ return defcmd;
+ }
+ }
+ return from_ascii("\\") + prefix + from_ascii("ref");
+}
+
+
+docstring InsetRef::getEscapedLabel(OutputParams const & rp) const
+{
+ InsetCommandParams const & p = params();
+ ParamInfo const & pi = p.info();
+ ParamInfo::ParamData const & pd = pi["reference"];
+ return p.prepareCommand(rp, getParam("reference"), pd.handling());
+}
+
+
+void InsetRef::latex(otexstream & os, OutputParams const & rp) const
+{
+ string const cmd = getCmdName();
+ docstring const data = getEscapedLabel(rp);
+
+ if (rp.inulemcmd > 0)
+ os << "\\mbox{";
+
+ 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);
+ }
+
+ if (rp.inulemcmd > 0)
+ os << "}";