Use symbols file to lookup entities for delimiters. Fixes bug #8280.

Based upon work by Josh Hieronymus.

(cherry picked from commit 04b8f5cdc4)
This commit is contained in:
Richard Heck 2016-06-29 22:39:42 -04:00
parent 98ba7cf49d
commit f3fbfcfd05
5 changed files with 43 additions and 87 deletions

View File

@ -107,48 +107,9 @@ void InsetMathBig::normalize(NormalStream & os) const
void InsetMathBig::mathmlize(MathStream & os) const
{
os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>";
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 << "&par;";
else if (delim_ == "\\\\" || delim_ == "\\backslash")
os <<" \\";
else if (delim_ == "\\langle")
os << "&lt;";
else if (delim_ == "\\rangle")
os << "&gt;";
else if (delim_ == "\\lceil")
os << "&lceil;";
else if (delim_ == "\\rceil")
os << "&rceil;";
else if (delim_ == "\\lfloor")
os << "&lfloor;";
else if (delim_ == "\\rfloor")
os << "&rfloor;";
else if (delim_ == "\\downarrow")
os << "&darr;";
else if (delim_ == "\\uparrow")
os << "&uarr;";
else if (delim_ == "\\Downarrow")
os << "&dArr;";
else if (delim_ == "\\Uparrow")
os << "&uArr;";
else if (delim_ == "\\updownarrow")
os << "&varr;";
else if (delim_ == "\\Updownarrow")
os << "&vArr;";
os << "</mo>";
os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
<< convertDelimToXMLEscape(delim_)
<< "</mo>";
}
@ -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 << "&par;";
else if (delim_ == "\\\\" || delim_ == "\\backslash")
os <<" \\";
else if (delim_ == "\\langle")
os << "&lt;";
else if (delim_ == "\\rangle")
os << "&gt;";
else if (delim_ == "\\lceil")
os << "&lceil;";
else if (delim_ == "\\rceil")
os << "&rceil;";
else if (delim_ == "\\lfloor")
os << "&lfloor;";
else if (delim_ == "\\rfloor")
os << "&rfloor;";
else if (delim_ == "\\downarrow")
os << "&darr;";
else if (delim_ == "\\uparrow")
os << "&uarr;";
else if (delim_ == "\\Downarrow")
os << "&dArr;";
else if (delim_ == "\\Uparrow")
os << "&uArr;";
else if (delim_ == "\\updownarrow")
os << "&varr;";
else if (delim_ == "\\Updownarrow")
os << "&vArr;";
os << ETag("span");
os << MTag("span", "class='" + name + "symbol'")
<< convertDelimToXMLEscape(delim_)
<< ETag("span");
}

View File

@ -192,14 +192,21 @@ void InsetMathDelim::mathematica(MathematicaStream & os) const
void InsetMathDelim::mathmlize(MathStream & os) const
{
os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>" << left_ << "</mo>"
<< cell(0) << "<mo form='postfix' fence='true' stretchy='true' symmetric='true'>" << right_ << "</mo>";
os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>"
<< convertDelimToXMLEscape(left_)
<< "</mo>\n"
<< cell(0)
<< "\n<mo form='postfix' fence='true' stretchy='true' symmetric='true'>"
<< convertDelimToXMLEscape(right_)
<< "</mo>\n";
}
void InsetMathDelim::htmlize(HtmlStream & os) const
{
os << left_ << cell(0) << right_;
os << convertDelimToXMLEscape(left_)
<< cell(0)
<< convertDelimToXMLEscape(right_);
}

View File

@ -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("&lt;");
else if (c == '>')
return from_ascii("&gt;");
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

View File

@ -589,6 +589,9 @@ OctaveStream & operator<<(OctaveStream &, char);
///
OctaveStream & operator<<(OctaveStream &, int);
docstring convertDelimToXMLEscape(docstring const & name);
} // namespace lyx
#endif

View File

@ -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