From 6f7659306987051fab92e3bd4b97d0be6a10cb64 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 10 Nov 2010 16:45:55 +0000 Subject: [PATCH] Fix a bug in getFormattedReference(). Also, change from using the "cha" prefix for chapters, a la prettyref, to the "chap" prefix, a la refstyle. We alias \pr@chap to \pr@cha for prettyref users. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36238 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/layouts/stdrefprefix.inc | 2 +- src/insets/InsetRef.cpp | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/layouts/stdrefprefix.inc b/lib/layouts/stdrefprefix.inc index 80ffc58c94..f5e4c875f4 100644 --- a/lib/layouts/stdrefprefix.inc +++ b/lib/layouts/stdrefprefix.inc @@ -14,7 +14,7 @@ IfStyle Part End IfStyle Chapter - RefPrefix cha + RefPrefix chap End IfStyle Section diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index b67c512cf1..8baf6c6e82 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -92,8 +92,15 @@ docstring InsetRef::getFormattedCmd(docstring const & ref, 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()) { - LYXERR0("Label `" << label << "' contains no prefix."); + // we have ":xxxx" label = ref; return defcmd; } @@ -283,19 +290,25 @@ void InsetRef::validate(LaTeXFeatures & features) const if (cmd == "vref" || cmd == "vpageref") features.require("varioref"); else if (getCmdName() == "formatted") { + docstring const data = getEscapedLabel(features.runparams()); + docstring label; + docstring prefix; if (buffer().params().use_refstyle) { features.require("refstyle"); - docstring const data = getEscapedLabel(features.runparams()); - docstring label; - 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 + } else if (prefix == "cha") + features.addPreambleSnippet("\\let\\charef=\\chapref"); + } else { features.require("prettyref"); + // prettyref uses "cha" for chapters, so we provide a kind of + // translation. + if (prefix == "chap") + features.addPreambleSnippet("\\let\\pr@chap=\\pr@cha"); + } } else if (getCmdName() == "eqref" && !buffer().params().use_refstyle) // refstyle defines its own version features.require("amsmath"); -- 2.39.2