From f3fbfcfd056f4f31b7994255ca3d2418622c02a1 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 29 Jun 2016 22:39:42 -0400 Subject: [PATCH] Use symbols file to lookup entities for delimiters. Fixes bug #8280. Based upon work by Josh Hieronymus. (cherry picked from commit 04b8f5cdc4b26105ea855fb9ec5b23227dfd55cb) --- src/mathed/InsetMathBig.cpp | 90 +++-------------------------------- src/mathed/InsetMathDelim.cpp | 13 +++-- src/mathed/MathStream.cpp | 22 +++++++++ src/mathed/MathStream.h | 3 ++ status.22x | 2 + 5 files changed, 43 insertions(+), 87 deletions(-) diff --git a/src/mathed/InsetMathBig.cpp b/src/mathed/InsetMathBig.cpp index 969dd472c7..293ff8b80d 100644 --- a/src/mathed/InsetMathBig.cpp +++ b/src/mathed/InsetMathBig.cpp @@ -107,48 +107,9 @@ void InsetMathBig::normalize(NormalStream & os) const void InsetMathBig::mathmlize(MathStream & os) const { - os << ""; - if (delim_ == "(" || delim_ == ")" - || delim_ == "[" || delim_ == "]" - || delim_ == "|" || delim_ == "/") - os << delim_; - else if (delim_ == "\\{" || delim_ == "\\lbrace") - os << "{"; - else if (delim_ == "\\}" || delim_ == "\\rbrace") - os << "}"; - else if (delim_ == "\\slash") - os << "/"; - else if (delim_ == "\\|" || delim_ == "\\vert") - os << "|"; - else if (delim_ == "\\Vert") - os << "∥"; - else if (delim_ == "\\\\" || delim_ == "\\backslash") - os <<" \\"; - else if (delim_ == "\\langle") - os << "<"; - else if (delim_ == "\\rangle") - os << ">"; - else if (delim_ == "\\lceil") - os << "⌈"; - else if (delim_ == "\\rceil") - os << "⌉"; - else if (delim_ == "\\lfloor") - os << "⌊"; - else if (delim_ == "\\rfloor") - os << "⌋"; - else if (delim_ == "\\downarrow") - os << "↓"; - else if (delim_ == "\\uparrow") - os << "↑"; - else if (delim_ == "\\Downarrow") - os << "⇓"; - else if (delim_ == "\\Uparrow") - os << "⇑"; - else if (delim_ == "\\updownarrow") - os << "↕"; - else if (delim_ == "\\Updownarrow") - os << "⇕"; - os << ""; + os << "" + << convertDelimToXMLEscape(delim_) + << ""; } @@ -161,48 +122,9 @@ void InsetMathBig::htmlize(HtmlStream & os) const case 4: case 5: name = "biggg"; break; default: name = "big"; break; } - os << MTag("span", "class='" + name + "symbol'"); - if (delim_ == "(" || delim_ == ")" - || delim_ == "[" || delim_ == "]" - || delim_ == "|" || delim_ == "/") - os << delim_; - else if (delim_ == "\\{" || delim_ == "\\lbrace") - os << "{"; - else if (delim_ == "\\}" || delim_ == "\\rbrace") - os << "}"; - else if (delim_ == "\\slash") - os << "/"; - else if (delim_ == "\\|" || delim_ == "\\vert") - os << "|"; - else if (delim_ == "\\Vert") - os << "∥"; - else if (delim_ == "\\\\" || delim_ == "\\backslash") - os <<" \\"; - else if (delim_ == "\\langle") - os << "<"; - else if (delim_ == "\\rangle") - os << ">"; - else if (delim_ == "\\lceil") - os << "⌈"; - else if (delim_ == "\\rceil") - os << "⌉"; - else if (delim_ == "\\lfloor") - os << "⌊"; - else if (delim_ == "\\rfloor") - os << "⌋"; - else if (delim_ == "\\downarrow") - os << "↓"; - else if (delim_ == "\\uparrow") - os << "↑"; - else if (delim_ == "\\Downarrow") - os << "⇓"; - else if (delim_ == "\\Uparrow") - os << "⇑"; - else if (delim_ == "\\updownarrow") - os << "↕"; - else if (delim_ == "\\Updownarrow") - os << "⇕"; - os << ETag("span"); + os << MTag("span", "class='" + name + "symbol'") + << convertDelimToXMLEscape(delim_) + << ETag("span"); } diff --git a/src/mathed/InsetMathDelim.cpp b/src/mathed/InsetMathDelim.cpp index 8e8b6e295b..b8adb1d812 100644 --- a/src/mathed/InsetMathDelim.cpp +++ b/src/mathed/InsetMathDelim.cpp @@ -192,14 +192,21 @@ void InsetMathDelim::mathematica(MathematicaStream & os) const void InsetMathDelim::mathmlize(MathStream & os) const { - os << "" << left_ << "" - << cell(0) << "" << right_ << ""; + os << "" + << convertDelimToXMLEscape(left_) + << "\n" + << cell(0) + << "\n" + << convertDelimToXMLEscape(right_) + << "\n"; } void InsetMathDelim::htmlize(HtmlStream & os) const { - os << left_ << cell(0) << right_; + os << convertDelimToXMLEscape(left_) + << cell(0) + << convertDelimToXMLEscape(right_); } diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp index dabfc0680f..ab2dcc7435 100644 --- a/src/mathed/MathStream.cpp +++ b/src/mathed/MathStream.cpp @@ -12,6 +12,7 @@ #include "MathStream.h" +#include "MathFactory.h" #include "MathData.h" #include "MathExtern.h" @@ -710,4 +711,25 @@ OctaveStream & operator<<(OctaveStream & os, string const & s) } +docstring convertDelimToXMLEscape(docstring const & name) +{ + if (name.size() == 1) { + char_type const c = name[0]; + if (c == '<') + return from_ascii("<"); + else if (c == '>') + return from_ascii(">"); + else + return name; + } + MathWordList const & words = mathedWordList(); + MathWordList::const_iterator it = words.find(name); + if (it != words.end()) { + docstring const escape = it->second.xmlname; + return escape; + } + LYXERR0("Unable to find `" << name <<"' in the mathWordList."); + return name; +} + } // namespace lyx diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h index 6cfd5855ec..f9a20112c5 100644 --- a/src/mathed/MathStream.h +++ b/src/mathed/MathStream.h @@ -589,6 +589,9 @@ OctaveStream & operator<<(OctaveStream &, char); /// OctaveStream & operator<<(OctaveStream &, int); + +docstring convertDelimToXMLEscape(docstring const & name); + } // namespace lyx #endif diff --git a/status.22x b/status.22x index 3bb7c3c996..a23d38815c 100644 --- a/status.22x +++ b/status.22x @@ -171,6 +171,8 @@ What's new - Fix output of vertical space in the middle of a paragraph (bug 8154). +- Output correct entities for named delimiters (bug 8280). + * TEX2LYX -- 2.39.5