2 * \file InsetMathHull.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathHull.h"
15 #include "InsetMathChar.h"
16 #include "InsetMathColor.h"
17 #include "MathExtern.h"
18 #include "MathFactory.h"
19 #include "MathStream.h"
20 #include "MathSupport.h"
23 #include "BufferParams.h"
24 #include "BufferView.h"
26 #include "CutAndPaste.h"
29 #include "FuncRequest.h"
30 #include "FuncStatus.h"
32 #include "LaTeXFeatures.h"
34 #include "MacroTable.h"
35 #include "output_xhtml.h"
36 #include "Paragraph.h"
37 #include "ParIterator.h"
39 #include "TextClass.h"
40 #include "TextPainter.h"
41 #include "TocBackend.h"
43 #include "insets/InsetLabel.h"
44 #include "insets/InsetRef.h"
45 #include "insets/RenderPreview.h"
47 #include "graphics/PreviewImage.h"
48 #include "graphics/PreviewLoader.h"
50 #include "frontends/alert.h"
51 #include "frontends/Painter.h"
53 #include "support/convert.h"
54 #include "support/lassert.h"
55 #include "support/debug.h"
56 #include "support/gettext.h"
57 #include "support/lstrings.h"
62 using namespace lyx::support;
66 using cap::grabAndEraseSelection;
70 int getCols(HullType type)
87 // returns position of first relation operator in the array
88 // used for "intelligent splitting"
89 size_t firstRelOp(MathData const & ar)
91 for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
93 return it - ar.begin();
98 char const * star(bool numbered)
100 return numbered ? "" : "*";
104 } // end anon namespace
107 HullType hullType(docstring const & s)
109 if (s == "none") return hullNone;
110 if (s == "simple") return hullSimple;
111 if (s == "equation") return hullEquation;
112 if (s == "eqnarray") return hullEqnArray;
113 if (s == "align") return hullAlign;
114 if (s == "alignat") return hullAlignAt;
115 if (s == "xalignat") return hullXAlignAt;
116 if (s == "xxalignat") return hullXXAlignAt;
117 if (s == "multline") return hullMultline;
118 if (s == "gather") return hullGather;
119 if (s == "flalign") return hullFlAlign;
120 if (s == "regexp") return hullRegexp;
121 lyxerr << "unknown hull type '" << to_utf8(s) << "'" << endl;
126 docstring hullName(HullType type)
129 case hullNone: return from_ascii("none");
130 case hullSimple: return from_ascii("simple");
131 case hullEquation: return from_ascii("equation");
132 case hullEqnArray: return from_ascii("eqnarray");
133 case hullAlign: return from_ascii("align");
134 case hullAlignAt: return from_ascii("alignat");
135 case hullXAlignAt: return from_ascii("xalignat");
136 case hullXXAlignAt: return from_ascii("xxalignat");
137 case hullMultline: return from_ascii("multline");
138 case hullGather: return from_ascii("gather");
139 case hullFlAlign: return from_ascii("flalign");
140 case hullRegexp: return from_ascii("regexp");
142 lyxerr << "unknown hull type '" << type << "'" << endl;
143 return from_ascii("none");
147 static InsetLabel * dummy_pointer = 0;
149 InsetMathHull::InsetMathHull(Buffer * buf)
150 : InsetMathGrid(buf, 1, 1), type_(hullNone), numbered_(1, true),
151 numbers_(1, empty_docstring()), label_(1, dummy_pointer),
152 preview_(new RenderPreview(this))
154 //lyxerr << "sizeof InsetMath: " << sizeof(InsetMath) << endl;
155 //lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
156 //lyxerr << "sizeof InsetMathChar: " << sizeof(InsetMathChar) << endl;
157 //lyxerr << "sizeof FontInfo: " << sizeof(FontInfo) << endl;
164 InsetMathHull::InsetMathHull(Buffer * buf, HullType type)
165 : InsetMathGrid(buf, getCols(type), 1), type_(type), numbered_(1, true),
166 numbers_(1, empty_docstring()), label_(1, dummy_pointer),
167 preview_(new RenderPreview(this))
175 InsetMathHull::InsetMathHull(InsetMathHull const & other) : InsetMathGrid(other)
181 InsetMathHull::~InsetMathHull()
183 for (size_t i = 0; i < label_.size(); ++i)
188 Inset * InsetMathHull::clone() const
190 return new InsetMathHull(*this);
194 InsetMathHull & InsetMathHull::operator=(InsetMathHull const & other)
198 InsetMathGrid::operator=(other);
200 numbered_ = other.numbered_;
201 numbers_ = other.numbers_;
202 buffer_ = other.buffer_;
203 for (size_t i = 0; i < label_.size(); ++i)
205 label_ = other.label_;
206 for (size_t i = 0; i != label_.size(); ++i) {
208 label_[i] = new InsetLabel(*label_[i]);
210 preview_.reset(new RenderPreview(*other.preview_, this));
216 void InsetMathHull::setBuffer(Buffer & buffer)
218 InsetMathGrid::setBuffer(buffer);
220 for (size_t i = 0; i != label_.size(); ++i) {
222 label_[i]->setBuffer(buffer);
227 void InsetMathHull::updateBuffer(ParIterator const & it, UpdateType utype)
230 //FIXME: buffer_ should be set at creation for this inset! Problem is
231 // This inset is created at too many places (see Parser::parse1() in
236 BufferParams const & bp = buffer_->params();
237 string const & lang = it->getParLanguage(bp)->code();
238 Counters & cnts = bp.documentClass().counters();
239 // so we don't have to write it ten times...
240 docstring const eqstr = from_ascii("equation");
242 for (size_t i = 0; i != label_.size(); ++i) {
243 if (numbered(i) && cnts.hasCounter(eqstr)) {
244 cnts.step(eqstr, utype);
245 numbers_[i] = cnts.theCounter(eqstr, lang);
247 numbers_[i] = empty_docstring();
249 label_[i]->updateBuffer(it, utype);
252 InsetMathGrid::updateBuffer(it, utype);
256 void InsetMathHull::addToToc(DocIterator const & pit)
259 //FIXME: buffer_ should be set at creation for this inset! Problem is
260 // This inset is created at too many places (see Parser::parse1() in
265 Toc & toc = buffer().tocBackend().toc("equation");
267 for (row_type row = 0; row != nrows(); ++row) {
271 label_[row]->addToToc(pit);
272 toc.push_back(TocItem(pit, 0, nicelabel(row)));
277 Inset * InsetMathHull::editXY(Cursor & cur, int x, int y)
283 return InsetMathNest::editXY(cur, x, y);
287 InsetMath::mode_type InsetMathHull::currentMode() const
289 if (type_ == hullNone)
290 return UNDECIDED_MODE;
291 // definitely math mode ...
296 bool InsetMathHull::idxFirst(Cursor & cur) const
304 bool InsetMathHull::idxLast(Cursor & cur) const
306 cur.idx() = nargs() - 1;
307 cur.pos() = cur.lastpos();
312 char InsetMathHull::defaultColAlign(col_type col)
314 if (type_ == hullEqnArray)
316 if (type_ == hullGather)
318 if (type_ >= hullAlign)
319 return "rl"[col & 1];
324 int InsetMathHull::defaultColSpace(col_type col)
326 if (type_ == hullAlign || type_ == hullAlignAt)
328 if (type_ == hullXAlignAt)
329 return (col & 1) ? 20 : 0;
330 if (type_ == hullXXAlignAt || type_ == hullFlAlign)
331 return (col & 1) ? 40 : 0;
336 docstring InsetMathHull::standardFont() const
341 font_name = from_ascii("texttt");
344 font_name = from_ascii("lyxnochange");
347 font_name = from_ascii("mathnormal");
353 ColorCode InsetMathHull::standardColor() const
359 color = Color_foreground;
368 bool InsetMathHull::previewState(BufferView * bv) const
370 if (!editing(bv) && RenderPreview::status() == LyXRC::PREVIEW_ON) {
371 graphics::PreviewImage const * pimage =
372 preview_->getPreviewImage(bv->buffer());
373 return pimage && pimage->image();
379 void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
381 if (previewState(mi.base.bv)) {
382 preview_->metrics(mi, dim);
383 // insert a one pixel gap in front of the formula
386 dim.des += displayMargin();
387 // Cache the inset dimension.
388 setDimCache(mi, dim);
392 FontSetChanger dummy1(mi.base, standardFont());
393 StyleChanger dummy2(mi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
395 // let the cells adjust themselves
396 InsetMathGrid::metrics(mi, dim);
399 dim.asc += displayMargin();
400 dim.des += displayMargin();
403 if (numberedType()) {
404 FontSetChanger dummy(mi.base, from_ascii("mathbf"));
406 for (row_type row = 0; row < nrows(); ++row)
407 l = max(l, mathed_string_width(mi.base.font, nicelabel(row)));
413 // make it at least as high as the current font
416 math_font_max_dim(mi.base.font, asc, des);
417 dim.asc = max(dim.asc, asc);
418 dim.des = max(dim.des, des);
419 // Cache the inset dimension.
420 // FIXME: This will overwrite InsetMathGrid dimension, is that OK?
421 setDimCache(mi, dim);
425 ColorCode InsetMathHull::backgroundColor(PainterInfo const & pi) const
427 if (previewState(pi.base.bv))
428 return graphics::PreviewLoader::backgroundColor();
433 void InsetMathHull::drawBackground(PainterInfo & pi, int x, int y) const
435 Dimension const dim = dimension(*pi.base.bv);
436 pi.pain.fillRectangle(x + 1, y - dim.asc + 1, dim.wid - 2,
437 dim.asc + dim.des - 1, pi.backgroundColor(this));
441 void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
443 use_preview_ = previewState(pi.base.bv);
445 if (type_ == hullRegexp) {
446 Dimension const dim = dimension(*pi.base.bv);
447 pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
448 dim.width() - 2, dim.height() - 2, Color_regexpframe);
451 // one pixel gap in front
452 preview_->draw(pi, x + 1, y);
453 setPosCache(pi, x, y);
457 ColorCode color = pi.selected && lyxrc.use_system_colors
458 ? Color_selectiontext : standardColor();
459 bool const really_change_color = pi.base.font.color() == Color_none;
460 ColorChanger dummy0(pi.base.font, color, really_change_color);
461 FontSetChanger dummy1(pi.base, standardFont());
462 StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
464 InsetMathGrid::draw(pi, x + 1, y);
466 if (numberedType()) {
467 int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
468 for (row_type row = 0; row < nrows(); ++row) {
469 int const yy = y + rowinfo_[row].offset_;
470 FontSetChanger dummy(pi.base, from_ascii("mathrm"));
471 docstring const nl = nicelabel(row);
475 setPosCache(pi, x, y);
479 void InsetMathHull::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
482 InsetMathGrid::metricsT(mi, dim);
485 WriteStream wi(os, false, true, WriteStream::wsDefault);
487 dim.wid = os.str().size();
494 void InsetMathHull::drawT(TextPainter & pain, int x, int y) const
497 InsetMathGrid::drawT(pain, x, y);
500 WriteStream wi(os, false, true, WriteStream::wsDefault);
502 pain.draw(x, y, os.str().c_str());
507 static docstring latexString(InsetMathHull const & inset)
510 // This has to be static, because a preview snippet or a math
511 // macro containing math in text mode (such as $\text{$\phi$}$ or
512 // \newcommand{\xxx}{\text{$\phi$}}) gets processed twice. The
513 // first time as a whole, and the second time only the inner math.
514 // In this last case inset.buffer() would be invalid.
515 static Encoding const * encoding = 0;
516 if (inset.isBufferValid())
517 encoding = &(inset.buffer().params().encoding());
518 WriteStream wi(ls, false, true, WriteStream::wsPreview, encoding);
524 void InsetMathHull::initUnicodeMath() const
526 // Trigger classification of the unicode symbols in this inset
527 docstring const dummy = latexString(*this);
531 void InsetMathHull::addPreview(DocIterator const & inset_pos,
532 graphics::PreviewLoader & /*ploader*/) const
534 if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
535 preparePreview(inset_pos);
540 void InsetMathHull::preparePreview(DocIterator const & pos,
541 bool forexport) const
543 // there is no need to do all the macro stuff if we're not
544 // actually going to generate the preview.
545 if (RenderPreview::status() != LyXRC::PREVIEW_ON && !forexport)
548 Buffer const * buffer = pos.buffer();
550 // collect macros at this position
552 buffer->listMacroNames(macros);
553 MacroNameSet::iterator it = macros.begin();
554 MacroNameSet::iterator end = macros.end();
555 odocstringstream macro_preamble;
556 for (; it != end; ++it) {
557 MacroData const * data = buffer->getMacro(*it, pos, true);
559 data->write(macro_preamble, true);
560 macro_preamble << endl;
564 docstring const snippet = macro_preamble.str() + latexString(*this);
565 LYXERR(Debug::MACROS, "Preview snippet: " << snippet);
566 preview_->addPreview(snippet, *buffer, forexport);
570 void InsetMathHull::reloadPreview(DocIterator const & pos) const
573 preview_->startLoading(*pos.buffer());
577 void InsetMathHull::loadPreview(DocIterator const & pos) const
579 bool const forexport = true;
580 preparePreview(pos, forexport);
581 preview_->startLoading(*pos.buffer(), forexport);
585 bool InsetMathHull::notifyCursorLeaves(Cursor const & old, Cursor & cur)
587 if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
589 cur.screenUpdateFlags(Update::Force);
595 docstring InsetMathHull::label(row_type row) const
597 LASSERT(row < nrows(), /**/);
598 if (InsetLabel * il = label_[row])
599 return il->screenLabel();
604 void InsetMathHull::label(row_type row, docstring const & label)
606 //lyxerr << "setting label '" << label << "' for row " << row << endl;
610 label_[row] = dummy_pointer;
613 label_[row]->updateCommand(label);
615 label_[row]->setParam("name", label);
619 InsetCommandParams p(LABEL_CODE);
621 label_[row] = new InsetLabel(buffer_, p);
623 label_[row]->setBuffer(buffer());
627 void InsetMathHull::numbered(row_type row, bool num)
629 numbered_[row] = num;
630 if (!numbered_[row] && label_[row]) {
637 bool InsetMathHull::numbered(row_type row) const
639 return numbered_[row];
643 bool InsetMathHull::ams() const
645 return type_ == hullAlign
646 || type_ == hullFlAlign
647 || type_ == hullMultline
648 || type_ == hullGather
649 || type_ == hullAlignAt
650 || type_ == hullXAlignAt
651 || type_ == hullXXAlignAt;
655 Inset::DisplayType InsetMathHull::display() const
657 if (type_ == hullSimple || type_ == hullNone || type_ == hullRegexp)
662 bool InsetMathHull::numberedType() const
664 if (type_ == hullNone)
666 if (type_ == hullSimple)
668 if (type_ == hullXXAlignAt)
670 if (type_ == hullRegexp)
672 for (row_type row = 0; row < nrows(); ++row)
679 void InsetMathHull::validate(LaTeXFeatures & features) const
681 if (features.runparams().isLaTeX()) {
683 features.require("amsmath");
685 if (type_ == hullRegexp) {
686 features.require("color");
687 string frcol = lcolor.getLaTeXName(Color_regexpframe);
688 string bgcol = "white";
689 features.addPreambleSnippet(
690 string("\\newcommand{\\regexp}[1]{\\fcolorbox{")
691 + frcol + string("}{")
692 + bgcol + string("}{\\texttt{#1}}}"));
695 // Validation is necessary only if not using AMS math.
696 // To be safe, we will always run mathedvalidate.
697 //if (features.amsstyle)
700 //features.binom = true;
701 } else if (features.runparams().math_flavor == OutputParams::MathAsHTML) {
702 // it would be better to do this elsewhere, but we can't validate in
703 // InsetMathMatrix and we have no way, outside MathExtern, to know if
704 // we even have any matrices.
705 features.addPreambleSnippet("<style type=\"text/css\">\n"
706 "table.matrix{display: inline-block; vertical-align: middle; text-align:center;}\n"
707 "table.matrix td{padding: 0.25px;}\n"
708 "td.ldelim{width: 0.5ex; border: thin solid black; border-right: none;}\n"
709 "td.rdelim{width: 0.5ex; border: thin solid black; border-left: none;}\n"
712 InsetMathGrid::validate(features);
716 void InsetMathHull::header_write(WriteStream & os) const
718 bool n = numberedType();
732 os << "\\begin{equation" << star(n) << "}\n";
742 os << "\\begin{" << hullName(type_) << star(n) << "}\n";
747 os << "\\begin{" << hullName(type_) << star(n) << '}'
748 << '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
752 os << "\\begin{" << hullName(type_) << '}'
753 << '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
761 os << "\\begin{unknown" << star(n) << "}\n";
767 void InsetMathHull::footer_write(WriteStream & os) const
769 bool n = numberedType();
782 os << "\n\\end{equation" << star(n) << "}\n";
794 os << "\n\\end{" << hullName(type_) << star(n) << "}\n";
798 os << "\n\\end{" << hullName(type_) << "}\n";
806 os << "\n\\end{unknown" << star(n) << "}\n";
812 bool InsetMathHull::rowChangeOK() const
815 type_ == hullEqnArray || type_ == hullAlign ||
816 type_ == hullFlAlign || type_ == hullAlignAt ||
817 type_ == hullXAlignAt || type_ == hullXXAlignAt ||
818 type_ == hullGather || type_ == hullMultline;
822 bool InsetMathHull::colChangeOK() const
825 type_ == hullAlign || type_ == hullFlAlign ||type_ == hullAlignAt ||
826 type_ == hullXAlignAt || type_ == hullXXAlignAt;
830 void InsetMathHull::addRow(row_type row)
835 bool numbered = numberedType();
837 if (type_ == hullMultline) {
838 if (row + 1 == nrows()) {
839 numbered_[row] = false;
845 numbered_.insert(numbered_.begin() + row + 1, numbered);
846 numbers_.insert(numbers_.begin() + row + 1, empty_docstring());
847 label_.insert(label_.begin() + row + 1, dummy_pointer);
850 InsetMathGrid::addRow(row);
854 void InsetMathHull::swapRow(row_type row)
858 if (row + 1 == nrows())
860 // gcc implements the standard std::vector<bool> which is *not* a container:
861 // http://www.gotw.ca/publications/N1185.pdf
862 // As a results, it doesn't like this:
863 // swap(numbered_[row], numbered_[row + 1]);
864 // so we do it manually:
865 bool const b = numbered_[row];
866 numbered_[row] = numbered_[row + 1];
867 numbered_[row + 1] = b;
868 swap(numbers_[row], numbers_[row + 1]);
869 swap(label_[row], label_[row + 1]);
870 InsetMathGrid::swapRow(row);
874 void InsetMathHull::delRow(row_type row)
876 if (nrows() <= 1 || !rowChangeOK())
878 if (row + 1 == nrows() && type_ == hullMultline) {
879 bool const b = numbered_[row - 1];
880 numbered_[row - 1] = numbered_[row];
882 swap(numbers_[row - 1], numbers_[row]);
883 swap(label_[row - 1], label_[row]);
884 InsetMathGrid::delRow(row);
887 InsetMathGrid::delRow(row);
888 // The last dummy row has no number info nor a label.
889 // Test nrows() + 1 because we have already erased the row.
890 if (row == nrows() + 1)
892 numbered_.erase(numbered_.begin() + row);
893 numbers_.erase(numbers_.begin() + row);
895 label_.erase(label_.begin() + row);
899 void InsetMathHull::addCol(col_type col)
903 InsetMathGrid::addCol(col);
907 void InsetMathHull::delCol(col_type col)
909 if (ncols() <= 1 || !colChangeOK())
911 InsetMathGrid::delCol(col);
915 docstring InsetMathHull::nicelabel(row_type row) const
919 docstring const & val = numbers_[row];
921 return '(' + val + ')';
922 return '(' + val + ',' + label_[row]->screenLabel() + ')';
926 void InsetMathHull::glueall(HullType type)
929 for (idx_type i = 0; i < nargs(); ++i)
931 InsetLabel * label = 0;
932 if (type == hullEquation) {
933 // preserve first non-empty label
934 for (row_type row = 0; row < nrows(); ++row) {
942 *this = InsetMathHull(buffer_, hullSimple);
949 void InsetMathHull::splitTo2Cols()
951 LASSERT(ncols() == 1, /**/);
952 InsetMathGrid::addCol(1);
953 for (row_type row = 0; row < nrows(); ++row) {
954 idx_type const i = 2 * row;
955 pos_type pos = firstRelOp(cell(i));
956 cell(i + 1) = MathData(buffer_, cell(i).begin() + pos, cell(i).end());
957 cell(i).erase(pos, cell(i).size());
962 void InsetMathHull::splitTo3Cols()
964 LASSERT(ncols() < 3, /**/);
967 InsetMathGrid::addCol(2);
968 for (row_type row = 0; row < nrows(); ++row) {
969 idx_type const i = 3 * row + 1;
970 if (cell(i).size()) {
971 cell(i + 1) = MathData(buffer_, cell(i).begin() + 1, cell(i).end());
972 cell(i).erase(1, cell(i).size());
978 void InsetMathHull::changeCols(col_type cols)
982 else if (ncols() < cols) {
988 while (ncols() < cols)
989 InsetMathGrid::addCol(ncols());
995 for (row_type row = 0; row < nrows(); ++row) {
996 idx_type const i = row * ncols();
997 for (col_type col = cols; col < ncols(); ++col) {
998 cell(i + cols - 1).append(cell(i + col));
1002 while (ncols() > cols) {
1003 InsetMathGrid::delCol(ncols() - 1);
1008 HullType InsetMathHull::getType() const
1014 void InsetMathHull::setType(HullType type)
1021 void InsetMathHull::mutate(HullType newtype)
1023 //lyxerr << "mutating from '" << type_ << "' to '" << newtype << "'" << endl;
1025 // we try to move along the chain
1026 // none <-> simple <-> equation <-> eqnarray -> *align* -> multline, gather -+
1028 // +-------------------------------------+
1029 // we use eqnarray as intermediate type for mutations that are not
1030 // directly supported because it handles labels and numbering for
1033 if (newtype == type_) {
1037 else if (newtype < hullNone) {
1042 else if (type_ == hullNone) {
1043 setType(hullSimple);
1048 else if (type_ == hullSimple) {
1049 if (newtype == hullNone) {
1053 setType(hullEquation);
1054 numbered(0, label_[0] ? true : false);
1059 else if (type_ == hullEquation) {
1060 if (newtype < type_) {
1061 setType(hullSimple);
1064 } else if (newtype == hullEqnArray) {
1065 // split it "nicely" on the first relop
1067 setType(hullEqnArray);
1068 } else if (newtype == hullMultline || newtype == hullGather) {
1071 // split it "nicely"
1078 else if (type_ == hullEqnArray) {
1079 if (newtype < type_) {
1082 } else { // align & Co.
1089 else if (type_ == hullAlign || type_ == hullAlignAt ||
1090 type_ == hullXAlignAt || type_ == hullFlAlign) {
1091 if (newtype < hullAlign) {
1093 setType(hullEqnArray);
1095 } else if (newtype == hullGather || newtype == hullMultline) {
1098 } else if (newtype == hullXXAlignAt) {
1099 for (row_type row = 0; row < nrows(); ++row)
1100 numbered(row, false);
1107 else if (type_ == hullXXAlignAt) {
1108 for (row_type row = 0; row < nrows(); ++row)
1109 numbered(row, false);
1110 if (newtype < hullAlign) {
1112 setType(hullEqnArray);
1114 } else if (newtype == hullGather || newtype == hullMultline) {
1122 else if (type_ == hullMultline || type_ == hullGather) {
1123 if (newtype == hullGather || newtype == hullMultline)
1125 else if (newtype == hullAlign || newtype == hullFlAlign ||
1126 newtype == hullAlignAt || newtype == hullXAlignAt) {
1129 } else if (newtype == hullXXAlignAt) {
1131 for (row_type row = 0; row < nrows(); ++row)
1132 numbered(row, false);
1136 setType(hullEqnArray);
1142 lyxerr << "mutation from '" << to_utf8(hullName(type_))
1143 << "' to '" << to_utf8(hullName(newtype))
1144 << "' not implemented" << endl;
1149 docstring InsetMathHull::eolString(row_type row, bool fragile, bool latex,
1150 bool last_eoln) const
1153 if (numberedType()) {
1154 if (label_[row] && numbered_[row]) {
1155 docstring const name =
1156 latex ? escape(label_[row]->getParam("name"))
1157 : label_[row]->getParam("name");
1158 res += "\\label{" + name + '}';
1160 if (!numbered_[row] && (type_ != hullMultline))
1161 res += "\\nonumber ";
1163 // Never add \\ on the last empty line of eqnarray and friends
1165 return res + InsetMathGrid::eolString(row, fragile, latex, last_eoln);
1169 void InsetMathHull::write(WriteStream & os) const
1171 ModeSpecifier specifier(os, MATH_MODE);
1173 InsetMathGrid::write(os);
1178 void InsetMathHull::normalize(NormalStream & os) const
1180 os << "[formula " << hullName(type_) << ' ';
1181 InsetMathGrid::normalize(os);
1186 void InsetMathHull::infoize(odocstream & os) const
1188 os << "Type: " << hullName(type_);
1192 void InsetMathHull::check() const
1194 LASSERT(numbered_.size() == nrows(), /**/);
1195 LASSERT(numbers_.size() == nrows(), /**/);
1196 LASSERT(label_.size() == nrows(), /**/);
1200 void InsetMathHull::doExtern(Cursor & cur, FuncRequest & func)
1204 idocstringstream iss(func.argument());
1205 iss >> dlang >> extra;
1207 extra = from_ascii("noextra");
1208 string const lang = to_ascii(dlang);
1210 // FIXME: temporarily disabled
1211 //if (cur.selection()) {
1214 // lyxerr << "use selection: " << ar << endl;
1215 // insert(pipeThroughExtern(lang, extra, ar));
1219 // only inline, display or eqnarray math is allowed
1220 if (getType() > hullEqnArray) {
1221 frontend::Alert::warning(_("Bad math environment"),
1222 _("Computation cannot be performed for AMS "
1223 "math environments.\nChange the math "
1224 "formula type and try again."));
1229 eq.push_back(MathAtom(new InsetMathChar('=')));
1231 // go to first item in line
1232 cur.idx() -= cur.idx() % ncols();
1235 if (getType() == hullSimple) {
1236 size_type pos = cur.cell().find_last(eq);
1238 if (cur.inMathed() && cur.selection()) {
1239 asArray(grabAndEraseSelection(cur), ar);
1240 } else if (pos == cur.cell().size()) {
1242 lyxerr << "use whole cell: " << ar << endl;
1244 ar = MathData(buffer_, cur.cell().begin() + pos + 1, cur.cell().end());
1245 lyxerr << "use partial cell form pos: " << pos << endl;
1247 cur.cell().append(eq);
1248 cur.cell().append(pipeThroughExtern(lang, extra, ar));
1249 cur.pos() = cur.lastpos();
1253 if (getType() == hullEquation) {
1254 lyxerr << "use equation inset" << endl;
1255 mutate(hullEqnArray);
1256 MathData & ar = cur.cell();
1257 lyxerr << "use cell: " << ar << endl;
1261 cur.cell() = pipeThroughExtern(lang, extra, ar);
1262 // move to end of line
1263 cur.pos() = cur.lastpos();
1268 lyxerr << "use eqnarray" << endl;
1269 cur.idx() += 2 - cur.idx() % ncols();
1271 MathData ar = cur.cell();
1272 lyxerr << "use cell: " << ar << endl;
1273 // FIXME: temporarily disabled
1279 cur.cell() = pipeThroughExtern(lang, extra, ar);
1280 cur.pos() = cur.lastpos();
1285 void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
1287 //lyxerr << "action: " << cmd.action() << endl;
1288 switch (cmd.action()) {
1290 case LFUN_FINISHED_BACKWARD:
1291 case LFUN_FINISHED_FORWARD:
1292 case LFUN_FINISHED_RIGHT:
1293 case LFUN_FINISHED_LEFT:
1294 //lyxerr << "action: " << cmd.action() << endl;
1295 InsetMathGrid::doDispatch(cur, cmd);
1299 case LFUN_BREAK_PARAGRAPH:
1300 // just swallow this
1303 case LFUN_NEWLINE_INSERT:
1304 // some magic for the common case
1305 if (type_ == hullSimple || type_ == hullEquation) {
1306 cur.recordUndoInset();
1308 cur.bv().buffer().params().use_amsmath == BufferParams::package_on;
1309 mutate(align ? hullAlign : hullEqnArray);
1310 // mutate() may change labels and such.
1311 cur.forceBufferUpdate();
1312 cur.idx() = nrows() * ncols() - 1;
1313 cur.pos() = cur.lastpos();
1315 InsetMathGrid::doDispatch(cur, cmd);
1318 case LFUN_MATH_NUMBER_TOGGLE: {
1319 //lyxerr << "toggling all numbers" << endl;
1320 cur.recordUndoInset();
1321 bool old = numberedType();
1322 if (type_ == hullMultline)
1323 numbered(nrows() - 1, !old);
1325 for (row_type row = 0; row < nrows(); ++row)
1326 numbered(row, !old);
1328 cur.message(old ? _("No number") : _("Number"));
1329 cur.forceBufferUpdate();
1333 case LFUN_MATH_NUMBER_LINE_TOGGLE: {
1334 cur.recordUndoInset();
1335 row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
1336 bool old = numbered(r);
1337 cur.message(old ? _("No number") : _("Number"));
1339 cur.forceBufferUpdate();
1343 case LFUN_LABEL_INSERT: {
1344 cur.recordUndoInset();
1345 row_type r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
1346 docstring old_label = label(r);
1347 docstring const default_label = from_ascii("eq:");
1348 if (old_label.empty())
1349 old_label = default_label;
1351 InsetCommandParams p(LABEL_CODE);
1352 p["name"] = cmd.argument().empty() ? old_label : cmd.argument();
1353 string const data = InsetCommand::params2string(p);
1355 if (cmd.argument().empty())
1356 cur.bv().showDialog("label", data);
1358 FuncRequest fr(LFUN_INSET_INSERT, data);
1364 case LFUN_LABEL_COPY_AS_REF: {
1366 if (cmd.argument().empty() && &cur.inset() == this)
1367 // if there is no argument and we're inside math, we retrieve
1368 // the row number from the cursor position.
1369 row = (type_ == hullMultline) ? nrows() - 1 : cur.row();
1371 // if there is an argument, find the corresponding label, else
1372 // check whether there is at least one label.
1373 for (row = 0; row != nrows(); ++row)
1374 if (numbered_[row] && label_[row]
1375 && (cmd.argument().empty() || label(row) == cmd.argument()))
1382 InsetCommandParams p(REF_CODE, "ref");
1383 p["reference"] = label(row);
1384 cap::clearSelection();
1385 cap::copyInset(cur, new InsetRef(buffer_, p), label(row));
1389 case LFUN_WORD_DELETE_FORWARD:
1390 case LFUN_CHAR_DELETE_FORWARD:
1391 if (col(cur.idx()) + 1 == ncols()
1392 && cur.pos() == cur.lastpos()
1393 && !cur.selection()) {
1394 if (!label(row(cur.idx())).empty()) {
1395 cur.recordUndoInset();
1396 label(row(cur.idx()), docstring());
1397 } else if (numbered(row(cur.idx()))) {
1398 cur.recordUndoInset();
1399 numbered(row(cur.idx()), false);
1400 cur.forceBufferUpdate();
1402 InsetMathGrid::doDispatch(cur, cmd);
1406 InsetMathGrid::doDispatch(cur, cmd);
1411 case LFUN_INSET_INSERT: {
1412 //lyxerr << "arg: " << to_utf8(cmd.argument()) << endl;
1413 // FIXME: this should be cleaned up to use InsetLabel methods directly.
1414 string const name = cmd.getArg(0);
1415 if (name == "label") {
1416 InsetCommandParams p(LABEL_CODE);
1417 InsetCommand::string2params(to_utf8(cmd.argument()), p);
1418 docstring str = p["name"];
1419 cur.recordUndoInset();
1420 row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
1424 docstring old = label(r);
1427 // The label will take care of the reference update.
1431 // Newly created inset so initialize it.
1432 label_[r]->initView();
1435 cur.forceBufferUpdate();
1438 InsetMathGrid::doDispatch(cur, cmd);
1442 case LFUN_MATH_EXTERN:
1443 cur.recordUndoInset();
1447 case LFUN_MATH_MUTATE: {
1448 cur.recordUndoInset();
1449 row_type row = cur.row();
1450 col_type col = cur.col();
1451 mutate(hullType(cmd.argument()));
1452 cur.idx() = row * ncols() + col;
1453 if (cur.idx() > cur.lastidx()) {
1454 cur.idx() = cur.lastidx();
1455 cur.pos() = cur.lastpos();
1457 if (cur.pos() > cur.lastpos())
1458 cur.pos() = cur.lastpos();
1460 cur.forceBufferUpdate();
1461 // FIXME: find some more clever handling of the selection,
1462 // i.e. preserve it.
1463 cur.clearSelection();
1464 //cur.dispatched(FINISHED);
1468 case LFUN_MATH_DISPLAY: {
1469 cur.recordUndoInset();
1470 mutate(type_ == hullSimple ? hullEquation : hullSimple);
1472 cur.pos() = cur.lastpos();
1473 //cur.dispatched(FINISHED);
1478 InsetMathGrid::doDispatch(cur, cmd);
1484 bool InsetMathHull::getStatus(Cursor & cur, FuncRequest const & cmd,
1485 FuncStatus & status) const
1487 switch (cmd.action()) {
1488 case LFUN_FINISHED_BACKWARD:
1489 case LFUN_FINISHED_FORWARD:
1490 case LFUN_FINISHED_RIGHT:
1491 case LFUN_FINISHED_LEFT:
1494 case LFUN_NEWLINE_INSERT:
1495 case LFUN_MATH_EXTERN:
1497 status.setEnabled(true);
1500 // we never allow this in math, and we want to bind enter
1501 // to another actions in command-alternatives
1502 case LFUN_BREAK_PARAGRAPH:
1503 status.setEnabled(false);
1505 case LFUN_MATH_MUTATE: {
1506 HullType const ht = hullType(cmd.argument());
1507 status.setOnOff(type_ == ht);
1508 status.setEnabled(true);
1510 if (ht != hullSimple) {
1511 Cursor tmpcur = cur;
1512 while (!tmpcur.empty()) {
1513 InsetCode code = tmpcur.inset().lyxCode();
1514 if (code == BOX_CODE) {
1516 } else if (code == TABULAR_CODE) {
1517 FuncRequest tmpcmd(LFUN_MATH_DISPLAY);
1518 if (tmpcur.getStatus(tmpcmd, status) && !status.enabled())
1526 case LFUN_MATH_DISPLAY: {
1528 if (cur.depth() > 1) {
1529 Inset const & in = cur[cur.depth()-2].inset();
1530 if (in.lyxCode() == SCRIPT_CODE)
1531 enable = display() != Inline;
1533 status.setEnabled(enable);
1537 case LFUN_MATH_NUMBER_TOGGLE:
1538 // FIXME: what is the right test, this or the one of
1540 status.setEnabled(display() != Inline);
1541 status.setOnOff(numberedType());
1544 case LFUN_MATH_NUMBER_LINE_TOGGLE: {
1545 // FIXME: what is the right test, this or the one of
1547 bool const enable = (type_ == hullMultline)
1548 ? (nrows() - 1 == cur.row())
1549 : display() != Inline && nrows() > 1;
1550 row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();
1551 status.setEnabled(enable);
1552 status.setOnOff(enable && numbered(r));
1556 case LFUN_LABEL_INSERT:
1557 status.setEnabled(type_ != hullSimple);
1560 case LFUN_LABEL_COPY_AS_REF: {
1561 bool enabled = false;
1563 if (cmd.argument().empty() && &cur.inset() == this) {
1564 // if there is no argument and we're inside math, we retrieve
1565 // the row number from the cursor position.
1566 row = (type_ == hullMultline) ? nrows() - 1 : cur.row();
1567 enabled = numberedType() && label_[row] && numbered_[row];
1569 // if there is an argument, find the corresponding label, else
1570 // check whether there is at least one label.
1571 for (row_type row = 0; row != nrows(); ++row) {
1572 if (numbered_[row] && label_[row] &&
1573 (cmd.argument().empty() || label(row) == cmd.argument())) {
1579 status.setEnabled(enabled);
1583 case LFUN_INSET_INSERT:
1584 if (cmd.getArg(0) == "label") {
1585 status.setEnabled(type_ != hullSimple);
1588 return InsetMathGrid::getStatus(cur, cmd, status);
1590 case LFUN_INSET_MODIFY: {
1591 istringstream is(to_utf8(cmd.argument()));
1595 return InsetMathGrid::getStatus(cur, cmd, status);
1598 && (s == "append-row"
1599 || s == "delete-row"
1600 || s == "copy-row")) {
1601 status.message(bformat(
1602 from_utf8(N_("Can't change number of rows in '%1$s'")),
1604 status.setEnabled(false);
1608 && (s == "append-column"
1609 || s == "delete-column"
1610 || s == "copy-column")) {
1611 status.message(bformat(
1612 from_utf8(N_("Can't change number of columns in '%1$s'")),
1614 status.setEnabled(false);
1617 if ((type_ == hullSimple
1618 || type_ == hullEquation
1619 || type_ == hullNone) &&
1620 (s == "add-hline-above" || s == "add-hline-below")) {
1621 status.message(bformat(
1622 from_utf8(N_("Can't add horizontal grid lines in '%1$s'")),
1624 status.setEnabled(false);
1627 if (s == "add-vline-left" || s == "add-vline-right") {
1628 status.message(bformat(
1629 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
1631 status.setEnabled(false);
1634 if (s == "valign-top" || s == "valign-middle"
1635 || s == "valign-bottom" || s == "align-left"
1636 || s == "align-center" || s == "align-right") {
1637 status.setEnabled(false);
1640 return InsetMathGrid::getStatus(cur, cmd, status);
1644 return InsetMathGrid::getStatus(cur, cmd, status);
1647 // This cannot really happen, but inserted to shut-up gcc
1648 return InsetMathGrid::getStatus(cur, cmd, status);
1652 /////////////////////////////////////////////////////////////////////
1656 // simply scrap this function if you want
1657 void InsetMathHull::mutateToText()
1660 // translate to latex
1662 latex(os, false, false);
1663 string str = os.str();
1666 Text * lt = view_->cursor().innerText();
1667 string::const_iterator cit = str.begin();
1668 string::const_iterator end = str.end();
1669 for (; cit != end; ++cit)
1670 view_->getIntl()->getTransManager().TranslateAndInsert(*cit, lt);
1673 //dispatch(LFUN_ESCAPE);
1678 void InsetMathHull::handleFont(Cursor & cur, docstring const & arg,
1679 docstring const & font)
1681 // this whole function is a hack and won't work for incremental font
1684 if (cur.inset().asInsetMath()->name() == font)
1685 cur.handleFont(to_utf8(font));
1687 cur.handleNest(createInsetMath(font, cur.buffer()));
1693 void InsetMathHull::handleFont2(Cursor & cur, docstring const & arg)
1698 font.fromString(to_utf8(arg), b);
1699 if (font.fontInfo().color() != Color_inherit) {
1700 MathAtom at = MathAtom(new InsetMathColor(buffer_, true, font.fontInfo().color()));
1701 cur.handleNest(at, 0);
1706 void InsetMathHull::edit(Cursor & cur, bool front, EntryDirection entry_from)
1709 bool enter_front = (entry_from == Inset::ENTRY_DIRECTION_LEFT ||
1710 (entry_from == Inset::ENTRY_DIRECTION_IGNORE && front));
1711 enter_front ? idxFirst(cur) : idxLast(cur);
1712 // The inset formula dimension is not necessarily the same as the
1713 // one of the instant preview image, so we have to indicate to the
1714 // BufferView that a metrics update is needed.
1715 cur.screenUpdateFlags(Update::Force);
1719 void InsetMathHull::revealCodes(Cursor & cur) const
1721 if (!cur.inMathed())
1723 odocstringstream os;
1725 cur.message(os.str());
1727 // write something to the minibuffer
1728 // translate to latex
1732 string str = os.str();
1734 string::size_type pos = 0;
1736 for (string::iterator it = str.begin(); it != str.end(); ++it) {
1739 else if (*it == '\0') {
1741 pos = it - str.begin();
1747 res = res.substr(pos - 30);
1748 if (res.size() > 60)
1749 res = res.substr(0, 60);
1755 /////////////////////////////////////////////////////////////////////
1759 bool InsetMathHull::searchForward(BufferView * bv, string const & str,
1762 // FIXME: completely broken
1763 static InsetMathHull * lastformula = 0;
1764 static CursorBase current = DocIterator(ibegin(nucleus()));
1766 static string laststr;
1768 if (lastformula != this || laststr != str) {
1769 //lyxerr << "reset lastformula to " << this << endl;
1772 current = ibegin(nucleus());
1774 mathed_parse_cell(ar, str, Parse::NORMAL, &buffer());
1778 //lyxerr << "searching '" << str << "' in " << this << ar << endl;
1780 for (DocIterator it = current; it != iend(nucleus()); increment(it)) {
1781 CursorSlice & top = it.back();
1782 MathData const & a = top.asInsetMath()->cell(top.idx_);
1783 if (a.matchpart(ar, top.pos_)) {
1784 bv->cursor().setSelection(it, ar.size());
1786 top.pos_ += ar.size();
1792 //lyxerr << "not found!" << endl;
1799 void InsetMathHull::write(ostream & os) const
1801 odocstringstream oss;
1802 WriteStream wi(oss, false, false, WriteStream::wsDefault);
1805 os << to_utf8(oss.str());
1809 void InsetMathHull::read(Lexer & lex)
1812 mathed_parse_normal(buffer_, at, lex, Parse::TRACKMACRO);
1813 operator=(*at->asHullInset());
1817 bool InsetMathHull::readQuiet(Lexer & lex)
1820 bool success = mathed_parse_normal(buffer_, at, lex, Parse::QUIET);
1822 operator=(*at->asHullInset());
1827 int InsetMathHull::plaintext(odocstream & os, OutputParams const &) const
1829 // disables ASCII-art for export of equations. See #2275.
1830 if (0 && display()) {
1834 TextPainter tpain(dim.width(), dim.height());
1835 drawT(tpain, 0, dim.ascent());
1837 // reset metrics cache to "real" values
1839 return tpain.textheight();
1841 odocstringstream oss;
1842 Encoding const * const enc = encodings.fromLyXName("utf8");
1843 WriteStream wi(oss, false, true, WriteStream::wsDefault, enc);
1845 if (type_ == hullRegexp)
1849 docstring const str = oss.str();
1856 int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) const
1861 if (getType() == hullSimple)
1862 name = from_ascii("inlineequation");
1864 name = from_ascii("informalequation");
1866 docstring bname = name;
1867 if (!label(0).empty())
1868 bname += " id='" + sgml::cleanID(buffer(), runparams, label(0)) + "'";
1870 ++ms.tab(); ms.cr(); ms.os() << '<' << bname << '>';
1872 odocstringstream ls;
1873 if (runparams.flavor == OutputParams::XML) {
1874 ms << MTag("alt role='tex' ");
1875 // Workaround for db2latex: db2latex always includes equations with
1876 // \ensuremath{} or \begin{display}\end{display}
1877 // so we strip LyX' math environment
1878 WriteStream wi(ls, false, false, WriteStream::wsDefault, runparams.encoding);
1879 InsetMathGrid::write(wi);
1880 ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"));
1885 InsetMathGrid::mathmlize(ms);
1888 ms << MTag("alt role='tex'");
1889 res = latex(ls, runparams);
1890 ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<"));
1894 ms << from_ascii("<graphic fileref=\"eqn/");
1895 if (!label(0).empty())
1896 ms << sgml::cleanID(buffer(), runparams, label(0));
1898 ms << sgml::uniqueID(from_ascii("anon"));
1900 if (runparams.flavor == OutputParams::XML)
1901 ms << from_ascii("\"/>");
1903 ms << from_ascii("\">");
1905 ms.cr(); --ms.tab(); ms.os() << "</" << name << '>';
1907 return ms.line() + res;
1912 // We need to do something about alignment here.
1914 // This duplicates code from InsetMathGrid, but
1915 // we need access here to number information,
1916 // and we simply do not have that in InsetMathGrid.
1917 void InsetMathHull::htmlize(HtmlStream & os) const
1919 bool havenumbers = false;
1920 for (size_t i = 0; i != numbered_.size(); ++i) {
1926 bool const havetable = havenumbers || nrows() > 1 || ncols() > 1;
1929 os << cell(index(0, 0));
1933 os << MTag("table", "class='mathtable'");
1934 for (row_type row = 0; row < nrows(); ++row) {
1936 for (col_type col = 0; col < ncols(); ++col) {
1938 os << cell(index(row, col));
1943 docstring const & num = numbers_[row];
1945 os << '(' << num << ')';
1950 os << ETag("table");
1954 // this duplicates code from InsetMathGrid, but
1955 // we need access here to number information,
1956 // and we simply do not have that in InsetMathGrid.
1957 void InsetMathHull::mathmlize(MathStream & os) const
1959 bool havenumbers = false;
1960 for (size_t i = 0; i != numbered_.size(); ++i) {
1966 bool const havetable = havenumbers || nrows() > 1 || ncols() > 1;
1969 os << MTag("mtable");
1970 char const * const celltag = havetable ? "mtd" : "mrow";
1971 // FIXME There does not seem to be wide support at the moment
1972 // for mlabeledtr, so we have to use just mtr for now.
1973 // char const * const rowtag = havenumbers ? "mlabeledtr" : "mtr";
1974 char const * const rowtag = "mtr";
1975 for (row_type row = 0; row < nrows(); ++row) {
1978 for (col_type col = 0; col < ncols(); ++col) {
1980 << cell(index(row, col))
1986 docstring const & num = numbers_[row];
1988 os << '(' << num << ')';
1995 os << ETag("mtable");
1999 void InsetMathHull::mathAsLatex(WriteStream & os) const
2001 MathEnsurer ensurer(os, false);
2002 bool havenumbers = false;
2003 for (size_t i = 0; i != numbered_.size(); ++i) {
2009 bool const havetable = havenumbers || nrows() > 1 || ncols() > 1;
2012 os << cell(index(0, 0));
2016 os << "<table class='mathtable'>";
2017 for (row_type row = 0; row < nrows(); ++row) {
2019 for (col_type col = 0; col < ncols(); ++col) {
2020 os << "<td class='math'>";
2021 os << cell(index(row, col));
2026 docstring const & num = numbers_[row];
2028 os << '(' << num << ')';
2037 docstring InsetMathHull::xhtml(XHTMLStream & xs, OutputParams const & op) const
2039 BufferParams::MathOutput const mathtype =
2040 buffer().params().html_math_output;
2042 bool success = false;
2043 // FIXME Eventually we would like to do this inset by inset.
2044 if (mathtype == BufferParams::MathML) {
2045 odocstringstream os;
2050 } catch (MathExportException const &) {}
2052 if (getType() == hullSimple)
2053 xs << html::StartTag("math",
2054 "xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
2056 xs << html::StartTag("math",
2057 "display=\"block\" xmlns=\"http://www.w3.org/1998/Math/MathML\"", true);
2058 xs << XHTMLStream::ESCAPE_NONE
2060 << html::EndTag("math");
2062 } else if (mathtype == BufferParams::HTML) {
2063 odocstringstream os;
2068 } catch (MathExportException const &) {}
2070 string const tag = (getType() == hullSimple) ? "span" : "div";
2071 xs << html::StartTag(tag, "class='formula'", true)
2072 << XHTMLStream::ESCAPE_NONE
2074 << html::EndTag(tag);
2078 // what we actually want is this:
2080 // ((mathtype == BufferParams::MathML || mathtype == BufferParams::HTML)
2082 // || mathtype == BufferParams::Images
2084 // but what follows is equivalent, since we'll enter only if either (a) we
2085 // tried and failed with MathML or HTML or (b) didn't try yet at all but
2086 // aren't doing LaTeX, in which case we are doing Images.
2087 if (!success && mathtype != BufferParams::LaTeX) {
2088 loadPreview(docit_);
2089 graphics::PreviewImage const * pimage = preview_->getPreviewImage(buffer());
2091 // FIXME Do we always have png?
2092 string const tag = (getType() == hullSimple) ? "span" : "div";
2093 FileName const & mathimg = pimage->filename();
2094 xs << html::StartTag(tag)
2095 << html::CompTag("img", "src=\"" + mathimg.onlyFileName() + "\"")
2096 << html::EndTag(tag);
2098 // add the file to the list of files to be exported
2099 op.exportdata->addExternalFile("xhtml", mathimg);
2104 // so we'll pass this test if we've failed everything else, or
2105 // if mathtype was LaTeX, since we won't have entered any of the
2107 if (!success /* || mathtype != BufferParams::LaTeX */) {
2108 string const tag = (getType() == hullSimple) ? "span" : "div";
2109 // Unfortunately, we cannot use latexString() because we do not want
2110 // $...$ or whatever.
2111 odocstringstream ls;
2112 WriteStream wi(ls, false, true, WriteStream::wsPreview);
2113 ModeSpecifier specifier(wi, MATH_MODE);
2115 docstring const latex = ls.str();
2117 // class='math' allows for use of jsMath
2118 // http://www.math.union.edu/~dpvc/jsMath/
2120 // probably should allow for some kind of customization here
2121 xs << html::StartTag(tag, "class='math'")
2122 << XHTMLStream::ESCAPE_AND
2124 << html::EndTag(tag);
2131 void InsetMathHull::toString(odocstream & os) const
2133 plaintext(os, OutputParams(0));
2137 void InsetMathHull::forToc(docstring & os, size_t) const
2139 odocstringstream ods;
2140 plaintext(ods, OutputParams(0));
2145 docstring InsetMathHull::contextMenuName() const
2147 return from_ascii("context-math");
2151 void InsetMathHull::recordLocation(DocIterator const & di)