Author: uwestoehr
Date: Sun Mar 4 14:27:53 2012
New Revision: 40850
URL: http://www.lyx.org/trac/changeset/40850
Log:
- text.cpp: - fix tex2lyx parsing of verbatim environments
- Parser.cpp: - new function to parse verbatim environments
- test/test-structure.tex: updated example
Modified:
lyx-devel/trunk/src/tex2lyx/Parser.cpp
lyx-devel/trunk/src/tex2lyx/Parser.h
lyx-devel/trunk/src/tex2lyx/test/test-structure.tex
lyx-devel/trunk/src/tex2lyx/text.cpp
Modified: lyx-devel/trunk/src/tex2lyx/Parser.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/Parser.cpp Sun Mar 4 02:23:46 2012
(r40849)
+++ lyx-devel/trunk/src/tex2lyx/Parser.cpp Sun Mar 4 14:27:53 2012
(r40850)
@@ -481,6 +481,30 @@
}
+string const Parser::plainEnvironment(string const & name)
+{
+ if (!good())
+ return string();
+
+ ostringstream os;
+ for (Token t = get_token(); good(); t = get_token()) {
+ if (t.cat() == catBegin) {
+ putback();
+ os << '{' << verbatim_item() << '}';
+ } else if (t.asInput() == "\\end") {
+ string const end = getArg('{', '}');
+ if (end == name)
+ return os.str();
+ else
+ os << "\\end{" << end << '}';
+ } else
+ os << t.asInput();
+ }
+ cerr << "unexpected end of input" << endl;
+ return os.str();
+}
+
+
void Parser::tokenize_one()
{
catInit();
Modified: lyx-devel/trunk/src/tex2lyx/Parser.h
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/Parser.h Sun Mar 4 02:23:46 2012
(r40849)
+++ lyx-devel/trunk/src/tex2lyx/Parser.h Sun Mar 4 14:27:53 2012
(r40850)
@@ -196,6 +196,12 @@
* is parsed but not returned.
*/
std::string const verbatimEnvironment(std::string const & name);
+ /*
+ * The same as verbatimEnvironment(std::string const & name) but
+ * \begin and \end commands inside the name environment are not parsed.
+ * This function is designed to parse verbatim environments.
+ */
+ std::string const plainEnvironment(std::string const & name);
/*!
* Returns the character of the current token and increments
* the token position.
Modified: lyx-devel/trunk/src/tex2lyx/test/test-structure.tex
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/test/test-structure.tex Sun Mar 4 02:23:46
2012 (r40849)
+++ lyx-devel/trunk/src/tex2lyx/test/test-structure.tex Sun Mar 4 14:27:53
2012 (r40850)
@@ -293,10 +293,11 @@
verbat im % $ 02/19/12
hjkh
jkh \ blah
-atesta
+\begin{centering}
zzz
+\end{raggedleft}
\end{verbatim}
and bibliography:
Modified: lyx-devel/trunk/src/tex2lyx/text.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/text.cpp Sun Mar 4 02:23:46 2012
(r40849)
+++ lyx-devel/trunk/src/tex2lyx/text.cpp Sun Mar 4 14:27:53 2012
(r40850)
@@ -1344,8 +1344,8 @@
}
else if (name == "verbatim") {
- os << "\n\\begin_layout Verbatim\n";
- string const s = p.verbatimEnvironment("verbatim");
+ os << "\n\\end_layout\n\n\\begin_layout Verbatim\n";
+ string const s = p.plainEnvironment("verbatim");
string::const_iterator it2 = s.begin();
for (string::const_iterator it = s.begin(), et = s.end(); it !=
et; ++it) {
if (*it == '\\')