]> git.lyx.org Git - features.git/commitdiff
tex2lyx: support for Spreadsheet and chess external templates
authorUwe Stöhr <uwestoehr@web.de>
Fri, 25 Nov 2011 01:01:45 +0000 (01:01 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Fri, 25 Nov 2011 01:01:45 +0000 (01:01 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40270 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/Preamble.cpp
src/tex2lyx/TODO.txt
src/tex2lyx/test/test-insets.tex
src/tex2lyx/text.cpp

index 4ebfbc1c1a5f736615b447117a4a4b08812555ac..8ea4fa24c6251e4b1df4165f754bff525fb92e95 100644 (file)
@@ -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));
 
index f76c51f123631f07991fbd3afc26b0d0f748ba8b..597beab52b0cbf9404ac1f2f90ff586546ee41d2 100644 (file)
@@ -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
index be26f232db5c2c00a34196a8a556f5eaf077e108..5ef363b3e5074fa127271df78d76f1290214e06e 100644 (file)
@@ -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}.
index 6f597c5584cdbf0444ffac4451fea2447464d676..4e39654d2935c9e065418ad3b60c25882a6e9627 100644 (file)
@@ -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,