"rotfloat", "splitidx", "setspace", "subscript", "textcomp", "tipa", "tipx",
"tone", "ulem", "url", "varioref", "verbatim", "wrapfig", "xcolor", "xunicode", 0};
-// used for the handling of \newindex
-int index_number = 0;
-
// codes used to remove packages that are loaded automatically by LyX.
// Syntax: package_beg_sep<name>package_mid_sep<package loading code>package_end_sep
const char package_beg_sep = '\001';
Preamble::Preamble() : one_language(true), explicit_babel(false),
- title_layout_found(false), h_font_cjk_set(false)
+ title_layout_found(false), index_number(0), h_font_cjk_set(false),
+ h_use_microtype(false)
{
//h_backgroundcolor;
//h_boxbgcolor;
h_secnumdepth = "3";
h_shortcut[0] = "idx";
h_spacing = "single";
+ h_save_transient_properties = "true";
h_suppress_date = "false";
h_textclass = "article";
h_tocdepth = "3";
h_use_geometry = "false";
h_use_default_options = "false";
h_use_hyperref = "false";
+ h_use_microtype = false;
h_use_refstyle = false;
h_use_packages["amsmath"] = "1";
h_use_packages["amssymb"] = "0";
void Preamble::handle_package(Parser &p, string const & name,
- string const & opts, bool in_lyx_preamble)
+ string const & opts, bool in_lyx_preamble,
+ bool detectEncoding)
{
vector<string> options = split_options(opts);
add_package(name, options);
if (is_known(name, known_roman_fonts) || is_known(name, known_sans_fonts)
|| is_known(name, known_typewriter_fonts) || is_known(name, known_math_fonts))
;
-
+ //"On". See the enum Package in BufferParams.h if you thought that "2" should have been "42"
else if (name == "amsmath" || name == "amssymb" || name == "cancel" ||
name == "esint" || name == "mhchem" || name == "mathdots" ||
name == "mathtools" || name == "stackrel" ||
string const encoding = options.back();
Encoding const * const enc = encodings.fromLaTeXName(
encoding, Encoding::inputenc, true);
- if (!enc)
- cerr << "Unknown encoding " << encoding << ". Ignoring." << std::endl;
- else {
+ if (!enc) {
+ if (!detectEncoding)
+ cerr << "Unknown encoding " << encoding
+ << ". Ignoring." << std::endl;
+ } else {
if (!enc->unsafe() && options.size() == 1 && one_language == true)
h_inputencoding = enc->name();
p.setEncoding(enc->iconvName());
h_options += ',' + join(options, ",");
}
}
+ else if (name == "microtype") {
+ //we internally support only microtype without params
+ if (options.empty())
+ h_use_microtype = true;
+ else
+ h_preamble << "\\usepackage[" << opts << "]{microtype}";
+ }
else if (!in_lyx_preamble) {
if (options.empty())
}
// We need to do something with the options...
- if (!options.empty())
+ if (!options.empty() && !detectEncoding)
cerr << "Ignoring options '" << join(options, ",")
<< "' of package " << name << '.' << endl;
<< "\\lyxformat " << LYX_FORMAT << '\n'
<< "\\begin_document\n"
<< "\\begin_header\n"
+ << "\\save_transient_properties " << h_save_transient_properties << "\n"
<< "\\origin " << origin << "\n"
<< "\\textclass " << h_textclass << "\n";
string const raw = subdoc ? empty_string() : h_preamble.str();
<< ' ' << h_font_tt_scale[1] << '\n';
if (!h_font_cjk.empty())
os << "\\font_cjk " << h_font_cjk << '\n';
- os << "\\graphics " << h_graphics << '\n'
+ os << "\\use_microtype " << h_use_microtype << '\n'
+ << "\\graphics " << h_graphics << '\n'
<< "\\default_output_format " << h_default_output_format << "\n"
<< "\\output_sync " << h_output_sync << "\n";
if (h_output_sync == "1")
{
// initialize fixed types
special_columns_['D'] = 3;
+ parse(p, forceclass, false, tc);
+}
+
+
+void Preamble::parse(Parser & p, string const & forceclass,
+ bool detectEncoding, TeX2LyXDocClass & tc)
+{
bool is_full_document = false;
bool is_lyx_file = false;
bool in_lyx_preamble = false;
}
p.reset();
+ if (detectEncoding && !is_full_document)
+ return;
+
while (is_full_document && p.good()) {
+ if (detectEncoding && h_inputencoding != "auto" &&
+ h_inputencoding != "default")
+ return;
+
Token const & t = p.get_token();
#ifdef FILEDEBUG
- cerr << "t: " << t << "\n";
+ if (!detectEncoding)
+ cerr << "t: " << t << '\n';
#endif
//
if (comment.size() > magicXeLaTeX.size()
&& comment.substr(0, magicXeLaTeX.size()) == magicXeLaTeX
&& h_inputencoding == "auto") {
- cerr << "XeLaTeX comment found, switching to UTF8\n";
+ if (!detectEncoding)
+ cerr << "XeLaTeX comment found, switching to UTF8\n";
h_inputencoding = "utf8";
}
smatch sub;
// check the case that a standard color is used
if (space.empty() && is_known(argument, known_basic_colors)) {
h_fontcolor = rgbcolor2code(argument);
- preamble.registerAutomaticallyLoadedPackage("color");
+ registerAutomaticallyLoadedPackage("color");
} else if (space.empty() && argument == "document_fontcolor")
- preamble.registerAutomaticallyLoadedPackage("color");
+ registerAutomaticallyLoadedPackage("color");
// check the case that LyX's document_fontcolor is defined
// but not used for \color
else {
if (is_known(argument, known_basic_colors)) {
h_backgroundcolor = rgbcolor2code(argument);
} else if (argument == "page_backgroundcolor")
- preamble.registerAutomaticallyLoadedPackage("color");
+ registerAutomaticallyLoadedPackage("color");
// check the case that LyX's page_backgroundcolor is defined
// but not used for \pagecolor
else {
vector<string>::const_iterator end = vecnames.end();
for (; it != end; ++it)
handle_package(p, trimSpaceAndEol(*it), options,
- in_lyx_preamble);
+ in_lyx_preamble, detectEncoding);
}
else if (t.cs() == "inputencoding") {
string const encoding = p.getArg('{','}');
Encoding const * const enc = encodings.fromLaTeXName(
encoding, Encoding::inputenc, true);
- if (!enc)
- cerr << "Unknown encoding " << encoding << ". Ignoring." << std::endl;
- else {
+ if (!enc) {
+ if (!detectEncoding)
+ cerr << "Unknown encoding " << encoding
+ << ". Ignoring." << std::endl;
+ } else {
if (!enc->unsafe())
h_inputencoding = enc->name();
p.setEncoding(enc->iconvName());
}
+string Preamble::parseEncoding(Parser & p, string const & forceclass)
+{
+ TeX2LyXDocClass dummy;
+ parse(p, forceclass, true, dummy);
+ if (h_inputencoding != "auto" && h_inputencoding != "default")
+ return h_inputencoding;
+ return "";
+}
+
+
string babel2lyx(string const & language)
{
char const * const * where = is_known(language, known_languages);