X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmathed%2FInsetMathHull.cpp;h=537d6670c5ffa0d090ffb0b2acfd5c372a001f83;hb=4ed0312c51704780af1c452d3a82a84171b3725a;hp=f5dce8088492f6f4a3cb502b43af37ceb93f7405;hpb=e500dc19c153341fa9d60f3b6dd5b4fddc165607;p=lyx.git diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index f5dce80884..537d6670c5 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -148,7 +148,7 @@ namespace { } // namespace -static InsetLabel * dummy_pointer = 0; +static InsetLabel * dummy_pointer = nullptr; InsetMathHull::InsetMathHull(Buffer * buf) : InsetMathGrid(buf, 1, 1), type_(hullNone), numbered_(1, NONUMBER), @@ -703,26 +703,13 @@ static docstring latexString(InsetMathHull const & inset) // \newcommand{\xxx}{\text{$\phi$}}) gets processed twice. The // first time as a whole, and the second time only the inner math. // In this last case inset.buffer() would be invalid. - static Encoding const * encoding = 0; + static Encoding const * encoding = nullptr; if (inset.isBufferValid()) encoding = &(inset.buffer().params().encoding()); otexrowstream ots(ls); TeXMathStream wi(ots, false, true, TeXMathStream::wsPreview, encoding); inset.write(wi); - docstring const s = ls.str(); - docstring res; - for (char_type c : s) { - if (encoding->encodable(c)) - res += c; - else { - // indicate the encoding error by a boxed '?' - res += "{\\fboxsep=1pt\\fbox{?}}"; - LYXERR0("Uncodable character" << " '" - << c - << "'"); - } - } - return res; + return ls.str(); } @@ -1369,7 +1356,7 @@ void InsetMathHull::glueall(HullType type) MathData ar; for (idx_type i = 0; i < nargs(); ++i) ar.append(cell(i)); - InsetLabel * label = 0; + InsetLabel * label = nullptr; if (type == hullEquation) { // preserve first non-empty label for (row_type row = 0; row < nrows(); ++row) { @@ -2432,7 +2419,7 @@ void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) cons } odocstringstream osmath; - MathMLStream ms(osmath, mathmlNamespacePrefix, true); + MathMLStream ms(osmath, mathmlNamespacePrefix); // Output the MathML subtree. // TeX transcription. Avoid MTag/ETag so that there are no extraneous spaces. @@ -2455,7 +2442,7 @@ void InsetMathHull::docbook(XMLStream & xs, OutputParams const & runparams) cons // First, generate the MathML expression. If there is an error in the generation, this block is not fully // executed, and the formula is not output to the DocBook stream. odocstringstream ostmp; - MathMLStream mstmp(ostmp, ms.xmlns(), ms.xmlMode()); + MathMLStream mstmp(ostmp, ms.xmlns()); mathmlize(mstmp); // Choose the display style for the formula, to be output as an attribute near the formula root. @@ -2545,33 +2532,37 @@ void InsetMathHull::mathmlize(MathMLStream & ms) const { bool const havetable = haveNumbers() || nrows() > 1 || ncols() > 1; - if (havetable) { - if (getType() == hullSimple) { - ms << MTag("mtable"); - } else if (getType() >= hullAlign && getType() <= hullXXAlignAt) { - string alignment; - for (col_type col = 0; col < ncols(); ++col) { - alignment += (col % 2) ? "left " : "right "; - } - ms << MTag("mtable", "displaystyle='true' columnalign='" + alignment + "'"); - } else { - ms << MTag("mtable", "displaystyle='true'"); + // Simplest case: single row, single column, no numbering. + if (!havetable) { + ms << cell(index(0, 0)); + return; + } + + // More complex case: wrap elements in a table. + if (getType() == hullSimple) { + ms << MTag("mtable"); + } else if (getType() >= hullAlign && getType() <= hullXXAlignAt) { + // hullAlign, hullAlignAt, hullXAlignAt, hullXXAlignAt + string alignment; + for (col_type col = 0; col < ncols(); ++col) { + alignment += (col % 2) ? "left " : "right "; } + ms << MTag("mtable", "displaystyle='true' columnalign='" + alignment + "'"); + } else { + ms << MTag("mtable", "displaystyle='true'"); } - char const * const celltag = havetable ? "mtd" : "mrow"; - // FIXME There does not seem to be wide support at the moment - // for mlabeledtr, so we have to use just mtr for now. - // char const * const rowtag = haveNumbers() ? "mlabeledtr" : "mtr"; - char const * const rowtag = "mtr"; for (row_type row = 0; row < nrows(); ++row) { - if (havetable) - ms << MTag(rowtag); + // No Wed browser supports mlabeledtr in 2023, even though it has been introduced in + // MathML 2 (2003). Moreover, it is not supported in MathML 4 Core. + ms << MTag("mtr"); + for (col_type col = 0; col < ncols(); ++col) { - ms << MTag(celltag) + ms << MTag("mtd") << cell(index(row, col)) - << ETag(celltag); + << ETag("mtd"); } + // fleqn? if (haveNumbers()) { ms << MTag("mtd"); @@ -2580,18 +2571,18 @@ void InsetMathHull::mathmlize(MathMLStream & ms) const ms << MTagInline("mtext") << '(' << num << ')' << ETagInline("mtext"); ms << ETag("mtd"); } - if (havetable) - ms << ETag(rowtag); + + ms << ETag("mtr"); } - if (havetable) - ms << ETag("mtable"); + + ms << ETag("mtable"); } void InsetMathHull::mathAsLatex(TeXMathStream & os) const { MathEnsurer ensurer(os, false); - bool havenumbers = haveNumbers(); + bool const havenumbers = haveNumbers(); bool const havetable = havenumbers || nrows() > 1 || ncols() > 1; if (!havetable) { @@ -2612,7 +2603,7 @@ void InsetMathHull::mathAsLatex(TeXMathStream & os) const docstring const & num = numbers_[row]; if (!num.empty()) os << '(' << num << ')'; - os << ""; + os << ""; } os << ""; } @@ -2645,16 +2636,23 @@ docstring InsetMathHull::xhtml(XMLStream & xs, OutputParams const & op) const success = true; } catch (MathExportException const &) {} if (success) { + string const name_space_declaration = "xmlns='http://www.w3.org/1998/Math/MathML'"; if (getType() == hullSimple) - xs << xml::StartTag("math", - "xmlns=\"http://www.w3.org/1998/Math/MathML\"", true); - else - xs << xml::StartTag("math", - "display=\"block\" xmlns=\"http://www.w3.org/1998/Math/MathML\"", true); + xs << xml::StartTag("math", name_space_declaration, true); + else { + if (!xs.isLastTagCR()) + xs << xml::CR(); + xs << xml::StartTag("math", name_space_declaration + " display='block'", true); + } + xs << XMLStream::ESCAPE_NONE - << os.str() - << xml::EndTag("math"); + << os.str(); + + if (!xs.isLastTagCR()) + xs << xml::CR(); + xs << xml::EndTag("math") << xml::CR(); } + // In case of failure, generate an image. } else if (mathtype == BufferParams::HTML) { odocstringstream os; HtmlStream ms(os); @@ -2669,6 +2667,7 @@ docstring InsetMathHull::xhtml(XMLStream & xs, OutputParams const & op) const << os.str() << xml::EndTag(tag); } + // In case of failure, generate an image. } // what we actually want is this: @@ -2683,7 +2682,7 @@ docstring InsetMathHull::xhtml(XMLStream & xs, OutputParams const & op) const // // so this is for Images. if (!success && mathtype != BufferParams::LaTeX) { - graphics::PreviewImage const * pimage = 0; + graphics::PreviewImage const * pimage = nullptr; if (!op.dryrun) { loadPreview(docit_); pimage = preview_->getPreviewImage(buffer()); @@ -2746,7 +2745,7 @@ docstring InsetMathHull::xhtml(XMLStream & xs, OutputParams const & op) const void InsetMathHull::toString(odocstream & os) const { odocstringstream ods; - plaintext(ods, OutputParams(0)); + plaintext(ods, OutputParams(nullptr)); os << ods.str(); } @@ -2754,7 +2753,7 @@ void InsetMathHull::toString(odocstream & os) const void InsetMathHull::forOutliner(docstring & os, size_t const, bool const) const { odocstringstream ods; - OutputParams op(0); + OutputParams op(nullptr); op.for_toc = true; // FIXME: this results in spilling TeX into the LyXHTML output since the // outliner is used to generate the LyXHTML list of figures/etc.