mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-09-19 22:40:26 +00:00
Refstyle support. The user can now choose between prettyref and restyle
for formatted references. Fixes #2295, in so far as it makes it possible to translate formatted references. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35623 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
8a5cde8fbf
commit
01013c0785
@ -7,7 +7,14 @@ The good example would be 2010-01-10 entry.
|
|||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
2010-10-11 Richard Heck <rgheck@comcast.net>
|
2010-10-13 Richard Heck <rgheck@comcast.net>
|
||||||
|
* Format incremented to 404: refstyle support
|
||||||
|
Changed the LaTeXCommand for InsetRef from "prettyref"
|
||||||
|
to "formatted", where "formatted" is now interprted
|
||||||
|
differently, depending upon whether the new buffer param
|
||||||
|
use_refstyle is true or false.
|
||||||
|
|
||||||
|
2010-10-12 Richard Heck <rgheck@comcast.net>
|
||||||
* Format incremented to 403: renaming of flex insets
|
* Format incremented to 403: renaming of flex insets
|
||||||
changed
|
changed
|
||||||
\begin_inset Flex TAG:Style
|
\begin_inset Flex TAG:Style
|
||||||
|
@ -287,6 +287,7 @@
|
|||||||
\TestPackage{pdfpages}
|
\TestPackage{pdfpages}
|
||||||
\TestPackage{prettyref}
|
\TestPackage{prettyref}
|
||||||
\TestPackage{preview}
|
\TestPackage{preview}
|
||||||
|
\TestPackage{refstyle}
|
||||||
\TestPackage{rotating}
|
\TestPackage{rotating}
|
||||||
\TestPackage{rotfloat}
|
\TestPackage{rotfloat}
|
||||||
\TestPackage{setspace}
|
\TestPackage{setspace}
|
||||||
|
@ -1960,6 +1960,52 @@ def revert_IEEEtran(document):
|
|||||||
del document.body[i:j + 1]
|
del document.body[i:j + 1]
|
||||||
|
|
||||||
|
|
||||||
|
def convert_prettyref(document):
|
||||||
|
" Converts prettyref references to neutral formatted refs "
|
||||||
|
re_ref = re.compile("^\s*reference\s+\"(\w+):(\S+)\"")
|
||||||
|
nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
while True:
|
||||||
|
i = find_token(document.body, "\\begin_inset CommandInset ref", i)
|
||||||
|
if i == -1:
|
||||||
|
break
|
||||||
|
j = find_end_of_inset(document.body, i)
|
||||||
|
if j == -1:
|
||||||
|
document.warning("Malformed LyX document: No end of InsetRef!")
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
k = find_token(document.body, "LatexCommand prettyref", i)
|
||||||
|
if k != -1 and k < j:
|
||||||
|
document.body[k] = "LatexCommand formatted"
|
||||||
|
i = j + 1
|
||||||
|
document.header.insert(-1, "\\use_refstyle 0")
|
||||||
|
|
||||||
|
|
||||||
|
def revert_refstyle(document):
|
||||||
|
" Reverts neutral formatted refs to prettyref "
|
||||||
|
re_ref = re.compile("^reference\s+\"(\w+):(\S+)\"")
|
||||||
|
nm_ref = re.compile("^\s*name\s+\"(\w+):(\S+)\"")
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
while True:
|
||||||
|
i = find_token(document.body, "\\begin_inset CommandInset ref", i)
|
||||||
|
if i == -1:
|
||||||
|
break
|
||||||
|
j = find_end_of_inset(document.body, i)
|
||||||
|
if j == -1:
|
||||||
|
document.warning("Malformed LyX document: No end of InsetRef")
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
k = find_token(document.body, "LatexCommand formatted", i)
|
||||||
|
if k != -1 and k < j:
|
||||||
|
document.body[k] = "LatexCommand prettyref"
|
||||||
|
i = j + 1
|
||||||
|
i = find_token(document.header, "\\use_refstyle", 0)
|
||||||
|
if i != -1:
|
||||||
|
document.header.pop(i)
|
||||||
|
|
||||||
|
|
||||||
def revert_nameref(document):
|
def revert_nameref(document):
|
||||||
" Convert namerefs to regular references "
|
" Convert namerefs to regular references "
|
||||||
cmds = ["Nameref", "nameref"]
|
cmds = ["Nameref", "nameref"]
|
||||||
@ -2311,6 +2357,7 @@ def convert_bibtexClearpage(document):
|
|||||||
" insert a clear(double)page bibliographystyle if bibtotoc option is used "
|
" insert a clear(double)page bibliographystyle if bibtotoc option is used "
|
||||||
while True:
|
while True:
|
||||||
i = find_token(document.header, '\\papersides', 0)
|
i = find_token(document.header, '\\papersides', 0)
|
||||||
|
#document.warning(str(i))
|
||||||
if i == -1:
|
if i == -1:
|
||||||
document.warning("Malformed LyX document: Can't find papersides definition.")
|
document.warning("Malformed LyX document: Can't find papersides definition.")
|
||||||
return
|
return
|
||||||
@ -2397,10 +2444,12 @@ convert = [[346, []],
|
|||||||
[400, [convert_rule]],
|
[400, [convert_rule]],
|
||||||
[401, []],
|
[401, []],
|
||||||
[402, [convert_bibtexClearpage]],
|
[402, [convert_bibtexClearpage]],
|
||||||
[403, [convert_flexnames]]
|
[403, [convert_flexnames]],
|
||||||
|
[404, [convert_prettyref]]
|
||||||
]
|
]
|
||||||
|
|
||||||
revert = [[402, [revert_flexnames]],
|
revert = [[403, [revert_refstyle]],
|
||||||
|
[402, [revert_flexnames]],
|
||||||
[401, []],
|
[401, []],
|
||||||
[400, [revert_diagram]],
|
[400, [revert_diagram]],
|
||||||
[399, [revert_rule]],
|
[399, [revert_rule]],
|
||||||
|
@ -136,6 +136,7 @@ rgathered split none
|
|||||||
# references
|
# references
|
||||||
pageref ref none
|
pageref ref none
|
||||||
prettyref ref none
|
prettyref ref none
|
||||||
|
refstyle ref none
|
||||||
ref ref none
|
ref ref none
|
||||||
vpageref ref none
|
vpageref ref none
|
||||||
vref ref none
|
vref ref none
|
||||||
|
@ -90,7 +90,7 @@ Menuset
|
|||||||
Item "<Page>|P" "inset-modify changetype pageref"
|
Item "<Page>|P" "inset-modify changetype pageref"
|
||||||
Item "On Page <Page>|O" "inset-modify changetype vpageref"
|
Item "On Page <Page>|O" "inset-modify changetype vpageref"
|
||||||
Item "<Reference> on Page <Page>|f" "inset-modify changetype vref"
|
Item "<Reference> on Page <Page>|f" "inset-modify changetype vref"
|
||||||
Item "Formatted Reference|t" "inset-modify changetype prettyref"
|
Item "Formatted Reference|t" "inset-modify changetype formatted"
|
||||||
Item "Textual Reference|x" "inset-modify changetype nameref"
|
Item "Textual Reference|x" "inset-modify changetype nameref"
|
||||||
Separator
|
Separator
|
||||||
Item "Settings...|S" "inset-settings"
|
Item "Settings...|S" "inset-settings"
|
||||||
|
@ -127,7 +127,7 @@ namespace {
|
|||||||
|
|
||||||
// Do not remove the comment below, so we get merge conflict in
|
// Do not remove the comment below, so we get merge conflict in
|
||||||
// independent branches. Instead add your own.
|
// independent branches. Instead add your own.
|
||||||
int const LYX_FORMAT = 403; // rgh: Dummy format for InsetFlex name conversion
|
int const LYX_FORMAT = 404; // rgh: refstyle
|
||||||
|
|
||||||
typedef map<string, bool> DepClean;
|
typedef map<string, bool> DepClean;
|
||||||
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
|
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
|
||||||
|
@ -415,6 +415,7 @@ BufferParams::BufferParams()
|
|||||||
html_math_img_scale = 1.0;
|
html_math_img_scale = 1.0;
|
||||||
|
|
||||||
output_sync = false;
|
output_sync = false;
|
||||||
|
use_refstyle = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -853,6 +854,8 @@ string BufferParams::readToken(Lexer & lex, string const & token,
|
|||||||
lex >> output_sync;
|
lex >> output_sync;
|
||||||
} else if (token == "\\output_sync_macro") {
|
} else if (token == "\\output_sync_macro") {
|
||||||
lex >> output_sync_macro;
|
lex >> output_sync_macro;
|
||||||
|
} else if (token == "\\use_refstyle") {
|
||||||
|
lex >> use_refstyle;
|
||||||
} else {
|
} else {
|
||||||
lyxerr << "BufferParams::readToken(): Unknown token: " <<
|
lyxerr << "BufferParams::readToken(): Unknown token: " <<
|
||||||
token << endl;
|
token << endl;
|
||||||
@ -980,6 +983,7 @@ void BufferParams::writeFile(ostream & os) const
|
|||||||
<< "\n\\use_indices " << convert<string>(use_indices)
|
<< "\n\\use_indices " << convert<string>(use_indices)
|
||||||
<< "\n\\paperorientation " << string_orientation[orientation]
|
<< "\n\\paperorientation " << string_orientation[orientation]
|
||||||
<< "\n\\suppress_date " << convert<string>(suppress_date)
|
<< "\n\\suppress_date " << convert<string>(suppress_date)
|
||||||
|
<< "\n\\use_refstyle " << use_refstyle
|
||||||
<< '\n';
|
<< '\n';
|
||||||
if (isbackgroundcolor == true)
|
if (isbackgroundcolor == true)
|
||||||
os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n';
|
os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n';
|
||||||
|
@ -405,6 +405,8 @@ public:
|
|||||||
bool output_sync;
|
bool output_sync;
|
||||||
/// custom LaTeX macro from user instead our own
|
/// custom LaTeX macro from user instead our own
|
||||||
std::string output_sync_macro;
|
std::string output_sync_macro;
|
||||||
|
/// use refstyle? or prettyref?
|
||||||
|
bool use_refstyle;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
|
@ -256,6 +256,25 @@ static docstring const ogonek_def = from_ascii(
|
|||||||
" \\mathchar\"0\\hexnumber@\\symtipasymb0C}{#2}}\n"
|
" \\mathchar\"0\\hexnumber@\\symtipasymb0C}{#2}}\n"
|
||||||
"\\newcommand{\\ogonek}[1]{\\mathpalette\\doogonek{#1}}\n");
|
"\\newcommand{\\ogonek}[1]{\\mathpalette\\doogonek{#1}}\n");
|
||||||
|
|
||||||
|
static docstring const lyxref_def = from_ascii(
|
||||||
|
"\\makeatletter\n"
|
||||||
|
"\\def\\lyxref#1{\\@lyxref#1:@@@@@:}\n"
|
||||||
|
"\\def\\@lyxref#1:#2:{%\n"
|
||||||
|
"\\ifthenelse{\\equal{#2}{@@@@@}}%\n"
|
||||||
|
" {\\ref{#1}}%\n"
|
||||||
|
" {\\@@lyxref#1:#2:}%\n"
|
||||||
|
"}\n"
|
||||||
|
"\\def\\@@lyxref#1:#2:@@@@@:{%\n"
|
||||||
|
" \\RS@ifundefined{#1ref}%\n"
|
||||||
|
" {\\ref{#1:#2}}%\n"
|
||||||
|
" {\\RS@nameuse{#1ref}{#2}}%\n"
|
||||||
|
"}\n"
|
||||||
|
"\\RS@ifundefined{\thmref}\n"
|
||||||
|
" {\\def\\RSthmtxt{theorem~}\\newref{thm}{name = \\RSthmtxt}}\n"
|
||||||
|
" {}\n"
|
||||||
|
"\\makeatother\n"
|
||||||
|
);
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// LaTeXFeatures
|
// LaTeXFeatures
|
||||||
@ -507,6 +526,7 @@ char const * simplefeatures[] = {
|
|||||||
// subfig is handled in BufferParams.cpp
|
// subfig is handled in BufferParams.cpp
|
||||||
"varioref",
|
"varioref",
|
||||||
"prettyref",
|
"prettyref",
|
||||||
|
"refstyle",
|
||||||
/*For a successful cooperation of the `wrapfig' package with the
|
/*For a successful cooperation of the `wrapfig' package with the
|
||||||
`float' package you should load the `wrapfig' package *after*
|
`float' package you should load the `wrapfig' package *after*
|
||||||
the `float' package. See the caption package documentation
|
the `float' package. See the caption package documentation
|
||||||
@ -900,6 +920,9 @@ docstring const LaTeXFeatures::getMacros() const
|
|||||||
|
|
||||||
// floats
|
// floats
|
||||||
getFloatDefinitions(macros);
|
getFloatDefinitions(macros);
|
||||||
|
|
||||||
|
if (mustProvide("refstyle"))
|
||||||
|
macros << lyxref_def << '\n';
|
||||||
|
|
||||||
// change tracking
|
// change tracking
|
||||||
if (mustProvide("ct-dvipost"))
|
if (mustProvide("ct-dvipost"))
|
||||||
|
@ -2311,7 +2311,7 @@ void LyXAction::init()
|
|||||||
pageref -- <page> \n
|
pageref -- <page> \n
|
||||||
vpageref -- on <page> \n
|
vpageref -- on <page> \n
|
||||||
vref -- <reference> on <page> \n
|
vref -- <reference> on <page> \n
|
||||||
prettyref -- Formatted reference
|
formatted -- Formatted reference
|
||||||
* \endvar
|
* \endvar
|
||||||
*/
|
*/
|
||||||
{ LFUN_INSET_INSERT, "inset-insert", Noop, Edit },
|
{ LFUN_INSET_INSERT, "inset-insert", Noop, Edit },
|
||||||
|
@ -1118,6 +1118,8 @@ GuiDocument::GuiDocument(GuiView & lv)
|
|||||||
this, SLOT(browseMaster()));
|
this, SLOT(browseMaster()));
|
||||||
connect(latexModule->suppressDateCB, SIGNAL(clicked()),
|
connect(latexModule->suppressDateCB, SIGNAL(clicked()),
|
||||||
this, SLOT(change_adaptor()));
|
this, SLOT(change_adaptor()));
|
||||||
|
connect(latexModule->refstyleCB, SIGNAL(clicked()),
|
||||||
|
this, SLOT(change_adaptor()));
|
||||||
|
|
||||||
// postscript drivers
|
// postscript drivers
|
||||||
for (int n = 0; tex_graphics[n][0]; ++n) {
|
for (int n = 0; tex_graphics[n][0]; ++n) {
|
||||||
@ -2106,6 +2108,7 @@ void GuiDocument::applyView()
|
|||||||
|
|
||||||
// date
|
// date
|
||||||
bp_.suppress_date = latexModule->suppressDateCB->isChecked();
|
bp_.suppress_date = latexModule->suppressDateCB->isChecked();
|
||||||
|
bp_.use_refstyle = latexModule->refstyleCB->isChecked();
|
||||||
|
|
||||||
// biblio
|
// biblio
|
||||||
bp_.setCiteEngine(ENGINE_BASIC);
|
bp_.setCiteEngine(ENGINE_BASIC);
|
||||||
@ -2531,6 +2534,7 @@ void GuiDocument::paramsToDialog()
|
|||||||
|
|
||||||
// date
|
// date
|
||||||
latexModule->suppressDateCB->setChecked(bp_.suppress_date);
|
latexModule->suppressDateCB->setChecked(bp_.suppress_date);
|
||||||
|
latexModule->refstyleCB->setChecked(bp_.use_refstyle);
|
||||||
|
|
||||||
// biblio
|
// biblio
|
||||||
biblioModule->citeDefaultRB->setChecked(
|
biblioModule->citeDefaultRB->setChecked(
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>341</width>
|
<width>341</width>
|
||||||
<height>319</height>
|
<height>442</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -187,7 +187,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="1">
|
<item row="6" column="1">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -200,6 +200,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="5" column="0" colspan="4">
|
||||||
|
<widget class="QCheckBox" name="refstyleCB">
|
||||||
|
<property name="text">
|
||||||
|
<string>Use refstyle for cross-references</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "InsetRef.h"
|
#include "InsetRef.h"
|
||||||
|
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
|
#include "BufferParams.h"
|
||||||
#include "Cursor.h"
|
#include "Cursor.h"
|
||||||
#include "DispatchResult.h"
|
#include "DispatchResult.h"
|
||||||
#include "InsetLabel.h"
|
#include "InsetLabel.h"
|
||||||
@ -50,7 +51,7 @@ bool InsetRef::isCompatibleCommand(string const & s) {
|
|||||||
|| s == "pageref"
|
|| s == "pageref"
|
||||||
|| s == "vref"
|
|| s == "vref"
|
||||||
|| s == "vpageref"
|
|| s == "vpageref"
|
||||||
|| s == "prettyref"
|
|| s == "formatted"
|
||||||
|| s == "eqref"
|
|| s == "eqref"
|
||||||
|| s == "nameref";
|
|| s == "nameref";
|
||||||
}
|
}
|
||||||
@ -70,11 +71,24 @@ ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
|
|||||||
|
|
||||||
int InsetRef::latex(odocstream & os, OutputParams const & runparams) const
|
int InsetRef::latex(odocstream & os, OutputParams const & runparams) const
|
||||||
{
|
{
|
||||||
// We don't want to output p_["name"], since that is only used
|
string const cmd = getCmdName();
|
||||||
// in docbook. So we construct new params, without it, and use that.
|
docstring const ref = getParam("reference");
|
||||||
InsetCommandParams p(REF_CODE, getCmdName());
|
if (cmd != "formatted") {
|
||||||
p["reference"] = getParam("reference");
|
// We don't want to output p_["name"], since that is only used
|
||||||
os << p.getCommand(runparams);
|
// in docbook. So we construct new params, without it, and use that.
|
||||||
|
InsetCommandParams p(REF_CODE, cmd);
|
||||||
|
p["reference"] = ref;
|
||||||
|
os << p.getCommand(runparams);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// so we're doing a formatted reference.
|
||||||
|
if (!buffer().params().use_refstyle) {
|
||||||
|
os << "\\prettyref{" << ref << '}';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "\\lyxref{" << ref << '}';
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,9 +225,14 @@ void InsetRef::validate(LaTeXFeatures & features) const
|
|||||||
string const cmd = getCmdName();
|
string const cmd = getCmdName();
|
||||||
if (cmd == "vref" || cmd == "vpageref")
|
if (cmd == "vref" || cmd == "vpageref")
|
||||||
features.require("varioref");
|
features.require("varioref");
|
||||||
else if (cmd == "prettyref")
|
else if (getCmdName() == "formatted") {
|
||||||
features.require("prettyref");
|
if (buffer().params().use_refstyle) {
|
||||||
else if (cmd == "eqref")
|
features.require("refstyle");
|
||||||
|
//features.addPreambleSnippet("");
|
||||||
|
} else
|
||||||
|
features.require("prettyref");
|
||||||
|
} else if (getCmdName() == "eqref" && !buffer().params().use_refstyle)
|
||||||
|
// refstyle defines its own version
|
||||||
features.require("amsmath");
|
features.require("amsmath");
|
||||||
else if (cmd == "nameref")
|
else if (cmd == "nameref")
|
||||||
features.require("nameref");
|
features.require("nameref");
|
||||||
@ -226,7 +245,7 @@ InsetRef::type_info InsetRef::types[] = {
|
|||||||
{ "pageref", N_("Page Number"), N_("Page: ")},
|
{ "pageref", N_("Page Number"), N_("Page: ")},
|
||||||
{ "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
|
{ "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
|
||||||
{ "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
|
{ "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
|
||||||
{ "prettyref", N_("PrettyRef"), N_("FrmtRef: ")},
|
{ "formatted", N_("Formatted"), N_("Format: ")},
|
||||||
{ "nameref", N_("Reference to Name"), N_("NameRef:")},
|
{ "nameref", N_("Reference to Name"), N_("NameRef:")},
|
||||||
{ "", "", "" }
|
{ "", "", "" }
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user