mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-09 10:47:57 +00:00
Implement the EnsureMath inset in mathed for nesting math mode in text mode.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26304 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
2807761e65
commit
8fde2a6fa7
@ -338,6 +338,7 @@ SOURCEFILESMATHED = \
|
||||
mathed/InsetMathDelim.cpp \
|
||||
mathed/InsetMathDiff.cpp \
|
||||
mathed/InsetMathDots.cpp \
|
||||
mathed/InsetMathEnsureMath.cpp \
|
||||
mathed/InsetMathEnv.cpp \
|
||||
mathed/InsetMathExFunc.cpp \
|
||||
mathed/InsetMathExInt.cpp \
|
||||
@ -400,6 +401,7 @@ HEADERFILESMATHED = \
|
||||
mathed/InsetMathDelim.h \
|
||||
mathed/InsetMathDiff.h \
|
||||
mathed/InsetMathDots.h \
|
||||
mathed/InsetMathEnsureMath.h \
|
||||
mathed/InsetMathEnv.h \
|
||||
mathed/InsetMathExFunc.h \
|
||||
mathed/InsetMathExInt.h \
|
||||
|
76
src/mathed/InsetMathEnsureMath.cpp
Normal file
76
src/mathed/InsetMathEnsureMath.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* \file InsetMathEnsureMath.cpp
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author André Pönitz
|
||||
* \author Enrico Forestieri
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "InsetMathEnsureMath.h"
|
||||
|
||||
#include "MathStream.h"
|
||||
#include "MathData.h"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
InsetMathEnsureMath::InsetMathEnsureMath()
|
||||
: InsetMathNest(1)
|
||||
{}
|
||||
|
||||
|
||||
Inset * InsetMathEnsureMath::clone() const
|
||||
{
|
||||
return new InsetMathEnsureMath(*this);
|
||||
}
|
||||
|
||||
|
||||
void InsetMathEnsureMath::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
{
|
||||
FontSetChanger dummy(mi.base, "mathnormal");
|
||||
cell(0).metrics(mi, dim);
|
||||
metricsMarkers(dim);
|
||||
}
|
||||
|
||||
|
||||
void InsetMathEnsureMath::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
FontSetChanger dummy(pi.base, "mathnormal");
|
||||
cell(0).draw(pi, x, y);
|
||||
drawMarkers(pi, x, y);
|
||||
}
|
||||
|
||||
|
||||
void InsetMathEnsureMath::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
||||
{
|
||||
cell(0).metricsT(mi, dim);
|
||||
}
|
||||
|
||||
|
||||
void InsetMathEnsureMath::drawT(TextPainter & pain, int x, int y) const
|
||||
{
|
||||
cell(0).drawT(pain, x, y);
|
||||
}
|
||||
|
||||
|
||||
void InsetMathEnsureMath::write(WriteStream & os) const
|
||||
{
|
||||
ModeSpecifier specifier(os, MATH_MODE);
|
||||
os << "\\ensuremath{" << cell(0) << "}";
|
||||
}
|
||||
|
||||
|
||||
void InsetMathEnsureMath::infoize(odocstream & os) const
|
||||
{
|
||||
os << "EnsureMath";
|
||||
}
|
||||
|
||||
|
||||
} // namespace lyx
|
47
src/mathed/InsetMathEnsureMath.h
Normal file
47
src/mathed/InsetMathEnsureMath.h
Normal file
@ -0,0 +1,47 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file InsetMathEnsureMath.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author André Pönitz
|
||||
* \author Enrico Forestieri
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef MATH_ENSUREMATHINSET_H
|
||||
#define MATH_ENSUREMATHINSET_H
|
||||
|
||||
#include "InsetMathNest.h"
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
|
||||
/// Inset for ensuring math mode
|
||||
class InsetMathEnsureMath : public InsetMathNest {
|
||||
public:
|
||||
InsetMathEnsureMath();
|
||||
///
|
||||
mode_type currentMode() const { return MATH_MODE; }
|
||||
///
|
||||
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
||||
///
|
||||
void draw(PainterInfo & pi, int x, int y) const;
|
||||
///
|
||||
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
|
||||
///
|
||||
void drawT(TextPainter & pi, int x, int y) const;
|
||||
///
|
||||
void write(WriteStream & os) const;
|
||||
///
|
||||
void infoize(odocstream & os) const;
|
||||
private:
|
||||
virtual Inset * clone() const;
|
||||
};
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
#endif
|
@ -20,6 +20,7 @@
|
||||
#include "InsetMathColor.h"
|
||||
#include "InsetMathDecoration.h"
|
||||
#include "InsetMathDots.h"
|
||||
#include "InsetMathEnsureMath.h"
|
||||
#include "InsetMathFont.h"
|
||||
#include "InsetMathFontOld.h"
|
||||
#include "InsetMathFrac.h"
|
||||
@ -443,6 +444,8 @@ MathAtom createInsetMath(docstring const & s)
|
||||
return MathAtom(new InsetMathPhantom(InsetMathPhantom::phantom));
|
||||
if (s == "vphantom")
|
||||
return MathAtom(new InsetMathPhantom(InsetMathPhantom::vphantom));
|
||||
if (s == "ensuremath")
|
||||
return MathAtom(new InsetMathEnsureMath);
|
||||
|
||||
return MathAtom(new MathMacro(s));
|
||||
}
|
||||
|
@ -1526,7 +1526,7 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
}
|
||||
#endif
|
||||
|
||||
else if (t.cs() == "lyxmathsym" || t.cs() == "ensuremath") {
|
||||
else if (t.cs() == "lyxmathsym") {
|
||||
skipSpaces();
|
||||
if (getToken().cat() != catBegin) {
|
||||
error("'{' expected in \\" + t.cs());
|
||||
@ -1547,22 +1547,16 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
||||
error("'}' expected in \\" + t.cs());
|
||||
return;
|
||||
}
|
||||
if (t.cs() == "ensuremath") {
|
||||
docstring rem;
|
||||
cmd = Encodings::fromLaTeXCommand(cmd, rem);
|
||||
for (size_t i = 0; i < cmd.size(); ++i)
|
||||
cell->push_back(MathAtom(new InsetMathChar(cmd[i])));
|
||||
if (rem.size()) {
|
||||
MathAtom at = createInsetMath(t.cs());
|
||||
cell->push_back(at);
|
||||
MathData ar;
|
||||
mathed_parse_cell(ar, cmd);
|
||||
mathed_parse_cell(ar, '{' + rem + '}');
|
||||
cell->append(ar);
|
||||
} else {
|
||||
docstring rem;
|
||||
cmd = Encodings::fromLaTeXCommand(cmd, rem);
|
||||
for (size_t i = 0; i < cmd.size(); ++i)
|
||||
cell->push_back(MathAtom(new InsetMathChar(cmd[i])));
|
||||
if (rem.size()) {
|
||||
MathAtom at = createInsetMath(t.cs());
|
||||
cell->push_back(at);
|
||||
MathData ar;
|
||||
mathed_parse_cell(ar, '{' + rem + '}');
|
||||
cell->append(ar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user