> So where is the patch ? Oops... didn't I attach it? I'll try again. > I did try your previous patch, and I got the following error: > bad option "map": must be compare, first, index, last, length, match, range, >tolower, toupper, trim, trimleft, trimright, wordend, or wordstart > while executing > "string map { \{ \[ \} \] } $str" > (procedure "maplize" line 3) > invoked from within > "maplize $lyxish" > > (I have tcl 8.0). Oh... I have 8.3. Looks like a new feature than. I will try to rewrite this in order to make it work with 8.0. > > If you invoke 'math-extern something' (preferably by some keybinding) > > in a math inset, the inset will translate its contents into some > > "normalized" form, invoke 'lyx2something <normalform> <outfilename>', > > and replaces its contents with LaTeX read back from the file <outfilename>. > > Can you keep the old contents of the inset and put an equal sign between the > old contents and the result of the script ? That's what I tried first, but somehow the inset got messed up... I'll retry anyway. Andre' -- André Pönitz ............................................. [EMAIL PROTECTED]
Index: src/LyXAction.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LyXAction.C,v retrieving revision 1.77 diff -u -p -r1.77 LyXAction.C --- src/LyXAction.C 2001/04/17 13:54:24 1.77 +++ src/LyXAction.C 2001/04/25 10:11:47 @@ -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 Index: src/commandtags.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/commandtags.h,v retrieving revision 1.57 diff -u -p -r1.57 commandtags.h --- src/commandtags.h 2001/04/17 13:54:24 1.57 +++ src/commandtags.h 2001/04/25 10:11:47 @@ -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 Index: src/lyxfunc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v retrieving revision 1.206 diff -u -p -r1.206 lyxfunc.C --- src/lyxfunc.C 2001/04/24 15:25:20 1.206 +++ src/lyxfunc.C 2001/04/25 10:11:47 @@ -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; Index: src/frontends/xforms/MathsSymbols.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/MathsSymbols.C,v retrieving revision 1.2 diff -u -p -r1.2 MathsSymbols.C --- src/frontends/xforms/MathsSymbols.C 2001/03/19 15:38:22 1.2 +++ src/frontends/xforms/MathsSymbols.C 2001/04/25 10:11:47 @@ -283,7 +283,7 @@ static char const ** pixmapFromBitmapDat char const ** get_pixmap_from_symbol(char const * arg, int wx, int hx) { char const ** data = 0; - latexkeys const * l = in_word_set (arg, strlen(arg)); + latexkeys const * l = in_word_set(arg); if (!l) return 0; Index: src/mathed/formula.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formula.C,v retrieving revision 1.99 diff -u -p -r1.99 formula.C --- src/mathed/formula.C 2001/04/24 16:13:38 1.99 +++ src/mathed/formula.C 2001/04/25 10:11:47 @@ -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" @@ -47,7 +49,9 @@ #include "mathed/support.h" #include "lyxfunc.h" +using std::ostringstream; using std::ostream; +using std::ifstream; using std::istream; using std::pair; using std::endl; @@ -1008,7 +1012,7 @@ InsetFormula::LocalDispatch(BufferView * 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; @@ -1020,7 +1024,7 @@ InsetFormula::LocalDispatch(BufferView * 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) @@ -1130,6 +1134,10 @@ InsetFormula::LocalDispatch(BufferView * _("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) @@ -1404,3 +1412,25 @@ bool math_insert_greek(BufferView * bv, } 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); +} + + Index: src/mathed/formula.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formula.h,v retrieving revision 1.38 diff -u -p -r1.38 formula.h --- src/mathed/formula.h 2001/04/24 16:13:38 1.38 +++ src/mathed/formula.h 2001/04/25 10:11:47 @@ -107,6 +107,8 @@ public: bool SetNumber(bool); /// std::vector<string> const getLabelList() const; + /// + void HandleExtern(string const & arg, BufferView * bv); protected: /// Index: src/mathed/lyx2maple =================================================================== RCS file: lyx2maple diff -N lyx2maple --- /dev/null Tue May 5 22:32:27 1998 +++ lyx2maple Wed Apr 25 12:11:47 2001 @@ -0,0 +1,60 @@ +#!/usr/bin/tclsh + +set lyxish [lindex $::argv 0] +set outfile [lindex $::argv 1] + +puts "outfile: '$outfile'" +puts "lyxish: '$lyxish'" + +proc binder {vars dats} { + foreach var $vars dat $dats { + uplevel set $var [list $dat] + } +} + +proc macro_mint {arg} { + binder {from to what var} $arg + return "int($what,$var=$from..$to)" +} + +proc macro {name args} { + set cmd macro_$name + if {[llength [info commands $cmd]] == 1} { + return [$cmd $args] + } else { + return "$name\($args)" + } +} + + +proc sqrt {arg} { + return "sqrt($arg)" +} + +proc frac {num denom} { + return "(($num)/($denom))" +} + +proc root {arg radix} { + return "(($arg)^(1/($radix))" +} + +proc cdot {} { + return "*" +} + +proc par {args} { + set args +} + +proc maplize {str} { + set str [lindex $str 0] + set str [string map { \{ \[ \} \] } $str] + puts "maplizing: '$str'" + set str [eval $str] + puts "maplizing res: '$str'" + set str +} + +exec echo "latex([maplize $lyxish]); quit;" | maple -q > $outfile + Index: src/mathed/math_accentinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_accentinset.C,v retrieving revision 1.6 diff -u -p -r1.6 math_accentinset.C --- src/mathed/math_accentinset.C 2001/02/28 11:56:35 1.6 +++ src/mathed/math_accentinset.C 2001/04/25 10:11:47 @@ -114,3 +114,25 @@ void MathAccentInset::Write(ostream & os 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 << "} "; +} Index: src/mathed/math_accentinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_accentinset.h,v retrieving revision 1.3 diff -u -p -r1.3 math_accentinset.h --- src/mathed/math_accentinset.h 2001/02/28 11:56:35 1.3 +++ src/mathed/math_accentinset.h 2001/04/25 10:11:47 @@ -22,6 +22,8 @@ public: /// void Write(std::ostream &, bool fragile); /// + void WriteNormal(std::ostream &); + /// void Metrics(); /// int getAccentCode() const; Index: src/mathed/math_bigopinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_bigopinset.C,v retrieving revision 1.4 diff -u -p -r1.4 math_bigopinset.C --- src/mathed/math_bigopinset.C 2001/02/28 11:56:35 1.4 +++ src/mathed/math_bigopinset.C 2001/04/25 10:11:47 @@ -59,8 +59,24 @@ void MathBigopInset::Write(ostream & os, } -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; Index: src/mathed/math_bigopinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_bigopinset.h,v retrieving revision 1.4 diff -u -p -r1.4 math_bigopinset.h --- src/mathed/math_bigopinset.h 2001/02/28 11:56:35 1.4 +++ src/mathed/math_bigopinset.h 2001/04/25 10:11:47 @@ -17,6 +17,8 @@ public: /// void Write(std::ostream &, bool fragile); /// + void WriteNormal(std::ostream &); + /// void Metrics(); /// bool GetLimits() const; Index: src/mathed/math_deliminset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_deliminset.C,v retrieving revision 1.6 diff -u -p -r1.6 math_deliminset.C --- src/mathed/math_deliminset.C 2001/02/26 12:53:35 1.6 +++ src/mathed/math_deliminset.C 2001/04/25 10:11:47 @@ -55,8 +55,7 @@ void MathDelimInset::Write(ostream & os, } -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 } -void -MathDelimInset::Metrics() +void MathDelimInset::Metrics() { MathParInset::Metrics(); Index: src/mathed/math_dotsinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_dotsinset.C,v retrieving revision 1.5 diff -u -p -r1.5 math_dotsinset.C --- src/mathed/math_dotsinset.C 2001/02/28 11:56:35 1.5 +++ src/mathed/math_dotsinset.C 2001/04/25 10:11:47 @@ -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 << "} "; } Index: src/mathed/math_dotsinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_dotsinset.h,v retrieving revision 1.4 diff -u -p -r1.4 math_dotsinset.h --- src/mathed/math_dotsinset.h 2001/02/28 11:56:35 1.4 +++ src/mathed/math_dotsinset.h 2001/04/25 10:11:47 @@ -21,6 +21,8 @@ public: /// void Write(std::ostream &, bool fragile); /// + void WriteNormal(std::ostream &); + /// void Metrics(); protected: /// Index: src/mathed/math_fracinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_fracinset.C,v retrieving revision 1.10 diff -u -p -r1.10 math_fracinset.C --- src/mathed/math_fracinset.C 2001/02/28 17:21:16 1.10 +++ src/mathed/math_fracinset.C 2001/04/25 10:11:47 @@ -41,7 +41,17 @@ bool MathFracInset::setArgumentIdx(int i return false; } +int MathFracInset::getArgumentIdx() const +{ + return idx_; +} + +int MathFracInset::getMaxArgumentIdx() const +{ + return 1; +} + void MathFracInset::SetStyle(short st) { MathParInset::SetStyle(st); @@ -114,8 +124,7 @@ void MathFracInset::SetFocus(int /*x*/, } -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 } -void -MathFracInset::Metrics() +void MathFracInset::Metrics() { if (!dh_) { int a; @@ -165,4 +173,13 @@ void MathFracInset::Write(ostream & os, os << "}{"; den_.Write(os, fragile); os << '}'; +} + +void MathFracInset::WriteNormal(ostream & os) +{ + os << '{' << name << ' '; + MathParInset::WriteNormal(os); + os << " "; + den_.WriteNormal(os); + os << "} "; } Index: src/mathed/math_fracinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_fracinset.h,v retrieving revision 1.6 diff -u -p -r1.6 math_fracinset.h --- src/mathed/math_fracinset.h 2001/02/28 17:21:16 1.6 +++ src/mathed/math_fracinset.h 2001/04/25 10:11:47 @@ -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 Index: src/mathed/math_funcinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_funcinset.C,v retrieving revision 1.4 diff -u -p -r1.4 math_funcinset.C --- src/mathed/math_funcinset.C 2001/02/28 11:56:35 1.4 +++ src/mathed/math_funcinset.C 2001/04/25 10:11:47 @@ -47,6 +47,11 @@ void MathFuncInset::Write(std::ostream & os << "\\" << name << ' '; } +void MathFuncInset::WriteNormal(std::ostream & os) +{ + os << "{" << name << "} "; +} + void MathFuncInset::Metrics() { Index: src/mathed/math_funcinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_funcinset.h,v retrieving revision 1.4 diff -u -p -r1.4 math_funcinset.h --- src/mathed/math_funcinset.h 2001/02/28 11:56:35 1.4 +++ src/mathed/math_funcinset.h 2001/04/25 10:11:47 @@ -25,6 +25,8 @@ public: /// void Write(std::ostream &, bool fragile); /// + void WriteNormal(std::ostream &); + /// void Metrics(); /// bool GetLimits() const; Index: src/mathed/math_hash.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_hash.C,v retrieving revision 1.15 diff -u -p -r1.15 math_hash.C --- src/mathed/math_hash.C 2001/03/20 01:22:45 1.15 +++ src/mathed/math_hash.C 2001/04/25 10:11:47 @@ -1,44 +1,12 @@ -/* 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 +283,53 @@ 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); + } }; -} // namespace anon +// global maps +std::map<symbolindex, int> LatexkeyById; +std::map<string, int> LatexkeyByName; -latexkeys const * -in_word_set (register char const * str, register int len) -{ - 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; - } + +// 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; } } - return 0; -} +}; +// the "Initializer": Its default constructor is executed on loading and +// fills the maps +static init dummy; -latexkeys const * in_word_set(string const & str) -{ - return in_word_set(str.c_str(), str.length()); -} +} // namespace anon -latexkeys const * lm_get_key_by_id(int t, short tk) +latexkeys const * in_word_set(string const & str) { - 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; + std::map<string, int>::const_iterator pos = LatexkeyByName.find(str); + return pos == LatexkeyByName.end() ? 0 : &wordlist[pos->second]; } - - -latexkeys const * lm_get_key_by_index(int i) + +latexkeys const * lm_get_key_by_id(int id, short tc) { - 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]; } Index: src/mathed/math_inset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_inset.h,v retrieving revision 1.27 diff -u -p -r1.27 math_inset.h --- src/mathed/math_inset.h 2001/04/24 16:13:38 1.27 +++ src/mathed/math_inset.h 2001/04/25 10:11:47 @@ -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 Index: src/mathed/math_macro.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macro.C,v retrieving revision 1.52 diff -u -p -r1.52 math_macro.C --- src/mathed/math_macro.C 2001/04/24 16:13:38 1.52 +++ src/mathed/math_macro.C 2001/04/25 10:11:47 @@ -48,7 +48,7 @@ MathMacro::MathMacro(MathMacroTemplate c : 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 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() 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 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); } @@ -287,4 +282,13 @@ void MathMacro::Write(ostream & os, bool } if (nargs() == 0) os << ' '; +} + + +void MathMacro::WriteNormal(ostream & os) +{ + os << "{macro " << name << " "; + for (int i = 0; i < nargs(); ++i) + arg(i)->WriteNormal(os); + os << "} "; } Index: src/mathed/math_macro.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macro.h,v retrieving revision 1.39 diff -u -p -r1.39 math_macro.h --- src/mathed/math_macro.h 2001/04/24 16:13:38 1.39 +++ src/mathed/math_macro.h 2001/04/25 10:11:47 @@ -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); /// Index: src/mathed/math_macroarg.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macroarg.C,v retrieving revision 1.6 diff -u -p -r1.6 math_macroarg.C --- src/mathed/math_macroarg.C 2001/04/24 16:13:38 1.6 +++ src/mathed/math_macroarg.C 2001/04/25 10:11:47 @@ -64,3 +64,8 @@ void MathMacroArgument::Write(std::ostre os << '#' << number_ << ' '; } + +void MathMacroArgument::WriteNormal(std::ostream & os) +{ + os << "{macroarg " << number_ << "} "; +} Index: src/mathed/math_macroarg.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macroarg.h,v retrieving revision 1.7 diff -u -p -r1.7 math_macroarg.h --- src/mathed/math_macroarg.h 2001/04/24 16:13:38 1.7 +++ src/mathed/math_macroarg.h 2001/04/25 10:11:47 @@ -26,8 +26,9 @@ public: /// void Write(std::ostream &, bool fragile); /// + void WriteNormal(std::ostream &); + /// int number() const; - private: /// A number between 1 and 9 Index: src/mathed/math_macrotable.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macrotable.C,v retrieving revision 1.10 diff -u -p -r1.10 math_macrotable.C --- src/mathed/math_macrotable.C 2001/04/24 16:13:38 1.10 +++ src/mathed/math_macrotable.C 2001/04/25 10:11:47 @@ -85,6 +85,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); @@ -99,9 +108,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('(', ')'); Index: src/mathed/math_macrotemplate.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_macrotemplate.C,v retrieving revision 1.15 diff -u -p -r1.15 math_macrotemplate.C --- src/mathed/math_macrotemplate.C 2001/04/24 16:13:38 1.15 +++ src/mathed/math_macrotemplate.C 2001/04/25 10:11:47 @@ -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 << "\n\\newcommand{\\" << name << "}"; - if (na_ > 0 ) + if (na_ > 0) os << "[" << na_ << "]"; os << "{"; @@ -64,3 +65,4 @@ void MathMacroTemplate::draw(Painter & p int h = Height(); pain.rectangle(x, y - a, w, h, LColor::blue); } + Index: src/mathed/math_parinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parinset.C,v retrieving revision 1.17 diff -u -p -r1.17 math_parinset.C --- src/mathed/math_parinset.C 2001/04/24 16:13:38 1.17 +++ src/mathed/math_parinset.C 2001/04/25 10:11:47 @@ -408,6 +408,110 @@ void MathParInset::Write(ostream & os, b } +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(); Index: src/mathed/math_parinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parinset.h,v retrieving revision 1.14 diff -u -p -r1.14 math_parinset.h --- src/mathed/math_parinset.h 2001/04/24 16:13:38 1.14 +++ src/mathed/math_parinset.h 2001/04/25 10:11:47 @@ -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(); /// Index: src/mathed/math_parser.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parser.C,v retrieving revision 1.49 diff -u -p -r1.49 math_parser.C --- src/mathed/math_parser.C 2001/04/24 16:13:38 1.49 +++ src/mathed/math_parser.C 2001/04/25 10:11:47 @@ -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, M break; } } - MathedInsetTypes fractype = LM_OT_FRAC; + switch (t) { case LM_TK_ALPHA: @@ -674,12 +674,11 @@ void mathed_parse(MathedArray & array, M 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; Index: src/mathed/math_parser.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parser.h,v retrieving revision 1.9 diff -u -p -r1.9 math_parser.h --- src/mathed/math_parser.h 2001/02/16 09:25:43 1.9 +++ src/mathed/math_parser.h 2001/04/25 10:11:47 @@ -46,6 +46,8 @@ enum MathTokenEnum /// LM_TK_FRAC, /// + LM_TK_CHOOSE, + /// LM_TK_SQRT, /// LM_TK_BEGIN, @@ -112,16 +114,9 @@ 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 Index: src/mathed/math_root.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_root.C,v retrieving revision 1.24 diff -u -p -r1.24 math_root.C --- src/mathed/math_root.C 2001/02/28 17:21:16 1.24 +++ src/mathed/math_root.C 2001/04/25 10:11:47 @@ -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) @@ -140,4 +152,13 @@ void MathRootInset::Write(ostream & os, os << "]{"; MathParInset::Write(os, fragile); os << '}'; +} + +void MathRootInset::WriteNormal(ostream & os) +{ + os << "{root "; + uroot_.WriteNormal(os); + os << " "; + MathParInset::WriteNormal(os); + os << "} "; } Index: src/mathed/math_root.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_root.h,v retrieving revision 1.27 diff -u -p -r1.27 math_root.h --- src/mathed/math_root.h 2001/02/28 17:21:16 1.27 +++ src/mathed/math_root.h 2001/04/25 10:11:47 @@ -38,6 +38,8 @@ public: /// void Write(std::ostream &, bool fragile); /// + void WriteNormal(std::ostream &); + /// void Metrics(); /// bool Inside(int, int); @@ -69,19 +71,5 @@ private: /// int dh_; }; - - -inline -int MathRootInset::getArgumentIdx() const -{ - return idx_; -} - - -inline -int MathRootInset::getMaxArgumentIdx() const -{ - return 1; -} #endif Index: src/mathed/math_spaceinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_spaceinset.C,v retrieving revision 1.4 diff -u -p -r1.4 math_spaceinset.C --- src/mathed/math_spaceinset.C 2001/02/28 11:56:36 1.4 +++ src/mathed/math_spaceinset.C 2001/04/25 10:11:47 @@ -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 } -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; Index: src/mathed/math_spaceinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_spaceinset.h,v retrieving revision 1.4 diff -u -p -r1.4 math_spaceinset.h --- src/mathed/math_spaceinset.h 2001/02/28 11:56:36 1.4 +++ src/mathed/math_spaceinset.h 2001/04/25 10:11:47 @@ -21,6 +21,8 @@ public: /// void Write(std::ostream &, bool fragile); /// + void WriteNormal(std::ostream &); + /// void Metrics(); /// void SetSpace(int sp); Index: src/mathed/math_sqrtinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_sqrtinset.C,v retrieving revision 1.8 diff -u -p -r1.8 math_sqrtinset.C --- src/mathed/math_sqrtinset.C 2001/04/24 16:13:38 1.8 +++ src/mathed/math_sqrtinset.C 2001/04/25 10:11:47 @@ -49,6 +49,14 @@ void MathSqrtInset::Write(ostream & os, } +void MathSqrtInset::WriteNormal(ostream & os) +{ + os << "{sqrt "; + MathParInset::WriteNormal(os); + os << "} "; +} + + void MathSqrtInset::Metrics() { MathParInset::Metrics(); Index: src/mathed/math_sqrtinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_sqrtinset.h,v retrieving revision 1.3 diff -u -p -r1.3 math_sqrtinset.h --- src/mathed/math_sqrtinset.h 2001/02/26 12:53:35 1.3 +++ src/mathed/math_sqrtinset.h 2001/04/25 10:11:47 @@ -22,6 +22,8 @@ public: /// void Write(std::ostream &, bool fragile); /// + void WriteNormal(std::ostream &); + /// void Metrics(); /// bool Inside(int, int);