uwesto...@lyx.org wrote: > Author: uwestoehr > Date: Tue Feb 21 00:38:13 2012 > New Revision: 40785 > URL: http://www.lyx.org/trac/changeset/40785 > > Log: > support for verbatim: step 2: tex2lyx support
Uwe, this is far more complicated than what you implemented. Believe me, if it was that easy I would have added verbatim support a long time ago. > Modified: > lyx-devel/trunk/src/tex2lyx/text.cpp > lyx-devel/trunk/src/version.h > > Modified: lyx-devel/trunk/src/tex2lyx/text.cpp > ============================================================================== > --- lyx-devel/trunk/src/tex2lyx/text.cpp Mon Feb 20 03:10:33 2012 (r40784) > +++ lyx-devel/trunk/src/tex2lyx/text.cpp Tue Feb 21 00:38:13 2012 (r40785) > @@ -1343,6 +1343,29 @@ > preamble.registerAutomaticallyLoadedPackage("verbatim"); > } > > + else if (name == "verbatim") { > + eat_whitespace(p, os, parent_context, false); eat_whitespace is wrong here. > + os << "\n\\begin_layout Verbatim\n"; > + string const s = p.verbatimEnvironment("verbatim"); The environment nesting in verbatimEnvironment() is not suitable for verbatim environments. Instead, you need to implement exactly the same algorithm as used by TeX for detecting the environment end. In order to do this, you probably also need to temporarily change the cat codes in the parser. > + string::const_iterator it2 = s.begin(); > + for (string::const_iterator it = s.begin(), et = s.end(); it != et; > ++it) { > + if (*it == '\n') { > + it2 = it + 1; > + // avoid adding an empty paragraph at the end > + // if there are 2 consecutive spaces at the end ignore it > + // because LyX will re-add a \n > + if ((it + 1 != et) && (it + 2 != et || *it2 != '\n')) > + os << "\n\\end_layout\n\\begin_layout Verbatim\n"; > + } else > + os << *it; This test for consecutive space looks wrong. In a verbatim block you should be able to write as many consecutive spaces (even at the end), and LyX should output them as is. If this special treatment is really needed the verbatim implementation in LyX looks wrong. > + } > + os << "\n\\end_layout\n\n"; > + p.skip_spaces(); > + skip_braces(p); // eat {} that might by set by LyX behind comments skip_braces() is wrong. > + // reset to Standard layout > + os << "\n\\begin_layout Standard\n"; > + } > + > else if (name == "lyxgreyedout") { > eat_whitespace(p, os, parent_context, false); > parent_context.check_layout(os); Note that you do not escape backslashes, but this is needed in the .lyx file format. Please add a test case as well. Georg