diff --git a/lib/syntax.default b/lib/syntax.default index f713cfae8a..67d25bd07c 100644 --- a/lib/syntax.default +++ b/lib/syntax.default @@ -703,30 +703,30 @@ thebibliography{} % Environments that start math mode. % $...$, $$...$$, \(...\) and \[...\] are hardcoded in tex2lyx. -% The arguments are currently ignored. +% The arguments are currently ignored (apart from displaymath). \begin{mathenvironments} -equation -equation* -eqnarray -eqnarray* -align -align* -gather -gather* -multline -multline* -math -displaymath -flalign -flalign +equation{displaymath} +equation*{displaymath} +eqnarray{displaymath} +eqnarray*{displaymath} +align{displaymath} +align*{displaymath} +gather{displaymath} +gather*{displaymath} +multline{displaymath} +multline*{displaymath} +math{} +displaymath{displaymath} +flalign{displaymath} +flalign{displaymath} % These require extra args -alignat -alignat* -xalignat -xalignat* -xxalignat +alignat{}{displaymath} +alignat*{displaymath} +xalignat{}{displaymath} +xalignat*{}{displaymath} +xxalignat{}{displaymath} % These are not known by LyX but work nevertheless: -empheq +empheq[]{}{displaymath} \end{mathenvironments} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/tex2lyx/math.cpp b/src/tex2lyx/math.cpp index f615926efa..d17d1d9017 100644 --- a/src/tex2lyx/math.cpp +++ b/src/tex2lyx/math.cpp @@ -27,6 +27,16 @@ bool is_math_env(string const & name) } +bool is_display_math_env(string const & name) +{ + CommandMap::const_iterator it = known_math_environments.find(name); + if (it != known_math_environments.end()) + if (!it->second.empty()) + return it->second.back() == displaymath; + return false; +} + + void parse_math(Parser & p, ostream & os, unsigned flags, const mode_type mode) { while (p.good()) { diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index c6b4b68bbc..addfe3f8c7 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -357,6 +357,8 @@ void read_command(Parser & p, string command, CommandMap & commands) arguments.push_back(required); else if (arg == "item") arguments.push_back(item); + else if (arg == "displaymath") + arguments.push_back(displaymath); else arguments.push_back(verbatim); } else { diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h index e1d779a115..ce201c2cec 100644 --- a/src/tex2lyx/tex2lyx.h +++ b/src/tex2lyx/tex2lyx.h @@ -84,6 +84,7 @@ std::string join(std::vector const & input, char const * delim); bool is_math_env(std::string const & name); +bool is_display_math_env(std::string const & name); char const * const * is_known(std::string const &, char const * const *); /*! @@ -117,7 +118,8 @@ enum ArgumentType { required, verbatim, item, - optional + optional, + displaymath, }; class FullCommand { diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 1886c08956..1fb0e18aa4 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -689,6 +689,7 @@ void parse_arguments(string const & command, else ert += p.verbatim_item(); break; + case displaymath: case verbatim: // This argument may contain special characters ert += '{' + p.verbatim_item() + '}'; @@ -1157,6 +1158,12 @@ void parse_environment(Parser & p, ostream & os, bool outer, parse_math(p, os, FLAG_END, MATH_MODE); os << "\\end{" << name << "}"; end_inset(os); + if (is_display_math_env(name)) { + // Prevent the conversion of a line break to a space + // (bug 7668). This does not change the output, but + // looks ugly in LyX. + eat_whitespace(p, os, parent_context, false); + } } else if (unstarred_name == "tabular" || name == "longtable") { @@ -1900,7 +1907,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, context.check_layout(os); begin_inset(os, "Formula "); Token const & n = p.get_token(); - if (n.cat() == catMath && outer) { + bool const display(n.cat() == catMath && outer); + if (display) { // TeX's $$...$$ syntax for displayed math os << "\\["; parse_math(p, os, FLAG_SIMPLE, MATH_MODE); @@ -1914,6 +1922,12 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, os << '$'; } end_inset(os); + if (display) { + // Prevent the conversion of a line break to a + // space (bug 7668). This does not change the + // output, but looks ugly in LyX. + eat_whitespace(p, os, context, false); + } } else if (t.cat() == catSuper || t.cat() == catSub) @@ -2160,6 +2174,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, parse_math(p, os, FLAG_EQUATION, MATH_MODE); os << "\\]"; end_inset(os); + // Prevent the conversion of a line break to a space + // (bug 7668). This does not change the output, but + // looks ugly in LyX. + eat_whitespace(p, os, context, false); } else if (t.cs() == "begin")