]> git.lyx.org Git - features.git/commitdiff
- text.cpp: - fix tex2lyx parsing of verbatim environments
authorUwe Stöhr <uwestoehr@web.de>
Sun, 4 Mar 2012 13:27:53 +0000 (13:27 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Sun, 4 Mar 2012 13:27:53 +0000 (13:27 +0000)
- Parser.cpp: - new function to parse verbatim environments
- test/test-structure.tex: updated example

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40850 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/Parser.cpp
src/tex2lyx/Parser.h
src/tex2lyx/test/test-structure.tex
src/tex2lyx/text.cpp

index c48301207a447ec0e5593c64fea0e2b39881a2c0..75eb5182033af6a2021df6972ddc18c4b035bf75 100644 (file)
@@ -481,6 +481,30 @@ string const Parser::verbatimEnvironment(string const & name)
 }
 
 
+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();
index 5e749e3019f40d8be6897664d0e68fed87ae94cb..2f4e26a5873be876e107b649ed21e1cba1cbbdd6 100644 (file)
@@ -196,6 +196,12 @@ public:
         * 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.
index ec61f6fc43b4223d7e6d26d5cb6ec316a4cab6da..b487bf17b4ba8f14ebc8acfc962a3772dad90726 100644 (file)
@@ -293,10 +293,11 @@ verbatim:
 verbat  im % $ 02/19/12
 hjkh
 jkh \ blah
-atesta
+\begin{centering}
 
 
 zzz
+\end{raggedleft}
 
 \end{verbatim}
 and bibliography:
index 99db3eab11b0535f595bf1bdb518377f25e367d9..e4c16027dc88662a37ae873f880a220ad3994672 100644 (file)
@@ -1344,8 +1344,8 @@ void parse_environment(Parser & p, ostream & os, bool outer,
        }
 
        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 == '\\')