From 19aa16756c0155e3eb36ba4e11f1e55f1dd015e9 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Mon, 8 Nov 2010 17:50:02 +0000 Subject: [PATCH] Fix bug in fallback reference output with refstyle. Based on idea by Jean-Pierre Chretien. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36211 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/InsetRef.cpp | 32 ++++++++++++++++++++++---------- src/insets/InsetRef.h | 7 +++++-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index 73ee8cbbcb..b67c512cf1 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -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 diff --git a/src/insets/InsetRef.h b/src/insets/InsetRef.h index 5d2483fe0f..61620d3f25 100644 --- a/src/insets/InsetRef.h +++ b/src/insets/InsetRef.h @@ -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_;