[LyX/master] MathML: let the user change the MathML version.
commit 7feffb89e931973bc1e9f3b2622724baca656df7 Author: Thibaut Cuvelier Date: Tue Oct 1 23:53:30 2024 +0200 MathML: let the user change the MathML version. Discussed in https://www.lyx.org/trac/ticket/13058. development/FORMAT | 7 +- lib/lyx2lyx/lyx_2_5.py | 46 +- src/Buffer.cpp | 7 +- src/BufferParams.cpp | 8 +- src/BufferParams.h | 8 +- src/CutAndPaste.cpp| 2 +- src/OutputParams.h | 3 +- src/frontends/qt/GuiDocument.cpp | 8 + src/frontends/qt/ui/OutputUi.ui| 899 - src/mathed/InsetMathBox.cpp| 12 +- src/mathed/InsetMathEnsureMath.cpp | 3 +- src/mathed/InsetMathHull.cpp | 8 +- src/tex2lyx/Preamble.cpp | 4 +- src/tex2lyx/Preamble.h | 1 + src/version.h | 4 +- 15 files changed, 596 insertions(+), 424 deletions(-) -- lyx-cvs mailing list lyx-cvs@lists.lyx.org https://lists.lyx.org/mailman/listinfo/lyx-cvs
[LyX/master] Math: use the new MathFontInfo class to determine HTML and MathML attributes.
commit 78ce5ebc45d3663f5d8ec6b821c67c575455b666 Author: Thibaut Cuvelier Date: Tue Oct 29 04:12:29 2024 +0100 Math: use the new MathFontInfo class to determine HTML and MathML attributes. --- src/mathed/InsetMathFont.cpp | 61 +++- 1 file changed, 9 insertions(+), 52 deletions(-) diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index 584de5c1ad..079ed56bba 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -299,35 +299,11 @@ void InsetMathFont::htmlize(HtmlStream & os) const // FIXME These are not quite right, because they do not nest // correctly. A proper fix would presumably involve tracking // the fonts already in effect. - std::string variant; - docstring const & tag = key_->name; - if (tag == "mathnormal" || tag == "mathrm" - || tag == "text" || tag == "textnormal" - || tag == "textrm" || tag == "textup" - || tag == "textmd") - variant = "normal"; - else if (tag == "frak" || tag == "mathfrak") - variant = "fraktur"; - else if (tag == "mathbf" || tag == "textbf") - variant = "bold"; - else if (tag == "mathbb" || tag == "mathbbm" -|| tag == "mathds") - variant = "double-struck"; - else if (tag == "mathcal") - variant = "script"; - else if (tag == "mathit" || tag == "textsl" -|| tag == "emph" || tag == "textit") - variant = "italic"; - else if (tag == "mathsf" || tag == "textsf") - variant = "sans"; - else if (tag == "mathtt" || tag == "texttt") - variant = "monospace"; - else if (tag == "textipa" || tag == "textsc" || tag == "noun") - variant = "noun"; - - docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4); - if (!variant.empty()) { - os << MTag("span", "class='" + variant + "'") + const MathFontInfo font = MathFontInfo::fromMacro(key_->name); + const std::string span_class = font.toHTMLSpanClass(); + + if (!span_class.empty()) { + os << MTag("span", "class='" + span_class + "'") << cell(0) << ETag("span"); } else @@ -341,29 +317,10 @@ void InsetMathFont::mathmlize(MathMLStream & ms) const // FIXME These are not quite right, because they do not nest // correctly. A proper fix would presumably involve tracking // the fonts already in effect. - std::string variant; - docstring const & tag = key_->name; - if (tag == "mathnormal" || tag == "mathrm") - variant = "normal"; - else if (tag == "frak" || tag == "mathfrak") - variant = "fraktur"; - else if (tag == "mathbf" || tag == "textbf") - variant = "bold"; - else if (tag == "mathbb" || tag == "mathbbm" || tag == "mathds") - variant = "double-struck"; - else if (tag == "mathcal") - variant = "script"; - else if (tag == "mathit" || tag == "textsl" || tag == "emph" || - tag == "textit") - variant = "italic"; - else if (tag == "mathsf" || tag == "textsf") - variant = "sans-serif"; - else if (tag == "mathtt" || tag == "texttt") - variant = "monospace"; - // no support at present for textipa, textsc, noun - - if (tag == "text" || tag == "textnormal" || tag == "textrm" || - tag == "textup" || tag == "textmd") { + const MathFontInfo font = MathFontInfo::fromMacro(key_->name); + const std::string variant = font.toMathMLMathVariant(ms.version()); + + if (font.shape() == MathFontInfo::MATH_UP_SHAPE) { SetMode textmode(ms, true); ms << cell(0); } else if (!variant.empty()) { -- lyx-cvs mailing list lyx-cvs@lists.lyx.org https://lists.lyx.org/mailman/listinfo/lyx-cvs
[LyX/master] MathML: add a note about small caps.
commit 477e36db9f8f9a27bbe7e0c58d57aabc291bf5b3 Author: Thibaut Cuvelier Date: Tue Oct 29 03:17:12 2024 +0100 MathML: add a note about small caps. --- src/mathed/InsetMathFont.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index 25ee4ae53b..73822563c7 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -178,6 +178,7 @@ void InsetMathFont::htmlize(HtmlStream & os) const else if (tag == "mathtt" || tag == "texttt") variant = "monospace"; else if (tag == "textipa" || tag == "textsc" || tag == "noun") + // TODO: MathML doesn't seem to support small caps! variant = "noun"; docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4); -- lyx-cvs mailing list lyx-cvs@lists.lyx.org https://lists.lyx.org/mailman/listinfo/lyx-cvs
[LyX/master] Math: add a structure to hold font information.
commit 9a81bb36f4a51891730f052b84ca535f20583c52 Author: Thibaut Cuvelier Date: Tue Oct 29 04:06:07 2024 +0100 Math: add a structure to hold font information. It will allow to merge a lot of code for MathML and HTML: same parsing, slightly different outputs. The refactoring also shows clearly what parts are missing in HTML (while being easily fixable). The change is a prerequisite for implementing font nesting (although it is not done yet). The new class is not yet used within InsetMathFont; it will come in the next commit. Open question: should we use InsetMath::mode_type somewhere? I believe so, to determine whether the current default is italics or not in MathML. --- src/mathed/InsetMathFont.cpp | 145 +++ 1 file changed, 145 insertions(+) diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index 25ee4ae53b..584de5c1ad 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -28,6 +28,151 @@ using namespace lyx::support; namespace lyx { +namespace { +// Similar to FontInfo and its related enums, but specifically for the math +// mode. +// +// All types have enumerations, like FontEnums.h, even though there are +// sometimes only two cases: this design ensures some future-proofness and +// ensures that you cannot inadvertently swap two values. +class MathFontInfo { +public: + enum MathFontFamily { + MATH_NORMAL_FAMILY = 0, // Default value in MathML. + MATH_FRAKTUR_FAMILY, + MATH_SANS_FAMILY, + MATH_MONOSPACE_FAMILY, + MATH_DOUBLE_STRUCK_FAMILY, + MATH_SCRIPT_FAMILY, + MATH_SMALL_CAPS // Not natively supported in any version of MathML. + }; + + enum MathFontSeries { + MATH_MEDIUM_SERIES = 0, // Default value in MathML. // Default value in MathML. + MATH_BOLD_SERIES + }; + + enum MathFontShape { + MATH_UP_SHAPE = 0, + MATH_ITALIC_SHAPE // Default value in MathML mi, not outside. + }; + + MathFontInfo() : + family_(MATH_NORMAL_FAMILY), series_(MATH_MEDIUM_SERIES), shape_(MATH_UP_SHAPE) {} + MathFontInfo(const MathFontFamily family, const MathFontSeries series, const MathFontShape shape) : + family_(family), series_(series), shape_(shape) {} + + static MathFontInfo fromMacro(const docstring& tag) + { + MathFontInfo font; + if (tag == "mathnormal" || tag == "mathrm" + || tag == "text" || tag == "textnormal" + || tag == "textrm" || tag == "textup" + || tag == "textmd") + font.shape_ = MATH_UP_SHAPE; + else if (tag == "frak" || tag == "mathfrak") + font.family_ = MATH_FRAKTUR_FAMILY; + else if (tag == "mathbf" || tag == "textbf") + font.series_ = MATH_BOLD_SERIES; + else if (tag == "mathbb" || tag == "mathbbm" +|| tag == "mathds") + font.family_ = MATH_DOUBLE_STRUCK_FAMILY; + else if (tag == "mathcal") + font.family_ = MATH_SCRIPT_FAMILY; + else if (tag == "mathit" || tag == "textsl" +|| tag == "emph" || tag == "textit") + font.shape_ = MATH_ITALIC_SHAPE; + else if (tag == "mathsf" || tag == "textsf") + font.family_ = MATH_SANS_FAMILY; + else if (tag == "mathtt" || tag == "texttt") + font.family_ = MATH_MONOSPACE_FAMILY; + else if (tag == "textipa" || tag == "textsc" || tag == "noun") + font.family_ = MATH_SMALL_CAPS; + + return font; + } + + MathFontFamily family() const { return family_; } + MathFontSeries series() const { return series_; } + MathFontShape shape() const { return shape_; } + + std::string toMathMLMathVariant(MathMLStream::MathMLVersion mathml_version) const + { + return mathml_version == MathMLStream::MathMLVersion::mathml3 ? + toMathVariantForMathML3() : toMathVariantForMathMLCore(); + } + + std::string toHTMLSpanClass() const + { + // See the existing classes in InsetMathFont::validate. In particular, + // there is no double-struck style! + switch (family_) { + case MATH_MONOSPACE_FAMILY: + return "monospace"; + case MATH_FRAKTUR_FAMILY: + return "fraktur"; + case MATH_SCRIPT_FAMILY: + return "script"; + case MATH_SMALL_CAPS: + return "noun"; +
[LyX/master] Amend 477e36db.
commit 91a85dd96aa490ce2ba0d6593d382be2e44ccea0 Author: Thibaut Cuvelier Date: Tue Oct 29 03:55:40 2024 +0100 Amend 477e36db. This was the wrong place... --- src/mathed/InsetMathFont.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index 73822563c7..25ee4ae53b 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -178,7 +178,6 @@ void InsetMathFont::htmlize(HtmlStream & os) const else if (tag == "mathtt" || tag == "texttt") variant = "monospace"; else if (tag == "textipa" || tag == "textsc" || tag == "noun") - // TODO: MathML doesn't seem to support small caps! variant = "noun"; docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4); -- lyx-cvs mailing list lyx-cvs@lists.lyx.org https://lists.lyx.org/mailman/listinfo/lyx-cvs
[LyX/master] Math: support all font combinations in HTML.
commit 5c17e07bd11f5fc1e80d2f81f2a5741e5ee0b0a6 Author: Thibaut Cuvelier Date: Tue Oct 29 04:21:05 2024 +0100 Math: support all font combinations in HTML. This code cannot yet be triggered, we need nesting first. --- src/mathed/InsetMathFont.cpp | 75 ++-- 1 file changed, 52 insertions(+), 23 deletions(-) diff --git a/src/mathed/InsetMathFont.cpp b/src/mathed/InsetMathFont.cpp index 079ed56bba..97c250c2d7 100644 --- a/src/mathed/InsetMathFont.cpp +++ b/src/mathed/InsetMathFont.cpp @@ -104,28 +104,41 @@ public: std::string toHTMLSpanClass() const { - // See the existing classes in InsetMathFont::validate. In particular, - // there is no double-struck style! + std::string span_class; switch (family_) { - case MATH_MONOSPACE_FAMILY: - return "monospace"; - case MATH_FRAKTUR_FAMILY: - return "fraktur"; - case MATH_SCRIPT_FAMILY: - return "script"; - case MATH_SMALL_CAPS: - return "noun"; - case MATH_SANS_FAMILY: - return "sans"; - case MATH_NORMAL_FAMILY: - if (series_ == MATH_MEDIUM_SERIES) { - return shape_ == MATH_UP_SHAPE ? "normal" : "italic"; - } - return "bold"; - case MATH_DOUBLE_STRUCK_FAMILY: - // No support for double-struck font in CSS. - return ""; + case MATH_NORMAL_FAMILY: + break; + case MATH_FRAKTUR_FAMILY: + span_class = "fraktur"; + break; + case MATH_SANS_FAMILY: + span_class = "sans"; + break; + case MATH_MONOSPACE_FAMILY: + span_class = "monospace"; + break; + case MATH_DOUBLE_STRUCK_FAMILY: + // This style does not exist in HTML and cannot be implemented in CSS. + break; + case MATH_SCRIPT_FAMILY: + span_class = "script"; + break; + case MATH_SMALL_CAPS: + span_class = "noun"; + break; + } + + if (series_ == MATH_BOLD_SERIES) { + if (!span_class.empty()) span_class += "-"; + span_class += "bold"; + } + + if (shape_ == MATH_ITALIC_SHAPE) { + if (!span_class.empty()) span_class += "-"; + span_class += "italic"; } + + return span_class; } private: @@ -282,13 +295,29 @@ void InsetMathFont::validate(LaTeXFeatures & features) const } else if (features.runparams().math_flavor == OutputParams::MathAsHTML) { features.addCSSSnippet( "span.normal{font: normal normal normal inherit serif;}\n" - "span.fraktur{font: normal normal normal inherit cursive;}\n" "span.bold{font: normal normal bold inherit serif;}\n" - "span.script{font: normal normal normal inherit cursive;}\n" "span.italic{font: italic normal normal inherit serif;}\n" + "span.bold-italic{font: italic normal bold inherit serif;}\n" + "span.fraktur{font: normal normal normal inherit cursive;}\n" + "span.fraktur-bold{font: normal normal bold inherit cursive;}\n" + "span.fraktur-italic{font: italic normal normal inherit cursive;}\n" + "span.fraktur-bold-italic{font: italic normal bold inherit cursive;}\n" + "span.script{font: normal normal normal inherit cursive;}\n" + "span.script-bold{font: normal normal bold inherit cursive;}\n" + "span.script-italic{font: italic normal normal inherit cursive;}\n" + "span.script-bold-italic{font: italic normal bold inherit cursive;}\n" "span.sans{font: normal normal normal inherit sans-serif;}\n" + "span.sans-bold{font: normal normal normal inherit bold-serif;}\n" + "span.sans-italic{font: italic normal normal inherit sans-serif;}\n" + "span.sans-bold-italic{font: italic normal normal inherit bold-serif;}\n" "span.monospace{font: normal normal normal in
[LyX/master] Amend 7feffb89: restore the meaning of the elements in the QComboBox.
commit 73c19cae414f4f31841191baf060017b57a6dc1d Author: Thibaut Cuvelier Date: Tue Oct 29 04:31:41 2024 +0100 Amend 7feffb89: restore the meaning of the elements in the QComboBox. The order is not user-friendly, but correct. Before this patch, the elements in the UI didn't correspond to the implemented behaviour. The problem is the order: the first element is always MathML, the second HTML, etc. I think we should rather use some `userData` in QComboBox items to decouple the order from the semantics. --- src/frontends/qt/ui/OutputUi.ui | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/frontends/qt/ui/OutputUi.ui b/src/frontends/qt/ui/OutputUi.ui index 842cd4fa94..a0a6879568 100644 --- a/src/frontends/qt/ui/OutputUi.ui +++ b/src/frontends/qt/ui/OutputUi.ui @@ -295,22 +295,22 @@ -MathML 3 +HTML -HTML +Images -Images +LaTeX -LaTeX +MathML 3 -- lyx-cvs mailing list lyx-cvs@lists.lyx.org https://lists.lyx.org/mailman/listinfo/lyx-cvs