mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Beautify output of \usepckage statements (each statement is on its own line
now) and move more packages to the new exclude mechanism. The remaining ones are not so easy. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40442 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b37abaf655
commit
bb0432d74a
@ -175,8 +175,8 @@ docstring convertLaTeXCommands(docstring const & str)
|
|||||||
val.insert(2, from_ascii("{"));
|
val.insert(2, from_ascii("{"));
|
||||||
}
|
}
|
||||||
docstring rem;
|
docstring rem;
|
||||||
docstring const cnvtd = Encodings::fromLaTeXCommand(val, rem,
|
docstring const cnvtd = Encodings::fromLaTeXCommand(val,
|
||||||
Encodings::TEXT_CMD);
|
Encodings::TEXT_CMD, rem);
|
||||||
if (!cnvtd.empty()) {
|
if (!cnvtd.empty()) {
|
||||||
// it did, so we'll take that bit and proceed with what's left
|
// it did, so we'll take that bit and proceed with what's left
|
||||||
ret += cnvtd;
|
ret += cnvtd;
|
||||||
|
@ -1006,7 +1006,7 @@ void BufferParams::writeFile(ostream & os) const
|
|||||||
<< "\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\\justification " << convert<string>(justification)
|
<< "\n\\justification " << convert<string>(justification)
|
||||||
<< "\n\\use_refstyle " << use_refstyle
|
<< "\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';
|
||||||
|
@ -420,15 +420,26 @@ bool Encodings::latexMathChar(char_type c, bool mathmode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char_type Encodings::fromLaTeXCommand(docstring const & cmd, bool & combining)
|
char_type Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
|
||||||
|
bool & combining, set<string> * req)
|
||||||
{
|
{
|
||||||
CharInfoMap::const_iterator const end = unicodesymbols.end();
|
CharInfoMap::const_iterator const end = unicodesymbols.end();
|
||||||
CharInfoMap::const_iterator it = unicodesymbols.begin();
|
CharInfoMap::const_iterator it = unicodesymbols.begin();
|
||||||
for (combining = false; it != end; ++it) {
|
for (combining = false; it != end; ++it) {
|
||||||
docstring const math = it->second.mathcommand;
|
docstring const math = it->second.mathcommand;
|
||||||
docstring const text = it->second.textcommand;
|
docstring const text = it->second.textcommand;
|
||||||
if (math == cmd || text == cmd) {
|
if ((cmdtype && MATH_CMD) && math == cmd) {
|
||||||
combining = it->second.combining;
|
combining = it->second.combining;
|
||||||
|
if (req && it->second.mathfeature &&
|
||||||
|
!it->second.mathpreamble.empty())
|
||||||
|
req->insert(it->second.mathpreamble);
|
||||||
|
return it->first;
|
||||||
|
}
|
||||||
|
if ((cmdtype & TEXT_CMD) && text == cmd) {
|
||||||
|
combining = it->second.combining;
|
||||||
|
if (req && it->second.textfeature &&
|
||||||
|
!it->second.textpreamble.empty())
|
||||||
|
req->insert(it->second.textpreamble);
|
||||||
return it->first;
|
return it->first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -436,8 +447,8 @@ char_type Encodings::fromLaTeXCommand(docstring const & cmd, bool & combining)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
docstring Encodings::fromLaTeXCommand(docstring const & cmd, docstring & rem,
|
docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
|
||||||
int cmdtype)
|
docstring & rem, set<string> * req)
|
||||||
{
|
{
|
||||||
bool const mathmode = cmdtype & MATH_CMD;
|
bool const mathmode = cmdtype & MATH_CMD;
|
||||||
bool const textmode = cmdtype & TEXT_CMD;
|
bool const textmode = cmdtype & TEXT_CMD;
|
||||||
@ -521,6 +532,14 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, docstring & rem,
|
|||||||
j = k - 1;
|
j = k - 1;
|
||||||
i = j + 1;
|
i = j + 1;
|
||||||
unicmd_size = cur_size;
|
unicmd_size = cur_size;
|
||||||
|
if (req) {
|
||||||
|
if (math == tmp && it->second.mathfeature &&
|
||||||
|
!it->second.mathpreamble.empty())
|
||||||
|
req->insert(it->second.mathpreamble);
|
||||||
|
if (text == tmp && it->second.textfeature &&
|
||||||
|
!it->second.textpreamble.empty())
|
||||||
|
req->insert(it->second.textpreamble);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unicmd_size)
|
if (unicmd_size)
|
||||||
|
@ -232,7 +232,8 @@ public:
|
|||||||
* Convert the LaTeX command in \p cmd to the corresponding unicode
|
* Convert the LaTeX command in \p cmd to the corresponding unicode
|
||||||
* point and set \p combining to true if it is a combining symbol
|
* point and set \p combining to true if it is a combining symbol
|
||||||
*/
|
*/
|
||||||
static char_type fromLaTeXCommand(docstring const & cmd, bool & combining);
|
static char_type fromLaTeXCommand(docstring const & cmd, int cmdtype,
|
||||||
|
bool & combining, std::set<std::string> * req = 0);
|
||||||
///
|
///
|
||||||
enum LatexCmd {
|
enum LatexCmd {
|
||||||
///
|
///
|
||||||
@ -248,8 +249,8 @@ public:
|
|||||||
* The \p cmdtype parameter can be used to limit recognized
|
* The \p cmdtype parameter can be used to limit recognized
|
||||||
* commands to math or text mode commands only.
|
* commands to math or text mode commands only.
|
||||||
*/
|
*/
|
||||||
static docstring fromLaTeXCommand(docstring const & cmd,
|
static docstring fromLaTeXCommand(docstring const & cmd, int cmdtype,
|
||||||
docstring & rem, int cmdtype = MATH_CMD | TEXT_CMD);
|
docstring & rem, std::set<std::string> * req = 0);
|
||||||
/**
|
/**
|
||||||
* Add the preamble snippet needed for the output of \p c to
|
* Add the preamble snippet needed for the output of \p c to
|
||||||
* \p features.
|
* \p features.
|
||||||
|
@ -1821,7 +1821,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
}
|
}
|
||||||
docstring rem;
|
docstring rem;
|
||||||
do {
|
do {
|
||||||
cmd = Encodings::fromLaTeXCommand(cmd, rem);
|
cmd = Encodings::fromLaTeXCommand(cmd,
|
||||||
|
Encodings::MATH_CMD | Encodings::TEXT_CMD, rem);
|
||||||
for (size_t i = 0; i < cmd.size(); ++i)
|
for (size_t i = 0; i < cmd.size(); ++i)
|
||||||
cell->push_back(MathAtom(new InsetMathChar(cmd[i])));
|
cell->push_back(MathAtom(new InsetMathChar(cmd[i])));
|
||||||
if (rem.size()) {
|
if (rem.size()) {
|
||||||
@ -1913,8 +1914,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool is_combining;
|
bool is_combining;
|
||||||
char_type c =
|
char_type c = Encodings::fromLaTeXCommand(cmd,
|
||||||
Encodings::fromLaTeXCommand(cmd, is_combining);
|
Encodings::MATH_CMD | Encodings::TEXT_CMD,
|
||||||
|
is_combining);
|
||||||
if (is_combining) {
|
if (is_combining) {
|
||||||
if (cat == catLetter)
|
if (cat == catLetter)
|
||||||
cmd += '{';
|
cmd += '{';
|
||||||
@ -1922,7 +1924,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
|||||||
++num_tokens;
|
++num_tokens;
|
||||||
if (cat == catLetter)
|
if (cat == catLetter)
|
||||||
cmd += '}';
|
cmd += '}';
|
||||||
c = Encodings::fromLaTeXCommand(cmd, is_combining);
|
c = Encodings::fromLaTeXCommand(cmd,
|
||||||
|
Encodings::MATH_CMD | Encodings::TEXT_CMD,
|
||||||
|
is_combining);
|
||||||
}
|
}
|
||||||
if (c) {
|
if (c) {
|
||||||
is_unicode_symbol = true;
|
is_unicode_symbol = true;
|
||||||
|
@ -599,10 +599,10 @@ void Preamble::handle_package(Parser &p, string const & name,
|
|||||||
h_font_sc = "true";
|
h_font_sc = "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == "mathpazo")
|
else if (name == "mathpazo")
|
||||||
h_font_roman = "palatino";
|
h_font_roman = "palatino";
|
||||||
|
|
||||||
if (name == "mathptmx")
|
else if (name == "mathptmx")
|
||||||
h_font_roman = "times";
|
h_font_roman = "times";
|
||||||
|
|
||||||
// sansserif fonts
|
// sansserif fonts
|
||||||
@ -714,17 +714,8 @@ void Preamble::handle_package(Parser &p, string const & name,
|
|||||||
else if (name == "prettyref")
|
else if (name == "prettyref")
|
||||||
; // ignore this FIXME: Use the package separator mechanism instead
|
; // ignore this FIXME: Use the package separator mechanism instead
|
||||||
|
|
||||||
else if (name == "varioref")
|
|
||||||
; // ignore this FIXME: Use the package separator mechanism instead
|
|
||||||
|
|
||||||
else if (name == "verbatim")
|
|
||||||
; // ignore this FIXME: Use the package separator mechanism instead
|
|
||||||
|
|
||||||
else if (name == "textcomp")
|
|
||||||
; // ignore this FIXME: Use the package separator mechanism instead
|
|
||||||
|
|
||||||
else if (name == "pdfpages")
|
else if (name == "pdfpages")
|
||||||
; // ignore this
|
; // ignore this FIXME: Use the package separator mechanism instead
|
||||||
|
|
||||||
else if (name == "lyxskak") {
|
else if (name == "lyxskak") {
|
||||||
// ignore this and its options
|
// ignore this and its options
|
||||||
@ -733,15 +724,16 @@ void Preamble::handle_package(Parser &p, string const & name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (name == "array" || name == "booktabs" || name == "calc" ||
|
else if (name == "array" || name == "booktabs" || name == "calc" ||
|
||||||
name == "color" || name == "hhline" || name == "ifthen" ||
|
name == "color" || name == "float" || name == "hhline" ||
|
||||||
name == "float" || name == "longtable" || name == "makeidx" ||
|
name == "ifthen" || name == "longtable" || name == "makeidx" ||
|
||||||
name == "multirow" || name == "nomencl" || name == "setspace" ||
|
name == "multirow" || name == "nomencl" || name == "rotfloat" ||
|
||||||
name == "splitidx" || name == "subscript" || name == "ulem" ||
|
name == "splitidx" || name == "setspace" || name == "subscript" ||
|
||||||
name == "url") {
|
name == "textcomp" || name == "ulem" || name == "url" ||
|
||||||
|
name == "varioref" || name == "verbatim" || name == "wrapfig") {
|
||||||
if (!in_lyx_preamble)
|
if (!in_lyx_preamble)
|
||||||
h_preamble << package_beg_sep << name
|
h_preamble << package_beg_sep << name
|
||||||
<< package_mid_sep << "\\usepackage{"
|
<< package_mid_sep << "\\usepackage{"
|
||||||
<< name << '}' << package_end_sep;
|
<< name << "}\n" << package_end_sep;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (name == "graphicx")
|
else if (name == "graphicx")
|
||||||
@ -750,12 +742,6 @@ void Preamble::handle_package(Parser &p, string const & name,
|
|||||||
else if (name == "geometry")
|
else if (name == "geometry")
|
||||||
handle_geometry(options);
|
handle_geometry(options);
|
||||||
|
|
||||||
else if (name == "rotfloat")
|
|
||||||
; // ignore this FIXME: Use the package separator mechanism instead
|
|
||||||
|
|
||||||
else if (name == "wrapfig")
|
|
||||||
; // ignore this FIXME: Use the package separator mechanism instead
|
|
||||||
|
|
||||||
else if (name == "subfig")
|
else if (name == "subfig")
|
||||||
; // ignore this FIXME: Use the package separator mechanism instead
|
; // ignore this FIXME: Use the package separator mechanism instead
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
#include "Preamble.h"
|
||||||
#include "tex2lyx.h"
|
#include "tex2lyx.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -231,6 +232,11 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
|
|||||||
os << "\\\\";
|
os << "\\\\";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (t.cs() == "vref" || t.cs() == "vpageref") {
|
||||||
|
os << t.asInput();
|
||||||
|
preamble.registerAutomaticallyLoadedPackage("varioref");
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
os << t.asInput();
|
os << t.asInput();
|
||||||
|
|
||||||
|
@ -455,8 +455,11 @@ docstring convert_unicodesymbols(docstring s)
|
|||||||
}
|
}
|
||||||
s = s.substr(i);
|
s = s.substr(i);
|
||||||
docstring rem;
|
docstring rem;
|
||||||
docstring parsed = encodings.fromLaTeXCommand(s, rem,
|
set<string> req;
|
||||||
Encodings::TEXT_CMD);
|
docstring parsed = encodings.fromLaTeXCommand(s,
|
||||||
|
Encodings::TEXT_CMD, rem, &req);
|
||||||
|
for (set<string>::const_iterator it = req.begin(); it != req.end(); it++)
|
||||||
|
preamble.registerAutomaticallyLoadedPackage(*it);
|
||||||
os << parsed;
|
os << parsed;
|
||||||
s = rem;
|
s = rem;
|
||||||
if (s.empty() || s[0] != '\\')
|
if (s.empty() || s[0] != '\\')
|
||||||
@ -1262,6 +1265,7 @@ void parse_environment(Parser & p, ostream & os, bool outer,
|
|||||||
// we must make sure that the next item gets a \begin_layout.
|
// we must make sure that the next item gets a \begin_layout.
|
||||||
parent_context.new_paragraph(os);
|
parent_context.new_paragraph(os);
|
||||||
p.skip_spaces();
|
p.skip_spaces();
|
||||||
|
preamble.registerAutomaticallyLoadedPackage("rotfloat");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (name == "wrapfigure" || name == "wraptable") {
|
else if (name == "wrapfigure" || name == "wraptable") {
|
||||||
@ -1294,6 +1298,7 @@ void parse_environment(Parser & p, ostream & os, bool outer,
|
|||||||
// we must make sure that the next item gets a \begin_layout.
|
// we must make sure that the next item gets a \begin_layout.
|
||||||
parent_context.new_paragraph(os);
|
parent_context.new_paragraph(os);
|
||||||
p.skip_spaces();
|
p.skip_spaces();
|
||||||
|
preamble.registerAutomaticallyLoadedPackage("wrapfig");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (name == "minipage") {
|
else if (name == "minipage") {
|
||||||
@ -1333,6 +1338,7 @@ void parse_environment(Parser & p, ostream & os, bool outer,
|
|||||||
end_inset(os);
|
end_inset(os);
|
||||||
p.skip_spaces();
|
p.skip_spaces();
|
||||||
skip_braces(p); // eat {} that might by set by LyX behind comments
|
skip_braces(p); // eat {} that might by set by LyX behind comments
|
||||||
|
preamble.registerAutomaticallyLoadedPackage("verbatim");
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (name == "lyxgreyedout") {
|
else if (name == "lyxgreyedout") {
|
||||||
@ -3019,6 +3025,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
<< convert_command_inset_arg(p.verbatim_item())
|
<< convert_command_inset_arg(p.verbatim_item())
|
||||||
<< "\"\n";
|
<< "\"\n";
|
||||||
end_inset(os);
|
end_inset(os);
|
||||||
|
if (t.cs() == "vref" || t.cs() == "vpageref")
|
||||||
|
preamble.registerAutomaticallyLoadedPackage("varioref");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// LyX does not support optional arguments of ref commands
|
// LyX does not support optional arguments of ref commands
|
||||||
handle_ert(os, t.asInput() + '[' + opt + "]{" +
|
handle_ert(os, t.asInput() + '[' + opt + "]{" +
|
||||||
@ -3435,13 +3444,17 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
string command = t.asInput() + "{"
|
string command = t.asInput() + "{"
|
||||||
+ trimSpaceAndEol(p.verbatim_item())
|
+ trimSpaceAndEol(p.verbatim_item())
|
||||||
+ "}";
|
+ "}";
|
||||||
docstring s = encodings.fromLaTeXCommand(from_utf8(command), rem);
|
set<string> req;
|
||||||
|
docstring s = encodings.fromLaTeXCommand(from_utf8(command),
|
||||||
|
Encodings::TEXT_CMD | Encodings::MATH_CMD, rem, &req);
|
||||||
if (!s.empty()) {
|
if (!s.empty()) {
|
||||||
if (!rem.empty())
|
if (!rem.empty())
|
||||||
cerr << "When parsing " << command
|
cerr << "When parsing " << command
|
||||||
<< ", result is " << to_utf8(s)
|
<< ", result is " << to_utf8(s)
|
||||||
<< "+" << to_utf8(rem) << endl;
|
<< "+" << to_utf8(rem) << endl;
|
||||||
os << to_utf8(s);
|
os << to_utf8(s);
|
||||||
|
for (set<string>::const_iterator it = req.begin(); it != req.end(); it++)
|
||||||
|
preamble.registerAutomaticallyLoadedPackage(*it);
|
||||||
} else
|
} else
|
||||||
// we did not find a non-ert version
|
// we did not find a non-ert version
|
||||||
handle_ert(os, command, context);
|
handle_ert(os, command, context);
|
||||||
@ -3575,6 +3588,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
begin_command_inset(os, "include", name);
|
begin_command_inset(os, "include", name);
|
||||||
os << "preview false\n"
|
os << "preview false\n"
|
||||||
"filename \"" << outname << "\"\n";
|
"filename \"" << outname << "\"\n";
|
||||||
|
if (t.cs() == "verbatiminput")
|
||||||
|
preamble.registerAutomaticallyLoadedPackage("verbatim");
|
||||||
}
|
}
|
||||||
end_inset(os);
|
end_inset(os);
|
||||||
}
|
}
|
||||||
@ -4029,8 +4044,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
// Only use text mode commands, since we are in text mode here,
|
// Only use text mode commands, since we are in text mode here,
|
||||||
// and math commands may be invalid (bug 6797)
|
// and math commands may be invalid (bug 6797)
|
||||||
docstring rem;
|
docstring rem;
|
||||||
|
set<string> req;
|
||||||
docstring s = encodings.fromLaTeXCommand(from_utf8(t.asInput()),
|
docstring s = encodings.fromLaTeXCommand(from_utf8(t.asInput()),
|
||||||
rem, Encodings::TEXT_CMD);
|
Encodings::TEXT_CMD, rem, &req);
|
||||||
if (!s.empty()) {
|
if (!s.empty()) {
|
||||||
if (!rem.empty())
|
if (!rem.empty())
|
||||||
cerr << "When parsing " << t.cs()
|
cerr << "When parsing " << t.cs()
|
||||||
@ -4039,6 +4055,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
|||||||
context.check_layout(os);
|
context.check_layout(os);
|
||||||
os << to_utf8(s);
|
os << to_utf8(s);
|
||||||
skip_spaces_braces(p);
|
skip_spaces_braces(p);
|
||||||
|
for (set<string>::const_iterator it = req.begin(); it != req.end(); it++)
|
||||||
|
preamble.registerAutomaticallyLoadedPackage(*it);
|
||||||
}
|
}
|
||||||
//cerr << "#: " << t << " mode: " << mode << endl;
|
//cerr << "#: " << t << " mode: " << mode << endl;
|
||||||
// heuristic: read up to next non-nested space
|
// heuristic: read up to next non-nested space
|
||||||
|
Loading…
Reference in New Issue
Block a user