diff --git a/src/tex2lyx/preamble.C b/src/tex2lyx/preamble.C index 7c565068c6..70c9a6bb06 100644 --- a/src/tex2lyx/preamble.C +++ b/src/tex2lyx/preamble.C @@ -13,6 +13,7 @@ #include #include #include +#include using std::cerr; using std::endl; @@ -24,6 +25,8 @@ using std::ostringstream; using std::string; using std::vector; +// special columntypes +extern std::map special_columns; namespace { @@ -127,8 +130,8 @@ void handle_package(string const & name, string const & options) void end_preamble(ostream & os) { - os << "# tex2lyx 0.0.2 created this file\n" - << "\\lyxformat 222\n" + os << "# tex2lyx 0.0.3 created this file\n" + << "\\lyxformat 224\n" << "\\textclass " << h_textclass << "\n" << "\\begin_preamble\n" << h_preamble.str() << "\n\\end_preamble\n"; if (h_options.size()) @@ -284,6 +287,23 @@ void parse_preamble(Parser & p, ostream & os) h_preamble << "\\def\\" << name << '{' << p.verbatim_item() << "}\n"; } + else if (t.cs() == "newcolumntype") { + string const name = p.getArg('{', '}'); + trim(name); + int nargs = 0; + string opts = p.getOpt(); + if (opts.size()) { + istringstream is(string(opts, 1)); + //cerr << "opt: " << is.str() << "\n"; + is >> nargs; + } + special_columns[name[0]] = nargs; + h_preamble << "\\newcolumntype{" << name << "}"; + if (nargs) + h_preamble << "[" << nargs << "]"; + h_preamble << "{" << p.verbatim_item() << "}\n"; + } + else if (t.cs() == "setcounter") { string const name = p.getArg('{', '}'); string const content = p.getArg('{', '}'); @@ -303,7 +323,7 @@ void parse_preamble(Parser & p, ostream & os) else if (name == "parindent") h_paragraph_separation = "skip"; else - h_preamble << "\\setlength{" + name + "}{" + content + "}\n"; + h_preamble << "\\setlength{" << name << "}{" << content << "}\n"; } else if (t.cs() == "par") diff --git a/src/tex2lyx/table.C b/src/tex2lyx/table.C index 3e1b694a00..5059c95cdf 100644 --- a/src/tex2lyx/table.C +++ b/src/tex2lyx/table.C @@ -13,6 +13,7 @@ #include #include #include +#include using std::cerr; using std::endl; @@ -21,9 +22,15 @@ using std::ostream; using std::ostringstream; using std::string; using std::vector; +using std::map; #include "mathed/math_gridinfo.h" + +// filled in preamble.C +std::map special_columns; + + namespace { int string2int(string const & s, int deflt = 0) @@ -56,7 +63,6 @@ string read_hlines(Parser & p) } - /* rather brutish way to code table structure in a string: \begin{tabular}{ccc} @@ -125,7 +131,19 @@ void handle_colalign(Parser & p, vector & colinfo) break; } default: - cerr << "ignoring special separator '" << t << "'\n"; + if (special_columns.find(t.character()) != special_columns.end()) { + ColInfo ci; + ci.align = 'c'; + ci.special += t.character(); + int const nargs = special_columns[t.character()]; + for (int i = 0; i < nargs; ++i) + ci.special += "{" + p.verbatim_item() + "}"; + //cerr << "handling special column '" << t << "' " << nargs + // << " '" << ci.special << "'\n"; + colinfo.push_back(ci); + } else { + cerr << "ignoring special separator '" << t << "'\n"; + } break; } }