diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 4ebfbc1c1a..8ea4fa24c6 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -727,12 +727,19 @@ void Preamble::handle_package(Parser &p, string const & name, else if (name == "textcomp") ; // ignore this + else if (name == "lyxskak") { + // ignore this and its options + if (!options.empty()) + options.clear(); + } + 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 @@ void Preamble::parse(Parser & p, string const & forceclass, 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)); diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt index f76c51f123..597beab52b 100644 --- a/src/tex2lyx/TODO.txt +++ b/src/tex2lyx/TODO.txt @@ -11,8 +11,11 @@ LyX feature: LyX inset or document setting Format LaTeX feature LyX feature 224 external insets defined in InsetExternal - lib/external_templates. This is - quite difficult to recognize. + lib/external_templates. + (Date and RasterImage cannot be supported + (Chess diagram and Spreadsheet are supported) + (Xfig figure, Lilypond, Dia diagram can be supported by looking at the file extension) + (for PDFpages work is in progress by uwestoehr) 226 nothing (impossible to import) InsetBranch, \branch...\end_branch 226 transformations InsetExternal 228 draft InsetExternal diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex index be26f232db..5ef363b3e5 100644 --- a/src/tex2lyx/test/test-insets.tex +++ b/src/tex2lyx/test/test-insets.tex @@ -114,8 +114,19 @@ M., \& Rasio, F.~A. 2004, ApJ, 604, 632\end{thebibliography} \section{Input files\index{Input files}} We can input files too, like this \input{DummyDocument}, or with the include -variant \include{DummyDocument} % unfortunately, including the doc twice -% generates a multiply defined label +variant \include{DummyDocument} % unfortunately, including the doc twice generates a multiply defined label + +We can also import chess diagrams: + +\loadgame{../../../lib/examples/iecc05}\showboard + +Spreadsheets: + +\def\inputGnumericTable{}\input{../../../lib/examples/longsheet.gnumeric} + +and PDF pages: + +\includepdf[pages=-,angle=22,origin=Bl,width=5cm,height=40mm,keepaspectratio]{../../../lib/examples/beamer-icsi-logo} If you prefer verbatim input, you can choose between~\verbatiminput{foo} or~\verbatiminput*{foo}. diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 6f597c5584..4e39654d29 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -2306,8 +2306,45 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } } - else if (is_macro(p)) - parse_macro(p, os, context); + else if (is_macro(p)) { + // catch the case of \def\inputGnumericTable + if (t.cs() == "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 (is_macro(p)) + parse_macro(p, os, context); + } else if (t.cs() == "noindent") { p.skip_spaces(); @@ -3638,7 +3675,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, t.cs() == "DeclareRobustCommandx" || t.cs() == "newcommand" || t.cs() == "newcommandx" || - t.cs() == "providecommand" || + t.cs() == "providecommand" || t.cs() == "providecommandx" || t.cs() == "renewcommand" || t.cs() == "renewcommandx") { @@ -3822,6 +3859,37 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, end_inset(os); } + else if (t.cs() == "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. + 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 "); + 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(); + } + else { // try to see whether the string is in unicodesymbols // Only use text mode commands, since we are in text mode here,