-/** The .tex to .lyx converter
- \author André Pönitz (2003)
+/**
+ * \file table.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ * \author Jean-Marc Lasgouttes
+ *
+ * Full author contact details are available in file CREDITS.
*/
// {[(
#include <iostream>
#include <sstream>
#include <vector>
+#include <map>
using std::cerr;
using std::endl;
#include "mathed/math_gridinfo.h"
+// filled in preamble.C
+std::map<char, int> special_columns;
+
+
namespace {
int string2int(string const & s, int deflt = 0)
}
-
/* rather brutish way to code table structure in a string:
\begin{tabular}{ccc}
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;
}
}
p.error("found 'end' unexpectedly");
}
- else
+ else
os << t.asInput();
}
}
}
-void handle_tabular(Parser & p, ostream & os)
+void handle_tabular(Parser & p, ostream & os,
+ Context & context)
{
string posopts = p.getOpt();
if (posopts.size())
vector< vector<CellInfo> > cellinfo(lines.size());
vector<RowInfo> rowinfo(lines.size());
-
+
// split into rows
//cerr << "// split into rows\n";
for (size_t row = 0; row < rowinfo.size(); ++row) {
// init row
cellinfo[row].resize(colinfo.size());
- // split row
+ // split row
vector<string> dummy;
//cerr << "\n########### LINE: " << lines[row] << "########\n";
split(lines[row], dummy, HLINE);
//cerr << "line: " << row << " below 2: " << dummy[2] << "\n";
//cerr << "line: " << row << " cells 1: " << dummy[1] << "\n";
- for (int i = 0; i <= 2; i += 2) {
+ for (int i = 0; i <= 2; i += 2) {
//cerr << " reading from line string '" << dummy[i] << "'\n";
Parser p1(dummy[i]);
while (p1.good()) {
handle_hline_above(rowinfo[row], cellinfo[row]);
//cerr << "above row: " << row << endl;
}
- } else {
+ } else {
//cerr << "below row: " << row << endl;
handle_hline_below(rowinfo[row], cellinfo[row]);
}
cell < cells.size() && col < colinfo.size(); ++col, ++cell) {
//cerr << "cell content: '" << cells[cell] << "'\n";
Parser p(cells[cell]);
- p.skip_spaces();
+ p.skip_spaces();
//cells[cell] << "'\n";
if (p.next_token().cs() == "multicolumn") {
// how many cells?
p.get_token();
size_t const ncells = string2int(p.verbatim_item());
- // special cell properties alignment
+ // special cell properties alignment
vector<ColInfo> t;
handle_colalign(p, t);
cellinfo[row][col].multi = 1;
cellinfo[row][col].align = t.front().align;
- cellinfo[row][col].content = parse_text(p, FLAG_ITEM, false);
+ ostringstream os;
+ parse_text_in_inset(p, os, FLAG_ITEM, false, context);
+ cellinfo[row][col].content = os.str();
cellinfo[row][col].leftline |= t.front().leftline;
cellinfo[row][col].rightline |= t.front().rightline;
if (t.front().rightline > 1)
cellinfo[row][col + 1].leftline = true;
- } else {
+ } else {
// FLAG_END is a hack, we need to read all of it
- cellinfo[row][col].content = parse_text(p, FLAG_END, false);
+ cellinfo[row][col].leftline = colinfo[col].leftline;
+ cellinfo[row][col].rightline = colinfo[col].rightline;
+ cellinfo[row][col].align = colinfo[col].align;
+ ostringstream os;
+ parse_text_in_inset(p, os, FLAG_CELL, false, context);
+ cellinfo[row][col].content = os.str();
}
}
//cerr << "// output what we have\n";
// output what we have
- os << "<lyxtabular version=\"3\" rows=\"" << rowinfo.size()
+ os << "\n<lyxtabular version=\"3\" rows=\"" << rowinfo.size()
<< "\" columns=\"" << colinfo.size() << "\">\n"
<< "<features>\n";
//cerr << "// after header\n";
for (size_t col = 0; col < colinfo.size(); ++col) {
- os << "<column alignment=\"" << colinfo[col].align << "\"";
- if (colinfo[col].rightline)
- os << " rightline=\"true\"";
+ os << "<column alignment=\""
+ << verbose_align(colinfo[col].align) << "\"";
+ os << " valignment=\"top\"";
if (colinfo[col].leftline)
os << " leftline=\"true\"";
- os << " valignment=\"top\"";
- os << " width=\"" << colinfo[col].width << "\"";
+ if (colinfo[col].rightline)
+ os << " rightline=\"true\"";
+ if (colinfo[col].width.size())
+ os << " width=\"" << colinfo[col].width << "\"";
+ if (colinfo[col].special.size())
+ os << " special=\"" << colinfo[col].special << "\"";
os << ">\n";
}
//cerr << "// after cols\n";
os << "<cell";
if (cell.multi)
os << " multicolumn=\"" << cell.multi << "\"";
- if (cell.leftline)
- os << " leftline=\"true\"";
- if (cell.rightline)
- os << " rightline=\"true\"";
+ os << " alignment=\"" << verbose_align(cell.align)
+ << "\""
+ << " valignment=\"top\"";
if (cell.topline)
os << " topline=\"true\"";
if (cell.bottomline)
os << " bottomline=\"true\"";
+ if (cell.leftline)
+ os << " leftline=\"true\"";
+ if (cell.rightline)
+ os << " rightline=\"true\"";
//cerr << "\nrow: " << row << " col: " << col;
//if (cell.topline)
// cerr << " topline=\"true\"";
//if (cell.bottomline)
// cerr << " bottomline=\"true\"";
- os << " alignment=\"" << verbose_align(cell.align) << "\""
- << " valignment=\"top\""
- << " usebox=\"none\""
- << ">"
- << "\n\\begin_inset Text"
- << "\n\n\\layout Standard\n\n"
+ os << " usebox=\"none\""
+ << ">"
+ << "\n\\begin_inset Text\n"
<< cell.content
- << "\n\\end_inset\n\n"
+ << "\n\\end_inset \n"
<< "</cell>\n";
}
os << "</row>\n";
}
-
+
os << "</lyxtabular>\n";
}