void CommandInset::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode() && needs_math_mode_) {
- os << "\\ensuremath{";
- os.textMode(false);
- }
+ bool brace = ensureMath(os, needs_math_mode_);
os << '\\' << name_.c_str();
if (cell(1).size())
os << '[' << cell(1) << ']';
void InsetMath::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- }
+ bool brace = ensureMath(os);
docstring const s = name();
os << "\\" << s;
// We need an extra ' ' unless this is a single-char-non-ASCII name
}
+bool InsetMath::ensureMath(WriteStream & os, bool needs_math_mode) const
+{
+ bool brace = os.pendingBrace();
+ os.pendingBrace(false);
+ if (os.latex() && os.textMode() && needs_math_mode) {
+ os << "\\ensuremath{";
+ os.textMode(false);
+ brace = true;
+ }
+ return brace;
+}
+
+
int InsetMath::plaintext(odocstream &, OutputParams const &) const
{
// all math plain text output shall take place in InsetMathHull
/// write content as something readable by Octave
virtual void octave(OctaveStream &) const;
+ /// ensure math mode when writing LaTeX
+ bool ensureMath(WriteStream & os, bool needs_math_mode = true) const;
+
/// plain text output in ucs4 encoding
int plaintext(odocstream &, OutputParams const &) const;
void InsetMathAMSArray::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << "\\begin{" << name_ << '}';
InsetMathGrid::write(os);
os << "\\end{" << name_ << '}';
void InsetMathArray::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
if (os.fragile())
os << "\\protect";
void InsetMathBig::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << '\\' << name_ << delim_;
if (delim_[0] == '\\')
os.pendingSpace(true);
void InsetMathBoldSymbol::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
switch (kind_) {
case AMS_BOLD:
os << "\\boldsymbol{" << cell(0) << "}";
void InsetMathCases::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
if (os.fragile())
os << "\\protect";
os << "\\begin{cases}\n";
void InsetMathDecoration::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
if (os.fragile() && protect())
os << "\\protect";
os << '\\' << key_->name << '{' << cell(0) << '}';
void InsetMathDelim::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
-
+ bool brace = ensureMath(os);
os << "\\left" << convertDelimToLatexName(left_) << cell(0)
<< "\\right" << convertDelimToLatexName(right_);
-
os.pendingBrace(brace);
}
void InsetMathEnv::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << "\\begin{" << name_ << '}' << cell(0) << "\\end{" << name_ << '}';
os.pendingBrace(brace);
}
void InsetMathFrac::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
switch (kind_) {
case ATOP:
void InsetMathBinom::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
switch (kind_) {
case BINOM:
void InsetMathOverset::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- }
+ bool brace = ensureMath(os);
os << "\\overset{" << cell(0) << "}{" << cell(1) << '}';
os.pendingBrace(brace);
}
void InsetMathPhantom::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
switch (kind_) {
case phantom:
os << "\\phantom{";
void InsetMathRoot::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
os.pendingBrace(brace);
}
void InsetMathScript::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
if (nuc().size()) {
os << nuc();
void InsetMathSize::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << "{\\" << key_->name << ' ' << cell(0) << '}';
os.pendingBrace(brace);
}
void InsetMathSpace::write(WriteStream & os) const
{
if (space_ >= 0 && space_ < nSpace) {
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << '\\' << latex_mathspace[space_];
os.pendingSpace(true);
os.pendingBrace(brace);
void InsetMathSplit::write(WriteStream & ws) const
{
- bool brace = ws.pendingBrace();
- ws.pendingBrace(false);
- if (ws.latex() && ws.textMode()) {
- ws << "\\ensuremath{";
- ws.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(ws);
if (ws.fragile())
ws << "\\protect";
ws << "\\begin{" << name_ << '}';
void InsetMathSqrt::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << "\\sqrt{" << cell(0) << '}';
os.pendingBrace(brace);
}
void InsetMathStackrel::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << "\\stackrel{" << cell(0) << "}{" << cell(1) << '}';
os.pendingBrace(brace);
}
void InsetMathSubstack::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << "\\substack{";
InsetMathGrid::write(os);
os << "}\n";
void InsetMathSymbol::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << '\\' << name();
os.pendingBrace(brace);
void InsetMathUnderset::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << "\\underset{" << cell(0) << "}{" << cell(1) << '}';
os.pendingBrace(brace);
}
void InsetMathXArrow::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
-
+ bool brace = ensureMath(os);
os << '\\' << name_;
if (cell(1).size())
os << '[' << cell(1) << ']';
os << '{' << cell(0) << '}';
-
os.pendingBrace(brace);
}
void InsetMathXYArrow::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << "\\ar";
if (cell(0).size())
os << '[' << cell(0) << ']';
void InsetMathXYMatrix::write(WriteStream & os) const
{
- bool brace = os.pendingBrace();
- os.pendingBrace(false);
- if (os.latex() && os.textMode()) {
- os << "\\ensuremath{";
- os.textMode(false);
- brace = true;
- }
+ bool brace = ensureMath(os);
os << "\\xymatrix";
switch (spacing_code_) {
case 'R':