]> git.lyx.org Git - features.git/commitdiff
tex2lyx: Add a newline at the end of comment if not at the end of a paragraph.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 9 Sep 2015 09:47:47 +0000 (11:47 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 20 Nov 2015 14:07:21 +0000 (15:07 +0100)
When importing TeX code like
  %comment
  TEXT
the LyX document currently becomes
  [ERT %comment] TEXT
so that TEXT is now part of the comment.

Now output_comment adds a trailing newline if the token after the
comment is not a newline. Note that the newline that marks the end of
the comment has already been parsed at this point.

tex2lyx tests have been checked manually and updated.

Fixes ticket #9551.

src/tex2lyx/test/CJK.lyx.lyx
src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
src/tex2lyx/test/box-color-size-space-align.lyx.lyx
src/tex2lyx/test/test-insets-basic.lyx.lyx
src/tex2lyx/test/test-insets.lyx.lyx
src/tex2lyx/test/test-structure.lyx.lyx
src/tex2lyx/test/test.lyx.lyx
src/tex2lyx/text.cpp

index 802fd0b2dd1e6f088b6d6be185180a72d6f21a9b..49c8dd517b930ed50be01937f36f77cb5dfd84ac 100644 (file)
@@ -167,6 +167,10 @@ status collapsed
 % The following Bg5 encoded text cannot be processed as is by latex.
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -177,6 +181,10 @@ status collapsed
 % It needs to be preprocessed by bg5conv or bg5latex needs to be used.
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -213,6 +221,10 @@ status collapsed
 % The following SJIS encoded text cannot be processed as is by latex.
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -223,6 +235,10 @@ status collapsed
 % It needs to be preprocessed by sjisconv or sjislatex needs to be used.
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
index 966cfc1e8f039b4c02d961c04079d71ddd772fe4..f5fe7ea80882fad9c4ff3b5794855f74b46e28ac 100644 (file)
@@ -175,6 +175,10 @@ status collapsed
 %empty language paragraph
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
index fe269d536e59b0c3e4f4b3d56a4493b797bb6bbf..649220448e16326a9cf35776f6e1567a3d0dea0a 100644 (file)
@@ -2400,6 +2400,10 @@ status collapsed
 %set back to justified
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
index d1bc2a187b1cb2098a6134e3f66a4b6bce249774..984660ad658a8f38414cd810cbc0484348ece2f5 100644 (file)
@@ -663,6 +663,10 @@ status collapsed
 bibliography since LaTeX throws an error.
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -675,6 +679,10 @@ status collapsed
 bibliographystyle{unsrt}
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -4348,6 +4356,10 @@ status collapsed
 % some comment
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -6753,6 +6765,10 @@ status collapsed
 % and another
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
index 89ebe8ae8a6cc6c9b0c45a2d2d8cc954617afed6..d8bac4e343b6d95379345ae79b90819bffbc96be 100644 (file)
@@ -112,6 +112,10 @@ status collapsed
 %stupid stuff
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -639,6 +643,10 @@ status collapsed
 bibliography since LaTeX throws an error.
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -651,6 +659,10 @@ status collapsed
 bibliographystyle{unsrt}
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -4401,6 +4413,10 @@ status collapsed
 % some comment
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
@@ -7192,6 +7208,10 @@ status collapsed
 % and another
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
index 961821333b6277a845b2dfbe6ea14dd584bf44cf..2f9c0954d0ffa499998a65dcd48b8e010974bbb9 100644 (file)
@@ -124,6 +124,10 @@ status collapsed
 % this should be recognized as empty date:
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
index 53e3ec463dea6e1862ec1819924112a6c3d2dbcc..68b2dc678a3798e071f007cf6bee6fd9f5b23239 100644 (file)
@@ -120,6 +120,10 @@ status collapsed
 %Midline comment
 \end_layout
 
+\begin_layout Plain Layout
+
+\end_layout
+
 \end_inset
 
 
index 0e593ceca540515bb20d04ac25720e50fa34d814..ab4c75fc4d64ffc0de9ea6e7dd8babc3eea17c23 100644 (file)
@@ -580,6 +580,16 @@ void output_ert_inset(ostream & os, string const & s, Context & context)
 }
 
 
+void output_comment(Parser & p, ostream & os, string const & s,
+                    Context & context)
+{
+       if (p.next_token().cat() == catNewline)
+               output_ert_inset(os, '%' + s, context);
+       else
+               output_ert_inset(os, '%' + s + '\n', context);
+}
+
+
 Layout const * findLayout(TextClass const & textclass, string const & name, bool command)
 {
        Layout const * layout = findLayoutWithoutModule(textclass, name, command);
@@ -1189,13 +1199,13 @@ void parse_box(Parser & p, ostream & os, unsigned outer_flags,
                // LyX puts a % after the end of the minipage
                if (p.next_token().cat() == catNewline && p.next_token().cs().size() > 1) {
                        // new paragraph
-                       //output_ert_inset(os, "%dummy", parent_context);
+                       //output_comment(p, os, "dummy", parent_context);
                        p.get_token();
                        p.skip_spaces();
                        parent_context.new_paragraph(os);
                }
                else if (p.next_token().cat() == catSpace || p.next_token().cat() == catNewline) {
-                       //output_ert_inset(os, "%dummy", parent_context);
+                       //output_comment(p, os, "dummy", parent_context);
                        p.get_token();
                        p.skip_spaces();
                        // We add a protected space if something real follows
@@ -1880,7 +1890,7 @@ void parse_comment(Parser & p, ostream & os, Token const & t, Context & context)
        LASSERT(t.cat() == catComment, return);
        if (!t.cs().empty()) {
                context.check_layout(os);
-               output_ert_inset(os, '%' + t.cs(), context);
+               output_comment(p, os, t.cs(), context);
                if (p.next_token().cat() == catNewline) {
                        // A newline after a comment line starts a new
                        // paragraph
@@ -2826,8 +2836,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        context.check_layout(os);
                        // FIXME: This is a hack to prevent paragraph
                        // deletion if it is empty. Handle this better!
-                       output_ert_inset(os,
-                               "%dummy comment inserted by tex2lyx to "
+                       output_comment(p, os,
+                               "dummy comment inserted by tex2lyx to "
                                "ensure that this paragraph is not empty",
                                context);
                        // Both measures above may generate an additional