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.
% The following Bg5 encoded text cannot be processed as is by latex.
\end_layout
% The following Bg5 encoded text cannot be processed as is by latex.
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
% It needs to be preprocessed by bg5conv or bg5latex needs to be used.
\end_layout
% It needs to be preprocessed by bg5conv or bg5latex needs to be used.
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
% The following SJIS encoded text cannot be processed as is by latex.
\end_layout
% The following SJIS encoded text cannot be processed as is by latex.
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
% It needs to be preprocessed by sjisconv or sjislatex needs to be used.
\end_layout
% It needs to be preprocessed by sjisconv or sjislatex needs to be used.
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
%empty language paragraph
\end_layout
%empty language paragraph
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
%set back to justified
\end_layout
%set back to justified
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
bibliography since LaTeX throws an error.
\end_layout
bibliography since LaTeX throws an error.
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
bibliographystyle{unsrt}
\end_layout
bibliographystyle{unsrt}
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
% some comment
\end_layout
% some comment
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
% and another
\end_layout
% and another
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
%stupid stuff
\end_layout
%stupid stuff
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
bibliography since LaTeX throws an error.
\end_layout
bibliography since LaTeX throws an error.
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
bibliographystyle{unsrt}
\end_layout
bibliographystyle{unsrt}
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
% some comment
\end_layout
% some comment
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
% and another
\end_layout
% and another
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
% this should be recognized as empty date:
\end_layout
% this should be recognized as empty date:
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
%Midline comment
\end_layout
%Midline comment
\end_layout
+\begin_layout Plain Layout
+
+\end_layout
+
+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);
Layout const * findLayout(TextClass const & textclass, string const & name, bool command)
{
Layout const * layout = findLayoutWithoutModule(textclass, name, command);
// LyX puts a % after the end of the minipage
if (p.next_token().cat() == catNewline && p.next_token().cs().size() > 1) {
// new paragraph
// 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) {
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
p.get_token();
p.skip_spaces();
// We add a protected space if something real follows
LASSERT(t.cat() == catComment, return);
if (!t.cs().empty()) {
context.check_layout(os);
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
if (p.next_token().cat() == catNewline) {
// A newline after a comment line starts a new
// paragraph
context.check_layout(os);
// FIXME: This is a hack to prevent paragraph
// deletion if it is empty. Handle this better!
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
"ensure that this paragraph is not empty",
context);
// Both measures above may generate an additional