* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
- * \author André Pönitz
+ * \author André Pönitz
+ * \author Uwe Stöhr
*
* Full author contact details are available in file CREDITS.
*/
string h_textclass = "article";
string h_options = string();
string h_language = "english";
-string h_inputencoding = "latin1";
+string h_inputencoding = "auto";
string h_fontscheme = "default";
string h_graphics = "default";
string h_paperfontsize = "default";
if (opts.empty())
return;
+ // the last language option is the document language (for babel and LyX)
+ // the last size option is the document font size
+ vector<string>::iterator it;
+ vector<string>::iterator position = opts.begin();
for (; *what; ++what) {
- vector<string>::iterator it = find(opts.begin(), opts.end(), *what);
+ it = find(opts.begin(), opts.end(), *what);
if (it != opts.end()) {
- //cerr << "### found option '" << *what << "'\n";
- target = *what;
+ if (it >= position) {
+ target = *what;
+ position = it;
+ }
+ // remove found options from the list
opts.erase(it);
- return;
}
}
}
while (p.good()) {
Token const & t = p.get_token();
if (t.asInput() == ",") {
- options.push_back(option);
+ options.push_back(trim(option));
option.erase();
} else if (t.asInput() == "=") {
option += '=';
}
if (!option.empty())
- options.push_back(option);
+ options.push_back(trim(option));
return options;
}
else if (name == "fontenc")
; // ignore this
else if (name == "inputenc") {
- h_inputencoding = opts;
+ // only set when there is not more than one inputenc option
+ // therefore check for the "," character
+ if (opts.find(",", 0) == string::npos)
+ h_inputencoding = opts;
options.clear();
} else if (name == "makeidx")
; // ignore this
void end_preamble(ostream & os, TextClass const & /*textclass*/)
{
- os << "#LyX file created by tex2lyx 0.1.2\n"
+ os << "#LyX file created by tex2lyx " << PACKAGE_VERSION << "\n"
<< "\\lyxformat 246\n"
<< "\\begin_document\n"
<< "\\begin_header\n"
- << "\\textclass " << h_textclass << "\n"
- << "\\begin_preamble\n" << h_preamble.str() << "\n\\end_preamble\n";
+ << "\\textclass " << h_textclass << "\n";
+ if (!h_preamble.str().empty())
+ os << "\\begin_preamble\n" << h_preamble.str() << "\n\\end_preamble\n";
if (!h_options.empty())
- os << "\\options " << h_options << "\n";
+ os << "\\options " << h_options << "\n";
os << "\\language " << h_language << "\n"
<< "\\inputencoding " << h_inputencoding << "\n"
<< "\\fontscheme " << h_fontscheme << "\n"
}
else if (t.cs() == "documentclass") {
- vector<string> opts;
- split(p.getArg('[', ']'), opts, ',');
+ vector<string> opts = split_options(p.getArg('[', ']'));
handle_opt(opts, known_languages, h_language);
if (is_known(h_language, known_french_languages))
h_language = "french";
*
* \author André Pönitz
* \author Jean-Marc Lasgouttes
+ * \author Uwe Stöhr
*
* Full author contact details are available in file CREDITS.
*/
Context & context)
{
LayoutPtr newlayout;
+ // store the current selectlanguage to be used after \foreignlanguage
+ string selectlang;
// Store the latest bibliographystyle (needed for bibtex inset)
string bibliographystyle;
bool const use_natbib = used_packages.find("natbib") != used_packages.end();
eat_whitespace(p, os, context, false);
}
+ else if (t.cs() == "selectlanguage") {
+ context.check_layout(os);
+ // save the language for the case that a \foreignlanguage is used
+ selectlang = subst(p.verbatim_item(), "\n", " ");
+ os << "\\lang " << selectlang << "\n";
+
+ }
+
+ else if (t.cs() == "foreignlanguage") {
+ context.check_layout(os);
+ os << "\n\\lang " << subst(p.verbatim_item(), "\n", " ") << "\n";
+ os << subst(p.verbatim_item(), "\n", " ");
+ // set back to last selectlanguage
+ os << "\n\\lang " << selectlang << "\n";
+ }
+
+ else if (t.cs() == "inputencoding")
+ // write nothing because this is done by LyX using the "\lang"
+ // information given by selectlanguage and foreignlanguage
+ subst(p.verbatim_item(), "\n", " ");
+
else if (t.cs() == "LyX" || t.cs() == "TeX"
|| t.cs() == "LaTeX") {
context.check_layout(os);