2 * \file InsetMathEnsureMath.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Enrico Forestieri
9 * Full author contact details are available in file CREDITS.
14 #include "InsetMathEnsureMath.h"
17 #include "MathStream.h"
18 #include "MathSupport.h"
20 #include "LaTeXFeatures.h"
21 #include "MetricsInfo.h"
28 InsetMathEnsureMath::InsetMathEnsureMath(Buffer * buf)
29 : InsetMathNest(buf, 1)
33 Inset * InsetMathEnsureMath::clone() const
35 return new InsetMathEnsureMath(*this);
39 void InsetMathEnsureMath::metrics(MetricsInfo & mi, Dimension & dim) const
41 bool really_change_font = isTextFont(mi.base.fontname);
42 Changer dummy = really_change_font ? mi.base.changeFontSet("mathnormal")
44 cell(0).metrics(mi, dim);
45 metricsMarkers(mi, dim);
49 void InsetMathEnsureMath::draw(PainterInfo & pi, int x, int y) const
51 bool really_change_font = isTextFont(pi.base.fontname);
52 Changer dummy = really_change_font ? pi.base.changeFontSet("mathnormal")
54 cell(0).draw(pi, x, y);
55 drawMarkers(pi, x, y);
59 void InsetMathEnsureMath::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
61 cell(0).metricsT(mi, dim);
65 void InsetMathEnsureMath::drawT(TextPainter & pain, int x, int y) const
67 cell(0).drawT(pain, x, y);
71 void InsetMathEnsureMath::write(WriteStream & os) const
73 ModeSpecifier specifier(os, MATH_MODE);
74 os << "\\ensuremath{" << cell(0) << "}";
78 void InsetMathEnsureMath::mathmlize(MathStream & os) const
80 SetMode mathmode(os, false);
81 os << MTag("mstyle", "class='math'")
87 void InsetMathEnsureMath::htmlize(HtmlStream & os) const
89 SetHTMLMode mathmode(os, false);
90 os << MTag("span", "class='math'")
96 void InsetMathEnsureMath::infoize(odocstream & os) const
102 void InsetMathEnsureMath::validate(LaTeXFeatures & features) const
105 // It'd be better to be able to get this from an InsetLayout, but at present
106 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
107 if (features.runparams().math_flavor == OutputParams::MathAsMathML)
108 features.addCSSSnippet("mstyle.math { font-style: italic; }");
109 else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
110 features.addCSSSnippet("span.mathbox { font-style: italic; }");
112 InsetMathNest::validate(features);