mathed65.diff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1954 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-04-25 15:43:57 +00:00
parent 598981975c
commit 47b341b996
35 changed files with 395 additions and 214 deletions

View File

@ -322,6 +322,7 @@ void LyXAction::init()
{ LFUN_MATH_MODE, "math-mode", N_("Math mode"), Noop },
{ LFUN_MATH_NONUMBER, "math-nonumber", "", Noop },
{ LFUN_MATH_NUMBER, "math-number", "", Noop },
{ LFUN_MATH_EXTERN, "math-extern", "", Noop },
{ LFUN_MATH_PANEL, "math-panel", "", Noop },
{ LFUN_MATH_SIZE, "math-size", "", Noop },
#if 0

View File

@ -141,6 +141,7 @@ enum kb_action {
LFUN_MATH_SIZE, // Alejandro 150896
LFUN_MATH_MACRO, // ale970510
LFUN_MATH_MACROARG, // ale970510 // 120
LFUN_MATH_EXTERN, // Andre' 20010424
LFUN_MATH_PANEL,
LFUN_FIGURE,
#if 0

View File

@ -282,8 +282,10 @@ static char const ** pixmapFromBitmapData(char const * s, int wx, int hx)
char const ** get_pixmap_from_symbol(char const * arg, int wx, int hx)
{
lyx::Assert(arg);
char const ** data = 0;
latexkeys const * l = in_word_set (arg, strlen(arg));
latexkeys const * l = in_word_set(arg);
if (!l)
return 0;

View File

@ -1374,11 +1374,11 @@ string const LyXFunc::Dispatch(int ac,
}
break;
case LFUN_MATH_EXTERN:
case LFUN_MATH_NUMBER:
case LFUN_MATH_LIMITS:
{
setErrorMessage(N_("This is only allowed in math mode!"));
}
break;

View File

@ -14,6 +14,7 @@
*/
#include <config.h>
#include <fstream>
#include "Lsstream.h"
@ -33,10 +34,11 @@
#include "debug.h"
#include "lyx_gui_misc.h"
#include "support/LOstream.h"
#include "support/lyxlib.h"
#include "support/syscall.h"
#include "LyXView.h"
#include "Painter.h"
#include "font.h"
#include "support/lyxlib.h"
#include "lyxrc.h"
#include "math_inset.h"
#include "math_parinset.h"
@ -46,7 +48,9 @@
#include "math_deliminset.h"
#include "mathed/support.h"
using std::ostringstream;
using std::ostream;
using std::ifstream;
using std::istream;
using std::pair;
using std::endl;
@ -1007,7 +1011,7 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
ilf = lyx::atoi(lf);
else
if (lf[1]) {
l = in_word_set(lf, strlen(lf));
l = in_word_set(lf);
// Long words will cause l == 0; so check.
if (l)
ilf = l->id;
@ -1019,7 +1023,7 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
irg = lyx::atoi(rg);
else
if (rg[1]) {
l = in_word_set(rg, strlen(rg));
l = in_word_set(rg);
if (l)
irg = l->id;
} else if (vdelim.find(rg[0]) != string::npos)
@ -1126,6 +1130,10 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
bv->owner()->message(_("Invalid action in math mode!"));
break;
case LFUN_MATH_EXTERN:
HandleExtern(arg, bv);
break;
//------- dummy actions
#ifdef WITH_WARNINGS
#warning Is this needed here? Shouldnt the main dispatch handle this? (Lgb)
@ -1403,3 +1411,25 @@ bool math_insert_greek(BufferView * bv, char c)
}
return false;
}
void InsetFormula::HandleExtern(const string & arg, BufferView * bv)
{
//string outfile = lyx::tempName("maple.out");
string outfile = "/tmp/lyx2" + arg + ".out";
ostringstream os;
par->WriteNormal(os);
string code = os.str();
string script = "lyx2" + arg + " '" + code + "' " + outfile;
lyxerr << "calling: " << script << endl;
Systemcalls cmd(Systemcalls::System, script, 0);
ifstream is(outfile.c_str());
MathedArray ar;
mathed_parser_file(is, 0);
mathed_parse(ar, par, 0);
par->array = ar;
UpdateLocal(bv);
}

View File

@ -107,6 +107,8 @@ public:
bool SetNumber(bool);
///
std::vector<string> const getLabelList() const;
///
void HandleExtern(string const & arg, BufferView * bv);
protected:
///

View File

@ -114,3 +114,25 @@ void MathAccentInset::Write(ostream & os, bool fragile)
if (code!= LM_not)
os << '}';
}
void MathAccentInset::WriteNormal(ostream & os)
{
latexkeys const * l = lm_get_key_by_id(code, LM_TK_ACCENT);
os << "{accent " << l->name << " ";
if (inset) {
inset->WriteNormal(os);
} else {
if (fn>= LM_TC_RM && fn <= LM_TC_TEXTRM) {
os << "{font " << math_font_name[fn - LM_TC_RM] << "}";
}
if (MathIsSymbol(fn)) {
latexkeys const * l = lm_get_key_by_id(c, LM_TK_SYM);
if (l)
os << "{symbol " << l->name << "}";
} else
os << "{char " << char(c) << "}";
}
os << "} ";
}

View File

@ -22,6 +22,8 @@ public:
///
void Write(std::ostream &, bool fragile);
///
void WriteNormal(std::ostream &);
///
void Metrics();
///
int getAccentCode() const;

View File

@ -59,8 +59,24 @@ void MathBigopInset::Write(ostream & os, bool /* fragile */)
}
void
MathBigopInset::Metrics()
void MathBigopInset::WriteNormal(ostream & os)
{
bool const limp = GetLimits();
os << "{bigop " << name;
if (limp && !(sym_ != LM_int && sym_ != LM_oint
&& (GetStyle() == LM_ST_DISPLAY)))
os << " limits";
else
if (!limp && (sym_ != LM_int && sym_ != LM_oint
&& (GetStyle() == LM_ST_DISPLAY)))
os << " nolimits";
os << "} ";
}
void MathBigopInset::Metrics()
{
//char c;
string s;

View File

@ -17,6 +17,8 @@ public:
///
void Write(std::ostream &, bool fragile);
///
void WriteNormal(std::ostream &);
///
void Metrics();
///
bool GetLimits() const;

View File

@ -55,8 +55,7 @@ void MathDelimInset::Write(ostream & os, bool fragile)
}
void
MathDelimInset::draw(Painter & pain, int x, int y)
void MathDelimInset::draw(Painter & pain, int x, int y)
{
xo(x);
yo(y);
@ -78,8 +77,7 @@ MathDelimInset::draw(Painter & pain, int x, int y)
}
void
MathDelimInset::Metrics()
void MathDelimInset::Metrics()
{
MathParInset::Metrics();

View File

@ -21,32 +21,36 @@ MathedInset * MathDotsInset::Clone()
}
void
MathDotsInset::draw(Painter & pain, int x, int y)
void MathDotsInset::draw(Painter & pain, int x, int y)
{
mathed_draw_deco(pain, x + 2, y - dh_, width - 2, ascent, code_);
if (code_ == LM_vdots || code_ == LM_ddots) ++x;
if (code_ != LM_vdots) --y;
if (code_ == LM_vdots || code_ == LM_ddots)
++x;
if (code_ != LM_vdots)
--y;
mathed_draw_deco(pain, x + 2, y - dh_, width - 2, ascent, code_);
}
void
MathDotsInset::Metrics()
void MathDotsInset::Metrics()
{
mathed_char_height(LM_TC_VAR, size(), 'M', ascent, descent);
width = mathed_char_width(LM_TC_VAR, size(), 'M');
switch (code_) {
case LM_ldots: dh_ = 0; break;
case LM_cdots: dh_ = ascent/2; break;
case LM_vdots: width /= 2;
case LM_ddots: dh_ = ascent; break;
case LM_ldots: dh_ = 0; break;
case LM_cdots: dh_ = ascent/2; break;
case LM_vdots: width /= 2;
case LM_ddots: dh_ = ascent; break;
}
}
void
MathDotsInset::Write(ostream & os, bool /* fragile */)
void MathDotsInset::Write(ostream & os, bool /* fragile */)
{
os << '\\' << name << ' ';
}
void MathDotsInset::WriteNormal(ostream & os)
{
os << "{" << name << "} ";
}

View File

@ -21,6 +21,8 @@ public:
///
void Write(std::ostream &, bool fragile);
///
void WriteNormal(std::ostream &);
///
void Metrics();
protected:
///

View File

@ -41,6 +41,16 @@ bool MathFracInset::setArgumentIdx(int i)
return false;
}
int MathFracInset::getArgumentIdx() const
{
return idx_;
}
int MathFracInset::getMaxArgumentIdx() const
{
return 1;
}
void MathFracInset::SetStyle(short st)
{
@ -114,8 +124,7 @@ void MathFracInset::SetFocus(int /*x*/, int y)
}
void
MathFracInset::draw(Painter & pain, int x, int y)
void MathFracInset::draw(Painter & pain, int x, int y)
{
int const idxp = idx_;
int const sizex = size();
@ -132,8 +141,7 @@ MathFracInset::draw(Painter & pain, int x, int y)
}
void
MathFracInset::Metrics()
void MathFracInset::Metrics()
{
if (!dh_) {
int a;
@ -166,3 +174,12 @@ void MathFracInset::Write(ostream & os, bool fragile)
den_.Write(os, fragile);
os << '}';
}
void MathFracInset::WriteNormal(ostream & os)
{
os << '{' << name << ' ';
MathParInset::WriteNormal(os);
os << " ";
den_.WriteNormal(os);
os << "} ";
}

View File

@ -22,6 +22,8 @@ public:
///
void Write(std::ostream &, bool fragile);
///
void WriteNormal(std::ostream &);
///
void Metrics();
/** This does the same that SetData(MathedArray const &) but for both
@ -63,17 +65,4 @@ private:
int dh_;
};
inline
int MathFracInset::getArgumentIdx() const
{
return idx_;
}
inline
int MathFracInset::getMaxArgumentIdx() const
{
return 1;
}
#endif

View File

@ -47,6 +47,11 @@ void MathFuncInset::Write(std::ostream & os, bool /* fragile */)
os << "\\" << name << ' ';
}
void MathFuncInset::WriteNormal(std::ostream & os)
{
os << "{" << name << "} ";
}
void MathFuncInset::Metrics()
{

View File

@ -25,6 +25,8 @@ public:
///
void Write(std::ostream &, bool fragile);
///
void WriteNormal(std::ostream &);
///
void Metrics();
///
bool GetLimits() const;

View File

@ -1,44 +1,13 @@
/* C code produced by gperf version 2.5 (GNU C++ version) */
/* Command-line: gperf -a -p -o -t -G -D keywords */
#include <config.h>
#include <map>
#include "math_defs.h"
#include "math_parser.h"
#include "support/lstrings.h"
int const TOTAL_KEYWORDS = 269;
int const MIN_WORD_LENGTH = 2;
int const MAX_WORD_LENGTH = 18;
int const MIN_HASH_VALUE = 8;
int const MAX_HASH_VALUE = 490;
/* maximum key range = 483, duplicates = 40 */
namespace {
unsigned int
math_hash (register char const * str, register int len)
{
static unsigned short asso_values[] =
{
491, 491, 491, 491, 491, 491, 491, 491, 491, 491,
491, 491, 491, 491, 491, 491, 491, 491, 491, 491,
491, 491, 491, 491, 491, 491, 491, 491, 491, 491,
491, 491, 491, 491, 491, 491, 491, 491, 491, 491,
491, 491, 491, 491, 491, 491, 491, 491, 491, 491,
491, 491, 491, 491, 491, 491, 491, 491, 491, 491,
491, 491, 491, 491, 491, 491, 491, 491, 95, 491,
491, 45, 491, 10, 491, 491, 255, 491, 491, 65,
30, 491, 0, 70, 80, 70, 15, 491, 10, 491,
491, 491, 491, 491, 491, 491, 491, 50, 200, 140,
219, 35, 135, 237, 230, 69, 0, 20, 10, 180,
105, 247, 55, 208, 125, 0, 25, 42, 255, 75,
5, 0, 0, 491, 491, 491, 491, 491,
};
return len + asso_values[str[len - 1]] + asso_values[str[0]];
}
latexkeys const wordlist[] =
{
{"",0,0}, {"",0,0}, {"",0,0}, {"",0,0},
@ -315,104 +284,54 @@ latexkeys const wordlist[] =
};
short lookup[] =
{
-1, -1, -1, -1, -1, -1, -1, -1, 8, -1, -1, -1, -1, -1,
-1, 9, 10, -1, 11, -1, -1, -1, 12, -1, -1, 491, -13, -2,
-1, 15, 16, 491, -17, -2, 19, -1, -1, 20, -1, 21, 22, 23,
-1, -1, 24, -1, 25, 26, 27, -1, -1, 28, 29, -1, 30, 31,
32, -1, 33, -1, 635, 37, 38, 39, -1, 40, 41, -1, 617, 44,
45, 46, 47, 48, 49, 50, 51, -1, 52, -1, 53, 54, 588, 57,
-1, 58, 59, 60, 61, -1, 491, -62, -2, 64, 65, 66, -1, 67,
68, 565, 71, 72, 499, 75, -1, 76, -1, 77, 78, -1, 79, -73,
-2, 80, 81, 82, -1, 83, -1, 84, 85, -1, 86, 87, 88, 89,
90, 501, 93, 94, 95, -1, 96, 493, -1, 99, -97, -2, -91, -2,
100, 101, 102, 517, 105, 106, -1, 107, 108, 109, 110, 497, 113, -1,
114, 115, 116, 117,-111, -2, 118, 491,-119, -2, 121, 122, 123, -1,
124, 125,-103, -2, -1, 126, -69, -2, 491,-127, -2, 129, -55, -2,
130, 491,-131, -2, 133, 492, 136,-134, -2, -1, 137, 138, 139, -42,
-2, 140, 495, 143, 144, -1, 145,-141, -2, -34, -3, 146, 613, 149,
150, 605, 154, 155, 156, 157, 503, -1, 491,-160, -2, 162, -1, 163,
491,-164, -2, -1, 166,-158, -2, 167, 168, -1, 169, 170, -1, 577,
173, -1, 174, 554, -1, 177, -1, 178, 179, 543, 182, 183, 184, -1,
185, 509, 188, 189, 190, 191, 192, 193, 194, 499, -1, 197, 198, -1,
199, 200, 201, 202,-195, -2,-186, -2, 203, -1, 500, 206, 492, 209,
-207, -2, -1, 210, 211, 212,-204, -2, 213, -1, 498, 216, 494, 219,
-1, 220,-217, -2,-214, -2,-180, -2, 221, 222, 223,-175, -2, -1,
224, -1, 225, 226, -1, 491,-227, -2, 229, -1, 230, 231, 232, 491,
-233, -2,-171, -2,-151, -3, 235, 236, 237,-147, -2, -1, 238, 239,
240, -1, -1, 241, -1, -1, -1, 242, 498, 245, -1, 246, 247, -1,
248, 249,-243, -2, -1, -1, -1, -1, -1, 250, -1, -1, -1, -1,
-1, 251, 252, -1, -1, -1, 253, -1, -1, -1, 492, 256,-254, -2,
-1, -1, -1, 257, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 258, -1, -1, -1, 491,-259, -2, -1,
-1, -1, -1, -1, -1, -1, -1, 261, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 262, -1, -1, -1, -1, -1, -1, -1, 263, 492, 266,
-264, -2, -1, -1, -1, 267, -1, -1, -1, -1, -1, 268, -1, -1,
269, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 491,-270, -2,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
272, 273, -1, 274, -1, -1, -1, 275, -1, -1, -1, -1, -1, -1,
276,
struct symbolindex {
int id;
short token;
symbolindex(int i, short t) : id(i), token(t)
{}
bool operator<(symbolindex const & s) const
{
return (id < s.id) || (id == s.id && token < s.token);
}
};
// global maps
std::map<symbolindex, int> LatexkeyById;
std::map<string, int> LatexkeyByName;
// helper structure to initialize the maps on startup:
struct init {
init() {
int const n = sizeof(wordlist)/sizeof(wordlist[0]);
for (latexkeys const * it = wordlist; it != wordlist + n; ++it) {
LatexkeyByName[it->name] = it - wordlist;
LatexkeyById[symbolindex(it->id, it->token)] = it - wordlist;
}
}
};
// the "Initializer": Its default constructor is executed on loading and
// fills the maps
static init dummy;
} // namespace anon
latexkeys const *
in_word_set (register char const * str, register int len)
latexkeys const * in_word_set(string const & str)
{
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) {
int const key = math_hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0) {
int const idx = lookup[key];
if (idx >= 0 && idx < MAX_HASH_VALUE) {
char const * s = wordlist[idx].name;
if (*s == *str && !compare(str + 1, s + 1))
return &wordlist[idx];
} else if (idx < 0 && idx >= -MAX_HASH_VALUE) {
return 0;
} else {
int const offset = key + idx + (idx > 0 ? -MAX_HASH_VALUE : MAX_HASH_VALUE);
latexkeys const * base = &wordlist[-lookup[offset]];
latexkeys const * ptr = base + -lookup[offset + 1];
while (--ptr >= base)
if (*str == *ptr->name
&& !compare(str + 1,
ptr->name + 1))
return ptr;
}
}
}
return 0;
std::map<string, int>::const_iterator pos = LatexkeyByName.find(str);
return pos == LatexkeyByName.end() ? 0 : &wordlist[pos->second];
}
latexkeys const * in_word_set(string const & str)
latexkeys const * lm_get_key_by_id(int id, short tc)
{
return in_word_set(str.c_str(), str.length());
}
latexkeys const * lm_get_key_by_id(int t, short tk)
{
latexkeys const * l = &wordlist[MIN_HASH_VALUE+TOTAL_KEYWORDS];
latexkeys const * base = &wordlist[MIN_HASH_VALUE];
while (--l >= base) {
if (t == l->id && tk == l->token)
return l;
}
return 0;
}
latexkeys const * lm_get_key_by_index(int i)
{
if (i > 0 && i < TOTAL_KEYWORDS + 2)
return &wordlist[i];
else
return 0;
std::map<symbolindex, int>::const_iterator pos
= LatexkeyById.find(symbolindex(id, tc));
return pos == LatexkeyById.end() ? 0 : &wordlist[pos->second];
}

View File

@ -49,6 +49,8 @@ public:
virtual void draw(Painter &, int x, int baseline) = 0;
/// Write LaTeX and Lyx code
virtual void Write(std::ostream &, bool fragile) = 0;
/// Write normalized content
virtual void WriteNormal(std::ostream &) = 0;
/// Reproduces itself
virtual MathedInset * Clone() = 0;
/// Reproduces itself with macro arguments substituted

View File

@ -48,7 +48,7 @@ MathMacro::MathMacro(MathMacroTemplate const & t)
: MathParInset(LM_ST_TEXT, t.GetName(), LM_OT_MACRO),
tmplate_(const_cast<MathMacroTemplate *>(&t)),
args_(t.nargs()),
idx_(-1)
idx_(t.nargs() ? 0 : -1)
{
array = tmplate_->GetData();
for (int i = 0; i < nargs(); ++i)
@ -77,10 +77,10 @@ MathParInset const * MathMacro::arg(int i) const
lyx::Assert(0);
return 0;
}
return i >= 0 ? args_[i].get() : static_cast<MathParInset const *>(this);
}
MathParInset * MathMacro::arg(int i)
{
if (i < 0 || i >= nargs()) {
@ -88,7 +88,6 @@ MathParInset * MathMacro::arg(int i)
lyx::Assert(0);
return 0;
}
return i >= 0 ? args_[i].get() : static_cast<MathParInset *>(this);
}
@ -101,12 +100,9 @@ MathMacroTemplate * MathMacro::tmplate() const
extern bool is_mathcursor_inside(MathParInset *);
void MathMacro::Metrics()
{
if (is_mathcursor_inside(this)) {
tmplate_->Metrics();
width = tmplate_->Width() + 4;
ascent = tmplate_->Ascent() + 2;
@ -124,10 +120,9 @@ void MathMacro::Metrics()
} else {
expand();
expanded_->Metrics();
width = expanded_->Width() + 4;
ascent = expanded_->Ascent() + 2;
descent = expanded_->Descent() + 2;
width = expanded_->Width() + 6;
ascent = expanded_->Ascent() + 3;
descent = expanded_->Descent() + 3;
}
}
@ -144,25 +139,25 @@ void MathMacro::draw(Painter & pain, int x, int y)
p->draw(pain, x + 30, h);
char str[] = "#1:";
str[1] += i;
drawStr(pain, LM_TC_TEX, size(), x + 1, h, str);
drawStr(pain, LM_TC_TEX, size(), x + 3, h, str);
h -= p->Ascent() + 5;
}
h -= tmplate_->Descent();
int w = mathed_string_width(LM_TC_TEXTRM, size(), GetName());
drawStr(pain, LM_TC_TEXTRM, size(), x + 2, h, GetName());
drawStr(pain, LM_TC_TEXTRM, size(), x + 3, h, GetName());
tmplate_->draw(pain, x + w + 12, h);
col = LColor::red;
} else {
expanded_->draw(pain, x + 2, y - 1);
expanded_->draw(pain, x + 3, y);
col = LColor::black;
}
int w = Width();
int a = Ascent();
int h = Height();
pain.rectangle(x, y - a, w, h, col);
pain.rectangle(x + 1, y - a + 1, w - 2, h - 2, col);
}
@ -288,3 +283,12 @@ void MathMacro::Write(ostream & os, bool fragile)
if (nargs() == 0)
os << ' ';
}
void MathMacro::WriteNormal(ostream & os)
{
os << "{macro " << name << " ";
for (int i = 0; i < nargs(); ++i)
arg(i)->WriteNormal(os);
os << "} ";
}

View File

@ -47,6 +47,8 @@ public:
MathedInset * Clone();
///
void Write(std::ostream &, bool fragile);
///
void WriteNormal(std::ostream &);
/// Index 0 is the template, index 1..nargs() are the parameters
bool setArgumentIdx(int);
///

View File

@ -64,3 +64,8 @@ void MathMacroArgument::Write(std::ostream & os, bool /*fragile*/)
os << '#' << number_ << ' ';
}
void MathMacroArgument::WriteNormal(std::ostream & os)
{
os << "{macroarg " << number_ << "} ";
}

View File

@ -26,9 +26,10 @@ public:
///
void Write(std::ostream &, bool fragile);
///
void WriteNormal(std::ostream &);
///
int number() const;
private:
/// A number between 1 and 9
int number_;

View File

@ -88,6 +88,15 @@ void MathMacroTable::builtinMacros()
LM_TC_INSET);
}
// This macro doesn't have arguments
{
MathMacroTemplate & m = provideTemplate("silentmult", 0);
istringstream is("\\cdot\0");
mathed_parser_file(is, 0);
MathParInset * p = &m;
mathed_parse(m.array, p, 0);
}
// These two are only while we are still with LyX 2.x
{
MathMacroTemplate & m = provideTemplate("emptyset", 0);
@ -102,9 +111,25 @@ void MathMacroTable::builtinMacros()
iter.insert(LM_bot, LM_TC_BOP);
}
// binom has two arguments
{
MathMacroTemplate & m = provideTemplate("lint", 4);
istringstream is("\\int_{#1}^{#2}#3 d#4\0");
mathed_parser_file(is, 0);
MathParInset * p = &m;
mathed_parse(m.array, p, 0);
}
{
MathMacroTemplate & m = provideTemplate("binom", 2);
istringstream is("\\choose{#1}{#2}");
mathed_parser_file(is, 0);
MathParInset * p = &m;
mathed_parse(m.array, p, 0);
}
// binom has two arguments
{
MathMacroTemplate & m = provideTemplate("binom1", 2);
MathedIter iter(&m.GetData());
MathParInset * inset = new MathDelimInset('(', ')');

View File

@ -19,6 +19,7 @@ MathMacroTemplate::MathMacroTemplate() :
na_(0), users_()
{}
MathMacroTemplate::MathMacroTemplate(string const & nm, int na) :
MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
na_(na), users_()
@ -35,7 +36,7 @@ void MathMacroTemplate::WriteDef(ostream & os, bool fragile) const
{
os << "\n\\newcommand{\\" << name << "}";
if (na_ > 0 )
if (na_ > 0)
os << "[" << na_ << "]";
os << "{";
@ -64,3 +65,4 @@ void MathMacroTemplate::draw(Painter & pain, int x, int y)
int h = Height();
pain.rectangle(x, y - a, w, h, LColor::blue);
}

View File

@ -408,6 +408,110 @@ void MathParInset::Write(ostream & os, bool fragile)
}
void MathParInset::WriteNormal(ostream & os)
{
if (array.empty()) {
os << "{}";
return;
}
os << "{par ";
int brace = 0;
latexkeys const * l;
MathedIter data(&array);
// hack
MathedRowContainer::iterator crow = getRowSt().begin();
data.Reset();
if (!Permit(LMPF_FIXED_SIZE)) {
l = lm_get_key_by_id(size(), LM_TK_STY);
if (l)
os << l->name << ' ';
}
while (data.OK()) {
byte cx = data.GetChar();
if (cx >= ' ') {
string str = data.GetString();
if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
os << "{font " << math_font_name[data.fcode()-LM_TC_RM] << '{';
}
for (string::const_iterator s = str.begin();
s != str.end(); ++s) {
byte c = *s;
if (MathIsSymbol(data.fcode())) {
l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
LM_TK_BIGSYM : LM_TK_SYM);
if (l) {
os << '{' << l->name << '}';
} else {
#ifdef WITH_WARNINGS
#warning this does not compile on gcc 2.97
#endif
//lyxerr << "Illegal symbol code[" << c
// << " " << str.end() - s << " " << data.fcode() << "]";
}
} else {
// Is there a standard logical XOR?
if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
(data.fcode() == LM_TC_SPECIAL))
os << '{';
else {
if (c == '{')
++brace;
if (c == '}')
--brace;
}
if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
lyxerr <<"Math warning: Unexpected closing brace."
<< endl;
else
os << char(c);
}
}
if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
os << "} ";
} else {
if (MathIsInset(cx)) {
MathedInset * p = data.GetInset();
if (cx == LM_TC_UP)
os << "{superscript ";
if (cx == LM_TC_DOWN)
os << "{subscript ";
p->WriteNormal(os);
if (cx == LM_TC_UP || cx == LM_TC_DOWN)
os << "} ";
data.Next();
} else {
switch (cx) {
case LM_TC_TAB:
{
os << "} {";
data.Next();
break;
}
case LM_TC_CR:
{
os << "}} ";
data.Next();
break;
}
default:
lyxerr << "WMath Error: unrecognized code[" << cx << "]";
return;
}
}
}
}
if (brace > 0)
os << string(brace, '}');
os << "} ";
}
void MathParInset::clear()
{
array.clear();

View File

@ -30,6 +30,8 @@ public:
virtual void draw(Painter &, int x, int baseline);
/// Write LaTeX code
virtual void Write(std::ostream &, bool fragile);
/// Write normalized content
virtual void WriteNormal(std::ostream &);
///
virtual void Metrics();
///

View File

@ -318,7 +318,7 @@ int yylex(void)
if (yyis->good())
yyis->putback(c);
//lyxerr << "reading: '" << yytext.data() << "'\n";
latexkeys const * l = in_word_set (yytext.data(), strlen(yytext.data()));
latexkeys const * l = in_word_set(yytext.data());
if (l) {
if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) {
int i;
@ -447,7 +447,7 @@ void mathed_parse(MathedArray & array, MathParInset * & par, unsigned flags)
break;
}
}
MathedInsetTypes fractype = LM_OT_FRAC;
switch (t) {
case LM_TK_ALPHA:
@ -674,12 +674,11 @@ void mathed_parse(MathedArray & array, MathParInset * & par, unsigned flags)
break;
}
case LM_TK_CHOOSE:
case LM_TK_STACK:
fractype = LM_OT_STACKREL;
// fallthru
case LM_TK_FRAC:
{
MathFracInset fc(fractype);
MathFracInset fc(t);
MathedArray num;
mathed_parse(num, par, FLAG_BRACE|FLAG_BRACE_LAST);
MathedArray den;

View File

@ -46,6 +46,8 @@ enum MathTokenEnum
///
LM_TK_FRAC,
///
LM_TK_CHOOSE,
///
LM_TK_SQRT,
///
LM_TK_BEGIN,
@ -111,17 +113,10 @@ struct latexkeys {
};
///
latexkeys const *
in_word_set (register char const * str, register int len);
///
latexkeys const * in_word_set(string const & str);
///
latexkeys * lm_get_key(int index);
///
latexkeys const * lm_get_key_by_id(int id, short tc = LM_TK_SYM);
latexkeys const * lm_get_key_by_id(int id, short tc);
#endif

View File

@ -57,6 +57,18 @@ bool MathRootInset::setArgumentIdx(int i)
}
int MathRootInset::getArgumentIdx() const
{
return idx_;
}
int MathRootInset::getMaxArgumentIdx() const
{
return 1;
}
void MathRootInset::GetXY(int & x, int & y) const
{
if (idx_ == 1)
@ -141,3 +153,12 @@ void MathRootInset::Write(ostream & os, bool fragile)
MathParInset::Write(os, fragile);
os << '}';
}
void MathRootInset::WriteNormal(ostream & os)
{
os << "{root ";
uroot_.WriteNormal(os);
os << " ";
MathParInset::WriteNormal(os);
os << "} ";
}

View File

@ -38,6 +38,8 @@ public:
///
void Write(std::ostream &, bool fragile);
///
void WriteNormal(std::ostream &);
///
void Metrics();
///
bool Inside(int, int);
@ -70,18 +72,4 @@ private:
int dh_;
};
inline
int MathRootInset::getArgumentIdx() const
{
return idx_;
}
inline
int MathRootInset::getMaxArgumentIdx() const
{
return 1;
}
#endif

View File

@ -24,8 +24,7 @@ MathedInset * MathSpaceInset::Clone()
}
void
MathSpaceInset::draw(Painter & pain, int x, int y)
void MathSpaceInset::draw(Painter & pain, int x, int y)
{
// XPoint p[4] = {{++x, y-3}, {x, y}, {x+width-2, y}, {x+width-2, y-3}};
@ -44,20 +43,26 @@ MathSpaceInset::draw(Painter & pain, int x, int y)
}
void
MathSpaceInset::Write(ostream & os, bool /* fragile */)
void MathSpaceInset::Write(ostream & os, bool /* fragile */)
{
if (space_ >= 0 && space_ < 6) {
os << '\\' << latex_mathspace[space_] << ' ';
}
}
void MathSpaceInset::WriteNormal(ostream & os)
{
os << "{space " << space_ << "} ";
}
void MathSpaceInset::Metrics()
{
width = space_ ? space_ * 2 : 2;
if (space_ > 3) width *= 2;
if (space_ == 5) width *= 2;
if (space_ > 3)
width *= 2;
if (space_ == 5)
width *= 2;
width += 4;
ascent = 4;
descent = 0;

View File

@ -21,6 +21,8 @@ public:
///
void Write(std::ostream &, bool fragile);
///
void WriteNormal(std::ostream &);
///
void Metrics();
///
void SetSpace(int sp);

View File

@ -49,6 +49,14 @@ void MathSqrtInset::Write(ostream & os, bool fragile)
}
void MathSqrtInset::WriteNormal(ostream & os)
{
os << "{sqrt ";
MathParInset::WriteNormal(os);
os << "} ";
}
void MathSqrtInset::Metrics()
{
MathParInset::Metrics();

View File

@ -22,6 +22,8 @@ public:
///
void Write(std::ostream &, bool fragile);
///
void WriteNormal(std::ostream &);
///
void Metrics();
///
bool Inside(int, int);