mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Improve texl2yx refstyle support
- Convert prettyref to the autopackage mechanism - Do not load refstyle automatically if some refstyle preamble code of LyX is found, since LyX will only load the package if an actual reference command is used. This is needed for mixed refstyle/prettyref documents. - Only recognize refstyle commands if refstyle was detected in the preamble - Only recognize prettyref commands if prettyref was detected in the preamble - Add a mixed refstyle/prettyref test case
This commit is contained in:
parent
aa3bbfc984
commit
b59547ebd5
@ -181,9 +181,9 @@ const char * const known_xetex_packages[] = {"arabxetex", "fixlatvian",
|
||||
const char * const known_lyx_packages[] = {"amsbsy", "amsmath", "amssymb",
|
||||
"amstext", "amsthm", "array", "babel", "booktabs", "calc", "CJK", "color",
|
||||
"float", "fontspec", "graphicx", "hhline", "ifthen", "longtable", "makeidx",
|
||||
"multirow", "nomencl", "pdfpages", "refstyle", "rotating", "rotfloat", "splitidx",
|
||||
"setspace", "subscript", "textcomp", "tipa", "tipx", "tone", "ulem", "url",
|
||||
"varioref", "verbatim", "wrapfig", "xunicode", 0};
|
||||
"multirow", "nomencl", "pdfpages", "prettyref", "refstyle", "rotating",
|
||||
"rotfloat", "splitidx", "setspace", "subscript", "textcomp", "tipa", "tipx",
|
||||
"tone", "ulem", "url", "varioref", "verbatim", "wrapfig", "xunicode", 0};
|
||||
|
||||
// used for the handling of \newindex
|
||||
int index_number = 0;
|
||||
@ -522,7 +522,7 @@ Preamble::Preamble() : one_language(true), explicit_babel(false),
|
||||
h_use_geometry = "false";
|
||||
h_use_default_options = "false";
|
||||
h_use_hyperref = "false";
|
||||
h_use_refstyle = "0";
|
||||
h_use_refstyle = false;
|
||||
h_use_packages["amsmath"] = "1";
|
||||
h_use_packages["amssymb"] = "0";
|
||||
h_use_packages["esint"] = "1";
|
||||
@ -897,9 +897,6 @@ void Preamble::handle_package(Parser &p, string const & name,
|
||||
h_language_package = "\\usepackage{" + name + "}";
|
||||
}
|
||||
|
||||
else if (name == "prettyref")
|
||||
; // ignore this FIXME: Use the package separator mechanism instead
|
||||
|
||||
else if (name == "lyxskak") {
|
||||
// ignore this and its options
|
||||
const char * const o[] = {"ps", "mover", 0};
|
||||
@ -910,7 +907,9 @@ void Preamble::handle_package(Parser &p, string const & name,
|
||||
if (name == "splitidx")
|
||||
h_use_indices = "true";
|
||||
if (name == "refstyle")
|
||||
h_use_refstyle = "1";
|
||||
h_use_refstyle = true;
|
||||
else if (name == "prettyref")
|
||||
h_use_refstyle = false;
|
||||
if (!in_lyx_preamble) {
|
||||
h_preamble << package_beg_sep << name
|
||||
<< package_mid_sep << "\\usepackage{"
|
||||
@ -1417,7 +1416,6 @@ void Preamble::parse(Parser & p, string const & forceclass,
|
||||
|| name == "thmref"
|
||||
|| name == "lemref") {
|
||||
p.skip_spaces();
|
||||
preamble.registerAutomaticallyLoadedPackage("refstyle");
|
||||
in_lyx_preamble = true;
|
||||
}
|
||||
// only non-lyxspecific stuff
|
||||
@ -1453,7 +1451,6 @@ void Preamble::parse(Parser & p, string const & forceclass,
|
||||
|| name == "\\providecommand\\corref[1]{\\ref{cor:#1}}"
|
||||
|| name == "\\providecommand\\propref[1]{\\ref{prop:#1}}") {
|
||||
p.skip_spaces();
|
||||
preamble.registerAutomaticallyLoadedPackage("refstyle");
|
||||
in_lyx_preamble = true;
|
||||
}
|
||||
// only non-lyxspecific stuff
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
///
|
||||
std::string notefontcolor() const { return h_notefontcolor; }
|
||||
///
|
||||
std::string refstyle() const { return h_use_refstyle; }
|
||||
bool refstyle() const { return h_use_refstyle; }
|
||||
///
|
||||
bool fontCJKSet() const { return h_font_cjk_set; }
|
||||
///
|
||||
@ -192,7 +192,7 @@ private:
|
||||
std::map<std::string, std::string> h_use_packages;
|
||||
std::string h_use_default_options;
|
||||
std::string h_use_hyperref;
|
||||
std::string h_use_refstyle;
|
||||
bool h_use_refstyle;
|
||||
|
||||
/*!
|
||||
* Add package \p name with options \p options to used_packages.
|
||||
|
@ -5,6 +5,11 @@
|
||||
\textclass article
|
||||
\begin_preamble
|
||||
|
||||
% Load refstyle before prettyref so that prettyref wins.
|
||||
% The real refstyle tests are in test-refstyle-theorems.tex.
|
||||
\usepackage{refstyle}
|
||||
|
||||
|
||||
\def\mycommand{\textquestiondown}
|
||||
|
||||
|
||||
@ -245,7 +250,49 @@ reference "lab:test"
|
||||
|
||||
\end_inset
|
||||
|
||||
.
|
||||
. The command
|
||||
\begin_inset ERT
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\backslash
|
||||
secref
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
|
||||
\begin_inset ERT
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
{
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
lab:test
|
||||
\begin_inset ERT
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
}
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
will be parsed in ERT, since
|
||||
\begin_inset ERT
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
LyX
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
does not support refstyle and prettyref natively at the same time.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Section
|
||||
|
@ -18,7 +18,6 @@
|
||||
\providecommand{\makenomenclature}{\makeglossary}
|
||||
\makenomenclature
|
||||
\usepackage{varioref}
|
||||
\usepackage{prettyref}
|
||||
\usepackage{splitidx}
|
||||
\makeindex
|
||||
\newindex[Index]{idx}
|
||||
@ -54,6 +53,12 @@
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
|
||||
|
||||
% Load refstyle before prettyref so that prettyref wins.
|
||||
% The real refstyle tests are in test-refstyle-theorems.tex.
|
||||
\usepackage{refstyle}
|
||||
\AtBeginDocument{\providecommand\secref[1]{\ref{sec:#1}}}
|
||||
\usepackage{prettyref}
|
||||
|
||||
\def\mycommand{\textquestiondown}
|
||||
|
||||
\begin{document}
|
||||
@ -82,6 +87,8 @@ reference~\pageref{lab:test}, but also equation
|
||||
reference~\eqref{lab:test} (from amsmath package), or varioref's
|
||||
equivalents~\vref{lab:test} and~\vpageref{lab:test}, without
|
||||
forgetting pretty references like~\prettyref{lab:test}.
|
||||
The command \secref{lab:test} will be parsed in ERT, since LyX
|
||||
does not support refstyle and prettyref natively at the same time.
|
||||
|
||||
\section{Cites\index{Cites}}
|
||||
|
||||
|
@ -3407,40 +3407,13 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
skip_spaces_braces(p);
|
||||
}
|
||||
|
||||
else if ((where = is_known(t.cs(), known_ref_commands))) {
|
||||
// \eqref can also occur if refstyle is used
|
||||
if (t.cs() == "eqref" && preamble.refstyle() == "1") {
|
||||
context.check_layout(os);
|
||||
begin_command_inset(os, "ref", "formatted");
|
||||
os << "reference \"eq:"
|
||||
<< convert_command_inset_arg(p.verbatim_item())
|
||||
<< "\"\n";
|
||||
end_inset(os);
|
||||
preamble.registerAutomaticallyLoadedPackage("refstyle");
|
||||
} else {
|
||||
string const opt = p.getOpt();
|
||||
if (opt.empty()) {
|
||||
context.check_layout(os);
|
||||
begin_command_inset(os, "ref",
|
||||
known_coded_ref_commands[where - known_ref_commands]);
|
||||
os << "reference \""
|
||||
<< convert_command_inset_arg(p.verbatim_item())
|
||||
<< "\"\n";
|
||||
end_inset(os);
|
||||
if (t.cs() == "vref" || t.cs() == "vpageref")
|
||||
preamble.registerAutomaticallyLoadedPackage("varioref");
|
||||
} else {
|
||||
// LyX does not yet support optional arguments of ref commands
|
||||
output_ert_inset(os, t.asInput() + '[' + opt + "]{" +
|
||||
p.verbatim_item() + "}", context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if ((where = is_known(t.cs(), known_refstyle_commands))) {
|
||||
// handle refstyle first to catch \eqref which can also occur
|
||||
// without refstyle. Only recognize these commands if
|
||||
// refstyle.sty was found in the preamble (otherwise \eqref
|
||||
// and user defined ref commands could be misdetected).
|
||||
else if ((where = is_known(t.cs(), known_refstyle_commands)) &&
|
||||
preamble.refstyle()) {
|
||||
context.check_layout(os);
|
||||
// \eqref can also occur if refstyle is not used
|
||||
// this case is already handled in the previous else if
|
||||
begin_command_inset(os, "ref", "formatted");
|
||||
os << "reference \"";
|
||||
os << known_refstyle_prefixes[where - known_refstyle_commands]
|
||||
@ -3451,6 +3424,30 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
preamble.registerAutomaticallyLoadedPackage("refstyle");
|
||||
}
|
||||
|
||||
// if refstyle is used, we must not convert \prettyref to a
|
||||
// formatted reference, since that would result in a refstyle command.
|
||||
else if ((where = is_known(t.cs(), known_ref_commands)) &&
|
||||
(t.cs() != "prettyref" || !preamble.refstyle())) {
|
||||
string const opt = p.getOpt();
|
||||
if (opt.empty()) {
|
||||
context.check_layout(os);
|
||||
begin_command_inset(os, "ref",
|
||||
known_coded_ref_commands[where - known_ref_commands]);
|
||||
os << "reference \""
|
||||
<< convert_command_inset_arg(p.verbatim_item())
|
||||
<< "\"\n";
|
||||
end_inset(os);
|
||||
if (t.cs() == "vref" || t.cs() == "vpageref")
|
||||
preamble.registerAutomaticallyLoadedPackage("varioref");
|
||||
else if (t.cs() == "prettyref")
|
||||
preamble.registerAutomaticallyLoadedPackage("prettyref");
|
||||
} else {
|
||||
// LyX does not yet support optional arguments of ref commands
|
||||
output_ert_inset(os, t.asInput() + '[' + opt + "]{" +
|
||||
p.verbatim_item() + '}', context);
|
||||
}
|
||||
}
|
||||
|
||||
else if (use_natbib &&
|
||||
is_known(t.cs(), known_natbib_commands) &&
|
||||
((t.cs() != "citefullauthor" &&
|
||||
|
Loading…
Reference in New Issue
Block a user