support for TeX's \choose

fix for return void


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2504 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-08-13 15:26:41 +00:00
parent 1e9b743bce
commit d586e9e856
10 changed files with 133 additions and 11 deletions

View File

@ -7,8 +7,10 @@
math_cursor.C:
math_hash.C: simplifications
* math_binom.[Ch]: new files for "native" \binom/\choose inset
* math_parser.C:
math_cursor.C: reading support for TeX style \over
math_cursor.C: reading support for TeX style \over and \choose
2001-08-10 André Pönitz <poenitz@gmx.net>

View File

@ -24,6 +24,8 @@ libmathed_la_SOURCES = \
math_arrayinset.h \
math_bigopinset.C \
math_bigopinset.h \
math_binominset.C \
math_binominset.h \
math_charinset.C \
math_charinset.h \
math_cursor.C \

View File

@ -0,0 +1,74 @@
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_binominset.h"
#include "math_parser.h"
#include "support.h"
#include "support/LOstream.h"
MathBinomInset::MathBinomInset()
{}
MathInset * MathBinomInset::clone() const
{
return new MathBinomInset(*this);
}
int MathBinomInset::dw() const
{
int w = height()/5;
if (w > 15)
w = 15;
if (w < 6)
w = 6;
return w;
}
void MathBinomInset::metrics(MathStyles st) const
{
size_ = smallerStyleFrac(st);
xcell(0).metrics(size_);
xcell(1).metrics(size_);
ascent_ = xcell(0).height() + 4 + 5;
descent_ = xcell(1).height() + 4 - 5;
width_ = std::max(xcell(0).width(), xcell(1).width()) + 2 * dw() + 4;
}
void MathBinomInset::draw(Painter & pain, int x, int y) const
{
xo(x);
yo(y);
int m = x + width() / 2;
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);
mathed_draw_deco(pain, x, y - ascent_,
dw(), height(), in_word_set("("));
mathed_draw_deco(pain, x + width() - dw(), y - ascent_,
dw(), height(), in_word_set(")"));
}
void MathBinomInset::write(std::ostream & os, bool fragile) const
{
os << '{';
cell(0).write(os, fragile);
os << " \\choose ";
cell(1).write(os, fragile);
os << '}';
}
void MathBinomInset::writeNormal(std::ostream & os) const
{
os << "[binom ";
cell(0).writeNormal(os);
os << " ";
cell(1).writeNormal(os);
os << "] ";
}

View File

@ -0,0 +1,33 @@
// -*- C++ -*-
#ifndef MATH_BINOMINSET_H
#define MATH_DINOMINSET_H
#include "math_fracbase.h"
#ifdef __GNUG__
#pragma interface
#endif
/** Binom like objects
\author André Pönitz
*/
class MathBinomInset : public MathFracbaseInset {
public:
///
MathBinomInset();
///
MathInset * clone() const;
///
void write(std::ostream &, bool fragile) const;
///
void writeNormal(std::ostream &) const;
///
void metrics(MathStyles st) const;
///
void draw(Painter &, int x, int y) const;
private:
///
int dw() const;
};
#endif

View File

@ -35,7 +35,6 @@
#include "math_charinset.h"
#include "math_decorationinset.h"
#include "math_deliminset.h"
#include "math_fracinset.h"
#include "math_funcinset.h"
#include "math_macro.h"
#include "math_macrotable.h"
@ -1283,9 +1282,9 @@ void MathCursor::interpret(string const & s)
return;
}
if (s == "\\over") {
if (s == "\\over" || s == "\\choose") {
MathArray ar = array();
MathFracInset * p = new MathFracInset;
MathInset * p = createMathInset(in_word_set(s.substr(1)));
p->cell(0).swap(array());
pos() = 0;
niceInsert(p);
@ -1305,8 +1304,10 @@ void MathCursor::interpret(string const & s)
return;
}
if (s.size() > 1)
return niceInsert(new MathFuncInset(s.substr(1)));
if (s.size() > 1) {
niceInsert(new MathFuncInset(s.substr(1)));
return;
}
// we got just a single char now

View File

@ -2,6 +2,7 @@
#include "math_parser.h"
#include "math_bigopinset.h"
#include "math_binominset.h"
#include "math_decorationinset.h"
#include "math_dotsinset.h"
#include "math_funcinset.h"
@ -31,6 +32,10 @@ MathInset * createMathInset(latexkeys const * l)
return new MathSymbolInset(l);
case LM_TK_STACK:
return new MathStackrelInset;
case LM_TK_BINOM:
case LM_TK_CHOOSE:
return new MathBinomInset;
case LM_TK_OVER:
case LM_TK_FRAC:
return new MathFracInset;
case LM_TK_SQRT:

View File

@ -83,6 +83,7 @@ latexkeys wordlist[] =
{"biguplus", LM_TK_NOGLYPHB, 0, LMB_NONE},
{"bigvee", LM_TK_NOGLYPHB, 0, LMB_NONE},
{"bigwedge", LM_TK_NOGLYPHB, 0, LMB_NONE},
{"binom", LM_TK_BINOM, 0, LMB_NONE},
{"bmod", LM_TK_FUNC, 0, LMB_NONE},
{"bot", LM_TK_SYM, LM_bot, LMB_NONE},
{"bowtie", LM_TK_NOGLYPH, 0, LMB_RELATION},
@ -94,6 +95,7 @@ latexkeys wordlist[] =
{"cdots", LM_TK_DOTS, LM_cdots, LMB_NONE},
{"check", LM_TK_DECORATION, LM_check, LMB_NONE},
{"chi", LM_TK_SYM, LM_chi, LMB_NONE},
{"choose", LM_TK_CHOOSE, 0, LMB_NONE},
{"circ", LM_TK_NOGLYPH, 0, LMB_OPERATOR},
{"clubsuit", LM_TK_SYM, LM_clubsuit, LMB_NONE},
{"cong", LM_TK_SYM, LM_cong, LMB_RELATION},

View File

@ -97,5 +97,5 @@ void MathMacroTable::builtinMacros()
createTemplate("to", 0, "\\rightarrow");
//createTemplate("lint", 4, "\\int_#1^#2#3 d#4");
//createTemplate("silentmult", 0, "\\cdot");
createTemplate("binom", 2, "\\left(\\frac#1#2\\right)");
//createTemplate("binom", 2, "\\left(\\frac#1#2\\right)");
}

View File

@ -30,7 +30,6 @@
#include "math_charinset.h"
#include "math_deliminset.h"
#include "math_factory.h"
#include "math_fracinset.h"
#include "math_funcinset.h"
#include "math_macro.h"
#include "math_macrotable.h"
@ -815,9 +814,11 @@ void Parser::parse_into(MathArray & array, unsigned flags)
curr_label_ = lexArg('{', true);
break;
case LM_TK_CHOOSE:
case LM_TK_OVER:
{
MathFracInset * p = new MathFracInset;
limits = 0;
MathInset * p = createMathInset(lval_);
p->cell(0).swap(array);
array.push_back(p);
parse_into(p->cell(1), FLAG_BLOCK);

View File

@ -45,10 +45,12 @@ enum MathTokenEnum
///
LM_TK_SYM,
///
LM_TK_OVER,
///
LM_TK_CHOOSE,
///
LM_TK_BINOM,
///
LM_TK_OVER,
///
LM_TK_FRAC,
///
LM_TK_SQRT,