#include "frontends/FontMetrics.h"
#include "support/debug.h"
-#include "support/lstrings.h"
#include "support/textutils.h"
#include <algorithm>
namespace lyx {
-extern bool has_math_fonts;
-
namespace {
latexkeys const * makeSubstitute(char_type c)
}
-void InsetMathChar::write(WriteStream & os) const
+void InsetMathChar::write(TeXMathStream & os) const
{
+ if (os.latex() && os.pendingSpace()) {
+ if (isAlphaASCII(char_))
+ os.os() << ' ';
+ os.pendingSpace(false);
+ }
os.os().put(char_);
}
// mathalpha, then we'll treat it as an identifier, otherwise as an
// operator.
// Worst case: We get bad spacing, or bad italics.
-void InsetMathChar::mathmlize(MathStream & ms) const
+// In any case, never let MathML stretch a single character when it
+// is recognised as an operator, to match TeX' behaviour.
+void InsetMathChar::mathmlize(MathMLStream & ms) const
{
std::string entity;
switch (char_) {
case '>': entity = ">"; break;
case '&': entity = "&"; break;
case ' ': {
- if (ms.xmlMode())
- ms << from_ascii(" ");
- else
- ms << from_ascii(" ");
+ ms << from_ascii(" ");
return;
}
default: break;
}
if (!entity.empty()) {
- ms << "<" << from_ascii(ms.namespacedTag("mo")) << ">"
+ ms << MTagInline("mo", "stretchy='false'")
<< from_ascii(entity)
- << "</" << from_ascii(ms.namespacedTag("mo")) << ">";
+ << ETagInline("mo");
return;
}
char const * type =
(isAlphaASCII(char_) || Encodings::isMathAlpha(char_))
? "mi" : "mo";
- // we don't use MTag and ETag because we do not want the spacing before the end tag.
- docstring tag = from_ascii(ms.namespacedTag(type));
- ms << "<" << tag << ">" << char_type(char_) << "</" << tag << ">";
+ ms << MTagInline(type, std::string(type) == "mo" ? "stretchy='false'" : "")
+ << char_type(char_)
+ << ETagInline(type);
}
case '<': entity = "<"; break;
case '>': entity = ">"; break;
case '&': entity = "&"; break;
- case ' ': entity = " "; break;
+ case ' ': entity = " "; break;
default: break;
}
MathClass InsetMathChar::mathClass() const
{
// this information comes from fontmath.ltx in LaTeX source.
- char const ch = static_cast<char>(char_);
if (subst_)
return string_to_class(subst_->extra);
- else if (support::contains(",;", ch))
+
+ if (!isASCII(char_))
+ return MC_ORD;
+
+ switch (static_cast<char>(char_)) {
+ case ',':
+ case ';':
return MC_PUNCT;
- else if (support::contains("([", ch))
+ case '(':
+ case '[':
return MC_OPEN;
- else if (support::contains(")]!?", ch))
+ case ')':
+ case ']':
+ case '!':
+ case '?':
return MC_CLOSE;
- else return MC_ORD;
+ default:
+ return MC_ORD;
+ }
}