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"
34 #include "textpainter.h"
37 #include "insets/render_preview.h"
39 #include "frontends/Alert.h"
41 #include "graphics/PreviewImage.h"
42 #include "graphics/PreviewLoader.h"
44 #include "support/lstrings.h"
46 #include <boost/bind.hpp>
50 using lyx::cap::grabAndEraseSelection;
51 using lyx::support::subst;
58 using std::istringstream;
60 using std::ostringstream;
68 int getCols(string const & type)
70 if (type == "eqnarray")
74 if (type == "flalign")
76 if (type == "alignat")
78 if (type == "xalignat")
80 if (type == "xxalignat")
86 // returns position of first relation operator in the array
87 // used for "intelligent splitting"
88 size_t firstRelOp(MathArray const & ar)
90 for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
92 return it - ar.begin();
97 char const * star(bool numbered)
99 return numbered ? "" : "*";
103 int typecode(string const & s)
105 if (s == "none") return 0;
106 if (s == "simple") return 1;
107 if (s == "equation") return 2;
108 if (s == "eqnarray") return 3;
109 if (s == "align") return 4;
110 if (s == "alignat") return 5;
111 if (s == "xalignat") return 6;
112 if (s == "xxalignat") return 7;
113 if (s == "multline") return 8;
114 if (s == "gather") return 9;
115 if (s == "flalign") return 10;
116 lyxerr << "unknown hull type '" << s << "'" << endl;
120 bool smaller(string const & s, string const & t)
122 return typecode(s) < typecode(t);
126 } // end anon namespace
130 MathHullInset::MathHullInset()
131 : MathGridInset(1, 1), type_("none"), nonum_(1), label_(1),
132 preview_(new RenderPreview(this))
134 //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << endl;
135 //lyxerr << "sizeof MetricsInfo: " << sizeof(MetricsInfo) << endl;
136 //lyxerr << "sizeof MathCharInset: " << sizeof(MathCharInset) << endl;
137 //lyxerr << "sizeof LyXFont: " << sizeof(LyXFont) << endl;
142 MathHullInset::MathHullInset(string const & type)
143 : MathGridInset(getCols(type), 1), type_(type), nonum_(1), label_(1),
144 preview_(new RenderPreview(this))
150 MathHullInset::MathHullInset(MathHullInset const & other)
151 : MathGridInset(other),
152 type_(other.type_), nonum_(other.nonum_), label_(other.label_),
153 preview_(new RenderPreview(this))
157 MathHullInset::~MathHullInset()
161 auto_ptr<InsetBase> MathHullInset::clone() const
163 return auto_ptr<InsetBase>(new MathHullInset(*this));
167 void MathHullInset::operator=(MathHullInset const & other)
171 *static_cast<MathGridInset*>(this) = MathGridInset(other);
173 nonum_ = other.nonum_;
174 label_ = other.label_;
175 preview_.reset(new RenderPreview(*other.preview_, this));
179 MathInset::mode_type MathHullInset::currentMode() const
182 return UNDECIDED_MODE;
183 // definitely math mode ...
188 bool MathHullInset::idxFirst(LCursor & cur) const
196 bool MathHullInset::idxLast(LCursor & cur) const
198 cur.idx() = nargs() - 1;
199 cur.pos() = cur.lastpos();
204 char MathHullInset::defaultColAlign(col_type col)
206 if (type_ == "eqnarray")
208 if (typecode(type_) >= typecode("align"))
209 return "rl"[col & 1];
214 int MathHullInset::defaultColSpace(col_type col)
216 if (type_ == "align" || type_ == "alignat")
218 if (type_ == "xalignat")
219 return (col & 1) ? 20 : 0;
220 if (type_ == "xxalignat" || type_ == "flalign")
221 return (col & 1) ? 40 : 0;
226 char const * MathHullInset::standardFont() const
229 return "lyxnochange";
234 void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const
236 BOOST_ASSERT(mi.base.bv && mi.base.bv->buffer());
238 bool use_preview = false;
239 if (!editing(mi.base.bv) &&
240 RenderPreview::status() == LyXRC::PREVIEW_ON) {
241 lyx::graphics::PreviewImage const * pimage =
242 preview_->getPreviewImage(*mi.base.bv->buffer());
243 use_preview = pimage && pimage->image();
247 preview_->metrics(mi, dim);
248 // insert a one pixel gap in front of the formula
256 FontSetChanger dummy1(mi.base, standardFont());
257 StyleChanger dummy2(mi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
259 // let the cells adjust themselves
260 MathGridInset::metrics(mi, dim);
267 if (numberedType()) {
268 FontSetChanger dummy(mi.base, "mathbf");
270 for (row_type row = 0; row < nrows(); ++row)
271 l = max(l, mathed_string_width(mi.base.font, nicelabel(row)));
277 // make it at least as high as the current font
280 math_font_max_dim(mi.base.font, asc, des);
281 dim.asc = max(dim.asc, asc);
282 dim.des = max(dim.des, des);
288 void MathHullInset::draw(PainterInfo & pi, int x, int y) const
290 BOOST_ASSERT(pi.base.bv && pi.base.bv->buffer());
292 bool use_preview = false;
293 if (!editing(pi.base.bv) &&
294 RenderPreview::status() == LyXRC::PREVIEW_ON) {
295 lyx::graphics::PreviewImage const * pimage =
296 preview_->getPreviewImage(*pi.base.bv->buffer());
297 use_preview = pimage && pimage->image();
301 // one pixel gap in front
302 preview_->draw(pi, x + 1, y);
303 setPosCache(pi, x, y);
307 FontSetChanger dummy1(pi.base, standardFont());
308 StyleChanger dummy2(pi.base, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
309 MathGridInset::draw(pi, x + 1, y);
311 if (numberedType()) {
312 int const xx = x + colinfo_.back().offset_ + colinfo_.back().width_ + 20;
313 for (row_type row = 0; row < nrows(); ++row) {
314 int const yy = y + rowinfo_[row].offset_;
315 FontSetChanger dummy(pi.base, "mathrm");
316 drawStr(pi, pi.base.font, xx, yy, nicelabel(row));
319 setPosCache(pi, x, y);
323 void MathHullInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
326 MathGridInset::metricsT(mi, dim);
329 WriteStream wi(os, false, true);
331 dim.wid = os.str().size();
338 void MathHullInset::drawT(TextPainter & pain, int x, int y) const
341 MathGridInset::drawT(pain, x, y);
344 WriteStream wi(os, false, true);
346 pain.draw(x, y, os.str().c_str());
353 string const latex_string(MathHullInset const & inset)
356 WriteStream wi(ls, false, false);
364 void MathHullInset::addPreview(lyx::graphics::PreviewLoader & ploader) const
366 if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
367 string const snippet = latex_string(*this);
368 preview_->addPreview(snippet, ploader);
373 void MathHullInset::notifyCursorLeaves(LCursor & cur)
375 if (RenderPreview::status() == LyXRC::PREVIEW_ON) {
376 Buffer const & buffer = cur.buffer();
377 string const snippet = latex_string(*this);
378 preview_->addPreview(snippet, buffer);
379 preview_->startLoading(buffer);
384 string MathHullInset::label(row_type row) const
386 row_type n = nrows();
387 BOOST_ASSERT(row < n);
392 void MathHullInset::label(row_type row, string const & label)
394 //lyxerr << "setting label '" << label << "' for row " << row << endl;
399 void MathHullInset::numbered(row_type row, bool num)
405 bool MathHullInset::numbered(row_type row) const
411 bool MathHullInset::ams() const
415 type_ == "flalign" ||
416 type_ == "multline" ||
418 type_ == "alignat" ||
419 type_ == "xalignat" ||
420 type_ == "xxalignat";
424 bool MathHullInset::display() const
426 return type_ != "simple" && type_ != "none";
430 void MathHullInset::getLabelList(Buffer const &, vector<string> & labels) const
432 for (row_type row = 0; row < nrows(); ++row)
433 if (!label_[row].empty() && nonum_[row] != 1)
434 labels.push_back(label_[row]);
438 bool MathHullInset::numberedType() const
442 if (type_ == "simple")
444 if (type_ == "xxalignat")
446 for (row_type row = 0; row < nrows(); ++row)
453 void MathHullInset::validate(LaTeXFeatures & features) const
456 features.require("amsmath");
459 // Validation is necessary only if not using AMS math.
460 // To be safe, we will always run mathedvalidate.
461 //if (features.amsstyle)
464 features.require("boldsymbol");
465 //features.binom = true;
467 MathGridInset::validate(features);
471 void MathHullInset::header_write(WriteStream & os) const
473 bool n = numberedType();
478 else if (type_ == "simple") {
484 else if (type_ == "equation") {
486 os << "\\begin{equation" << star(n) << "}\n";
491 else if (type_ == "eqnarray" || type_ == "align" || type_ == "flalign"
492 || type_ == "gather" || type_ == "multline")
493 os << "\\begin{" << type_ << star(n) << "}\n";
495 else if (type_ == "alignat" || type_ == "xalignat")
496 os << "\\begin{" << type_ << star(n) << '}'
497 << '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
499 else if (type_ == "xxalignat")
500 os << "\\begin{" << type_ << '}'
501 << '{' << static_cast<unsigned int>((ncols() + 1)/2) << "}\n";
504 os << "\\begin{unknown" << star(n) << '}';
508 void MathHullInset::footer_write(WriteStream & os) const
510 bool n = numberedType();
515 else if (type_ == "simple")
518 else if (type_ == "equation")
520 os << "\\end{equation" << star(n) << "}\n";
524 else if (type_ == "eqnarray" || type_ == "align" || type_ == "flalign"
525 || type_ == "alignat" || type_ == "xalignat"
526 || type_ == "gather" || type_ == "multline")
527 os << "\\end{" << type_ << star(n) << "}\n";
529 else if (type_ == "xxalignat")
530 os << "\\end{" << type_ << "}\n";
533 os << "\\end{unknown" << star(n) << '}';
537 bool MathHullInset::colChangeOK() const
540 type_ == "align" || type_ == "flalign" ||type_ == "alignat" ||
541 type_ == "xalignat" || type_ == "xxalignat";
545 void MathHullInset::addRow(row_type row)
547 nonum_.insert(nonum_.begin() + row + 1, !numberedType());
548 label_.insert(label_.begin() + row + 1, string());
549 MathGridInset::addRow(row);
553 void MathHullInset::swapRow(row_type row)
557 if (row + 1 == nrows())
559 swap(nonum_[row], nonum_[row + 1]);
560 swap(label_[row], label_[row + 1]);
561 MathGridInset::swapRow(row);
565 void MathHullInset::delRow(row_type row)
569 MathGridInset::delRow(row);
570 nonum_.erase(nonum_.begin() + row);
571 label_.erase(label_.begin() + row);
575 void MathHullInset::addCol(col_type col)
578 MathGridInset::addCol(col);
580 lyxerr << "Can't change number of columns in '" << type_ << "'" << endl;
584 void MathHullInset::delCol(col_type col)
587 MathGridInset::delCol(col);
589 lyxerr << "Can't change number of columns in '" << type_ << "'" << endl;
593 string MathHullInset::nicelabel(row_type row) const
597 if (label_[row].empty())
598 return string("(#)");
599 return '(' + label_[row] + ')';
603 void MathHullInset::glueall()
606 for (idx_type i = 0; i < nargs(); ++i)
608 *this = MathHullInset("simple");
614 void MathHullInset::splitTo2Cols()
616 BOOST_ASSERT(ncols() == 1);
617 MathGridInset::addCol(1);
618 for (row_type row = 0; row < nrows(); ++row) {
619 idx_type const i = 2 * row;
620 pos_type pos = firstRelOp(cell(i));
621 cell(i + 1) = MathArray(cell(i).begin() + pos, cell(i).end());
622 cell(i).erase(pos, cell(i).size());
627 void MathHullInset::splitTo3Cols()
629 BOOST_ASSERT(ncols() < 3);
632 MathGridInset::addCol(1);
633 for (row_type row = 0; row < nrows(); ++row) {
634 idx_type const i = 3 * row + 1;
635 if (cell(i).size()) {
636 cell(i + 1) = MathArray(cell(i).begin() + 1, cell(i).end());
637 cell(i).erase(1, cell(i).size());
643 void MathHullInset::changeCols(col_type cols)
647 else if (ncols() < cols) {
653 while (ncols() < cols)
654 MathGridInset::addCol(ncols() - 1);
660 for (row_type row = 0; row < nrows(); ++row) {
661 idx_type const i = row * ncols();
662 for (col_type col = cols; col < ncols(); ++col) {
663 cell(i + cols - 1).append(cell(i + col));
667 while (ncols() > cols) {
668 MathGridInset::delCol(ncols() - 1);
673 string const & MathHullInset::getType() const
679 void MathHullInset::setType(string const & type)
687 void MathHullInset::mutate(string const & newtype)
689 lyxerr << "mutating from '" << type_ << "' to '" << newtype << "'" << endl;
691 // we try to move along the chain
692 // none <-> simple <-> equation <-> eqnarray -> *align* -> multline, gather -+
694 // +-------------------------------------+
695 // we use eqnarray as intermediate type for mutations that are not
696 // directly supported because it handles labels and numbering for
699 if (newtype == "dump") {
703 else if (newtype == type_) {
707 else if (typecode(newtype) < 0) {
711 else if (type_ == "none") {
717 else if (type_ == "simple") {
718 if (newtype == "none") {
728 else if (type_ == "equation") {
729 if (smaller(newtype, type_)) {
733 } else if (newtype == "eqnarray") {
734 // split it "nicely" on the first relop
737 } else if (newtype == "multline" || newtype == "gather") {
747 else if (type_ == "eqnarray") {
748 if (smaller(newtype, type_)) {
749 // set correct (no)numbering
750 bool allnonum = true;
751 for (row_type row = 0; row < nrows(); ++row)
755 // set first non-empty label
757 for (row_type row = 0; row < nrows(); ++row) {
758 if (!label_[row].empty()) {
765 nonum_[0] = allnonum;
768 } else { // align & Co.
775 else if (type_ == "align" || type_ == "alignat" ||
776 type_ == "xalignat" || type_ == "flalign") {
777 if (smaller(newtype, "align")) {
781 } else if (newtype == "gather" || newtype == "multline") {
784 } else if (newtype == "xxalignat") {
785 for (row_type row = 0; row < nrows(); ++row)
786 numbered(row, false);
793 else if (type_ == "xxalignat") {
794 for (row_type row = 0; row < nrows(); ++row)
795 numbered(row, false);
796 if (smaller(newtype, "align")) {
800 } else if (newtype == "gather" || newtype == "multline") {
808 else if (type_ == "multline" || type_ == "gather") {
809 if (newtype == "gather" || newtype == "multline")
811 else if (newtype == "align" || newtype == "flalign" ||
812 newtype == "alignat" || newtype == "xalignat") {
815 } else if (newtype == "xxalignat") {
817 for (row_type row = 0; row < nrows(); ++row)
818 numbered(row, false);
828 lyxerr << "mutation from '" << type_
829 << "' to '" << newtype << "' not implemented" << endl;
834 string MathHullInset::eolString(row_type row, bool fragile) const
837 if (numberedType()) {
838 if (!label_[row].empty() && !nonum_[row])
839 res += "\\label{" + label_[row] + '}';
840 if (nonum_[row] && (type_ != "multline"))
841 res += "\\nonumber ";
843 return res + MathGridInset::eolString(row, fragile);
847 void MathHullInset::write(WriteStream & os) const
850 MathGridInset::write(os);
855 void MathHullInset::normalize(NormalStream & os) const
857 os << "[formula " << type_ << ' ';
858 MathGridInset::normalize(os);
863 void MathHullInset::mathmlize(MathMLStream & os) const
865 MathGridInset::mathmlize(os);
869 void MathHullInset::infoize(ostream & os) const
871 os << "Type: " << type_;
875 void MathHullInset::check() const
877 BOOST_ASSERT(nonum_.size() == nrows());
878 BOOST_ASSERT(label_.size() == nrows());
882 void MathHullInset::doExtern(LCursor & cur, FuncRequest & func)
886 istringstream iss(func.argument);
887 iss >> lang >> extra;
892 #warning temporarily disabled
893 //if (cur.selection()) {
896 // lyxerr << "use selection: " << ar << endl;
897 // insert(pipeThroughExtern(lang, extra, ar));
903 eq.push_back(MathAtom(new MathCharInset('=')));
905 // go to first item in line
906 cur.idx() -= cur.idx() % ncols();
909 if (getType() == "simple") {
910 size_type pos = cur.cell().find_last(eq);
912 if (cur.inMathed() && cur.selection()) {
913 asArray(grabAndEraseSelection(cur), ar);
914 } else if (pos == cur.cell().size()) {
916 lyxerr << "use whole cell: " << ar << endl;
918 ar = MathArray(cur.cell().begin() + pos + 1, cur.cell().end());
919 lyxerr << "use partial cell form pos: " << pos << endl;
921 cur.cell().append(eq);
922 cur.cell().append(pipeThroughExtern(lang, extra, ar));
923 cur.pos() = cur.lastpos();
927 if (getType() == "equation") {
928 lyxerr << "use equation inset" << endl;
930 MathArray & ar = cur.cell();
931 lyxerr << "use cell: " << ar << endl;
935 cur.cell() = pipeThroughExtern(lang, extra, ar);
936 // move to end of line
937 cur.pos() = cur.lastpos();
942 lyxerr << "use eqnarray" << endl;
943 cur.idx() += 2 - cur.idx() % ncols();
945 MathArray ar = cur.cell();
946 lyxerr << "use cell: " << ar << endl;
948 #warning temporarily disabled
955 cur.cell() = pipeThroughExtern(lang, extra, ar);
956 cur.pos() = cur.lastpos();
961 void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
963 switch (cmd.action) {
965 case LFUN_FINISHED_LEFT:
966 case LFUN_FINISHED_RIGHT:
967 case LFUN_FINISHED_UP:
968 case LFUN_FINISHED_DOWN:
969 MathGridInset::priv_dispatch(cur, cmd);
970 notifyCursorLeaves(cur);
973 case LFUN_BREAKPARAGRAPH:
978 // some magic for the common case
979 if (type_ == "simple" || type_ == "equation") {
980 recordUndoInset(cur);
983 cur.pos() = cur.lastpos();
985 MathGridInset::priv_dispatch(cur, cmd);
988 case LFUN_MATH_NUMBER:
989 //lyxerr << "toggling all numbers" << endl;
991 recordUndoInset(cur);
992 bool old = numberedType();
993 if (type_ == "multline")
994 numbered(nrows() - 1, !old);
996 for (row_type row = 0; row < nrows(); ++row)
998 cur.message(old ? _("No number") : _("Number"));
1002 case LFUN_MATH_NONUMBER:
1004 recordUndoInset(cur);
1005 row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
1006 bool old = numbered(r);
1007 cur.message(old ? _("No number") : _("Number"));
1012 case LFUN_INSERT_LABEL: {
1013 recordUndoInset(cur);
1014 row_type r = (type_ == "multline") ? nrows() - 1 : cur.row();
1015 string old_label = label(r);
1016 string new_label = cmd.argument;
1018 if (new_label.empty()) {
1019 string const default_label =
1020 (lyxrc.label_init_length >= 0) ? "eq:" : "";
1021 pair<bool, string> const res = old_label.empty()
1022 ? Alert::askForText(_("Enter new label to insert:"), default_label)
1023 : Alert::askForText(_("Enter label:"), old_label);
1025 new_label = lyx::support::trim(res.second);
1027 new_label = old_label;
1030 if (!new_label.empty())
1032 label(r, new_label);
1036 case LFUN_MATH_EXTERN:
1037 recordUndoInset(cur);
1041 case LFUN_MATH_MUTATE: {
1042 recordUndoInset(cur);
1043 row_type row = cur.row();
1044 col_type col = cur.col();
1045 mutate(cmd.argument);
1046 cur.idx() = row * ncols() + col;
1047 if (cur.idx() > cur.lastidx()) {
1048 cur.idx() = cur.lastidx();
1049 cur.pos() = cur.lastpos();
1051 if (cur.pos() > cur.lastpos())
1052 cur.pos() = cur.lastpos();
1053 //cur.dispatched(FINISHED);
1057 case LFUN_MATH_DISPLAY: {
1058 recordUndoInset(cur);
1059 mutate(type_ == "simple" ? "equation" : "simple");
1061 cur.pos() = cur.lastpos();
1062 //cur.dispatched(FINISHED);
1067 MathGridInset::priv_dispatch(cur, cmd);
1073 bool MathHullInset::getStatus(LCursor & cur, FuncRequest const & cmd,
1074 FuncStatus & flag) const
1076 switch (cmd.action) {
1077 case LFUN_BREAKLINE:
1078 case LFUN_MATH_NUMBER:
1079 case LFUN_MATH_NONUMBER:
1080 case LFUN_INSERT_LABEL:
1081 case LFUN_MATH_EXTERN:
1082 case LFUN_MATH_MUTATE:
1083 case LFUN_MATH_DISPLAY:
1086 case LFUN_TABULAR_FEATURE: {
1087 // should be more precise
1088 istringstream is(cmd.argument);
1091 if ((type_ == "simple" || type_ == "equation")
1092 && (s == "append-column"
1093 || s == "delete-column"
1094 || s == "swap-column"
1095 || s == "copy-column"
1096 || s == "delete-column"
1097 || s == "append-row"
1098 || s == "delete-row"
1100 || s == "copy-row"))
1102 if ((type_ == "eqnarray")
1103 && (s == "appen-column"
1104 || s == "delete-column"))
1106 return MathGridInset::getStatus(cur, cmd, flag);
1109 return MathGridInset::getStatus(cur, cmd, flag);
1114 /////////////////////////////////////////////////////////////////////
1116 #include "math_arrayinset.h"
1117 #include "math_deliminset.h"
1118 #include "math_factory.h"
1119 #include "math_parser.h"
1120 #include "math_spaceinset.h"
1121 #include "ref_inset.h"
1123 #include "bufferview_funcs.h"
1124 #include "lyxtext.h"
1126 #include "frontends/LyXView.h"
1127 #include "frontends/Dialogs.h"
1129 #include "support/lyxlib.h"
1132 // simply scrap this function if you want
1133 void MathHullInset::mutateToText()
1136 // translate to latex
1138 latex(NULL, os, false, false);
1139 string str = os.str();
1142 LyXText * lt = view_->getLyXText();
1143 string::const_iterator cit = str.begin();
1144 string::const_iterator end = str.end();
1145 for (; cit != end; ++cit)
1146 view_->owner()->getIntl()->getTransManager().TranslateAndInsert(*cit, lt);
1149 //view_->owner()->dispatch(LFUN_ESCAPE);
1154 void MathHullInset::handleFont(LCursor & cur, string const & arg,
1155 string const & font)
1157 // this whole function is a hack and won't work for incremental font
1160 if (cur.inset().asMathInset()->name() == font)
1161 cur.handleFont(font);
1163 cur.handleNest(createMathInset(font));
1169 void MathHullInset::handleFont2(LCursor & cur, string const & arg)
1174 bv_funcs::string2font(arg, font, b);
1175 if (font.color() != LColor::inherit) {
1176 MathAtom at = createMathInset("color");
1177 asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
1178 cur.handleNest(at, 1);
1183 void MathHullInset::edit(LCursor & cur, bool left)
1186 left ? idxFirst(cur) : idxLast(cur);
1190 string const MathHullInset::editMessage() const
1192 return _("Math editor mode");
1196 void MathHullInset::getCursorDim(int & asc, int & desc) const
1200 //math_font_max_dim(font_, asc, des);
1204 void MathHullInset::revealCodes(LCursor & cur) const
1206 if (!cur.inMathed())
1210 cur.message(os.str());
1212 // write something to the minibuffer
1213 // translate to latex
1217 string str = os.str();
1219 string::size_type pos = 0;
1221 for (string::iterator it = str.begin(); it != str.end(); ++it) {
1224 else if (*it == '\0') {
1226 pos = it - str.begin();
1232 res = res.substr(pos - 30);
1233 if (res.size() > 60)
1234 res = res.substr(0, 60);
1240 InsetBase::Code MathHullInset::lyxCode() const
1246 /////////////////////////////////////////////////////////////////////
1250 bool MathHullInset::searchForward(BufferView * bv, string const & str,
1253 #ifdef WITH_WARNINGS
1254 #warning completely broken
1256 static MathHullInset * lastformula = 0;
1257 static CursorBase current = DocIterator(ibegin(nucleus()));
1258 static MathArray ar;
1259 static string laststr;
1261 if (lastformula != this || laststr != str) {
1262 //lyxerr << "reset lastformula to " << this << endl;
1265 current = ibegin(nucleus());
1267 mathed_parse_cell(ar, str);
1271 //lyxerr << "searching '" << str << "' in " << this << ar << endl;
1273 for (DocIterator it = current; it != iend(nucleus()); increment(it)) {
1274 CursorSlice & top = it.back();
1275 MathArray const & a = top.asMathInset()->cell(top.idx_);
1276 if (a.matchpart(ar, top.pos_)) {
1277 bv->cursor().setSelection(it, ar.size());
1279 top.pos_ += ar.size();
1285 //lyxerr << "not found!" << endl;
1292 void MathHullInset::write(Buffer const &, std::ostream & os) const
1294 WriteStream wi(os, false, false);
1300 void MathHullInset::read(Buffer const &, LyXLex & lex)
1303 mathed_parse_normal(at, lex);
1304 operator=(*at->asHullInset());
1308 int MathHullInset::plaintext(Buffer const &, ostream & os,
1309 OutputParams const &) const
1311 if (0 && display()) {
1315 TextPainter tpain(dim.width(), dim.height());
1316 drawT(tpain, 0, dim.ascent());
1318 // reset metrics cache to "real" values
1320 return tpain.textheight();
1322 WriteStream wi(os, false, true);
1329 int MathHullInset::linuxdoc(Buffer const & buf, ostream & os,
1330 OutputParams const & runparams) const
1332 return docbook(buf, os, runparams);
1336 int MathHullInset::docbook(Buffer const & buf, ostream & os,
1337 OutputParams const & runparams) const
1339 MathMLStream ms(os);
1342 if (getType() == "simple")
1343 name= "inlineequation";
1345 name = "informalequation";
1347 string bname = name;
1348 if (!label(0).empty())
1349 bname += " id=\"" + sgml::cleanID(label(0)) + "\"";
1350 ms << MTag(bname.c_str());
1353 if (runparams.flavor == OutputParams::XML) {
1354 ms << MTag("alt role=\"tex\" ");
1355 // Workaround for db2latex: db2latex always includes equations with
1356 // \ensuremath{} or \begin{display}\end{display}
1357 // so we strip LyX' math environment
1358 WriteStream wi(ls, false, false);
1359 MathGridInset::write(wi);
1360 ms << subst(subst(ls.str(), "&", "&"), "<", "<");
1363 MathGridInset::mathmlize(ms);
1366 ms << MTag("alt role=\"tex\"");
1367 res = latex(buf, ls, runparams);
1368 ms << subst(subst(ls.str(), "&", "&"), "<", "<");
1372 ms << "<graphic fileref=\"eqn/";
1373 if ( !label(0).empty())
1374 ms << sgml::cleanID(label(0));
1376 // Some arbitrary unique number for this os.
1377 // Note that each call of math_hullinset::docbook()
1378 // will increase the os position by at least 60 chars or more
1379 ms << sgml::uniqueID("anon");
1381 if (runparams.flavor == OutputParams::XML)
1386 ms << ETag(name.c_str());
1387 return ms.line() + res;