The attached patch adds support for the template "chess", "Gnumeric" and "PDFPages".
I had to introduce a trick to overcome MSVC's limitation of 128 else-if statements per routine. OK with it?
The Gnumeric routine works, but we have http://www.lyx.org/trac/ticket/7897. If this is not a bug, I will adjust the routine to make the .tex extension an extension the template understands. So I will only commit the PDFPages and chess support if you agree to my 128 esle-if statements hack.
thanks and regards Uwe
Index: Preamble.cpp =================================================================== --- Preamble.cpp (revision 40194) +++ Preamble.cpp (working copy) @@ -727,12 +727,19 @@ else if (name == "textcomp") ; // ignore this + else if (name == "pdfpages") + ; // ignore this + + else if (name == "lyxskak") + ; // ignore this + else if (name == "url") ; // ignore this - else if (name == "booktabs" || name == "color" || - name == "longtable" || name == "subscript" || - name == "ulem") { + else if (name == "array" || name == "booktabs" || + name == "color" || name == "hhline" || + name == "longtable" || name == "subscript" || + name == "ulem") { if (!in_lyx_preamble) h_preamble << package_beg_sep << name << package_mid_sep << "\\usepackage{" @@ -1146,6 +1153,11 @@ h_font_default_family = family.erase(0,1); } + // remove the lyxdot definition that is re-added by LyX + // if necessary + if (name == "\\lyxdot") + in_lyx_preamble = true; + // Add the command to the known commands add_known_command(name, opt1, !opt2.empty(), from_utf8(body)); Index: text.cpp =================================================================== --- text.cpp (revision 40194) +++ text.cpp (working copy) @@ -1858,6 +1858,95 @@ } // anonymous namespace +// this routine is the same as parse_text and only introduced to avoid having +// more than 128 if statements in parse_text as this is not allowed with the +// MSVC compiler +void parse_text2(Parser & p, ostream & os, unsigned flags, bool outer, + Context & context, Layout const * newlayout, + InsetLayout const * newinsetlayout, string const t2) +{ + if (t2 == "def") { + Token second = p.get_token(); + if (second.cs() == "inputGnumericTable") { + skip_braces(p); + Token third = p.get_token(); + if (third.cs() == "input") { + string name = normalize_filename(p.verbatim_item()); + string const path = getMasterFilePath(); + // We want to preserve relative / absolute filenames, + // therefore path is only used for testing + if (!makeAbsPath(name, path).exists()) { + // The file extension is probably missing. + // Now try to find it out. + char const * const Gnumeric_formats[] = {"gnumeric" + "ods", "xls", 0}; + string const Gnumeric_name = + find_file(name, path, Gnumeric_formats); + if (!Gnumeric_name.empty()) + name = Gnumeric_name; + } + if (makeAbsPath(name, path).exists()) + fix_relative_filename(name); + else + cerr << "Warning: Could not find file '" + << name << "'." << endl; + context.check_layout(os); + begin_inset(os, "External\n\ttemplate "); + os << "GnumericSpreadsheet\n\tfilename " + << name << "\n"; + end_inset(os); + context.check_layout(os); + } + } + } + + if (t2 == "includepdf" || t2 == "loadgame") { + p.skip_spaces(); + string name = normalize_filename(p.verbatim_item()); + string const path = getMasterFilePath(); + // We want to preserve relative / absolute filenames, + // therefore path is only used for testing + if (!makeAbsPath(name, path).exists()) { + // The file extension is probably missing. + // Now try to find it out. + if (t2 == "includepdf") { + char const * const pdfpages_format[] = {"pdf", 0}; + string const pdftex_name = + find_file(name, path, pdfpages_format); + if (!pdftex_name.empty()) { + name = pdftex_name; + pdflatex = true; + } + } + else if (t2 == "loadgame") { + char const * const lyxskak_format[] = {"fen", 0}; + string const lyxskak_name = + find_file(name, path, lyxskak_format); + if (!lyxskak_name.empty()) + name = lyxskak_name; + } + } + if (makeAbsPath(name, path).exists()) + fix_relative_filename(name); + else + cerr << "Warning: Could not find file '" + << name << "'." << endl; + context.check_layout(os); + begin_inset(os, "External\n\ttemplate "); + if (t2 == "includepdf") + os << "PDFPages\n\tfilename " + << name << "\n"; + else if (t2 == "loadgame") + os << "ChessDiagram\n\tfilename " + << name << "\n"; + end_inset(os); + context.check_layout(os); + // after a \loadgame follows a \showboard + if (p.get_token().asInput() == "showboard") + p.get_token(); + } +} + void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, Context & context) { @@ -2275,8 +2364,12 @@ } } - else if (is_macro(p)) - parse_macro(p, os, context); + else if (is_macro(p)) { + // catch the case of \def\inputGnumericTable + parse_text2(p, os, flags, outer, context, newlayout, newinsetlayout, t.cs()); + if (is_macro(p)) + parse_macro(p, os, context); + } else if (t.cs() == "noindent") { p.skip_spaces(); @@ -3670,7 +3763,7 @@ t.cs() == "DeclareRobustCommandx" || t.cs() == "newcommand" || t.cs() == "newcommandx" || - t.cs() == "providecommand" || + t.cs() == "providecommand" || t.cs() == "providecommandx" || t.cs() == "renewcommand" || t.cs() == "renewcommandx") { @@ -3854,6 +3947,12 @@ end_inset(os); } + else if (t.cs() == "includepdf" || t.cs() == "loadgame") { + // continue parsing in a separate routine because parse_text may only + // contain 128 if conditions (is a MSVC compiler restriction) + parse_text2(p, os, flags, outer, context, newlayout, newinsetlayout, t.cs()); + } + else { // try to see whether the string is in unicodesymbols // Only use text mode commands, since we are in text mode here,