2 * \file math_hullinset.C
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 "math_charinset.h"
14 #include "math_data.h"
15 #include "math_extern.h"
16 #include "math_hullinset.h"
17 #include "math_mathmlstream.h"
18 #include "math_streamstr.h"
19 #include "math_support.h"
21 #include "BufferView.h"
22 #include "CutAndPaste.h"
24 #include "LaTeXFeatures.h"
27 #include "dispatchresult.h"
28 #include "funcrequest.h"
32 #include "outputparams.h"
33 #include "textpainter.h"
36 #include "insets/render_preview.h"
38 #include "frontends/Alert.h"
40 #include "graphics/PreviewImage.h"
41 #include "graphics/PreviewLoader.h"
43 #include <boost/bind.hpp>
47 using lyx::cap::grabAndEraseSelection;
54 using std::istringstream;
56 using std::ostringstream;
64 int getCols(string const & type)
66 if (type == "eqnarray")
70 if (type == "flalign")
72 if (type == "alignat")
74 if (type == "xalignat")
76 if (type == "xxalignat")
82 // returns position of first relation operator in the array
83 // used for "intelligent splitting"
84 size_t firstRelOp(MathArray const & ar)
86 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
88 return it - ar.begin();
93 char const * star(bool numbered)
95 return numbered ? "" : "*";
99 int typecode(string const & s)
101 if (s == "none") return 0;
102 if (s == "simple") return 1;
103 if (s == "equation") return 2;
104 if (s == "eqnarray") return 3;
105 if (s == "align") return 4;
106 if (s == "alignat") return 5;
107 if (s == "xalignat") return 6;
108 if (s == "xxalignat") return 7;
109 if (s == "multline") return 8;
110 if (s == "gather") return 9;
111 if (s == "flalign") return 10;
112 lyxerr << "unknown hull type '" << s << "'" << endl;
116 bool smaller(string const & s, string const & t)
118 return typecode(s) < typecode(t);
122 } // end anon namespace
126 MathHullInset::MathHullInset()
127 : MathGridInset(1, 1), type_("none"), nonum_(1), label_(1),
128 preview_(new RenderPreview(this))
130 //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << endl;
131 //lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
132 //lyxerr << "sizeof MathCharInset: " << sizeof(MathCharInset) << endl;
133 //lyxerr << "sizeof LyXFont: " << sizeof(LyXFont) << endl;
138 MathHullInset::MathHullInset(string const & type)
139 : MathGridInset(getCols(type), 1), type_(type), nonum_(1), label_(1),
140 preview_(new RenderPreview(this))
146 MathHullInset::MathHullInset(MathHullInset const & other)
147 : MathGridInset(other),
148 type_(other.type_), nonum_(other.nonum_), label_(other.label_),
149 preview_(new RenderPreview(this))
153 MathHullInset::~MathHullInset()
157 auto_ptr<InsetBase> MathHullInset::clone() const
159 return auto_ptr<InsetBase>(new MathHullInset(*this));
163 void MathHullInset::operator=(MathHullInset const & other)
167 *static_cast<MathGridInset*>(this) = MathGridInset(other);
169 nonum_ = other.nonum_;
170 label_ = other.label_;
171 preview_.reset(new RenderPreview(*other.preview_, this));
175 MathInset::mode_type MathHullInset::currentMode() const
178 return UNDECIDED_MODE;
179 // definitely math mode ...
184 bool MathHullInset::idxFirst(LCursor & cur) const
192 bool MathHullInset::idxLast(LCursor & cur) const
194 cur.idx() = nargs() - 1;
195 cur.pos() = cur.lastpos();
200 char MathHullInset::defaultColAlign(col_type col)
202 if (type_ == "eqnarray")
204 if (typecode(type_) >= typecode("align"))
205 return "rl"[col & 1];
210 int MathHullInset::defaultColSpace(col_type col)
212 if (type_ == "align" || type_ == "alignat")
214 if (type_ == "xalignat")
215 return (col & 1) ? 20 : 0;
216 if (type_ == "xxalignat" || type_ == "flalign")
217 return (col & 1) ? 40 : 0;
222 char const * MathHullInset::standardFont() const
225 return "lyxnochange";
230 void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
232 BOOST_ASSERT(mi.base.bv && mi.base.bv->buffer());
234 bool use_preview = false;
235 if (!editing(mi.base.bv) &&
236 RenderPreview::status() == LyXRC::PREVIEW_ON) {
237 lyx::graphics::PreviewImage const * pimage =
238 preview_->getPreviewImage(*mi.base.bv->buffer());
239 use_preview = pimage && pimage->image();
243 preview_->metrics(mi, dim);
244 // insert a one pixel gap in front of the formula
252 FontSetChanger dummy1(mi.base, standardFont());
253 StyleChanger dummy2(mi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
255 // let the cells adjust themselves
256 MathGridInset::metrics(mi, dim);
263 if (numberedType()) {
264 FontSetChanger dummy(mi.base, "mathbf");
266 for (row_type row = 0; row < nrows(); ++row)
267 l = max(l, mathed_string_width(mi.base.font, nicelabel(row)));
273 // make it at least as high as the current font
276 math_font_max_dim(mi.base.font, asc, des);
277 dim.asc = max(dim.asc, asc);
278 dim.des = max(dim.des, des);
284 void MathHullInset::draw(PainterInfo & pi, int x, int y) const
286 BOOST_ASSERT(pi.base.bv && pi.base.bv->buffer());
288 bool use_preview = false;
289 if (!editing(pi.base.bv) &&
290 RenderPreview::status() == LyXRC::PREVIEW_ON) {
291 lyx::graphics::PreviewImage const * pimage =
292 preview_->getPreviewImage(*pi.base.bv->buffer());
293 use_preview = pimage && pimage->image();
297 // one pixel gap in front
298 preview_->draw(pi, x + 1, y);
299 setPosCache(pi, x, y);
303 FontSetChanger dummy1(pi.base, standardFont());
304 StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
305 MathGridInset::draw(pi, x + 1, y);
307 if (numberedType()) {
308 int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
309 for (row_type row = 0; row < nrows(); ++row) {
310 int const yy = y + rowinfo_[row].offset_;
311 FontSetChanger dummy(pi.base, "mathrm");
312 drawStr(pi, pi.base.font, xx, yy, nicelabel(row));
315 setPosCache(pi, x, y);
319 void MathHullInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
322 MathGridInset::metricsT(mi, dim);
325 WriteStream wi(os, false, true);
327 dim.wid = os.str().size();
334 void MathHullInset::drawT(TextPainter & pain, int x, int y) const
337 MathGridInset::drawT(pain, x, y);
340 WriteStream wi(os, false, true);
342 pain.draw(x, y, os.str().c_str());
349 string const latex_string(MathHullInset const & inset)
352 WriteStream wi(ls, false, false);
360 void MathHullInset::addPreview(lyx::graphics::PreviewLoader & ploader) const
362 if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
363 string const snippet = latex_string(*this);
364 preview_->addPreview(snippet, ploader);
369 void MathHullInset::notifyCursorLeaves(LCursor & cur)
371 if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
372 Buffer const & buffer = cur.buffer();
373 string const snippet = latex_string(*this);
374 preview_->addPreview(snippet, buffer);
375 preview_->startLoading(buffer);
380 string MathHullInset::label(row_type row) const
382 row_type n = nrows();
383 BOOST_ASSERT(row < n);
388 void MathHullInset::label(row_type row, string const & label)
390 //lyxerr << "setting label '" << label << "' for row " << row << endl;
395 void MathHullInset::numbered(row_type row, bool num)
401 bool MathHullInset::numbered(row_type row) const
407 bool MathHullInset::ams() const
411 type_ == "flalign" ||
412 type_ == "multline" ||
414 type_ == "alignat" ||
415 type_ == "xalignat" ||
416 type_ == "xxalignat";
420 bool MathHullInset::display() const
422 return type_ != "simple" && type_ != "none";
426 void MathHullInset::getLabelList(Buffer const &, vector<string> & labels) const
428 for (row_type row = 0; row < nrows(); ++row)
429 if (!label_[row].empty() && nonum_[row] != 1)
430 labels.push_back(label_[row]);
434 bool MathHullInset::numberedType() const
438 if (type_ == "simple")
440 if (type_ == "xxalignat")
442 for (row_type row = 0; row < nrows(); ++row)
449 void MathHullInset::validate(LaTeXFeatures & features) const
452 features.require("amsmath");
455 // Validation is necessary only if not using AMS math.
456 // To be safe, we will always run mathedvalidate.
457 //if (features.amsstyle)
460 features.require("boldsymbol");
461 //features.binom = true;
463 MathGridInset::validate(features);
467 void MathHullInset::header_write(WriteStream & os) const
469 bool n = numberedType();
474 else if (type_ == "simple") {
480 else if (type_ == "equation") {
482 os << "\\begin{equation" << star(n) << "}\n";
487 else if (type_ == "eqnarray" || type_ == "align" || type_ == "flalign"
488 || type_ == "gather" || type_ == "multline")
489 os << "\\begin{" << type_ << star(n) << "}\n";
491 else if (type_ == "alignat" || type_ == "xalignat")
492 os << "\\begin{" << type_ << star(n) << '}'
493 << '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
495 else if (type_ == "xxalignat")
496 os << "\\begin{" << type_ << '}'
497 << '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
500 os << "\\begin{unknown" << star(n) << '}';
504 void MathHullInset::footer_write(WriteStream & os) const
506 bool n = numberedType();
511 else if (type_ == "simple")
514 else if (type_ == "equation")
516 os << "\\end{equation" << star(n) << "}\n";
520 else if (type_ == "eqnarray" || type_ == "align" || type_ == "flalign"
521 || type_ == "alignat" || type_ == "xalignat"
522 || type_ == "gather" || type_ == "multline")
523 os << "\\end{" << type_ << star(n) << "}\n";
525 else if (type_ == "xxalignat")
526 os << "\\end{" << type_ << "}\n";
529 os << "\\end{unknown" << star(n) << '}';
533 bool MathHullInset::colChangeOK() const
536 type_ == "align" || type_ == "flalign" ||type_ == "alignat" ||
537 type_ == "xalignat" || type_ == "xxalignat";
541 void MathHullInset::addRow(row_type row)
543 nonum_.insert(nonum_.begin() + row + 1, !numberedType());
544 label_.insert(label_.begin() + row + 1, string());
545 MathGridInset::addRow(row);
549 void MathHullInset::swapRow(row_type row)
553 if (row + 1 == nrows())
555 swap(nonum_[row], nonum_[row + 1]);
556 swap(label_[row], label_[row + 1]);
557 MathGridInset::swapRow(row);
561 void MathHullInset::delRow(row_type row)
565 MathGridInset::delRow(row);
566 nonum_.erase(nonum_.begin() + row);
567 label_.erase(label_.begin() + row);
571 void MathHullInset::addCol(col_type col)
574 MathGridInset::addCol(col);
576 lyxerr << "Can't change number of columns in '" << type_ << "'" << endl;
580 void MathHullInset::delCol(col_type col)
583 MathGridInset::delCol(col);
585 lyxerr << "Can't change number of columns in '" << type_ << "'" << endl;
589 string MathHullInset::nicelabel(row_type row) const
593 if (label_[row].empty())
594 return string("(#)");
595 return '(' + label_[row] + ')';
599 void MathHullInset::glueall()
602 for (idx_type i = 0; i < nargs(); ++i)
604 *this = MathHullInset("simple");
610 void MathHullInset::splitTo2Cols()
612 BOOST_ASSERT(ncols() == 1);
613 MathGridInset::addCol(1);
614 for (row_type row = 0; row < nrows(); ++row) {
615 idx_type const i = 2 * row;
616 pos_type pos = firstRelOp(cell(i));
617 cell(i + 1) = MathArray(cell(i).begin() + pos, cell(i).end());
618 cell(i).erase(pos, cell(i).size());
623 void MathHullInset::splitTo3Cols()
625 BOOST_ASSERT(ncols() < 3);
628 MathGridInset::addCol(1);
629 for (row_type row = 0; row < nrows(); ++row) {
630 idx_type const i = 3 * row + 1;
631 if (cell(i).size()) {
632 cell(i + 1) = MathArray(cell(i).begin() + 1, cell(i).end());
633 cell(i).erase(1, cell(i).size());
639 void MathHullInset::changeCols(col_type cols)
643 else if (ncols() < cols) {
649 while (ncols() < cols)
650 MathGridInset::addCol(ncols() - 1);
656 for (row_type row = 0; row < nrows(); ++row) {
657 idx_type const i = row * ncols();
658 for (col_type col = cols; col < ncols(); ++col) {
659 cell(i + cols - 1).append(cell(i + col));
663 while (ncols() > cols) {
664 MathGridInset::delCol(ncols() - 1);
669 string const & MathHullInset::getType() const
675 void MathHullInset::setType(string const & type)
683 void MathHullInset::mutate(string const & newtype)
685 lyxerr << "mutating from '" << type_ << "' to '" << newtype << "'" << endl;
687 // we try to move along the chain
688 // none <-> simple <-> equation <-> eqnarray -> *align* -> multline, gather -+
690 // +-------------------------------------+
691 // we use eqnarray as intermediate type for mutations that are not
692 // directly supported because it handles labels and numbering for
695 if (newtype == "dump") {
699 else if (newtype == type_) {
703 else if (type_ == "none") {
709 else if (type_ == "simple") {
710 if (newtype == "none") {
720 else if (type_ == "equation") {
721 if (smaller(newtype, type_)) {
725 } else if (newtype == "eqnarray") {
726 // split it "nicely" on the first relop
729 } else if (newtype == "multline" || newtype == "gather") {
739 else if (type_ == "eqnarray") {
740 if (smaller(newtype, type_)) {
741 // set correct (no)numbering
742 bool allnonum = true;
743 for (row_type row = 0; row < nrows(); ++row)
747 // set first non-empty label
749 for (row_type row = 0; row < nrows(); ++row) {
750 if (!label_[row].empty()) {
757 nonum_[0] = allnonum;
760 } else { // align & Co.
767 else if (type_ == "align" || type_ == "alignat" ||
768 type_ == "xalignat" || type_ == "flalign") {
769 if (smaller(newtype, "align")) {
773 } else if (newtype == "gather" || newtype == "multline") {
776 } else if (newtype == "xxalignat") {
777 for (row_type row = 0; row < nrows(); ++row)
778 numbered(row, false);
785 else if (type_ == "xxalignat") {
786 for (row_type row = 0; row < nrows(); ++row)
787 numbered(row, false);
788 if (smaller(newtype, "align")) {
792 } else if (newtype == "gather" || newtype == "multline") {
800 else if (type_ == "multline" || type_ == "gather") {
801 if (newtype == "gather" || newtype == "multline")
803 else if (newtype == "align" || newtype == "flalign" ||
804 newtype == "alignat" || newtype == "xalignat") {
807 } else if (newtype == "xxalignat") {
809 for (row_type row = 0; row < nrows(); ++row)
810 numbered(row, false);
820 lyxerr << "mutation from '" << type_
821 << "' to '" << newtype << "' not implemented" << endl;
826 string MathHullInset::eolString(row_type row, bool fragile) const
829 if (numberedType()) {
830 if (!label_[row].empty() && !nonum_[row])
831 res += "\\label{" + label_[row] + '}';
832 if (nonum_[row] && (type_ != "multline"))
833 res += "\\nonumber ";
835 return res + MathGridInset::eolString(row, fragile);
839 void MathHullInset::write(WriteStream & os) const
842 MathGridInset::write(os);
847 void MathHullInset::normalize(NormalStream & os) const
849 os << "[formula " << type_ << ' ';
850 MathGridInset::normalize(os);
855 void MathHullInset::mathmlize(MathMLStream & os) const
857 MathGridInset::mathmlize(os);
861 void MathHullInset::infoize(ostream & os) const
863 os << "Type: " << type_;
867 void MathHullInset::check() const
869 BOOST_ASSERT(nonum_.size() == nrows());
870 BOOST_ASSERT(label_.size() == nrows());
874 void MathHullInset::doExtern(LCursor & cur, FuncRequest & func)
878 istringstream iss(func.argument);
879 iss >> lang >> extra;
884 #warning temporarily disabled
885 //if (cur.selection()) {
888 // lyxerr << "use selection: " << ar << endl;
889 // insert(pipeThroughExtern(lang, extra, ar));
895 eq.push_back(MathAtom(new MathCharInset('=')));
897 // go to first item in line
898 cur.idx() -= cur.idx() % ncols();
901 if (getType() == "simple") {
902 size_type pos = cur.cell().find_last(eq);
904 if (cur.inMathed() && cur.selection()) {
905 asArray(grabAndEraseSelection(cur), ar);
906 } else if (pos == cur.cell().size()) {
908 lyxerr << "use whole cell: " << ar << endl;
910 ar = MathArray(cur.cell().begin() + pos + 1, cur.cell().end());
911 lyxerr << "use partial cell form pos: " << pos << endl;
913 cur.cell().append(eq);
914 cur.cell().append(pipeThroughExtern(lang, extra, ar));
915 cur.pos() = cur.lastpos();
919 if (getType() == "equation") {
920 lyxerr << "use equation inset" << endl;
922 MathArray & ar = cur.cell();
923 lyxerr << "use cell: " << ar << endl;
927 cur.cell() = pipeThroughExtern(lang, extra, ar);
928 // move to end of line
929 cur.pos() = cur.lastpos();
934 lyxerr << "use eqnarray" << endl;
935 cur.idx() += 2 - cur.idx() % ncols();
937 MathArray ar = cur.cell();
938 lyxerr << "use cell: " << ar << endl;
940 #warning temporarily disabled
947 cur.cell() = pipeThroughExtern(lang, extra, ar);
948 cur.pos() = cur.lastpos();
953 void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
955 switch (cmd.action) {
957 case LFUN_FINISHED_LEFT:
958 case LFUN_FINISHED_RIGHT:
959 case LFUN_FINISHED_UP:
960 case LFUN_FINISHED_DOWN:
961 MathGridInset::priv_dispatch(cur, cmd);
962 notifyCursorLeaves(cur);
965 case LFUN_BREAKPARAGRAPH:
970 // some magic for the common case
971 if (type_ == "simple" || type_ == "equation") {
972 recordUndoInset(cur);
975 cur.pos() = cur.lastpos();
977 MathGridInset::priv_dispatch(cur, cmd);
980 case LFUN_MATH_NUMBER:
981 //lyxerr << "toggling all numbers" << endl;
983 recordUndoInset(cur);
984 bool old = numberedType();
985 if (type_ == "multline")
986 numbered(nrows() - 1, !old);
988 for (row_type row = 0; row < nrows(); ++row)
990 cur.message(old ? _("No number") : _("Number"));
994 case LFUN_MATH_NONUMBER:
996 recordUndoInset(cur);
997 row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
998 bool old = numbered(r);
999 cur.message(old ? _("No number") : _("Number"));
1004 case LFUN_INSERT_LABEL: {
1005 recordUndoInset(cur);
1006 row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
1007 string old_label = label(r);
1008 string new_label = cmd.argument;
1010 if (new_label.empty()) {
1011 string const default_label =
1012 (lyxrc.label_init_length >= 0) ? "eq:" : "";
1013 pair<bool, string> const res = old_label.empty()
1014 ? Alert::askForText(_("Enter new label to insert:"), default_label)
1015 : Alert::askForText(_("Enter label:"), old_label);
1017 new_label = lyx::support::trim(res.second);
1019 new_label = old_label;
1022 if (!new_label.empty())
1024 label(r, new_label);
1028 case LFUN_MATH_EXTERN:
1029 recordUndoInset(cur);
1033 case LFUN_MATH_MUTATE: {
1034 recordUndoInset(cur);
1035 row_type row = cur.row();
1036 col_type col = cur.col();
1037 mutate(cmd.argument);
1038 cur.idx() = row * ncols() + col;
1039 if (cur.idx() > cur.lastidx()) {
1040 cur.idx() = cur.lastidx();
1041 cur.pos() = cur.lastpos();
1043 if (cur.pos() > cur.lastpos())
1044 cur.pos() = cur.lastpos();
1045 //cur.dispatched(FINISHED);
1049 case LFUN_MATH_DISPLAY: {
1050 recordUndoInset(cur);
1051 mutate(type_ == "simple" ? "equation" : "simple");
1053 cur.pos() = cur.lastpos();
1054 //cur.dispatched(FINISHED);
1059 MathGridInset::priv_dispatch(cur, cmd);
1065 bool MathHullInset::getStatus(LCursor & cur, FuncRequest const & cmd,
1066 FuncStatus & flag) const
1068 switch (cmd.action) {
1069 case LFUN_BREAKLINE:
1070 case LFUN_MATH_NUMBER:
1071 case LFUN_MATH_NONUMBER:
1072 case LFUN_INSERT_LABEL:
1073 case LFUN_MATH_EXTERN:
1074 case LFUN_MATH_MUTATE:
1075 case LFUN_MATH_DISPLAY:
1078 case LFUN_TABULAR_FEATURE: {
1079 // should be more precise
1080 istringstream is(cmd.argument);
1083 if ((type_ == "simple" || type_ == "equation")
1084 && (s == "append-column"
1085 || s == "delete-column"
1086 || s == "swap-column"
1087 || s == "copy-column"
1088 || s == "delete-column"
1089 || s == "append-row"
1090 || s == "delete-row"
1092 || s == "copy-row"))
1094 if ((type_ == "eqnarray")
1095 && (s == "appen-column"
1096 || s == "delete-column"))
1098 return MathGridInset::getStatus(cur, cmd, flag);
1101 return MathGridInset::getStatus(cur, cmd, flag);
1106 /////////////////////////////////////////////////////////////////////
1108 #include "math_arrayinset.h"
1109 #include "math_deliminset.h"
1110 #include "math_factory.h"
1111 #include "math_parser.h"
1112 #include "math_spaceinset.h"
1113 #include "ref_inset.h"
1115 #include "bufferview_funcs.h"
1116 #include "lyxtext.h"
1118 #include "frontends/LyXView.h"
1119 #include "frontends/Dialogs.h"
1121 #include "support/lstrings.h"
1122 #include "support/lyxlib.h"
1125 // simply scrap this function if you want
1126 void MathHullInset::mutateToText()
1129 // translate to latex
1131 latex(NULL, os, false, false);
1132 string str = os.str();
1135 LyXText * lt = view_->getLyXText();
1136 string::const_iterator cit = str.begin();
1137 string::const_iterator end = str.end();
1138 for (; cit != end; ++cit)
1139 view_->owner()->getIntl()->getTransManager().TranslateAndInsert(*cit, lt);
1142 //view_->owner()->dispatch(LFUN_ESCAPE);
1147 void MathHullInset::handleFont(LCursor & cur, string const & arg,
1148 string const & font)
1150 // this whole function is a hack and won't work for incremental font
1153 if (cur.inset().asMathInset()->name() == font)
1154 cur.handleFont(font);
1156 cur.handleNest(createMathInset(font));
1162 void MathHullInset::handleFont2(LCursor & cur, string const & arg)
1167 bv_funcs::string2font(arg, font, b);
1168 if (font.color() != LColor::inherit) {
1169 MathAtom at = createMathInset("color");
1170 asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
1171 cur.handleNest(at, 1);
1176 void MathHullInset::edit(LCursor & cur, bool left)
1179 left ? idxFirst(cur) : idxLast(cur);
1183 string const MathHullInset::editMessage() const
1185 return _("Math editor mode");
1189 void MathHullInset::getCursorDim(int & asc, int & desc) const
1193 //math_font_max_dim(font_, asc, des);
1197 void MathHullInset::revealCodes(LCursor & cur) const
1199 if (!cur.inMathed())
1203 cur.message(os.str());
1205 // write something to the minibuffer
1206 // translate to latex
1210 string str = os.str();
1212 string::size_type pos = 0;
1214 for (string::iterator it = str.begin(); it != str.end(); ++it) {
1217 else if (*it == '\0') {
1219 pos = it - str.begin();
1225 res = res.substr(pos - 30);
1226 if (res.size() > 60)
1227 res = res.substr(0, 60);
1233 InsetBase::Code MathHullInset::lyxCode() const
1239 /////////////////////////////////////////////////////////////////////
1243 bool MathHullInset::searchForward(BufferView * bv, string const & str,
1246 #ifdef WITH_WARNINGS
1247 #warning completely broken
1249 static MathHullInset * lastformula = 0;
1250 static CursorBase current = DocIterator(ibegin(nucleus()));
1251 static MathArray ar;
1252 static string laststr;
1254 if (lastformula != this || laststr != str) {
1255 //lyxerr << "reset lastformula to " << this << endl;
1258 current = ibegin(nucleus());
1260 mathed_parse_cell(ar, str);
1264 //lyxerr << "searching '" << str << "' in " << this << ar << endl;
1266 for (DocIterator it = current; it != iend(nucleus()); increment(it)) {
1267 CursorSlice & top = it.back();
1268 MathArray const & a = top.asMathInset()->cell(top.idx_);
1269 if (a.matchpart(ar, top.pos_)) {
1270 bv->cursor().setSelection(it, ar.size());
1272 top.pos_ += ar.size();
1278 //lyxerr << "not found!" << endl;
1285 void MathHullInset::write(Buffer const &, std::ostream & os) const
1287 WriteStream wi(os, false, false);
1293 void MathHullInset::read(Buffer const &, LyXLex & lex)
1296 mathed_parse_normal(at, lex);
1297 operator=(*at->asHullInset());
1301 int MathHullInset::plaintext(Buffer const &, ostream & os,
1302 OutputParams const &) const
1304 if (0 && display()) {
1308 TextPainter tpain(dim.width(), dim.height());
1309 drawT(tpain, 0, dim.ascent());
1311 // reset metrics cache to "real" values
1313 return tpain.textheight();
1315 WriteStream wi(os, false, true);
1322 int MathHullInset::linuxdoc(Buffer const & buf, ostream & os,
1323 OutputParams const & runparams) const
1325 return docbook(buf, os, runparams);
1329 int MathHullInset::docbook(Buffer const & buf, ostream & os,
1330 OutputParams const & runparams) const
1332 MathMLStream ms(os);
1335 if (getType() == "simple")
1336 name= "inlineequation";
1338 name = "informalequation";
1340 string bname = name;
1341 if (! label(0).empty()) bname += " id=\"" + label(0)+ "\"";
1342 ms << MTag(bname.c_str());
1344 if (runparams.flavor == OutputParams::XML) {
1346 MathGridInset::mathmlize(ms);
1348 ms << MTag("alt role=\"tex\" ");
1350 WriteStream wi(ls, false, false);
1351 MathGridInset::write(wi);
1355 ms << MTag("alt role=\"tex\" ");
1356 res = latex(buf, ms.os(), runparams);
1360 ms << ETag(name.c_str());
1361 return ms.line() + res;