commit 7c816488b698e0c577e48da0f21678cda0337fb4
Author: Juergen Spitzmueller <[email protected]>
Date: Wed Mar 14 08:40:47 2018 +0100
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
(cherry picked from commit e51265b5f3c7765ad185303ac147792c7599386f)
---
src/tex2lyx/Context.cpp | 2 +
src/tex2lyx/Context.h | 2 +
src/tex2lyx/test/test-structure.lyx.lyx | 5 +-
src/tex2lyx/text.cpp | 86 +++++++++++++++----------------
4 files changed, 48 insertions(+), 47 deletions(-)
diff --git a/src/tex2lyx/Context.cpp b/src/tex2lyx/Context.cpp
index 6168518..cc95a1f 100644
--- a/src/tex2lyx/Context.cpp
+++ b/src/tex2lyx/Context.cpp
@@ -247,6 +247,8 @@ void Context::dump(ostream & os, string const & desc) const
os << "extrastuff=[" << extra_stuff << "] ";
if (!par_extra_stuff.empty())
os << "parextrastuff=[" << par_extra_stuff << "] ";
+ if (!list_extra_stuff.empty())
+ os << "listextrastuff=[" << list_extra_stuff << "] ";
os << "textclass=" << textclass.name()
<< " layout=" << to_utf8(layout->name())
<< " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["
diff --git a/src/tex2lyx/Context.h b/src/tex2lyx/Context.h
index b88a921..47b39fc 100644
--- a/src/tex2lyx/Context.h
+++ b/src/tex2lyx/Context.h
@@ -128,6 +128,8 @@ public:
std::string extra_stuff;
/// We may need to add something after this \\begin_layout command
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
/// \\end_deeper
bool need_end_deeper;
diff --git a/src/tex2lyx/test/test-structure.lyx.lyx
b/src/tex2lyx/test/test-structure.lyx.lyx
index 52f4e11..87d9f6b 100644
--- a/src/tex2lyx/test/test-structure.lyx.lyx
+++ b/src/tex2lyx/test/test-structure.lyx.lyx
@@ -892,9 +892,10 @@ the second item
\begin_layout Itemize
\begin_inset Argument item:1
-status open
+status collapsed
-\begin_layout Plain Layout
+
+\begin_layout Standard
custom label
\end_layout
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index a36b755..ac2bed1 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -47,7 +47,7 @@ namespace lyx {
namespace {
-void output_arguments(ostream &, Parser &, bool, bool, bool, Context &,
+void output_arguments(ostream &, Parser &, bool, bool, string, Context &,
Layout::LaTeXArgMap const &);
}
@@ -65,11 +65,11 @@ void parse_text_in_inset(Parser & p, ostream & os, unsigned
flags, bool outer,
else
newcontext.font = context.font;
if (layout)
- output_arguments(os, p, outer, false, false, newcontext,
+ output_arguments(os, p, outer, false, string(), newcontext,
layout->latexargs());
parse_text(p, os, flags, outer, newcontext, rdelim);
if (layout)
- output_arguments(os, p, outer, false, true, newcontext,
+ output_arguments(os, p, outer, false, "post", newcontext,
layout->postcommandargs());
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)
{
- if (need_layout) {
- context.check_layout(os);
- need_layout = false;
- } else
- need_layout = true;
+ if (context.layout->latextype != LATEX_ITEM_ENVIRONMENT ||
!prefix.empty()) {
+ if (need_layout) {
+ context.check_layout(os);
+ need_layout = false;
+ } else
+ need_layout = true;
+ }
int i = 0;
Layout::LaTeXArgMap::const_iterator lait = latexargs.begin();
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;
}
begin_inset(os, "Argument ");
- if (post)
- os << "post:";
+ if (!prefix.empty())
+ os << prefix << ':';
os << i << "\nstatus collapsed\n\n";
parse_text_in_inset(p, os, FLAG_RDELIM, outer, context,
0, rdelim);
end_inset(os);
@@ -806,8 +808,8 @@ void output_arguments(ostream & os, Parser & p, bool outer,
bool need_layout, bo
need_layout = false;
}
begin_inset(os, "Argument ");
- if (post)
- os << "post:";
+ if (!prefix.empty())
+ os << prefix << ':';
os << i << "\nstatus collapsed\n\n";
parse_text_in_inset(p, os, FLAG_RDELIM, outer, context,
0, rdelim);
end_inset(os);
@@ -840,10 +842,10 @@ void output_command_layout(ostream & os, Parser & p, bool
outer,
context.need_end_deeper = true;
}
context.check_deeper(os);
- output_arguments(os, p, outer, true, false, context,
+ output_arguments(os, p, outer, true, string(), context,
context.layout->latexargs());
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.check_end_layout(os);
if (parent_context.deeper_paragraph) {
@@ -2081,16 +2083,18 @@ void parse_environment(Parser & p, ostream & os, bool
outer,
}
context.check_deeper(os);
// handle known optional and required arguments
- // FIXME: for item environments, this is currently
- // placed wrongly (in an empty paragraph). It has to go to
- // 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,
+ if (context.layout->latextype == LATEX_ENVIRONMENT)
+ output_arguments(os, p, outer, false, string(), context,
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);
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.check_end_layout(os);
if (parent_context.deeper_paragraph) {
@@ -3074,10 +3078,10 @@ void parse_text(Parser & p, ostream & os, unsigned
flags, bool outer,
continue;
}
- if (t.cs() == "item") {
+ // "item" by default, but could be something else
+ if (t.cs() == context.layout->itemcommand()) {
string s;
- bool const optarg = p.hasOpt();
- if (optarg) {
+ if (context.layout->labeltype == LABEL_MANUAL) {
// FIXME: This swallows comments, but we cannot
use
// eat_whitespace() since we must not
output
// anything before the item.
@@ -3091,26 +3095,19 @@ void parse_text(Parser & p, ostream & os, unsigned
flags, bool outer,
// An item in an unknown list-like environment
// FIXME: Do this in check_layout()!
context.has_item = false;
- if (optarg)
- output_ert_inset(os, "\\item", context);
- else
- output_ert_inset(os, "\\item ",
context);
+ string item = "\\" +
context.layout->itemcommand();
+ if (!p.hasOpt())
+ item += " ";
+ output_ert_inset(os, item, context);
}
- if (optarg) {
- if (context.layout->labeltype != LABEL_MANUAL) {
- // handle option of itemize item
- begin_inset(os, "Argument item:1\n");
- os << "status open\n";
- os << "\n\\begin_layout Plain Layout\n";
- Parser p2(s + ']');
- os << parse_text_snippet(p2,
- 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()) {
+ if (context.layout->labeltype != LABEL_MANUAL)
+ output_arguments(os, p, outer, false, "item",
context,
+ context.layout->itemargs());
+ if (!context.list_extra_stuff.empty()) {
+ os << context.list_extra_stuff;
+ context.list_extra_stuff.clear();
+ }
+ else if (!s.empty()) {
// LyX adds braces around the argument,
// so we need to remove them here.
if (s.size() > 2 && s[0] == '{' &&
@@ -3132,7 +3129,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags,
bool outer,
os << ' ';
eat_whitespace(p, os, context, false);
}
- }
continue;
}