mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +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
|
||||
changed
|
||||
\begin_inset Flex TAG:Style
|
||||
|
@ -287,6 +287,7 @@
|
||||
\TestPackage{pdfpages}
|
||||
\TestPackage{prettyref}
|
||||
\TestPackage{preview}
|
||||
\TestPackage{refstyle}
|
||||
\TestPackage{rotating}
|
||||
\TestPackage{rotfloat}
|
||||
\TestPackage{setspace}
|
||||
|
@ -1960,6 +1960,52 @@ def revert_IEEEtran(document):
|
||||
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):
|
||||
" Convert namerefs to regular references "
|
||||
cmds = ["Nameref", "nameref"]
|
||||
@ -2311,6 +2357,7 @@ def convert_bibtexClearpage(document):
|
||||
" insert a clear(double)page bibliographystyle if bibtotoc option is used "
|
||||
while True:
|
||||
i = find_token(document.header, '\\papersides', 0)
|
||||
#document.warning(str(i))
|
||||
if i == -1:
|
||||
document.warning("Malformed LyX document: Can't find papersides definition.")
|
||||
return
|
||||
@ -2397,10 +2444,12 @@ convert = [[346, []],
|
||||
[400, [convert_rule]],
|
||||
[401, []],
|
||||
[402, [convert_bibtexClearpage]],
|
||||
[403, [convert_flexnames]]
|
||||
[403, [convert_flexnames]],
|
||||
[404, [convert_prettyref]]
|
||||
]
|
||||
|
||||
revert = [[402, [revert_flexnames]],
|
||||
revert = [[403, [revert_refstyle]],
|
||||
[402, [revert_flexnames]],
|
||||
[401, []],
|
||||
[400, [revert_diagram]],
|
||||
[399, [revert_rule]],
|
||||
|
@ -136,6 +136,7 @@ rgathered split none
|
||||
# references
|
||||
pageref ref none
|
||||
prettyref ref none
|
||||
refstyle ref none
|
||||
ref ref none
|
||||
vpageref ref none
|
||||
vref ref none
|
||||
|
@ -90,7 +90,7 @@ Menuset
|
||||
Item "<Page>|P" "inset-modify changetype pageref"
|
||||
Item "On Page <Page>|O" "inset-modify changetype vpageref"
|
||||
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"
|
||||
Separator
|
||||
Item "Settings...|S" "inset-settings"
|
||||
|
@ -127,7 +127,7 @@ namespace {
|
||||
|
||||
// Do not remove the comment below, so we get merge conflict in
|
||||
// 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<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
|
||||
|
@ -415,6 +415,7 @@ BufferParams::BufferParams()
|
||||
html_math_img_scale = 1.0;
|
||||
|
||||
output_sync = false;
|
||||
use_refstyle = true;
|
||||
}
|
||||
|
||||
|
||||
@ -853,6 +854,8 @@ string BufferParams::readToken(Lexer & lex, string const & token,
|
||||
lex >> output_sync;
|
||||
} else if (token == "\\output_sync_macro") {
|
||||
lex >> output_sync_macro;
|
||||
} else if (token == "\\use_refstyle") {
|
||||
lex >> use_refstyle;
|
||||
} else {
|
||||
lyxerr << "BufferParams::readToken(): Unknown token: " <<
|
||||
token << endl;
|
||||
@ -980,6 +983,7 @@ void BufferParams::writeFile(ostream & os) const
|
||||
<< "\n\\use_indices " << convert<string>(use_indices)
|
||||
<< "\n\\paperorientation " << string_orientation[orientation]
|
||||
<< "\n\\suppress_date " << convert<string>(suppress_date)
|
||||
<< "\n\\use_refstyle " << use_refstyle
|
||||
<< '\n';
|
||||
if (isbackgroundcolor == true)
|
||||
os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n';
|
||||
|
@ -405,6 +405,8 @@ public:
|
||||
bool output_sync;
|
||||
/// custom LaTeX macro from user instead our own
|
||||
std::string output_sync_macro;
|
||||
/// use refstyle? or prettyref?
|
||||
bool use_refstyle;
|
||||
|
||||
private:
|
||||
///
|
||||
|
@ -256,6 +256,25 @@ static docstring const ogonek_def = from_ascii(
|
||||
" \\mathchar\"0\\hexnumber@\\symtipasymb0C}{#2}}\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
|
||||
@ -507,6 +526,7 @@ char const * simplefeatures[] = {
|
||||
// subfig is handled in BufferParams.cpp
|
||||
"varioref",
|
||||
"prettyref",
|
||||
"refstyle",
|
||||
/*For a successful cooperation of the `wrapfig' package with the
|
||||
`float' package you should load the `wrapfig' package *after*
|
||||
the `float' package. See the caption package documentation
|
||||
@ -900,6 +920,9 @@ docstring const LaTeXFeatures::getMacros() const
|
||||
|
||||
// floats
|
||||
getFloatDefinitions(macros);
|
||||
|
||||
if (mustProvide("refstyle"))
|
||||
macros << lyxref_def << '\n';
|
||||
|
||||
// change tracking
|
||||
if (mustProvide("ct-dvipost"))
|
||||
|
@ -2311,7 +2311,7 @@ void LyXAction::init()
|
||||
pageref -- <page> \n
|
||||
vpageref -- on <page> \n
|
||||
vref -- <reference> on <page> \n
|
||||
prettyref -- Formatted reference
|
||||
formatted -- Formatted reference
|
||||
* \endvar
|
||||
*/
|
||||
{ LFUN_INSET_INSERT, "inset-insert", Noop, Edit },
|
||||
|
@ -1118,6 +1118,8 @@ GuiDocument::GuiDocument(GuiView & lv)
|
||||
this, SLOT(browseMaster()));
|
||||
connect(latexModule->suppressDateCB, SIGNAL(clicked()),
|
||||
this, SLOT(change_adaptor()));
|
||||
connect(latexModule->refstyleCB, SIGNAL(clicked()),
|
||||
this, SLOT(change_adaptor()));
|
||||
|
||||
// postscript drivers
|
||||
for (int n = 0; tex_graphics[n][0]; ++n) {
|
||||
@ -2106,6 +2108,7 @@ void GuiDocument::applyView()
|
||||
|
||||
// date
|
||||
bp_.suppress_date = latexModule->suppressDateCB->isChecked();
|
||||
bp_.use_refstyle = latexModule->refstyleCB->isChecked();
|
||||
|
||||
// biblio
|
||||
bp_.setCiteEngine(ENGINE_BASIC);
|
||||
@ -2531,6 +2534,7 @@ void GuiDocument::paramsToDialog()
|
||||
|
||||
// date
|
||||
latexModule->suppressDateCB->setChecked(bp_.suppress_date);
|
||||
latexModule->refstyleCB->setChecked(bp_.use_refstyle);
|
||||
|
||||
// biblio
|
||||
biblioModule->citeDefaultRB->setChecked(
|
||||
|
@ -6,7 +6,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>341</width>
|
||||
<height>319</height>
|
||||
<height>442</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -187,7 +187,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<item row="6" column="1">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -200,6 +200,13 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</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>
|
||||
</widget>
|
||||
<tabstops>
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "InsetRef.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
#include "BufferParams.h"
|
||||
#include "Cursor.h"
|
||||
#include "DispatchResult.h"
|
||||
#include "InsetLabel.h"
|
||||
@ -50,7 +51,7 @@ bool InsetRef::isCompatibleCommand(string const & s) {
|
||||
|| s == "pageref"
|
||||
|| s == "vref"
|
||||
|| s == "vpageref"
|
||||
|| s == "prettyref"
|
||||
|| s == "formatted"
|
||||
|| s == "eqref"
|
||||
|| s == "nameref";
|
||||
}
|
||||
@ -70,11 +71,24 @@ ParamInfo const & InsetRef::findInfo(string const & /* cmdName */)
|
||||
|
||||
int InsetRef::latex(odocstream & os, OutputParams const & runparams) const
|
||||
{
|
||||
// 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, getCmdName());
|
||||
p["reference"] = getParam("reference");
|
||||
os << p.getCommand(runparams);
|
||||
string const cmd = getCmdName();
|
||||
docstring const ref = getParam("reference");
|
||||
if (cmd != "formatted") {
|
||||
// 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);
|
||||
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;
|
||||
}
|
||||
|
||||
@ -211,9 +225,14 @@ void InsetRef::validate(LaTeXFeatures & features) const
|
||||
string const cmd = getCmdName();
|
||||
if (cmd == "vref" || cmd == "vpageref")
|
||||
features.require("varioref");
|
||||
else if (cmd == "prettyref")
|
||||
features.require("prettyref");
|
||||
else if (cmd == "eqref")
|
||||
else if (getCmdName() == "formatted") {
|
||||
if (buffer().params().use_refstyle) {
|
||||
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");
|
||||
else if (cmd == "nameref")
|
||||
features.require("nameref");
|
||||
@ -226,7 +245,7 @@ InsetRef::type_info InsetRef::types[] = {
|
||||
{ "pageref", N_("Page Number"), N_("Page: ")},
|
||||
{ "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
|
||||
{ "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:")},
|
||||
{ "", "", "" }
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user