mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-10 18:58:10 +00:00
tex2lyx: support extended varwidth table cells
This commit is contained in:
parent
af550b4589
commit
526d2841df
@ -85,7 +85,7 @@ Context::Context(bool need_layout_,
|
||||
new_layout_allowed(true), merging_hyphens_allowed(true),
|
||||
textclass(textclass_),
|
||||
layout(layout_), parent_layout(parent_layout_),
|
||||
font(font_), tablerotation(0)
|
||||
font(font_), tablerotation(0), in_table_cell(false), cell_align('c')
|
||||
{
|
||||
if (!layout)
|
||||
layout = &textclass.defaultLayout();
|
||||
|
@ -176,6 +176,10 @@ public:
|
||||
static TeXFont normalfont;
|
||||
/// Table rotation angle
|
||||
int tablerotation;
|
||||
///
|
||||
bool in_table_cell;
|
||||
///
|
||||
char cell_align;
|
||||
|
||||
private:
|
||||
void begin_layout(std::ostream & os, Layout const * const & l);
|
||||
|
@ -941,6 +941,7 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
|
||||
string const & tabularwidth, string const & halign,
|
||||
Context const & context)
|
||||
{
|
||||
Context newcontext = context;
|
||||
bool const is_long_tabular(name == "longtable" || name == "xltabular");
|
||||
bool booktabs = false;
|
||||
string tabularvalignment("middle");
|
||||
@ -1283,7 +1284,7 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
|
||||
cellinfo[row][col].mrxnum = ncells - 1;
|
||||
|
||||
ostringstream os2;
|
||||
parse_text_in_inset(parse, os2, FLAG_ITEM, false, context);
|
||||
parse_text_in_inset(parse, os2, FLAG_ITEM, false, newcontext);
|
||||
if (!cellinfo[row][col].content.empty()) {
|
||||
// This may or may not work in LaTeX,
|
||||
// but it does not work in LyX.
|
||||
@ -1320,7 +1321,7 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
|
||||
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_text_in_inset(parse, os2, FLAG_ITEM, false, newcontext);
|
||||
if (!cellinfo[row][col].content.empty()) {
|
||||
// This may or may not work in LaTeX,
|
||||
// but it does not work in LyX.
|
||||
@ -1378,7 +1379,38 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
|
||||
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 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];
|
||||
}
|
||||
}
|
||||
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)
|
||||
@ -1386,6 +1418,7 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
|
||||
} else {
|
||||
bool turn = false;
|
||||
int rotate = 0;
|
||||
bool varwidth = false;
|
||||
if (parse.next_token().cs() == "begin") {
|
||||
parse.pushPosition();
|
||||
parse.get_token();
|
||||
@ -1402,6 +1435,12 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
|
||||
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();
|
||||
}
|
||||
@ -1415,11 +1454,25 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
|
||||
active_environments.push_back(parse.getArg('{', '}'));
|
||||
if (turn)
|
||||
parse.getArg('{', '}');
|
||||
parse_text_in_inset(parse, os2, FLAG_END, false, context);
|
||||
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, FLAG_CELL, false, context);
|
||||
parse_text_in_inset(parse, os2, FLAG_CELL, false, newcontext);
|
||||
}
|
||||
cellinfo[row][col].content += os2.str();
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ std::string find_file(std::string const & name, std::string const & path,
|
||||
* Therefore this may only be used to parse text in insets or table cells.
|
||||
*/
|
||||
void parse_text_in_inset(Parser & p, std::ostream & os, unsigned flags,
|
||||
bool outer, Context const & context,
|
||||
bool outer, Context & context,
|
||||
InsetLayout const * layout = nullptr,
|
||||
std::string const & rdelim = "");
|
||||
|
||||
|
@ -54,7 +54,7 @@ void output_arguments(ostream &, Parser &, bool, bool, const string &, Context &
|
||||
|
||||
|
||||
void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
Context const & context, InsetLayout const * layout,
|
||||
Context & context, InsetLayout const * layout,
|
||||
string const & rdelim)
|
||||
{
|
||||
bool const forcePlainLayout =
|
||||
@ -66,6 +66,8 @@ void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
newcontext.font = context.font;
|
||||
// Inherit commands to pass through
|
||||
newcontext.pass_thru_cmds = context.pass_thru_cmds;
|
||||
// and table cell
|
||||
newcontext.in_table_cell = context.in_table_cell;
|
||||
if (layout)
|
||||
output_arguments(os, p, outer, false, string(), newcontext,
|
||||
layout->latexargs());
|
||||
@ -81,6 +83,7 @@ void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
output_arguments(os, p, outer, false, "post", newcontext,
|
||||
layout->postcommandargs());
|
||||
newcontext.check_end_layout(os);
|
||||
context.cell_align = newcontext.cell_align;
|
||||
}
|
||||
|
||||
|
||||
@ -95,7 +98,8 @@ void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
context.textclass.insetLayouts().find(from_ascii(name));
|
||||
if (it != context.textclass.insetLayouts().end())
|
||||
layout = &(it->second);
|
||||
parse_text_in_inset(p, os, flags, outer, context, layout, rdelim);
|
||||
Context newcontext = context;
|
||||
parse_text_in_inset(p, os, flags, outer, newcontext, layout, rdelim);
|
||||
}
|
||||
|
||||
/// parses a paragraph snippet, useful for example for \\emph{...}
|
||||
@ -5525,28 +5529,36 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
|
||||
// the code for the alignment was put here
|
||||
// put them in their own if if this is fixed
|
||||
if (t.cs() == "fboxrule" || t.cs() == "fboxsep"
|
||||
|| t.cs() == "shadowsize"
|
||||
|| t.cs() == "raggedleft" || t.cs() == "centering"
|
||||
|| t.cs() == "raggedright") {
|
||||
|| t.cs() == "shadowsize") {
|
||||
if (t.cs() == "fboxrule")
|
||||
fboxrule = "";
|
||||
if (t.cs() == "fboxsep")
|
||||
fboxsep = "";
|
||||
if (t.cs() == "shadowsize")
|
||||
shadow_size = "";
|
||||
if (t.cs() != "raggedleft" && t.cs() != "centering"
|
||||
&& t.cs() != "raggedright") {
|
||||
p.skip_spaces(true);
|
||||
while (p.good() && p.next_token().cat() != catSpace
|
||||
&& p.next_token().cat() != catNewline
|
||||
&& p.next_token().cat() != catEscape) {
|
||||
if (t.cs() == "fboxrule")
|
||||
fboxrule = fboxrule + p.get_token().asInput();
|
||||
if (t.cs() == "fboxsep")
|
||||
fboxsep = fboxsep + p.get_token().asInput();
|
||||
if (t.cs() == "shadowsize")
|
||||
shadow_size = shadow_size + p.get_token().asInput();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t.cs() == "raggedleft" || t.cs() == "centering" || t.cs() == "raggedright") {
|
||||
if (context.in_table_cell) {
|
||||
if (t.cs() == "raggedleft")
|
||||
context.cell_align = 'r';
|
||||
else if (t.cs() == "centering")
|
||||
context.cell_align = 'c';
|
||||
else if (t.cs() == "raggedright")
|
||||
context.cell_align = 'l';
|
||||
p.skip_spaces(true);
|
||||
while (p.good() && p.next_token().cat() != catSpace
|
||||
&& p.next_token().cat() != catNewline
|
||||
&& p.next_token().cat() != catEscape) {
|
||||
if (t.cs() == "fboxrule")
|
||||
fboxrule = fboxrule + p.get_token().asInput();
|
||||
if (t.cs() == "fboxsep")
|
||||
fboxsep = fboxsep + p.get_token().asInput();
|
||||
if (t.cs() == "shadowsize")
|
||||
shadow_size = shadow_size + p.get_token().asInput();
|
||||
}
|
||||
} else {
|
||||
output_ert_inset(os, t.asInput(), context);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user