tex2lyx: More work on beamer support

* Implement list item overlay support (\item<arg>)
* Implement itemcommand support (e.g., \overprint<arg>)
* Fix general list argument placement

Part of: #11068
This commit is contained in:
Juergen Spitzmueller 2018-03-14 08:40:47 +01:00
parent 18dc7a8e6b
commit e51265b5f3
4 changed files with 48 additions and 47 deletions

View File

@ -247,6 +247,8 @@ void Context::dump(ostream & os, string const & desc) const
os << "extrastuff=[" << extra_stuff << "] "; os << "extrastuff=[" << extra_stuff << "] ";
if (!par_extra_stuff.empty()) if (!par_extra_stuff.empty())
os << "parextrastuff=[" << par_extra_stuff << "] "; os << "parextrastuff=[" << par_extra_stuff << "] ";
if (!list_extra_stuff.empty())
os << "listextrastuff=[" << list_extra_stuff << "] ";
os << "textclass=" << textclass.name() os << "textclass=" << textclass.name()
<< " layout=" << to_utf8(layout->name()) << " layout=" << to_utf8(layout->name())
<< " parent_layout=" << to_utf8(parent_layout->name()) << "] font=[" << " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["

View File

@ -128,6 +128,8 @@ public:
std::string extra_stuff; std::string extra_stuff;
/// We may need to add something after this \\begin_layout command /// We may need to add something after this \\begin_layout command
std::string par_extra_stuff; std::string par_extra_stuff;
/// We may need to add something at the beginning of a list.
std::string list_extra_stuff;
/// If there has been an \\begin_deeper, we'll need a matching /// If there has been an \\begin_deeper, we'll need a matching
/// \\end_deeper /// \\end_deeper
bool need_end_deeper; bool need_end_deeper;

View File

@ -892,9 +892,10 @@ the second item
\begin_layout Itemize \begin_layout Itemize
\begin_inset Argument item:1 \begin_inset Argument item:1
status open status collapsed
\begin_layout Plain Layout
\begin_layout Standard
custom label custom label
\end_layout \end_layout

View File

@ -47,7 +47,7 @@ namespace lyx {
namespace { namespace {
void output_arguments(ostream &, Parser &, bool, bool, bool, Context &, void output_arguments(ostream &, Parser &, bool, bool, string, Context &,
Layout::LaTeXArgMap const &); Layout::LaTeXArgMap const &);
} }
@ -65,11 +65,11 @@ void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
else else
newcontext.font = context.font; newcontext.font = context.font;
if (layout) if (layout)
output_arguments(os, p, outer, false, false, newcontext, output_arguments(os, p, outer, false, string(), newcontext,
layout->latexargs()); layout->latexargs());
parse_text(p, os, flags, outer, newcontext, rdelim); parse_text(p, os, flags, outer, newcontext, rdelim);
if (layout) if (layout)
output_arguments(os, p, outer, false, true, newcontext, output_arguments(os, p, outer, false, "post", newcontext,
layout->postcommandargs()); layout->postcommandargs());
newcontext.check_end_layout(os); newcontext.check_end_layout(os);
} }
@ -749,14 +749,16 @@ void skip_spaces_braces(Parser & p, bool keepws = false)
} }
void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, bool post, void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, string const prefix,
Context & context, Layout::LaTeXArgMap const & latexargs) Context & context, Layout::LaTeXArgMap const & latexargs)
{ {
if (context.layout->latextype != LATEX_ITEM_ENVIRONMENT || !prefix.empty()) {
if (need_layout) { if (need_layout) {
context.check_layout(os); context.check_layout(os);
need_layout = false; need_layout = false;
} else } else
need_layout = true; need_layout = true;
}
int i = 0; int i = 0;
Layout::LaTeXArgMap::const_iterator lait = latexargs.begin(); Layout::LaTeXArgMap::const_iterator lait = latexargs.begin();
Layout::LaTeXArgMap::const_iterator const laend = latexargs.end(); Layout::LaTeXArgMap::const_iterator const laend = latexargs.end();
@ -780,8 +782,8 @@ void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, bo
need_layout = false; need_layout = false;
} }
begin_inset(os, "Argument "); begin_inset(os, "Argument ");
if (post) if (!prefix.empty())
os << "post:"; os << prefix << ':';
os << i << "\nstatus collapsed\n\n"; os << i << "\nstatus collapsed\n\n";
parse_text_in_inset(p, os, FLAG_RDELIM, outer, context, 0, rdelim); parse_text_in_inset(p, os, FLAG_RDELIM, outer, context, 0, rdelim);
end_inset(os); end_inset(os);
@ -806,8 +808,8 @@ void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, bo
need_layout = false; need_layout = false;
} }
begin_inset(os, "Argument "); begin_inset(os, "Argument ");
if (post) if (!prefix.empty())
os << "post:"; os << prefix << ':';
os << i << "\nstatus collapsed\n\n"; os << i << "\nstatus collapsed\n\n";
parse_text_in_inset(p, os, FLAG_RDELIM, outer, context, 0, rdelim); parse_text_in_inset(p, os, FLAG_RDELIM, outer, context, 0, rdelim);
end_inset(os); end_inset(os);
@ -840,10 +842,10 @@ void output_command_layout(ostream & os, Parser & p, bool outer,
context.need_end_deeper = true; context.need_end_deeper = true;
} }
context.check_deeper(os); context.check_deeper(os);
output_arguments(os, p, outer, true, false, context, output_arguments(os, p, outer, true, string(), context,
context.layout->latexargs()); context.layout->latexargs());
parse_text(p, os, FLAG_ITEM, outer, context); parse_text(p, os, FLAG_ITEM, outer, context);
output_arguments(os, p, outer, false, true, context, output_arguments(os, p, outer, false, "post", context,
context.layout->postcommandargs()); context.layout->postcommandargs());
context.check_end_layout(os); context.check_end_layout(os);
if (parent_context.deeper_paragraph) { if (parent_context.deeper_paragraph) {
@ -2081,16 +2083,18 @@ void parse_environment(Parser & p, ostream & os, bool outer,
} }
context.check_deeper(os); context.check_deeper(os);
// handle known optional and required arguments // handle known optional and required arguments
// FIXME: for item environments, this is currently if (context.layout->latextype == LATEX_ENVIRONMENT)
// placed wrongly (in an empty paragraph). It has to go to output_arguments(os, p, outer, false, string(), context,
// the first \item par instead.
if (context.layout->latextype == LATEX_ENVIRONMENT
|| context.layout->latextype == LATEX_ITEM_ENVIRONMENT)
output_arguments(os, p, outer, false, false, context,
context.layout->latexargs()); context.layout->latexargs());
else if (context.layout->latextype == LATEX_ITEM_ENVIRONMENT) {
ostringstream oss;
output_arguments(oss, p, outer, false, string(), context,
context.layout->latexargs());
context.list_extra_stuff = oss.str();
}
parse_text(p, os, FLAG_END, outer, context); parse_text(p, os, FLAG_END, outer, context);
if (context.layout->latextype == LATEX_ENVIRONMENT) if (context.layout->latextype == LATEX_ENVIRONMENT)
output_arguments(os, p, outer, false, true, context, output_arguments(os, p, outer, false, "post", context,
context.layout->postcommandargs()); context.layout->postcommandargs());
context.check_end_layout(os); context.check_end_layout(os);
if (parent_context.deeper_paragraph) { if (parent_context.deeper_paragraph) {
@ -3080,10 +3084,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
continue; continue;
} }
if (t.cs() == "item") { // "item" by default, but could be something else
if (t.cs() == context.layout->itemcommand()) {
string s; string s;
bool const optarg = p.hasOpt(); if (context.layout->labeltype == LABEL_MANUAL) {
if (optarg) {
// FIXME: This swallows comments, but we cannot use // FIXME: This swallows comments, but we cannot use
// eat_whitespace() since we must not output // eat_whitespace() since we must not output
// anything before the item. // anything before the item.
@ -3097,26 +3101,19 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
// An item in an unknown list-like environment // An item in an unknown list-like environment
// FIXME: Do this in check_layout()! // FIXME: Do this in check_layout()!
context.has_item = false; context.has_item = false;
if (optarg) string item = "\\" + context.layout->itemcommand();
output_ert_inset(os, "\\item", context); if (!p.hasOpt())
else item += " ";
output_ert_inset(os, "\\item ", context); output_ert_inset(os, item, context);
} }
if (optarg) { if (context.layout->labeltype != LABEL_MANUAL)
if (context.layout->labeltype != LABEL_MANUAL) { output_arguments(os, p, outer, false, "item", context,
// handle option of itemize item context.layout->itemargs());
begin_inset(os, "Argument item:1\n"); if (!context.list_extra_stuff.empty()) {
os << "status open\n"; os << context.list_extra_stuff;
os << "\n\\begin_layout Plain Layout\n"; context.list_extra_stuff.clear();
Parser p2(s + ']'); }
os << parse_text_snippet(p2, else if (!s.empty()) {
FLAG_BRACK_LAST, outer, context);
// we must not use context.check_end_layout(os)
// because that would close the outer itemize layout
os << "\n\\end_layout\n";
end_inset(os);
eat_whitespace(p, os, context, false);
} else if (!s.empty()) {
// LyX adds braces around the argument, // LyX adds braces around the argument,
// so we need to remove them here. // so we need to remove them here.
if (s.size() > 2 && s[0] == '{' && if (s.size() > 2 && s[0] == '{' &&
@ -3138,7 +3135,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
os << ' '; os << ' ';
eat_whitespace(p, os, context, false); eat_whitespace(p, os, context, false);
} }
}
continue; continue;
} }