handle special columns

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7232 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-07-03 11:47:44 +00:00
parent 83a3833d60
commit 6a970ad5d8
2 changed files with 43 additions and 5 deletions

View File

@ -13,6 +13,7 @@
#include <sstream>
#include <string>
#include <vector>
#include <map>
using std::cerr;
using std::endl;
@ -24,6 +25,8 @@ using std::ostringstream;
using std::string;
using std::vector;
// special columntypes
extern std::map<char, int> 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")

View File

@ -13,6 +13,7 @@
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
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<char, int> 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> & colinfo)
break;
}
default:
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;
}
}