char const * const known_coded_ref_commands[] = { "ref", "pageref", "vref",
"vpageref", "formatted", "eqref", 0 };
-/**
- * known polyglossia language names (including variants)
- */
-const char * const polyglossia_languages[] = {
-"albanian", "croatian", "hebrew", "norsk", "swedish", "amharic", "czech", "hindi",
-"nynorsk", "syriac", "arabic", "danish", "icelandic", "occitan", "tamil",
-"armenian", "divehi", "interlingua", "polish", "telugu", "asturian", "dutch",
-"irish", "portuges", "thai", "bahasai", "english", "italian", "romanian", "turkish",
-"bahasam", "esperanto", "lao", "russian", "turkmen", "basque", "estonian", "latin",
-"samin", "ukrainian", "bengali", "farsi", "latvian", "sanskrit", "urdu", "brazil",
-"brazilian", "finnish", "lithuanian", "scottish", "usorbian", "breton", "french",
-"lsorbian", "serbian", "vietnamese", "bulgarian", "galician", "magyar", "slovak",
-"welsh", "catalan", "german", "malayalam", "slovenian", "coptic", "greek",
-"marathi", "spanish",
-"american", "ancient", "australian", "british", "monotonic", "newzealand",
-"polytonic", 0};
+char const * const known_refstyle_commands[] = { "algref", "chapref", "corref",
+ "eqref", "enuref", "figref", "fnref", "lemref", "parref", "partref", "propref",
+ "secref", "subref", "tabref", "thmref", 0 };
+
+char const * const known_refstyle_prefixes[] = { "alg", "chap", "cor",
+ "eq", "enu", "fig", "fn", "lem", "par", "part", "prop",
+ "sec", "sub", "tab", "thm", 0 };
-/**
- * the same as polyglossia_languages with .lyx names
- * please keep this in sync with polyglossia_languages line by line!
- */
-const char * const coded_polyglossia_languages[] = {
-"albanian", "croatian", "hebrew", "norsk", "swedish", "amharic", "czech", "hindi",
-"nynorsk", "syriac", "arabic_arabi", "danish", "icelandic", "occitan", "tamil",
-"armenian", "divehi", "interlingua", "polish", "telugu", "asturian", "dutch",
-"irish", "portuges", "thai", "bahasa", "english", "italian", "romanian", "turkish",
-"bahasam", "esperanto", "lao", "russian", "turkmen", "basque", "estonian", "latin",
-"samin", "ukrainian", "bengali", "farsi", "latvian", "sanskrit", "urdu", "brazilian",
-"brazilian", "finnish", "lithuanian", "scottish", "uppersorbian", "breton", "french",
-"lowersorbian", "serbian", "vietnamese", "bulgarian", "galician", "magyar", "slovak",
-"welsh", "catalan", "ngerman", "malayalam", "slovene", "coptic", "greek",
-"marathi", "spanish",
-"american", "ancientgreek", "australian", "british", "greek", "newzealand",
-"polutonikogreek", 0};
/**
* supported CJK encodings
+ * JIS does not work with LyX's encoding conversion
*/
const char * const supported_CJK_encodings[] = {
-"EUC-JP", "KS", "GB", "UTF8", 0};
+"EUC-JP", "KS", "GB", "UTF8",
+"Bg5", /*"JIS",*/ "SJIS", 0};
/**
* the same as supported_CJK_encodings with their corresponding LyX language name
+ * FIXME: The mapping "UTF8" => "chinese-traditional" is only correct for files
+ * created by LyX.
+ * NOTE: "Bg5", "JIS" and "SJIS" are not supported by LyX, on re-export the
+ * encodings "UTF8", "EUC-JP" and "EUC-JP" will be used.
* please keep this in sync with supported_CJK_encodings line by line!
*/
-const char * const coded_supported_CJK_encodings[] = {
-"japanese-cjk", "korean", "chinese-simplified", "chinese-traditional", 0};
-
-string CJK2lyx(string const & encoding)
-{
- char const * const * where = is_known(encoding, supported_CJK_encodings);
- if (where)
- return coded_supported_CJK_encodings[where - supported_CJK_encodings];
- return encoding;
-}
+const char * const supported_CJK_languages[] = {
+"japanese-cjk", "korean", "chinese-simplified", "chinese-traditional",
+"chinese-traditional", /*"japanese-cjk",*/ "japanese-cjk", 0};
/*!
* natbib commands.
char const * const known_coded_phrases[] = {"LyX", "TeX", "LaTeX2e", "LaTeX", 0};
int const known_phrase_lengths[] = {3, 5, 7, 0};
+/// known TIPA combining diacritical marks
+char const * const known_tipa_marks[] = {"textsubwedge", "textsubumlaut",
+"textsubtilde", "textseagull", "textsubbridge", "textinvsubbridge",
+"textsubsquare", "textsubrhalfring", "textsublhalfring", "textsubplus",
+"textovercross", "textsubarch", "textsuperimposetilde", "textraising",
+"textlowering", "textadvancing", "textretracting", "textdoublegrave",
+"texthighrise", "textlowrise", "textrisefall", "textsyllabic",
+"textsubring", 0};
+
+/// TIPA tones that need special handling
+char const * const known_tones[] = {"15", "51", "45", "12", "454", 0};
+
// string to store the float type to be able to determine the type of subfloats
string float_type = "";
}
-void handle_backslash(ostream & os, string const & s)
-{
- for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
- if (*it == '\\')
- os << "\n\\backslash\n";
- else
- os << *it;
- }
-}
-
-
-void handle_ert(ostream & os, string const & s, Context & context)
+void output_ert(ostream & os, string const & s, Context & context)
{
- // We must have a valid layout before outputting the ERT inset.
context.check_layout(os);
- Context newcontext(true, context.textclass);
- begin_inset(os, "ERT");
- os << "\nstatus collapsed\n";
- newcontext.check_layout(os);
for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
if (*it == '\\')
os << "\n\\backslash\n";
else if (*it == '\n') {
- newcontext.new_paragraph(os);
- newcontext.check_layout(os);
+ context.new_paragraph(os);
+ context.check_layout(os);
} else
os << *it;
}
- newcontext.check_end_layout(os);
- end_inset(os);
+ context.check_end_layout(os);
}
-void handle_comment(ostream & os, string const & s, Context & context)
+void output_ert_inset(ostream & os, string const & s, Context & context)
{
- // TODO: Handle this better
+ // We must have a valid layout before outputting the ERT inset.
+ context.check_layout(os);
Context newcontext(true, context.textclass);
+ InsetLayout const & layout = context.textclass.insetLayout(from_ascii("ERT"));
+ if (layout.forcePlainLayout())
+ newcontext.layout = &context.textclass.plainLayout();
begin_inset(os, "ERT");
os << "\nstatus collapsed\n";
- newcontext.check_layout(os);
- handle_backslash(os, s);
- // make sure that our comment is the last thing on the line
- newcontext.new_paragraph(os);
- newcontext.check_layout(os);
- newcontext.check_end_layout(os);
+ output_ert(os, s, newcontext);
end_inset(os);
}
}
context.check_deeper(os);
context.check_layout(os);
- unsigned int optargs = 0;
- while (optargs < context.layout->optargs) {
+ // FIXME: Adjust to format 446!
+ // Since format 446, layouts do not require anymore all optional
+ // arguments before the required ones. Needs to be implemented!
+ int optargs = 0;
+ while (optargs < context.layout->optArgs()) {
eat_whitespace(p, os, context, false);
if (p.next_token().cat() == catEscape ||
p.next_token().character() != '[')
break;
p.get_token(); // eat '['
- begin_inset(os, "Argument\n");
+ // FIXME: Just a workaround. InsetArgument::updateBuffer
+ // will compute a proper ID for all "999" Arguments
+ // (which is also what lyx2lyx produces).
+ // However, tex2lyx should be able to output proper IDs
+ // itself.
+ begin_inset(os, "Argument 999\n");
os << "status collapsed\n\n";
parse_text_in_inset(p, os, FLAG_BRACK_LAST, outer, context);
end_inset(os);
eat_whitespace(p, os, context, false);
++optargs;
}
- unsigned int reqargs = 0;
- while (reqargs < context.layout->reqargs) {
+ int reqargs = 0;
+ while (reqargs < context.layout->requiredArgs()) {
eat_whitespace(p, os, context, false);
if (p.next_token().cat() != catBegin)
break;
p.get_token(); // eat '{'
- begin_inset(os, "Argument\n");
+ // FIXME: Just a workaround. InsetArgument::updateBuffer
+ // will compute a proper ID for all "999" Arguments
+ // (which is also what lyx2lyx produces).
+ // However, tex2lyx should be able to output proper IDs
+ // itself.
+ begin_inset(os, "Argument 999\n");
os << "status collapsed\n\n";
parse_text_in_inset(p, os, FLAG_BRACE_LAST, outer, context);
end_inset(os);
case required:
case req_group:
// This argument contains regular LaTeX
- handle_ert(os, ert + '{', context);
+ output_ert_inset(os, ert + '{', context);
eat_whitespace(p, os, context, false);
if (template_arguments[i] == required)
parse_text(p, os, FLAG_ITEM, outer, context);
break;
}
}
- handle_ert(os, ert, context);
+ output_ert_inset(os, ert, context);
}
if (inner_type != "makebox") {
latex_height = p.getArg('[', ']');
translate_box_len(latex_height, height_value, height_unit, height_special);
- } else
- hor_pos = p.getArg('[', ']');
+ } else {
+ string const opt = p.getArg('[', ']');
+ if (!opt.empty()) {
+ hor_pos = opt;
+ if (hor_pos != "l" && hor_pos != "c" &&
+ hor_pos != "r" && hor_pos != "s") {
+ cerr << "invalid hor_pos " << hor_pos
+ << " for " << inner_type << endl;
+ hor_pos = "c";
+ }
+ }
+ }
if (p.hasOpt()) {
inner_pos = p.getArg('[', ']');
if (!opt.empty()) {
hor_pos = opt;
if (hor_pos != "l" && hor_pos != "c" &&
- hor_pos != "r") {
+ hor_pos != "r" && hor_pos != "s") {
cerr << "invalid hor_pos " << hor_pos
<< " for " << outer_type << endl;
hor_pos = "c";
// If yes, we need to output ERT.
p.pushPosition();
if (inner_flags & FLAG_END)
- p.verbatimEnvironment(inner_type);
+ p.ertEnvironment(inner_type);
else
p.verbatim_item();
p.skip_spaces(true);
}
if (inner_type == "shaded")
ss << "\\begin{shaded}";
- handle_ert(os, ss.str(), parent_context);
+ output_ert_inset(os, ss.str(), parent_context);
if (!inner_type.empty()) {
parse_text(p, os, inner_flags, outer, parent_context);
if (inner_flags & FLAG_END)
- handle_ert(os, "\\end{" + inner_type + '}',
+ output_ert_inset(os, "\\end{" + inner_type + '}',
parent_context);
else
- handle_ert(os, "}", parent_context);
+ output_ert_inset(os, "}", parent_context);
}
if (!outer_type.empty()) {
// If we already read the inner box we have to pop
}
parse_text(p, os, outer_flags, outer, parent_context);
if (outer_flags & FLAG_END)
- handle_ert(os, "\\end{" + outer_type + '}',
+ output_ert_inset(os, "\\end{" + outer_type + '}',
parent_context);
else if (inner_type.empty() && outer_type == "framebox")
// in this case it is already closed later
;
else
- handle_ert(os, "}", parent_context);
+ output_ert_inset(os, "}", parent_context);
}
} else {
// LyX does not like empty positions, so we have
// LyX puts a % after the end of the minipage
if (p.next_token().cat() == catNewline && p.next_token().cs().size() > 1) {
// new paragraph
- //handle_comment(os, "%dummy", parent_context);
+ //output_ert_inset(os, "%dummy", parent_context);
p.get_token();
p.skip_spaces();
parent_context.new_paragraph(os);
}
else if (p.next_token().cat() == catSpace || p.next_token().cat() == catNewline) {
- //handle_comment(os, "%dummy", parent_context);
+ //output_ert_inset(os, "%dummy", parent_context);
p.get_token();
p.skip_spaces();
// We add a protected space if something real follows
if (p.hasOpt()) {
string arg = p.verbatimOption();
os << "lstparams " << '"' << arg << '"' << '\n';
+ if (arg.find("\\color") != string::npos)
+ preamble.registerAutomaticallyLoadedPackage("color");
}
if (in_line)
os << "inline true\n";
context.layout = &parent_context.textclass.plainLayout();
string s;
if (in_line) {
- s = p.plainCommand('!', '!', "lstinline");
- context.new_paragraph(os);
- context.check_layout(os);
+ // set catcodes to verbatim early, just in case.
+ p.setCatcodes(VERBATIM_CATCODES);
+ string delim = p.get_token().asInput();
+ s = p.verbatimStuff(delim);
+// context.new_paragraph(os);
} else
- s = p.plainEnvironment("lstlisting");
- for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
- if (*it == '\\')
- os << "\n\\backslash\n";
- else if (*it == '\n') {
- // avoid adding an empty paragraph at the end
- if (it + 1 != et) {
- context.new_paragraph(os);
- context.check_layout(os);
- }
- } else
- os << *it;
- }
- context.check_end_layout(os);
+ s = p.verbatimEnvironment("lstlisting");
+ output_ert(os, s, context);
end_inset(os);
}
bool const new_layout_allowed = parent_context.new_layout_allowed;
if (specialfont)
parent_context.new_layout_allowed = false;
- handle_ert(os, "\\begin{" + name + "}", parent_context);
+ output_ert_inset(os, "\\begin{" + name + "}", parent_context);
parse_text_snippet(p, os, flags, outer, parent_context);
- handle_ert(os, "\\end{" + name + "}", parent_context);
+ output_ert_inset(os, "\\end{" + name + "}", parent_context);
if (specialfont)
parent_context.new_layout_allowed = new_layout_allowed;
}
}
}
- else if (is_known(name, polyglossia_languages)) {
+ else if (is_known(name, preamble.polyglossia_languages)) {
// We must begin a new paragraph if not already done
if (! parent_context.atParagraphStart()) {
parent_context.check_end_layout(os);
}
// save the language in the context so that it is
// handled by parse_text
- parent_context.font.language = polyglossia2lyx(name);
+ parent_context.font.language = preamble.polyglossia2lyx(name);
parse_text(p, os, FLAG_END, outer, parent_context);
// Just in case the environment is empty
parent_context.extra_stuff.erase();
}
else if (name == "verbatim") {
- os << "\n\\end_layout\n\n\\begin_layout Verbatim\n";
- string const s = p.plainEnvironment("verbatim");
- string::const_iterator it2 = s.begin();
- for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
- if (*it == '\\')
- os << "\\backslash ";
- else if (*it == '\n') {
- it2 = it + 1;
- // avoid adding an empty paragraph at the end
- // FIXME: if there are 2 consecutive spaces at the end ignore it
- // because LyX will re-add a \n
- // This hack must be removed once bug 8049 is fixed!
- if ((it + 1 != et) && (it + 2 != et || *it2 != '\n'))
- os << "\n\\end_layout\n\\begin_layout Verbatim\n";
- } else
- os << *it;
- }
- os << "\n\\end_layout\n\n";
+ // FIXME: this should go in the generic code that
+ // handles environments defined in layout file that
+ // have "PassThru 1". However, the code over there is
+ // already too complicated for my taste.
+ parent_context.new_paragraph(os);
+ Context context(true, parent_context.textclass,
+ &parent_context.textclass[from_ascii("Verbatim")]);
+ string s = p.verbatimEnvironment("verbatim");
+ output_ert(os, s, context);
+ p.skip_spaces();
+ }
+
+ else if (name == "IPA") {
+ eat_whitespace(p, os, parent_context, false);
+ parent_context.check_layout(os);
+ begin_inset(os, "IPA\n");
+ parse_text_in_inset(p, os, FLAG_END, outer, parent_context);
+ end_inset(os);
p.skip_spaces();
- // reset to Standard layout
- os << "\n\\begin_layout Standard\n";
+ preamble.registerAutomaticallyLoadedPackage("tipa");
+ preamble.registerAutomaticallyLoadedPackage("tipx");
}
else if (name == "CJK") {
- // the scheme is \begin{CJK}{encoding}{mapping}{text}
+ // the scheme is \begin{CJK}{encoding}{mapping}text\end{CJK}
// It is impossible to decide if a CJK environment was in its own paragraph or within
// a line. We therefore always assume a paragraph since the latter is a rare case.
eat_whitespace(p, os, parent_context, false);
parent_context.check_end_layout(os);
// store the encoding to be able to reset it
- string const encoding_old = p.encoding_latex_;
+ string const encoding_old = p.getEncoding();
string const encoding = p.getArg('{', '}');
- // SJIS and BIG5 don't work with LaTeX according to the comment in unicode.cpp
- // JIS does not work with LyX's encoding conversion
- if (encoding != "SJIS" && encoding != "BIG5" && encoding != "JIS")
- p.setEncoding(encoding);
- else
- p.setEncoding("utf8");
- // LyX doesn't support the second argument so if
- // this is used we need to output everything as ERT
- string const mapping = p.getArg('{', '}');
- if ( (!mapping.empty() && mapping != " ")
- || (!is_known(encoding, supported_CJK_encodings))) {
+ // FIXME: For some reason JIS does not work. Although the text
+ // in tests/CJK.tex is identical with the SJIS version if you
+ // convert both snippets using the recode command line utility,
+ // the resulting .lyx file contains some extra characters if
+ // you set buggy_encoding to false for JIS.
+ bool const buggy_encoding = encoding == "JIS";
+ if (!buggy_encoding)
+ p.setEncoding(encoding, Encoding::CJK);
+ else {
+ // FIXME: This will read garbage, since the data is not encoded in utf8.
+ p.setEncoding("UTF-8");
+ }
+ // LyX only supports the same mapping for all CJK
+ // environments, so we might need to output everything as ERT
+ string const mapping = trim(p.getArg('{', '}'));
+ char const * const * const where =
+ is_known(encoding, supported_CJK_encodings);
+ if (!buggy_encoding && !preamble.fontCJKSet())
+ preamble.fontCJK(mapping);
+ bool knownMapping = mapping == preamble.fontCJK();
+ if (buggy_encoding || !knownMapping || !where) {
parent_context.check_layout(os);
- handle_ert(os, "\\begin{" + name + "}{" + encoding + "}{" + mapping + "}",
+ output_ert_inset(os, "\\begin{" + name + "}{" + encoding + "}{" + mapping + "}",
parent_context);
- // we must parse the content as verbatim because e.g. SJIS can contain
+ // we must parse the content as verbatim because e.g. JIS can contain
// normally invalid characters
+ // FIXME: This works only for the most simple cases.
+ // Since TeX control characters are not parsed,
+ // things like comments are completely wrong.
string const s = p.plainEnvironment("CJK");
- string::const_iterator it2 = s.begin();
for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
if (*it == '\\')
- handle_ert(os, "\\", parent_context);
+ output_ert_inset(os, "\\", parent_context);
else if (*it == '$')
- handle_ert(os, "$", parent_context);
- else
+ output_ert_inset(os, "$", parent_context);
+ else if (*it == '\n' && it + 1 != et && s.begin() + 1 != it)
+ os << "\n ";
+ else
os << *it;
}
- p.skip_spaces();
- handle_ert(os, "\\end{" + name + "}",
+ output_ert_inset(os, "\\end{" + name + "}",
parent_context);
} else {
- string const lang = CJK2lyx(encoding);
+ string const lang =
+ supported_CJK_languages[where - supported_CJK_encodings];
// store the language because we must reset it at the end
string const lang_old = parent_context.font.language;
parent_context.font.language = lang;
parent_context.font.language = lang_old;
parent_context.new_paragraph(os);
}
- p.encoding_latex_ = encoding_old;
+ p.setEncoding(encoding_old);
p.skip_spaces();
}
else if (name == "lstlisting") {
eat_whitespace(p, os, parent_context, false);
- // FIXME handle the automatic color package loading
- // uwestoehr asks: In what case color is loaded?
parse_listings(p, os, parent_context, false);
p.skip_spaces();
}
}
context.check_deeper(os);
// handle known optional and required arguments
- // layouts require all optional arguments before the required ones
+ // FIXME: Since format 446, layouts do not require anymore all optional
+ // arguments before the required ones. Needs to be implemented!
// Unfortunately LyX can't handle arguments of list arguments (bug 7468):
// It is impossible to place anything after the environment name,
// but before the first \\item.
if (context.layout->latextype == LATEX_ENVIRONMENT) {
bool need_layout = true;
- unsigned int optargs = 0;
- while (optargs < context.layout->optargs) {
+ int optargs = 0;
+ while (optargs < context.layout->optArgs()) {
eat_whitespace(p, os, context, false);
if (p.next_token().cat() == catEscape ||
p.next_token().character() != '[')
context.check_layout(os);
need_layout = false;
}
- begin_inset(os, "Argument\n");
+ // FIXME: Just a workaround. InsetArgument::updateBuffer
+ // will compute a proper ID for all "999" Arguments
+ // (which is also what lyx2lyx produces).
+ // However, tex2lyx should be able to output proper IDs
+ // itself.
+ begin_inset(os, "Argument 999\n");
os << "status collapsed\n\n";
parse_text_in_inset(p, os, FLAG_BRACK_LAST, outer, context);
end_inset(os);
eat_whitespace(p, os, context, false);
++optargs;
}
- unsigned int reqargs = 0;
- while (reqargs < context.layout->reqargs) {
+ int reqargs = 0;
+ while (reqargs < context.layout->requiredArgs()) {
eat_whitespace(p, os, context, false);
if (p.next_token().cat() != catBegin)
break;
context.check_layout(os);
need_layout = false;
}
- begin_inset(os, "Argument\n");
+ // FIXME: Just a workaround. InsetArgument::updateBuffer
+ // will compute a proper ID for all "999" Arguments
+ // (which is also what lyx2lyx produces).
+ // However, tex2lyx should be able to output proper IDs
+ // itself.
+ begin_inset(os, "Argument 999\n");
os << "status collapsed\n\n";
parse_text_in_inset(p, os, FLAG_BRACE_LAST, outer, context);
end_inset(os);
begin_inset(os, "Flex ");
os << to_utf8(newinsetlayout->name()) << '\n'
<< "status collapsed\n";
- parse_text_in_inset(p, os, FLAG_END, false, parent_context, newinsetlayout);
+ if (newinsetlayout->isPassThru()) {
+ string const arg = p.verbatimEnvironment(name);
+ Context context(true, parent_context.textclass,
+ &parent_context.textclass.plainLayout(),
+ parent_context.layout);
+ output_ert(os, arg, parent_context);
+ } else
+ parse_text_in_inset(p, os, FLAG_END, false, parent_context, newinsetlayout);
end_inset(os);
}
parse_arguments("\\begin{" + name + "}", arguments, p, os,
outer, parent_context);
if (contents == verbatim)
- handle_ert(os, p.verbatimEnvironment(name),
+ output_ert_inset(os, p.ertEnvironment(name),
parent_context);
else
parse_text_snippet(p, os, FLAG_END, outer,
parent_context);
- handle_ert(os, "\\end{" + name + "}", parent_context);
+ output_ert_inset(os, "\\end{" + name + "}", parent_context);
if (specialfont)
parent_context.new_layout_allowed = new_layout_allowed;
}
LASSERT(t.cat() == catComment, return);
if (!t.cs().empty()) {
context.check_layout(os);
- handle_comment(os, '%' + t.cs(), context);
+ output_ert_inset(os, '%' + t.cs(), context);
if (p.next_token().cat() == catNewline) {
// A newline after a comment line starts a new
// paragraph
// done (we might get called recursively)
context.new_paragraph(os);
} else
- handle_ert(os, "\n", context);
+ output_ert_inset(os, "\n", context);
eat_whitespace(p, os, context, true);
}
} else {
/// can understand
string const normalize_filename(string const & name)
{
- Parser p(trim(name, "\""));
+ Parser p(name);
ostringstream os;
while (p.good()) {
Token const & t = p.get_token();
} else if (t.cs() == "space") {
os << ' ';
p.skip_spaces();
+ } else if (t.cs() == "string") {
+ // Convert \string" to " and \string~ to ~
+ Token const & n = p.next_token();
+ if (n.asInput() != "\"" && n.asInput() != "~")
+ os << t.asInput();
} else
os << t.asInput();
}
- return os.str();
+ // Strip quotes. This is a bit complicated (see latex_path()).
+ string full = os.str();
+ if (!full.empty() && full[0] == '"') {
+ string base = removeExtension(full);
+ string ext = getExtension(full);
+ if (!base.empty() && base[base.length()-1] == '"')
+ // "a b"
+ // "a b".tex
+ return addExtension(trim(base, "\""), ext);
+ if (full[full.length()-1] == '"')
+ // "a b.c"
+ // "a b.c".tex
+ return trim(full, "\"");
+ }
+ return full;
}
/// Convert \p name from TeX convention (relative to master file) to LyX
/// convention (relative to .lyx file) if it is relative
-void fix_relative_filename(string & name)
+void fix_child_filename(string & name)
{
- if (FileName::isAbsolute(name))
- return;
+ string const absMasterTeX = getMasterFilePath(true);
+ bool const isabs = FileName::isAbsolute(name);
+ // convert from "relative to .tex master" to absolute original path
+ if (!isabs)
+ name = makeAbsPath(name, absMasterTeX).absFileName();
+ bool copyfile = copyFiles();
+ string const absParentLyX = getParentFilePath(false);
+ string abs = name;
+ if (copyfile) {
+ // convert from absolute original path to "relative to master file"
+ string const rel = to_utf8(makeRelPath(from_utf8(name),
+ from_utf8(absMasterTeX)));
+ // re-interpret "relative to .tex file" as "relative to .lyx file"
+ // (is different if the master .lyx file resides in a
+ // different path than the master .tex file)
+ string const absMasterLyX = getMasterFilePath(false);
+ abs = makeAbsPath(rel, absMasterLyX).absFileName();
+ // Do not copy if the new path is impossible to create. Example:
+ // absMasterTeX = "/foo/bar/"
+ // absMasterLyX = "/bar/"
+ // name = "/baz.eps" => new absolute name would be "/../baz.eps"
+ if (contains(name, "/../"))
+ copyfile = false;
+ }
+ if (copyfile) {
+ if (isabs)
+ name = abs;
+ else {
+ // convert from absolute original path to
+ // "relative to .lyx file"
+ name = to_utf8(makeRelPath(from_utf8(abs),
+ from_utf8(absParentLyX)));
+ }
+ }
+ else if (!isabs) {
+ // convert from absolute original path to "relative to .lyx file"
+ name = to_utf8(makeRelPath(from_utf8(name),
+ from_utf8(absParentLyX)));
+ }
+}
- name = to_utf8(makeRelPath(from_utf8(makeAbsPath(name, getMasterFilePath()).absFileName()),
- from_utf8(getParentFilePath())));
+
+void copy_file(FileName const & src, string dstname)
+{
+ if (!copyFiles())
+ return;
+ string const absParent = getParentFilePath(false);
+ FileName dst;
+ if (FileName::isAbsolute(dstname))
+ dst = FileName(dstname);
+ else
+ dst = makeAbsPath(dstname, absParent);
+ string const absMaster = getMasterFilePath(false);
+ FileName const srcpath = src.onlyPath();
+ FileName const dstpath = dst.onlyPath();
+ if (equivalent(srcpath, dstpath))
+ return;
+ if (!dstpath.isDirectory()) {
+ if (!dstpath.createPath()) {
+ cerr << "Warning: Could not create directory for file `"
+ << dst.absFileName() << "´." << endl;
+ return;
+ }
+ }
+ if (dst.isReadableFile()) {
+ if (overwriteFiles())
+ cerr << "Warning: Overwriting existing file `"
+ << dst.absFileName() << "´." << endl;
+ else {
+ cerr << "Warning: Not overwriting existing file `"
+ << dst.absFileName() << "´." << endl;
+ return;
+ }
+ }
+ if (!src.copyTo(dst))
+ cerr << "Warning: Could not copy file `" << src.absFileName()
+ << "´ to `" << dst.absFileName() << "´." << endl;
}
-/// Parse a NoWeb Scrap section. The initial "<<" is already parsed.
+/// Parse a NoWeb Chunk section. The initial "<<" is already parsed.
void parse_noweb(Parser & p, ostream & os, Context & context)
{
// assemble the rest of the keyword
string name("<<");
- bool scrap = false;
+ bool chunk = false;
while (p.good()) {
Token const & t = p.get_token();
if (t.asInput() == ">" && p.next_token().asInput() == ">") {
name += ">>";
p.get_token();
- scrap = (p.good() && p.next_token().asInput() == "=");
- if (scrap)
+ chunk = (p.good() && p.next_token().asInput() == "=");
+ if (chunk)
name += p.get_token().asInput();
break;
}
name += t.asInput();
}
- if (!scrap || !context.new_layout_allowed ||
- !context.textclass.hasLayout(from_ascii("Scrap"))) {
+ if (!chunk || !context.new_layout_allowed ||
+ !context.textclass.hasLayout(from_ascii("Chunk"))) {
cerr << "Warning: Could not interpret '" << name
<< "'. Ignoring it." << endl;
return;
// always must be in an own paragraph.
context.new_paragraph(os);
Context newcontext(true, context.textclass,
- &context.textclass[from_ascii("Scrap")]);
+ &context.textclass[from_ascii("Chunk")]);
newcontext.check_layout(os);
os << name;
while (p.good()) {
else {
ostringstream oss;
Context tmp(false, context.textclass,
- &context.textclass[from_ascii("Scrap")]);
+ &context.textclass[from_ascii("Chunk")]);
tmp.need_end_layout = true;
tmp.check_layout(oss);
os << subst(t.asInput(), "\n", oss.str());
}
- // The scrap chunk is ended by an @ at the beginning of a line.
+ // The chunk is ended by an @ at the beginning of a line.
// After the @ the line may contain a comment and/or
// whitespace, but nothing else.
if (t.asInput() == "@" && p.prev_token().cat() == catNewline &&
// followed by number?
if (p.next_token().cat() == catOther) {
- char c = p.getChar();
- paramtext += c;
+ string s = p.get_token().asInput();
+ paramtext += s;
// number = current arity + 1?
- if (c == arity + '0' + 1)
+ if (s.size() == 1 && s[0] == arity + '0' + 1)
++arity;
else
simple = false;
os << "\n\\def" << ert;
end_inset(os);
} else
- handle_ert(os, command + ert, context);
+ output_ert_inset(os, command + ert, context);
}
Layout const * newlayout = 0;
InsetLayout const * newinsetlayout = 0;
char const * const * where = 0;
- // Store the latest bibliographystyle and nocite{*} option
- // (needed for bibtex inset)
+ // Store the latest bibliographystyle, addcontentslineContent and
+ // nocite{*} option (needed for bibtex inset)
string btprint;
+ string contentslineContent;
string bibliographystyle = "default";
- bool const use_natbib = preamble.isPackageUsed("natbib");
- bool const use_jurabib = preamble.isPackageUsed("jurabib");
+ bool const use_natbib = isProvided("natbib");
+ bool const use_jurabib = isProvided("jurabib");
string last_env;
while (p.good()) {
Token const & t = p.get_token();
- // it is impossible to determine the correct document language if CJK is used.
- // Therefore write a note at the beginning of the document
- if (have_CJK) {
- context.check_layout(os);
- begin_inset(os, "Note Note\n");
- os << "status open\n\\begin_layout Plain Layout\n"
- << "\\series bold\n"
- << "Important information:\n"
- << "\\end_layout\n\n"
- << "\\begin_layout Plain Layout\n"
- << "This document contains text in Chinese, Japanese or Korean.\n"
- << " It was therefore impossible for tex2lyx to set the correct document langue for your document."
- << " Please set in the document settings by yourself!\n"
- << "\\end_layout\n";
- end_inset(os);
- have_CJK = false;
- }
-
// it is impossible to determine the correct encoding for non-CJK Japanese.
// Therefore write a note at the beginning of the document
if (is_nonCJKJapanese) {
<< "Important information:\n"
<< "\\end_layout\n\n"
<< "\\begin_layout Plain Layout\n"
- << "This document is in Japanese (non-CJK).\n"
- << " It was therefore impossible for tex2lyx to determine the correct encoding."
- << " The encoding EUC-JP was assumed. If this is incorrect, please set the correct"
- << " encoding in the document settings.\n"
+ << "The original LaTeX source for this document is in Japanese (pLaTeX).\n"
+ << " It was therefore impossible for tex2lyx to determine the correct encoding.\n"
+ << " The iconv encoding " << p.getEncoding() << " was used.\n"
+ << " If this is incorrect, you must run the tex2lyx program on the command line\n"
+ << " and specify the encoding using the -e command-line switch.\n"
+ << " In addition, you might want to double check that the desired output encoding\n"
+ << " is correctly selected in Document > Settings > Language.\n"
<< "\\end_layout\n";
end_inset(os);
is_nonCJKJapanese = false;
skip_braces(p);
}
+ else if (t.asInput() == "<"
+ && p.next_token().asInput() == "<" && noweb_mode) {
+ p.get_token();
+ parse_noweb(p, os, context);
+ }
+
else if (t.asInput() == "<" && p.next_token().asInput() == "<") {
context.check_layout(os);
begin_inset(os, "Quotes ");
skip_braces(p);
}
- else if (t.asInput() == "<"
- && p.next_token().asInput() == "<" && noweb_mode) {
- p.get_token();
- parse_noweb(p, os, context);
- }
-
else if (t.cat() == catSpace || (t.cat() == catNewline && ! p.isParagraph()))
check_space(p, os, context);
else
cerr << "Warning: Inserting missing ']' in '"
<< s << "'." << endl;
- handle_ert(os, s, context);
+ output_ert_inset(os, s, context);
}
else if (t.cat() == catLetter) {
for (int i = 1; i < *l && p.next_token().isAlnumASCII(); ++i)
phrase += p.get_token().cs();
if (is_known(phrase, known_coded_phrases)) {
- handle_ert(os, phrase, context);
+ output_ert_inset(os, phrase, context);
handled = true;
break;
} else {
if (context.new_layout_allowed)
context.new_paragraph(os);
else
- handle_ert(os, "\\par ", context);
+ output_ert_inset(os, "\\par ", context);
eat_whitespace(p, os, context, true);
}
p.next_token().character() == '-'))
; // ignore it in {}`` or -{}-
else
- handle_ert(os, "{}", context);
+ output_ert_inset(os, "{}", context);
} else if (next.cat() == catEscape &&
is_known(next.cs(), known_quotes) &&
end.cat() == catEnd) {
p.get_token();
} else {
p.putback();
- handle_ert(os, "{", context);
+ output_ert_inset(os, "{", context);
parse_text_snippet(p, os,
FLAG_BRACE_LAST,
outer, context);
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
}
} else if (! context.new_layout_allowed) {
- handle_ert(os, "{", context);
+ output_ert_inset(os, "{", context);
parse_text_snippet(p, os, FLAG_BRACE_LAST,
outer, context);
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
} else if (is_known(next.cs(), known_sizes)) {
// next will change the size, so we must
// reset it here
<< "\n\\shape "
<< context.font.shape << "\n";
} else {
- handle_ert(os, "{", context);
+ output_ert_inset(os, "{", context);
parse_text_snippet(p, os, FLAG_BRACE_LAST,
outer, context);
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
}
}
}
return;
}
cerr << "stray '}' in text\n";
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
}
else if (t.cat() == catComment)
// FIXME: Do this in check_layout()!
context.has_item = false;
if (optarg)
- handle_ert(os, "\\item", context);
+ output_ert_inset(os, "\\item", context);
else
- handle_ert(os, "\\item ", context);
+ output_ert_inset(os, "\\item ", context);
}
if (optarg) {
if (context.layout->labeltype != LABEL_MANUAL) {
// would misinterpret the space as
// item delimiter (bug 7663)
if (contains(s, ' ')) {
- handle_ert(os, s, context);
+ output_ert_inset(os, s, context);
} else {
Parser p2(s + ']');
os << parse_text_snippet(p2,
string key = convert_command_inset_arg(p.verbatim_item());
if (contains(label, '\\') || contains(key, '\\')) {
// LyX can't handle LaTeX commands in labels or keys
- handle_ert(os, t.asInput() + '[' + label +
+ output_ert_inset(os, t.asInput() + '[' + label +
"]{" + p.verbatim_item() + '}',
context);
} else {
skip_braces(p);
p.get_token();
string name = normalize_filename(p.verbatim_item());
- string const path = getMasterFilePath();
+ string const path = getMasterFilePath(true);
// We want to preserve relative / absolute filenames,
// therefore path is only used for testing
// The file extension is in every case ".tex".
if (!Gnumeric_name.empty())
name = Gnumeric_name;
}
- if (makeAbsPath(name, path).exists())
- fix_relative_filename(name);
- else
+ FileName const absname = makeAbsPath(name, path);
+ if (absname.exists()) {
+ fix_child_filename(name);
+ copy_file(absname, name);
+ } else
cerr << "Warning: Could not find file '"
<< name << "'." << endl;
context.check_layout(os);
end_inset(os);
context.check_layout(os);
macro = false;
- // register the packages that are automatically reloaded
+ // register the packages that are automatically loaded
// by the Gnumeric template
registerExternalTemplatePackages("GnumericSpreadsheet");
}
context.check_layout(os);
// FIXME: This is a hack to prevent paragraph
// deletion if it is empty. Handle this better!
- handle_comment(os,
+ output_ert_inset(os,
"%dummy comment inserted by tex2lyx to "
"ensure that this paragraph is not empty",
context);
for (; it != en; ++it)
preamble.registerAutomaticallyLoadedPackage(*it);
} else
- handle_ert(os,
+ output_ert_inset(os,
"\\date{" + p.verbatim_item() + '}',
context);
}
p.skip_spaces();
context.check_layout(os);
p.skip_spaces();
- begin_inset(os, "Caption\n");
- Context newcontext(true, context.textclass);
- newcontext.font = context.font;
+ begin_inset(os, "Caption Standard\n");
+ Context newcontext(true, context.textclass, 0, 0, context.font);
newcontext.check_layout(os);
+ // FIXME InsetArgument is now properly implemented in InsetLayout
+ // (for captions, but also for others)
if (p.next_token().cat() != catEscape &&
p.next_token().character() == '[') {
p.get_token(); // eat '['
- begin_inset(os, "Argument\n");
+ begin_inset(os, "Argument 1\n");
os << "status collapsed\n";
parse_text_in_inset(p, os, FLAG_BRACK_LAST, outer, context);
end_inset(os);
// we must make sure that the caption gets a \begin_layout
os << "\n\\begin_layout Plain Layout";
p.skip_spaces();
- begin_inset(os, "Caption\n");
- Context newcontext(true, context.textclass);
- newcontext.font = context.font;
+ begin_inset(os, "Caption Standard\n");
+ Context newcontext(true, context.textclass,
+ 0, 0, context.font);
newcontext.check_layout(os);
os << caption << "\n";
newcontext.check_end_layout(os);
// output it as ERT
if (p.hasOpt()) {
string opt_arg = convert_command_inset_arg(p.getArg('[', ']'));
- handle_ert(os, t.asInput() + '[' + opt_arg +
+ output_ert_inset(os, t.asInput() + '[' + opt_arg +
"]{" + p.verbatim_item() + '}', context);
} else
- handle_ert(os, t.asInput() + "{" + p.verbatim_item() + '}', context);
+ output_ert_inset(os, t.asInput() + "{" + p.verbatim_item() + '}', context);
}
}
opts["clip"] = string();
string name = normalize_filename(p.verbatim_item());
- string const path = getMasterFilePath();
+ string const path = getMasterFilePath(true);
// We want to preserve relative / absolute filenames,
// therefore path is only used for testing
if (!makeAbsPath(name, path).exists()) {
}
}
- if (makeAbsPath(name, path).exists())
- fix_relative_filename(name);
- else
+ FileName const absname = makeAbsPath(name, path);
+ if (absname.exists()) {
+ fix_child_filename(name);
+ copy_file(absname, name);
+ } else
cerr << "Warning: Could not find graphics file '"
<< name << "'." << endl;
if (s == "\xb1" || s == "\xb3" || s == "\xb2" || s == "\xb5")
os << s;
else
- handle_ert(os, "\\ensuremath{" + s + "}",
+ output_ert_inset(os, "\\ensuremath{" + s + "}",
context);
}
// swallow this
skip_spaces_braces(p);
} else
- handle_ert(os, t.asInput(), context);
+ output_ert_inset(os, t.asInput(), context);
}
else if (t.cs() == "tableofcontents" || t.cs() == "lstlistoflistings") {
end_inset(os);
p.get_token(); // swallow second arg
} else
- handle_ert(os, "\\listof{" + name + "}", context);
+ output_ert_inset(os, "\\listof{" + name + "}", context);
}
else if ((where = is_known(t.cs(), known_text_font_families)))
preamble.registerAutomaticallyLoadedPackage("color");
} else
// for custom defined colors
- handle_ert(os, t.asInput() + "{" + color + "}", context);
+ output_ert_inset(os, t.asInput() + "{" + color + "}", context);
}
else if (t.cs() == "underbar" || t.cs() == "uline") {
string localtime = p.getArg('{', '}');
preamble.registerAuthor(name);
Author const & author = preamble.getAuthor(name);
- // from_ctime() will fail if LyX decides to output the
- // time in the text language. It might also use a wrong
- // time zone (if the original LyX document was exported
- // with a different time zone).
- time_t ptime = from_ctime(localtime);
+ // from_asctime_utc() will fail if LyX decides to output the
+ // time in the text language.
+ time_t ptime = from_asctime_utc(localtime);
if (ptime == static_cast<time_t>(-1)) {
cerr << "Warning: Could not parse time `" << localtime
<< "´ for change tracking, using current time instead.\n";
}
}
+ else if (t.cs() == "textipa") {
+ context.check_layout(os);
+ begin_inset(os, "IPA\n");
+ parse_text_in_inset(p, os, FLAG_ITEM, outer, context);
+ end_inset(os);
+ preamble.registerAutomaticallyLoadedPackage("tipa");
+ preamble.registerAutomaticallyLoadedPackage("tipx");
+ }
+
+ else if (t.cs() == "texttoptiebar" || t.cs() == "textbottomtiebar") {
+ context.check_layout(os);
+ begin_inset(os, "IPADeco " + t.cs().substr(4) + "\n");
+ os << "status open\n";
+ parse_text_in_inset(p, os, FLAG_ITEM, outer, context);
+ end_inset(os);
+ p.skip_spaces();
+ }
+
+ // the TIPA Combining diacritical marks
+ else if (is_known(t.cs(), known_tipa_marks) || t.cs() == "textvertline") {
+ preamble.registerAutomaticallyLoadedPackage("tipa");
+ preamble.registerAutomaticallyLoadedPackage("tipx");
+ context.check_layout(os);
+ if (t.cs() == "textvertline") {
+ os << "|";
+ skip_braces(p);
+ continue;
+ }
+ // try to see whether the string is in unicodesymbols
+ bool termination;
+ docstring rem;
+ string content = trimSpaceAndEol(p.verbatim_item());
+ string command = t.asInput() + "{" + content + "}";
+ set<string> req;
+ docstring s = encodings.fromLaTeXCommand(from_utf8(command),
+ Encodings::TEXT_CMD | Encodings::MATH_CMD,
+ termination, rem, &req);
+ if (!s.empty()) {
+ if (!rem.empty())
+ cerr << "When parsing " << command
+ << ", result is " << to_utf8(s)
+ << "+" << to_utf8(rem) << endl;
+ os << content << to_utf8(s);
+ } else
+ // we did not find a non-ert version
+ output_ert_inset(os, command, context);
+ }
+
+ else if (t.cs() == "tone" ) {
+ context.check_layout(os);
+ // register the tone package
+ preamble.registerAutomaticallyLoadedPackage("tone");
+ string content = trimSpaceAndEol(p.verbatim_item());
+ string command = t.asInput() + "{" + content + "}";
+ // some tones can be detected by unicodesymbols, some need special code
+ if (is_known(content, known_tones)) {
+ os << "\\IPAChar " << command << "\n";
+ continue;
+ }
+ // try to see whether the string is in unicodesymbols
+ bool termination;
+ docstring rem;
+ set<string> req;
+ docstring s = encodings.fromLaTeXCommand(from_utf8(command),
+ Encodings::TEXT_CMD | Encodings::MATH_CMD,
+ termination, 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);
+ } else
+ // we did not find a non-ert version
+ output_ert_inset(os, command, context);
+ }
+
else if (t.cs() == "phantom" || t.cs() == "hphantom" ||
t.cs() == "vphantom") {
context.check_layout(os);
else if (t.cs() == "href") {
context.check_layout(os);
- string target = p.getArg('{', '}');
- string name = p.getArg('{', '}');
+ string target = convert_command_inset_arg(p.verbatim_item());
+ string name = convert_command_inset_arg(p.verbatim_item());
string type;
size_t i = target.find(':');
if (i != string::npos) {
}
else if ((where = is_known(t.cs(), known_ref_commands))) {
- string const opt = p.getOpt();
- if (opt.empty()) {
+ // \eqref can also occur if refstyle is used
+ if (t.cs() == "eqref" && preamble.refstyle() == "1") {
context.check_layout(os);
- begin_command_inset(os, "ref",
- known_coded_ref_commands[where - known_ref_commands]);
- os << "reference \""
+ begin_command_inset(os, "ref", "formatted");
+ os << "reference \"eq:"
<< convert_command_inset_arg(p.verbatim_item())
<< "\"\n";
end_inset(os);
- if (t.cs() == "vref" || t.cs() == "vpageref")
- preamble.registerAutomaticallyLoadedPackage("varioref");
-
+ preamble.registerAutomaticallyLoadedPackage("refstyle");
} else {
- // LyX does not support optional arguments of ref commands
- handle_ert(os, t.asInput() + '[' + opt + "]{" +
+ 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))) {
+ 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]
+ << ":";
+ os << convert_command_inset_arg(p.verbatim_item())
+ << "\"\n";
+ end_inset(os);
+ preamble.registerAutomaticallyLoadedPackage("refstyle");
+ }
+
else if (use_natbib &&
is_known(t.cs(), known_natbib_commands) &&
((t.cs() != "citefullauthor" &&
<< convert_command_inset_arg(p.verbatim_item())
<< "\"\n";
end_inset(os);
+ // Need to set the cite engine if natbib is loaded by
+ // the document class directly
+ if (preamble.citeEngine() == "basic")
+ preamble.citeEngine("natbib");
}
else if (use_jurabib &&
os << "before " << '"' << before << '"' << "\n";
os << "key " << '"' << citation << '"' << "\n";
end_inset(os);
+ // Need to set the cite engine if jurabib is loaded by
+ // the document class directly
+ if (preamble.citeEngine() == "basic")
+ preamble.citeEngine("jurabib");
}
else if (t.cs() == "cite"
end_inset(os);
}
- else if (t.cs() == "printindex") {
+ else if (t.cs() == "printindex" || t.cs() == "printsubindex") {
context.check_layout(os);
- begin_command_inset(os, "index_print", "printindex");
- os << "type \"idx\"\n";
+ string commandname = t.cs();
+ bool star = false;
+ if (p.next_token().asInput() == "*") {
+ commandname += "*";
+ star = true;
+ p.get_token();
+ }
+ begin_command_inset(os, "index_print", commandname);
+ string const indexname = p.getArg('[', ']');
+ if (!star) {
+ if (indexname.empty())
+ os << "type \"idx\"\n";
+ else
+ os << "type \"" << indexname << "\"\n";
+ }
end_inset(os);
skip_spaces_braces(p);
preamble.registerAutomaticallyLoadedPackage("makeidx");
context, "\\lang",
context.font.language, lang);
}
-
- else if (is_known(t.cs().substr(4, string::npos), polyglossia_languages)) {
+
+ else if (prefixIs(t.cs(), "text")
+ && is_known(t.cs().substr(4), preamble.polyglossia_languages)) {
// scheme is \textLANGUAGE{text} where LANGUAGE is in polyglossia_languages[]
string lang;
// We have to output the whole command if it has an option
// check if the option contains a variant, if yes, extract it
string::size_type pos_var = langopts.find("variant");
string::size_type i = langopts.find(',');
- if (pos_var != string::npos){
+ string::size_type k = langopts.find('=', pos_var);
+ if (pos_var != string::npos && i == string::npos) {
string variant;
- if (i == string::npos) {
- variant = langopts.substr(pos_var + 8, langopts.length() - pos_var - 9);
- lang = polyglossia2lyx(variant);
- parse_text_attributes(p, os, FLAG_ITEM, outer,
- context, "\\lang",
- context.font.language, lang);
- }
- else
- handle_ert(os, t.asInput() + langopts, context);
+ variant = langopts.substr(k + 1, langopts.length() - k - 2);
+ lang = preamble.polyglossia2lyx(variant);
+ parse_text_attributes(p, os, FLAG_ITEM, outer,
+ context, "\\lang",
+ context.font.language, lang);
} else
- handle_ert(os, t.asInput() + langopts, context);
+ output_ert_inset(os, t.asInput() + langopts, context);
} else {
- lang = polyglossia2lyx(t.cs().substr(4, string::npos));
+ lang = preamble.polyglossia2lyx(t.cs().substr(4, string::npos));
parse_text_attributes(p, os, FLAG_ITEM, outer,
context, "\\lang",
context.font.language, lang);
else if (t.cs() == "inputencoding") {
// nothing to write here
string const enc = subst(p.verbatim_item(), "\n", " ");
- p.setEncoding(enc);
+ p.setEncoding(enc, Encoding::inputenc);
}
else if ((where = is_known(t.cs(), known_special_chars))) {
os << '"';
skip_braces(p);
} else {
- handle_ert(os, "\\char`", context);
+ output_ert_inset(os, "\\char`", context);
}
} else {
- handle_ert(os, "\\char", context);
+ output_ert_inset(os, "\\char", context);
}
}
else if (t.cs() == "verb") {
context.check_layout(os);
- char const delimiter = p.next_token().character();
- string const arg = p.getArg(delimiter, delimiter);
- ostringstream oss;
- oss << "\\verb" << delimiter << arg << delimiter;
- handle_ert(os, oss.str(), context);
+ // set catcodes to verbatim early, just in case.
+ p.setCatcodes(VERBATIM_CATCODES);
+ string delim = p.get_token().asInput();
+ string const arg = p.verbatimStuff(delim);
+ output_ert_inset(os, "\\verb" + delim + arg + delim, context);
}
// Problem: \= creates a tabstop inside the tabbing environment
// and else an accent. In the latter case we really would want
// \={o} instead of \= o.
else if (t.cs() == "=" && (flags & FLAG_TABBING))
- handle_ert(os, t.asInput(), context);
+ output_ert_inset(os, t.asInput(), context);
// accents (see Table 6 in Comprehensive LaTeX Symbol List)
else if (t.cs().size() == 1
preamble.registerAutomaticallyLoadedPackage(*it);
} else
// we did not find a non-ert version
- handle_ert(os, command, context);
+ output_ert_inset(os, command, context);
}
else if (t.cs() == "\\") {
context.check_layout(os);
if (p.hasOpt())
- handle_ert(os, "\\\\" + p.getOpt(), context);
+ output_ert_inset(os, "\\\\" + p.getOpt(), context);
else if (p.next_token().asInput() == "*") {
p.get_token();
// getOpt() eats the following space if there
// is no optional argument, but that is OK
// here since it has no effect in the output.
- handle_ert(os, "\\\\*" + p.getOpt(), context);
+ output_ert_inset(os, "\\\\*" + p.getOpt(), context);
}
else {
begin_inset(os, "Newline newline");
name += p.get_token().asInput();
context.check_layout(os);
string filename(normalize_filename(p.getArg('{', '}')));
- string const path = getMasterFilePath();
+ string const path = getMasterFilePath(true);
// We want to preserve relative / absolute filenames,
// therefore path is only used for testing
if ((t.cs() == "include" || t.cs() == "input") &&
if (makeAbsPath(filename, path).exists()) {
string const abstexname =
makeAbsPath(filename, path).absFileName();
- string const abslyxname =
- changeExtension(abstexname, ".lyx");
string const absfigname =
changeExtension(abstexname, ".fig");
- fix_relative_filename(filename);
+ fix_child_filename(filename);
string const lyxname =
changeExtension(filename, ".lyx");
+ string const abslyxname = makeAbsPath(
+ lyxname, getParentFilePath(false)).absFileName();
bool xfig = false;
- external = FileName(absfigname).exists();
- if (t.cs() == "input") {
+ if (!skipChildren())
+ external = FileName(absfigname).exists();
+ if (t.cs() == "input" && !skipChildren()) {
string const ext = getExtension(abstexname);
// Combined PS/LaTeX:
}
if (external) {
outname = changeExtension(filename, ".fig");
+ FileName abssrc(changeExtension(abstexname, ".fig"));
+ copy_file(abssrc, outname);
} else if (xfig) {
// Don't try to convert, the result
// would be full of ERT.
outname = filename;
+ FileName abssrc(abstexname);
+ copy_file(abssrc, outname);
} else if (t.cs() != "verbatiminput" &&
+ !skipChildren() &&
tex2lyx(abstexname, FileName(abslyxname),
p.getEncoding())) {
outname = lyxname;
+ // no need to call copy_file
+ // tex2lyx creates the file
} else {
outname = filename;
+ FileName abssrc(abstexname);
+ copy_file(abssrc, outname);
}
} else {
cerr << "Warning: Could not find included file '"
registerExternalTemplatePackages("XFig");
} else {
begin_command_inset(os, "include", name);
+ outname = subst(outname, "\"", "\\\"");
os << "preview false\n"
"filename \"" << outname << "\"\n";
if (t.cs() == "verbatiminput")
else if (t.cs() == "bibliographystyle") {
// store new bibliographystyle
bibliographystyle = p.verbatim_item();
- // If any other command than \bibliography and
- // \nocite{*} follows, we need to output the style
+ // If any other command than \bibliography, \addcontentsline
+ // and \nocite{*} follows, we need to output the style
// (because it might be used by that command).
// Otherwise, it will automatically be output by LyX.
p.pushPosition();
continue;
} else if (t2.cs() == "bibliography")
output = false;
+ else if (t2.cs() == "phantomsection") {
+ output = false;
+ continue;
+ }
+ else if (t2.cs() == "addcontentsline") {
+ // get the 3 arguments of \addcontentsline
+ p.getArg('{', '}');
+ p.getArg('{', '}');
+ contentslineContent = p.getArg('{', '}');
+ // if the last argument is not \refname we must output
+ if (contentslineContent == "\\refname")
+ output = false;
+ }
break;
}
p.popPosition();
if (output) {
- handle_ert(os,
+ output_ert_inset(os,
"\\bibliographystyle{" + bibliographystyle + '}',
context);
}
}
+ else if (t.cs() == "phantomsection") {
+ // we only support this if it occurs between
+ // \bibliographystyle and \bibliography
+ if (bibliographystyle.empty())
+ output_ert_inset(os, "\\phantomsection", context);
+ }
+
+ else if (t.cs() == "addcontentsline") {
+ context.check_layout(os);
+ // get the 3 arguments of \addcontentsline
+ string const one = p.getArg('{', '}');
+ string const two = p.getArg('{', '}');
+ string const three = p.getArg('{', '}');
+ // only if it is a \refname, we support if for the bibtex inset
+ if (contentslineContent != "\\refname") {
+ output_ert_inset(os,
+ "\\addcontentsline{" + one + "}{" + two + "}{"+ three + '}',
+ context);
+ }
+ }
+
else if (t.cs() == "bibliography") {
context.check_layout(os);
+ string BibOpts;
begin_command_inset(os, "bibtex", "bibtex");
if (!btprint.empty()) {
os << "btprint " << '"' << "btPrintAll" << '"' << "\n";
btprint.clear();
}
os << "bibfiles " << '"' << p.verbatim_item() << '"' << "\n";
+ // Do we have addcontentsline?
+ if (contentslineContent == "\\refname") {
+ BibOpts = "bibtotoc";
+ // clear string because next BibTeX inset can be without addcontentsline
+ contentslineContent.clear();
+ }
// Do we have a bibliographystyle set?
- if (!bibliographystyle.empty())
- os << "options " << '"' << bibliographystyle << '"' << "\n";
+ if (!bibliographystyle.empty()) {
+ if (BibOpts.empty())
+ BibOpts = bibliographystyle;
+ else
+ BibOpts = BibOpts + ',' + bibliographystyle;
+ // clear it because each bibtex entry has its style
+ // and we need an empty string to handle \phantomsection
+ bibliographystyle.clear();
+ }
+ os << "options " << '"' << BibOpts << '"' << "\n";
end_inset(os);
}
arg += p.getFullParentheseArg();
arg += p.getFullOpt();
eat_whitespace(p, os, context, false);
- handle_ert(os, arg + '{', context);
- eat_whitespace(p, os, context, false);
+ output_ert_inset(os, arg + '{', context);
parse_text(p, os, FLAG_ITEM, outer, context);
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
} else {
string special = p.getFullOpt();
special += p.getOpt();
- parse_outer_box(p, os, FLAG_ITEM, outer,
- context, t.cs(), special);
+ // LyX does not yet support \framebox without any option
+ if (!special.empty())
+ parse_outer_box(p, os, FLAG_ITEM, outer,
+ context, t.cs(), special);
+ else {
+ eat_whitespace(p, os, context, false);
+ output_ert_inset(os, "\\framebox{", context);
+ parse_text(p, os, FLAG_ITEM, outer, context);
+ output_ert_inset(os, "}", context);
+ }
}
}
arg += p.getFullParentheseArg();
arg += p.getFullOpt();
eat_whitespace(p, os, context, false);
- handle_ert(os, arg + '{', context);
- eat_whitespace(p, os, context, false);
+ output_ert_inset(os, arg + '{', context);
parse_text(p, os, FLAG_ITEM, outer, context);
- handle_ert(os, "}", context);
+ output_ert_inset(os, "}", context);
} else
//the syntax is: \makebox[width][position]{content}
parse_box(p, os, 0, FLAG_ITEM, outer, context,
t.cs() == "providecommand" ||
t.cs() == "providecommandx" ||
name[name.length()-1] == '*')
- handle_ert(os, ert, context);
+ output_ert_inset(os, ert, context);
else {
context.check_layout(os);
begin_inset(os, "FormulaMacro");
CommandMap::iterator it = known_commands.find(command);
if (it != known_commands.end())
known_commands[t.asInput()] = it->second;
- handle_ert(os, ert, context);
+ output_ert_inset(os, ert, context);
}
else if (t.cs() == "hspace" || t.cs() == "vspace") {
name += '*';
if (valid) {
if (value == 1.0)
- handle_ert(os, name + '{' + unit + '}', context);
+ output_ert_inset(os, name + '{' + unit + '}', context);
else if (value == -1.0)
- handle_ert(os, name + "{-" + unit + '}', context);
+ output_ert_inset(os, name + "{-" + unit + '}', context);
else
- handle_ert(os, name + '{' + valstring + unit + '}', context);
+ output_ert_inset(os, name + '{' + valstring + unit + '}', context);
} else
- handle_ert(os, name + '{' + length + '}', context);
+ output_ert_inset(os, name + '{' + length + '}', context);
}
}
begin_inset(os, "Flex ");
os << to_utf8(newinsetlayout->name()) << '\n'
<< "status collapsed\n";
- parse_text_in_inset(p, os, FLAG_ITEM, false, context, newinsetlayout);
+ if (newinsetlayout->isPassThru()) {
+ // set catcodes to verbatim early, just in case.
+ p.setCatcodes(VERBATIM_CATCODES);
+ string delim = p.get_token().asInput();
+ if (delim != "{")
+ cerr << "Warning: bad delimiter for command " << t.asInput() << endl;
+ string const arg = p.verbatimStuff("}");
+ Context newcontext(true, context.textclass);
+ if (newinsetlayout->forcePlainLayout())
+ newcontext.layout = &context.textclass.plainLayout();
+ output_ert(os, arg, newcontext);
+ } else
+
+ parse_text_in_inset(p, os, FLAG_ITEM, false, context, newinsetlayout);
end_inset(os);
}
vector<string> keys;
split_map(arg, opts, keys);
string name = normalize_filename(p.verbatim_item());
- string const path = getMasterFilePath();
+ string const path = getMasterFilePath(true);
// We want to preserve relative / absolute filenames,
// therefore path is only used for testing
if (!makeAbsPath(name, path).exists()) {
pdflatex = true;
}
}
- if (makeAbsPath(name, path).exists())
- fix_relative_filename(name);
- else
+ FileName const absname = makeAbsPath(name, path);
+ if (absname.exists())
+ {
+ fix_child_filename(name);
+ copy_file(absname, name);
+ } else
cerr << "Warning: Could not find file '"
<< name << "'." << endl;
// write output
else if (t.cs() == "loadgame") {
p.skip_spaces();
string name = normalize_filename(p.verbatim_item());
- string const path = getMasterFilePath();
+ string const path = getMasterFilePath(true);
// We want to preserve relative / absolute filenames,
// therefore path is only used for testing
if (!makeAbsPath(name, path).exists()) {
if (!lyxskak_name.empty())
name = lyxskak_name;
}
- if (makeAbsPath(name, path).exists())
- fix_relative_filename(name);
- else
+ FileName const absname = makeAbsPath(name, path);
+ if (absname.exists())
+ {
+ fix_child_filename(name);
+ copy_file(absname, name);
+ } else
cerr << "Warning: Could not find file '"
<< name << "'." << endl;
context.check_layout(os);
bool termination;
docstring rem;
set<string> req;
- docstring s = encodings.fromLaTeXCommand(from_utf8(t.asInput()),
+ string name = t.asInput();
+ // handle some TIPA special characters
+ if (name == "\\textglobfall") {
+ name = "End";
+ skip_braces(p);
+ }
+ if (name == "\\textdoublevertline") {
+ name = "\\textbardbl";
+ skip_braces(p);
+ }
+ if (name == "\\!" ) {
+ if (p.next_token().asInput() == "b") {
+ p.get_token(); // eat 'b'
+ name = "\\texthtb";
+ skip_braces(p);
+ }
+ if (p.next_token().asInput() == "d") {
+ p.get_token();
+ name = "\\texthtd";
+ skip_braces(p);
+ }
+ if (p.next_token().asInput() == "g") {
+ p.get_token();
+ name = "\\texthtg";
+ skip_braces(p);
+ }
+ if (p.next_token().asInput() == "G") {
+ p.get_token();
+ name = "\\texthtscg";
+ skip_braces(p);
+ }
+ if (p.next_token().asInput() == "j") {
+ p.get_token();
+ name = "\\texthtbardotlessj";
+ skip_braces(p);
+ }
+ if (p.next_token().asInput() == "o") {
+ p.get_token();
+ name = "\\textbullseye";
+ skip_braces(p);
+ }
+ }
+ if (name == "\\*" ) {
+ if (p.next_token().asInput() == "k") {
+ p.get_token();
+ name = "\\textturnk";
+ skip_braces(p);
+ }
+ if (p.next_token().asInput() == "r") {
+ p.get_token(); // eat 'b'
+ name = "\\textturnr";
+ skip_braces(p);
+ }
+ if (p.next_token().asInput() == "t") {
+ p.get_token();
+ name = "\\textturnt";
+ skip_braces(p);
+ }
+ if (p.next_token().asInput() == "w") {
+ p.get_token();
+ name = "\\textturnw";
+ skip_braces(p);
+ }
+ }
+ // now get the character from unicodesymbols
+ docstring s = encodings.fromLaTeXCommand(from_utf8(name),
Encodings::TEXT_CMD, termination, rem, &req);
if (!s.empty()) {
if (!rem.empty())
/*
string s = t.asInput();
string z = p.verbatim_item();
- while (p.good() && z != " " && z.size()) {
+ while (p.good() && z != " " && !z.empty()) {
//cerr << "read: " << z << endl;
s += z;
z = p.verbatim_item();
}
cerr << "found ERT: " << s << endl;
- handle_ert(os, s + ' ', context);
+ output_ert_inset(os, s + ' ', context);
*/
else {
string name = t.asInput();
name += '*';
}
if (!parse_command(name, p, os, outer, context))
- handle_ert(os, name, context);
+ output_ert_inset(os, name, context);
}
}
}
}
+
+string guessLanguage(Parser & p, string const & lang)
+{
+ typedef std::map<std::string, size_t> LangMap;
+ // map from language names to number of characters
+ LangMap used;
+ used[lang] = 0;
+ for (char const * const * i = supported_CJK_languages; *i; i++)
+ used[string(*i)] = 0;
+
+ while (p.good()) {
+ Token const t = p.get_token();
+ // comments are not counted for any language
+ if (t.cat() == catComment)
+ continue;
+ // commands are not counted as well, but we need to detect
+ // \begin{CJK} and switch encoding if needed
+ if (t.cat() == catEscape) {
+ if (t.cs() == "inputencoding") {
+ string const enc = subst(p.verbatim_item(), "\n", " ");
+ p.setEncoding(enc, Encoding::inputenc);
+ continue;
+ }
+ if (t.cs() != "begin")
+ continue;
+ } else {
+ // Non-CJK content is counted for lang.
+ // We do not care about the real language here:
+ // If we have more non-CJK contents than CJK contents,
+ // we simply use the language that was specified as
+ // babel main language.
+ used[lang] += t.asInput().length();
+ continue;
+ }
+ // Now we are starting an environment
+ p.pushPosition();
+ string const name = p.getArg('{', '}');
+ if (name != "CJK") {
+ p.popPosition();
+ continue;
+ }
+ // It is a CJK environment
+ p.popPosition();
+ /* name = */ p.getArg('{', '}');
+ string const encoding = p.getArg('{', '}');
+ /* mapping = */ p.getArg('{', '}');
+ string const encoding_old = p.getEncoding();
+ char const * const * const where =
+ is_known(encoding, supported_CJK_encodings);
+ if (where)
+ p.setEncoding(encoding, Encoding::CJK);
+ else
+ p.setEncoding("UTF-8");
+ string const text = p.ertEnvironment("CJK");
+ p.setEncoding(encoding_old);
+ p.skip_spaces();
+ if (!where) {
+ // ignore contents in unknown CJK encoding
+ continue;
+ }
+ // the language of the text
+ string const cjk =
+ supported_CJK_languages[where - supported_CJK_encodings];
+ used[cjk] += text.length();
+ }
+ LangMap::const_iterator use = used.begin();
+ for (LangMap::const_iterator it = used.begin(); it != used.end(); ++it) {
+ if (it->second > use->second)
+ use = it;
+ }
+ return use->first;
+}
+
// }])