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("{"));
|
||||
}
|
||||
docstring rem;
|
||||
docstring const cnvtd = Encodings::fromLaTeXCommand(val, rem,
|
||||
Encodings::TEXT_CMD);
|
||||
docstring const cnvtd = Encodings::fromLaTeXCommand(val,
|
||||
Encodings::TEXT_CMD, rem);
|
||||
if (!cnvtd.empty()) {
|
||||
// it did, so we'll take that bit and proceed with what's left
|
||||
ret += cnvtd;
|
||||
|
@ -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 it = unicodesymbols.begin();
|
||||
for (combining = false; it != end; ++it) {
|
||||
docstring const math = it->second.mathcommand;
|
||||
docstring const text = it->second.textcommand;
|
||||
if (math == cmd || text == cmd) {
|
||||
if ((cmdtype && MATH_CMD) && math == cmd) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -436,8 +447,8 @@ char_type Encodings::fromLaTeXCommand(docstring const & cmd, bool & combining)
|
||||
}
|
||||
|
||||
|
||||
docstring Encodings::fromLaTeXCommand(docstring const & cmd, docstring & rem,
|
||||
int cmdtype)
|
||||
docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
|
||||
docstring & rem, set<string> * req)
|
||||
{
|
||||
bool const mathmode = cmdtype & MATH_CMD;
|
||||
bool const textmode = cmdtype & TEXT_CMD;
|
||||
@ -521,6 +532,14 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, docstring & rem,
|
||||
j = k - 1;
|
||||
i = j + 1;
|
||||
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)
|
||||
|
@ -232,7 +232,8 @@ public:
|
||||
* Convert the LaTeX command in \p cmd to the corresponding unicode
|
||||
* 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 {
|
||||
///
|
||||
@ -248,8 +249,8 @@ public:
|
||||
* The \p cmdtype parameter can be used to limit recognized
|
||||
* commands to math or text mode commands only.
|
||||
*/
|
||||
static docstring fromLaTeXCommand(docstring const & cmd,
|
||||
docstring & rem, int cmdtype = MATH_CMD | TEXT_CMD);
|
||||
static docstring fromLaTeXCommand(docstring const & cmd, int cmdtype,
|
||||
docstring & rem, std::set<std::string> * req = 0);
|
||||
/**
|
||||
* Add the preamble snippet needed for the output of \p c to
|
||||
* \p features.
|
||||
|
@ -1821,7 +1821,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
}
|
||||
docstring rem;
|
||||
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)
|
||||
cell->push_back(MathAtom(new InsetMathChar(cmd[i])));
|
||||
if (rem.size()) {
|
||||
@ -1913,8 +1914,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
}
|
||||
}
|
||||
bool is_combining;
|
||||
char_type c =
|
||||
Encodings::fromLaTeXCommand(cmd, is_combining);
|
||||
char_type c = Encodings::fromLaTeXCommand(cmd,
|
||||
Encodings::MATH_CMD | Encodings::TEXT_CMD,
|
||||
is_combining);
|
||||
if (is_combining) {
|
||||
if (cat == catLetter)
|
||||
cmd += '{';
|
||||
@ -1922,7 +1924,9 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
++num_tokens;
|
||||
if (cat == catLetter)
|
||||
cmd += '}';
|
||||
c = Encodings::fromLaTeXCommand(cmd, is_combining);
|
||||
c = Encodings::fromLaTeXCommand(cmd,
|
||||
Encodings::MATH_CMD | Encodings::TEXT_CMD,
|
||||
is_combining);
|
||||
}
|
||||
if (c) {
|
||||
is_unicode_symbol = true;
|
||||
|
@ -599,10 +599,10 @@ void Preamble::handle_package(Parser &p, string const & name,
|
||||
h_font_sc = "true";
|
||||
}
|
||||
|
||||
if (name == "mathpazo")
|
||||
else if (name == "mathpazo")
|
||||
h_font_roman = "palatino";
|
||||
|
||||
if (name == "mathptmx")
|
||||
else if (name == "mathptmx")
|
||||
h_font_roman = "times";
|
||||
|
||||
// sansserif fonts
|
||||
@ -714,17 +714,8 @@ void Preamble::handle_package(Parser &p, string const & name,
|
||||
else if (name == "prettyref")
|
||||
; // 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")
|
||||
; // ignore this
|
||||
; // ignore this FIXME: Use the package separator mechanism instead
|
||||
|
||||
else if (name == "lyxskak") {
|
||||
// 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" ||
|
||||
name == "color" || name == "hhline" || name == "ifthen" ||
|
||||
name == "float" || name == "longtable" || name == "makeidx" ||
|
||||
name == "multirow" || name == "nomencl" || name == "setspace" ||
|
||||
name == "splitidx" || name == "subscript" || name == "ulem" ||
|
||||
name == "url") {
|
||||
name == "color" || name == "float" || name == "hhline" ||
|
||||
name == "ifthen" || name == "longtable" || name == "makeidx" ||
|
||||
name == "multirow" || name == "nomencl" || name == "rotfloat" ||
|
||||
name == "splitidx" || name == "setspace" || name == "subscript" ||
|
||||
name == "textcomp" || name == "ulem" || name == "url" ||
|
||||
name == "varioref" || name == "verbatim" || name == "wrapfig") {
|
||||
if (!in_lyx_preamble)
|
||||
h_preamble << package_beg_sep << name
|
||||
<< package_mid_sep << "\\usepackage{"
|
||||
<< name << '}' << package_end_sep;
|
||||
<< name << "}\n" << package_end_sep;
|
||||
}
|
||||
|
||||
else if (name == "graphicx")
|
||||
@ -750,12 +742,6 @@ void Preamble::handle_package(Parser &p, string const & name,
|
||||
else if (name == "geometry")
|
||||
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")
|
||||
; // ignore this FIXME: Use the package separator mechanism instead
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "Preamble.h"
|
||||
#include "tex2lyx.h"
|
||||
|
||||
#include <iostream>
|
||||
@ -231,6 +232,11 @@ void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode)
|
||||
os << "\\\\";
|
||||
}
|
||||
|
||||
else if (t.cs() == "vref" || t.cs() == "vpageref") {
|
||||
os << t.asInput();
|
||||
preamble.registerAutomaticallyLoadedPackage("varioref");
|
||||
}
|
||||
|
||||
else
|
||||
os << t.asInput();
|
||||
|
||||
|
@ -455,8 +455,11 @@ docstring convert_unicodesymbols(docstring s)
|
||||
}
|
||||
s = s.substr(i);
|
||||
docstring rem;
|
||||
docstring parsed = encodings.fromLaTeXCommand(s, rem,
|
||||
Encodings::TEXT_CMD);
|
||||
set<string> req;
|
||||
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;
|
||||
s = rem;
|
||||
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.
|
||||
parent_context.new_paragraph(os);
|
||||
p.skip_spaces();
|
||||
preamble.registerAutomaticallyLoadedPackage("rotfloat");
|
||||
}
|
||||
|
||||
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.
|
||||
parent_context.new_paragraph(os);
|
||||
p.skip_spaces();
|
||||
preamble.registerAutomaticallyLoadedPackage("wrapfig");
|
||||
}
|
||||
|
||||
else if (name == "minipage") {
|
||||
@ -1333,6 +1338,7 @@ void parse_environment(Parser & p, ostream & os, bool outer,
|
||||
end_inset(os);
|
||||
p.skip_spaces();
|
||||
skip_braces(p); // eat {} that might by set by LyX behind comments
|
||||
preamble.registerAutomaticallyLoadedPackage("verbatim");
|
||||
}
|
||||
|
||||
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())
|
||||
<< "\"\n";
|
||||
end_inset(os);
|
||||
if (t.cs() == "vref" || t.cs() == "vpageref")
|
||||
preamble.registerAutomaticallyLoadedPackage("varioref");
|
||||
|
||||
} else {
|
||||
// LyX does not support optional arguments of ref commands
|
||||
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() + "{"
|
||||
+ 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 (!rem.empty())
|
||||
cerr << "When parsing " << command
|
||||
<< ", result is " << to_utf8(s)
|
||||
<< "+" << to_utf8(rem) << endl;
|
||||
os << to_utf8(s);
|
||||
for (set<string>::const_iterator it = req.begin(); it != req.end(); it++)
|
||||
preamble.registerAutomaticallyLoadedPackage(*it);
|
||||
} else
|
||||
// we did not find a non-ert version
|
||||
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);
|
||||
os << "preview false\n"
|
||||
"filename \"" << outname << "\"\n";
|
||||
if (t.cs() == "verbatiminput")
|
||||
preamble.registerAutomaticallyLoadedPackage("verbatim");
|
||||
}
|
||||
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,
|
||||
// and math commands may be invalid (bug 6797)
|
||||
docstring rem;
|
||||
set<string> req;
|
||||
docstring s = encodings.fromLaTeXCommand(from_utf8(t.asInput()),
|
||||
rem, Encodings::TEXT_CMD);
|
||||
Encodings::TEXT_CMD, rem, &req);
|
||||
if (!s.empty()) {
|
||||
if (!rem.empty())
|
||||
cerr << "When parsing " << t.cs()
|
||||
@ -4039,6 +4055,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
context.check_layout(os);
|
||||
os << to_utf8(s);
|
||||
skip_spaces_braces(p);
|
||||
for (set<string>::const_iterator it = req.begin(); it != req.end(); it++)
|
||||
preamble.registerAutomaticallyLoadedPackage(*it);
|
||||
}
|
||||
//cerr << "#: " << t << " mode: " << mode << endl;
|
||||
// heuristic: read up to next non-nested space
|
||||
|
Loading…
Reference in New Issue
Block a user