}
// Move the lines and alignment settings to the special field if
// necessary
- for (size_t col = 0; col < colinfo.size(); ++col)
- fix_colalign(colinfo[col]);
+ for (auto & col : colinfo)
+ fix_colalign(col);
}
void handle_hline_above(RowInfo & ri, vector<CellInfo> & ci)
{
ri.topline = true;
- for (size_t col = 0; col < ci.size(); ++col)
- ci[col].topline = true;
+ for (auto & col : ci)
+ col.topline = true;
}
void handle_hline_below(RowInfo & ri, vector<CellInfo> & ci)
{
ri.bottomline = true;
- for (size_t col = 0; col < ci.size(); ++col)
- ci[col].bottomline = true;
+ for (auto & col : ci)
+ col.bottomline = true;
+}
+
+
+void parse_cell_content(ostringstream & os2, Parser & parse, unsigned int flags, Context & newcontext,
+ vector< vector<CellInfo> > & cellinfo, vector<ColInfo> & colinfo,
+ size_t const row, size_t const col)
+{
+ bool turn = false;
+ int rotate = 0;
+ bool varwidth = false;
+ if (parse.next_token().cs() == "begin") {
+ parse.pushPosition();
+ parse.get_token();
+ string const env = parse.getArg('{', '}');
+ if (env == "sideways" || env == "turn") {
+ string angle = "90";
+ if (env == "turn") {
+ turn = true;
+ angle = parse.getArg('{', '}');
+ }
+ active_environments.push_back(env);
+ parse.ertEnvironment(env);
+ active_environments.pop_back();
+ parse.skip_spaces();
+ if (!parse.good() && support::isStrInt(angle))
+ rotate = convert<int>(angle);
+ } else if (env == "cellvarwidth") {
+ active_environments.push_back(env);
+ parse.ertEnvironment(env);
+ active_environments.pop_back();
+ parse.skip_spaces();
+ varwidth = true;
+ }
+ parse.popPosition();
+ }
+ if (rotate != 0) {
+ cellinfo[row][col].rotate = rotate;
+ parse.get_token();
+ active_environments.push_back(parse.getArg('{', '}'));
+ if (turn)
+ parse.getArg('{', '}');
+ parse_text_in_inset(parse, os2, FLAG_END, false, newcontext);
+ active_environments.pop_back();
+ preamble.registerAutomaticallyLoadedPackage("rotating");
+ } else if (varwidth) {
+ parse.get_token();
+ active_environments.push_back(parse.getArg('{', '}'));
+ // valign arg
+ if (parse.hasOpt())
+ cellinfo[row][col].valign = parse.getArg('[', ']')[1];
+ newcontext.in_table_cell = true;
+ parse_text_in_inset(parse, os2, FLAG_END, false, newcontext);
+ if (cellinfo[row][col].multi == CELL_NORMAL)
+ colinfo[col].align = newcontext.cell_align;
+ else
+ cellinfo[row][col].align = newcontext.cell_align;
+ active_environments.pop_back();
+ preamble.registerAutomaticallyLoadedPackage("varwidth");
+ } else {
+ parse_text_in_inset(parse, os2, flags, false, newcontext);
+ }
}
void handle_tabular(Parser & p, ostream & os, string const & name,
string const & tabularwidth, string const & halign,
- Context & context)
+ Context const & context)
{
+ Context newcontext = context;
bool const is_long_tabular(name == "longtable" || name == "xltabular");
bool booktabs = false;
string tabularvalignment("middle");
parse.skip_spaces(true);
}
- if (width != "*")
+ if (width != "*" && width != "=")
colinfo[col].width = width;
if (!vmove.empty())
cellinfo[row][col].mroffset = vmove;
cellinfo[row][col].mrxnum = ncells - 1;
ostringstream os2;
- parse_text_in_inset(parse, os2, FLAG_ITEM, false, context);
+ parse.get_token();// skip {
+ parse_cell_content(os2, parse, FLAG_BRACE_LAST, newcontext,
+ cellinfo, colinfo,
+ row, col);
+ parse.get_token();// skip }
if (!cellinfo[row][col].content.empty()) {
// This may or may not work in LaTeX,
// but it does not work in LyX.
cellinfo[row][col].leftlines = ci.leftlines;
cellinfo[row][col].rightlines = ci.rightlines;
ostringstream os2;
- parse_text_in_inset(parse, os2, FLAG_ITEM, false, context);
+ parse.get_token();// skip {
+ parse_cell_content(os2, parse, FLAG_BRACE_LAST, newcontext,
+ cellinfo, colinfo,
+ row, col);
+ parse.get_token();// skip }
if (!cellinfo[row][col].content.empty()) {
// This may or may not work in LaTeX,
// but it does not work in LyX.
cellinfo[row][col].align = colinfo[col].align;
cellinfo[row][col].multi = CELL_BEGIN_OF_MULTICOLUMN;
ostringstream os2;
- parse_text_in_inset(parse, os2, FLAG_CELL, false, context);
+ parse_text_in_inset(parse, os2, FLAG_CELL, false, newcontext);
cellinfo[row][col].content += os2.str();
// add dummy multicolumn cells
for (size_t c = 1; c < colinfo.size(); ++c)
cellinfo[row][c].multi = CELL_PART_OF_MULTICOLUMN;
- } else {
- bool turn = false;
- int rotate = 0;
- if (parse.next_token().cs() == "begin") {
- parse.pushPosition();
- parse.get_token();
- string const env = parse.getArg('{', '}');
- if (env == "sideways" || env == "turn") {
- string angle = "90";
- if (env == "turn") {
- turn = true;
- angle = parse.getArg('{', '}');
- }
- active_environments.push_back(env);
- parse.ertEnvironment(env);
- active_environments.pop_back();
- parse.skip_spaces();
- if (!parse.good() && support::isStrInt(angle))
- rotate = convert<int>(angle);
+ } else if (col == 0 && colinfo.size() > 1 &&
+ is_long_tabular &&
+ parse.next_token().cs() == "caption") {
+ // longtable caption support in LyX is a hack:
+ // Captions require a row of their own with
+ // the caption flag set to true, having only
+ // one multicolumn cell. The contents of that
+ // cell must contain exactly one caption inset
+ // and nothing else.
+ // Fortunately, the caption flag is only needed
+ // for tables with more than one column.
+ rowinfo[row].caption = true;
+ for (size_t c = 1; c < cells.size(); ++c) {
+ if (!cells[c].empty()) {
+ cerr << "Moving cell content '"
+ << cells[c]
+ << "' into the caption cell. "
+ "This will probably not work."
+ << endl;
+ cells[0] += cells[c];
}
- parse.popPosition();
}
+ cells.resize(1);
+ cellinfo[row][col].align = colinfo[col].align;
+ cellinfo[row][col].multi = CELL_BEGIN_OF_MULTICOLUMN;
+ ostringstream os2;
+ parse_text_in_inset(parse, os2, FLAG_CELL, false, newcontext);
+ cellinfo[row][col].content += os2.str();
+ // add dummy multicolumn cells
+ for (size_t c = 1; c < colinfo.size(); ++c)
+ cellinfo[row][c].multi = CELL_PART_OF_MULTICOLUMN;
+ } else {
+ ostringstream os2;
+ parse_cell_content(os2, parse, FLAG_CELL, newcontext,
+ cellinfo, colinfo,
+ row, col);
cellinfo[row][col].leftlines = colinfo[col].leftlines;
cellinfo[row][col].rightlines = colinfo[col].rightlines;
cellinfo[row][col].align = colinfo[col].align;
- ostringstream os2;
- if (rotate != 0) {
- cellinfo[row][col].rotate = rotate;
- parse.get_token();
- active_environments.push_back(parse.getArg('{', '}'));
- if (turn)
- parse.getArg('{', '}');
- parse_text_in_inset(parse, os2, FLAG_END, false, context);
- active_environments.pop_back();
- preamble.registerAutomaticallyLoadedPackage("rotating");
- } else {
- parse_text_in_inset(parse, os2, FLAG_CELL, false, context);
- }
cellinfo[row][col].content += os2.str();
}
}
//cerr << "// output what we have\n";
// output what we have
size_type cols = colinfo.size();
- for (size_t col = 0; col < colinfo.size(); ++col) {
- if (colinfo[col].decimal_point != '\0' && colinfo[col].align != 'd')
+ for (auto const & col : colinfo) {
+ if (col.decimal_point != '\0' && col.align != 'd')
--cols;
}
os << "\n<lyxtabular version=\"3\" rows=\"" << rowinfo.size()
os << write_attribute("tabularwidth", tabularwidth) << ">\n";
//cerr << "// after header\n";
- for (size_t col = 0; col < colinfo.size(); ++col) {
- if (colinfo[col].decimal_point != '\0' && colinfo[col].align != 'd')
+ for (auto const & col : colinfo) {
+ if (col.decimal_point != '\0' && col.align != 'd')
continue;
os << "<column alignment=\""
- << verbose_align(colinfo[col].align) << "\"";
- if (colinfo[col].decimal_point != '\0')
- os << " decimal_point=\"" << colinfo[col].decimal_point << "\"";
+ << verbose_align(col.align) << "\"";
+ if (col.decimal_point != '\0')
+ os << " decimal_point=\"" << col.decimal_point << "\"";
os << " valignment=\""
- << verbose_valign(colinfo[col].valign) << "\""
- << write_attribute("width", translate_len(colinfo[col].width))
- << write_attribute("special", colinfo[col].special)
- << write_attribute("varwidth", colinfo[col].varwidth)
+ << verbose_valign(col.valign) << "\""
+ << write_attribute("width", translate_len(col.width))
+ << write_attribute("special", col.special)
+ << write_attribute("varwidth", col.varwidth)
<< ">\n";
}
//cerr << "// after cols\n";