} // namespace
-static InsetLabel * dummy_pointer = 0;
+static InsetLabel * dummy_pointer = nullptr;
InsetMathHull::InsetMathHull(Buffer * buf)
: InsetMathGrid(buf, 1, 1), type_(hullNone), numbered_(1, NONUMBER),
}
-// FIXME This should really be controlled by the TOC level, or
-// something of the sort.
-namespace {
- const char * counters_to_save[] = {"section", "chapter"};
- unsigned int const numcnts = sizeof(counters_to_save)/sizeof(char *);
-} // namespace
-
-
void InsetMathHull::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
{
if (!buffer_) {
Counters & cnts =
buffer_->masterBuffer()->params().documentClass().counters();
- // right now, we only need to do this at export time
- if (utype == OutputUpdate) {
- for (size_t i = 0; i < numcnts; ++i) {
- docstring const cnt = from_ascii(counters_to_save[i]);
- if (cnts.hasCounter(cnt))
- counter_map[cnt] = cnts.value(cnt);
- }
- }
-
// this has to be done separately
docstring const eqstr = from_ascii("equation");
if (cnts.hasCounter(eqstr)) {
- if (utype == OutputUpdate)
- counter_map[eqstr] = cnts.value(eqstr);
for (size_t i = 0; i != label_.size(); ++i) {
+ docstring const oldnumber = numbers_[i];
if (numbered(i)) {
Paragraph const & par = it.paragraph();
if (!par.isDeleted(it.pos())) {
numbers_[i] = from_ascii("#");
} else
numbers_[i] = empty_docstring();
+ // If the numbering has changed, trigger a new preview
+ if (oldnumber != numbers_[i] && RenderPreview::previewMath()) {
+ // Do we need to remove it first?
+ //preview_->removePreview(*buffer_);
+ preparePreview(it);
+ }
}
}
}
// \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);
if (lsize != "normalsize" && !prefixIs(lsize, "error"))
setfont += from_ascii("\\" + lsize + '\n');
- docstring setcnt;
- if (forexport && haveNumbers()) {
- docstring eqstr = from_ascii("equation");
- CounterMap::const_iterator it = counter_map.find(eqstr);
- if (it != counter_map.end()) {
- int num = it->second;
- if (num >= 0)
- setcnt += from_ascii("\\setcounter{") + eqstr + '}' +
- '{' + convert<docstring>(num) + '}' + '\n';
- }
- for (size_t i = 0; i != numcnts; ++i) {
- docstring cnt = from_ascii(counters_to_save[i]);
- it = counter_map.find(cnt);
- if (it == counter_map.end())
- continue;
- int num = it->second;
- if (num > 0)
- setcnt += from_ascii("\\setcounter{") + cnt + '}' +
- '{' + convert<docstring>(num) + '}';
- }
- }
- docstring const snippet = macro_preamble + setfont + setcnt
- + latexString(*this) + endfont;
+ docstring const snippet = macro_preamble + setfont + latexString(*this) + endfont;
LYXERR(Debug::MACROS, "Preview snippet: " << snippet);
preview_->addPreview(snippet, *buffer, forexport);
}
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) {
}
-docstring InsetMathHull::eolString(row_type row, bool fragile, bool latex,
- bool last_eoln) const
+void InsetMathHull::eol(TeXMathStream & os, row_type row, bool fragile, bool latex,
+ bool last_eoln) const
{
- docstring res;
if (numberedType()) {
if (label_[row]) {
docstring const name =
latex ? escape(label_[row]->getParam("name"))
: label_[row]->getParam("name");
- res += "\\label{" + name + '}';
+ os << "\\label{" + name + '}';
}
if (type_ != hullMultline) {
if (numbered_[row] == NONUMBER)
- res += "\\nonumber ";
+ os << "\\nonumber ";
else if (numbered_[row] == NOTAG)
- res += "\\notag ";
+ os<< "\\notag ";
}
+ if (os.output() == TeXMathStream::wsPreview && !numbers_[row].empty()) {
+ os << "\\global\\def\\theequation{" << numbers_[row] << "}\n";
+ }
+
}
// Never add \\ on the last empty line of eqnarray and friends
last_eoln = false;
- return res + InsetMathGrid::eolString(row, fragile, latex, last_eoln);
+ InsetMathGrid::eol(os, row, fragile, latex, last_eoln);
}
void InsetMathHull::write(TeXMathStream & os) const
//lyxerr << "toggling all numbers" << endl;
cur.recordUndoInset();
bool old = numberedType();
- if (type_ == hullMultline)
- numbered(nrows() - 1, !old);
- else
- for (row_type row = 0; row < nrows(); ++row)
+ if (type_ == hullMultline) {
+ row_type row = nrows() - 1;
+ numbered(row, !old);
+ if (old && label_[row]) {
+ delete label_[row];
+ label_[row] = 0;
+ }
+ } else {
+ for (row_type row = 0; row < nrows(); ++row) {
numbered(row, !old);
+ if (old && label_[row]) {
+ delete label_[row];
+ label_[row] = 0;
+ }
+ }
+ }
cur.message(old ? _("No number") : _("Number"));
cur.forceBufferUpdate();
bool old = numbered(r);
cur.message(old ? _("No number") : _("Number"));
numbered(r, !old);
+ if (old && label_[r]) {
+ delete label_[r];
+ label_[r] = 0;
+ }
cur.forceBufferUpdate();
break;
}
}
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.
// 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.
{
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");
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) {
docstring const & num = numbers_[row];
if (!num.empty())
os << '(' << num << ')';
- os << "</td>";
+ os << "</td>";
}
os << "</tr>";
}
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);
<< os.str()
<< xml::EndTag(tag);
}
+ // In case of failure, generate an image.
}
// what we actually want is this:
//
// 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());
void InsetMathHull::toString(odocstream & os) const
{
odocstringstream ods;
- plaintext(ods, OutputParams(0));
+ plaintext(ods, OutputParams(nullptr));
os << ods.str();
}
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.