From: André Pönitz Date: Tue, 21 Aug 2001 14:20:50 +0000 (+0000) Subject: some support for TeX's \kern primitive in the parser. X-Git-Tag: 1.6.10~20776 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=50a865b664bafafea99d135e8032feb8f650eb8d;p=features.git some support for TeX's \kern primitive in the parser. use \kern instead of yesterday's home grown CheatInset git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2569 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 61e5df60f5..a0f324a867 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -26,8 +26,6 @@ libmathed_la_SOURCES = \ math_bigopinset.h \ math_binominset.C \ math_binominset.h \ - math_cheatinset.C \ - math_cheatinset.h \ math_charinset.C \ math_charinset.h \ math_cursor.C \ @@ -56,6 +54,8 @@ libmathed_la_SOURCES = \ math_hash.C \ math_inset.C \ math_inset.h \ + math_kerninset.C \ + math_kerninset.h \ math_macro.C \ math_macro.h \ math_macroarg.C \ diff --git a/src/mathed/math_cheatinset.C b/src/mathed/math_cheatinset.C deleted file mode 100644 index f1b5da1b31..0000000000 --- a/src/mathed/math_cheatinset.C +++ /dev/null @@ -1,39 +0,0 @@ -#ifdef __GNUG__ -#pragma implementation -#endif - -#include "math_cheatinset.h" -#include "support.h" -#include "support/LOstream.h" - - - -MathCheatInset::MathCheatInset(double w) - : wid_(w) -{} - - -MathInset * MathCheatInset::clone() const -{ - return new MathCheatInset(*this); -} - - -void MathCheatInset::draw(Painter &, int, int) const -{} - - -void MathCheatInset::write(std::ostream &, bool) const -{} - - -void MathCheatInset::writeNormal(std::ostream &) const -{} - - -void MathCheatInset::metrics(MathStyles st) const -{ - // mimic -.1em - mathed_char_dim(LM_TC_CONST, st, 'm', ascent_, descent_, width_); - width_ *= wid_; -} diff --git a/src/mathed/math_cheatinset.h b/src/mathed/math_cheatinset.h deleted file mode 100644 index 5569c5a958..0000000000 --- a/src/mathed/math_cheatinset.h +++ /dev/null @@ -1,31 +0,0 @@ -// -*- C++ -*- -#ifndef MATH_CHEATINSET_H -#define MATH_CHEATINSET_H - -#include "math_diminset.h" - -#ifdef __GNUG__ -#pragma interface -#endif - -/// Some cheating for displaying things like \ll etc - -class MathCheatInset : public MathDimInset { -public: - /// - explicit MathCheatInset(double wid); - /// - MathInset * clone() const; - /// - void draw(Painter &, int x, int y) const; - /// - void write(std::ostream &, bool fragile) const; - /// - void writeNormal(std::ostream &) const; - /// - void metrics(MathStyles st) const; -private: - /// width in em - double wid_; -}; -#endif diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index 57ed1e1d97..342f1e50b7 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -8,6 +8,7 @@ #include "math_funcinset.h" #include "math_funcliminset.h" #include "math_fracinset.h" +#include "math_kerninset.h" #include "math_macro.h" #include "math_macrotable.h" #include "math_noglyphinset.h" @@ -33,6 +34,8 @@ MathInset * createMathInset(latexkeys const * l) return new MathSymbolInset(l); case LM_TK_STACK: return new MathStackrelInset; + case LM_TK_KERN: + return new MathKernInset; case LM_TK_BINOM: case LM_TK_CHOOSE: return new MathBinomInset; diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 4f86b4be7a..ad0db48da8 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -27,7 +27,7 @@ MathGridInset::RowInfo::RowInfo() int MathGridInset::RowInfo::skipPixels() const { #ifdef WITH_WARNINGS -#warning fix this once the interface to LyXLength has oimproved +#warning fix this once the interface to LyXLength has improved #endif return int(skip_.value()); } diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C index 65a59112de..140231b76c 100644 --- a/src/mathed/math_hash.C +++ b/src/mathed/math_hash.C @@ -153,6 +153,7 @@ latexkeys wordlist[] = {"jmath", LM_TK_NOGLYPH, 0, LMB_NONE}, {"kappa", LM_TK_SYM, LM_kappa, LMB_NONE}, {"ker", LM_TK_FUNC, 0, LMB_NONE}, + {"kern", LM_TK_KERN, 0, LMB_NONE}, {"label", LM_TK_LABEL, 0, LMB_NONE}, {"lambda", LM_TK_SYM, LM_lambda, LMB_NONE}, {"langle", LM_TK_SYM, LM_langle, LMB_NONE}, diff --git a/src/mathed/math_kerninset.C b/src/mathed/math_kerninset.C new file mode 100644 index 0000000000..37e24e93a5 --- /dev/null +++ b/src/mathed/math_kerninset.C @@ -0,0 +1,54 @@ +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_kerninset.h" +#include "support.h" +#include "support/LOstream.h" + + +MathKernInset::MathKernInset() +{} + + +MathKernInset::MathKernInset(LyXLength const & w) + : wid_(w) +{} + + +MathKernInset::MathKernInset(string const & s) + : wid_(s) +{} + + +MathInset * MathKernInset::clone() const +{ + return new MathKernInset(*this); +} + + +void MathKernInset::draw(Painter &, int, int) const +{} + + +void MathKernInset::write(std::ostream & os, bool) const +{ + os << "\\kern" << wid_.asLatexString() << " "; +} + + +void MathKernInset::writeNormal(std::ostream & os) const +{ + os << "[kern " << wid_.asLatexString() << "]"; +} + + +void MathKernInset::metrics(MathStyles) const +{ + ascent_ = 0; + descent_ = 0; +#ifdef WITH_WARNINGS +#warning fix this once the interface to LyXLength has improved +#endif + width_ = static_cast(wid_.value()); +} diff --git a/src/mathed/math_kerninset.h b/src/mathed/math_kerninset.h new file mode 100644 index 0000000000..978dd10409 --- /dev/null +++ b/src/mathed/math_kerninset.h @@ -0,0 +1,37 @@ +// -*- C++ -*- +#ifndef MATH_CHEATINSET_H +#define MATH_CHEATINSET_H + +#include "math_diminset.h" +#include "vspace.h" +#include "LString.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/// The \kern primitive + +class MathKernInset : public MathDimInset { +public: + /// + MathKernInset(); + /// + explicit MathKernInset(LyXLength const & wid); + /// + explicit MathKernInset(string const & wid); + /// + MathInset * clone() const; + /// + void draw(Painter &, int x, int y) const; + /// + void write(std::ostream &, bool fragile) const; + /// + void writeNormal(std::ostream &) const; + /// + void metrics(MathStyles st) const; +private: + /// width in em + LyXLength wid_; +}; +#endif diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index c7cc1a4819..854f99bd5c 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -10,9 +10,6 @@ #include "math_macro.h" #include "math_macrotemplate.h" #include "math_parser.h" -#include "math_fracinset.h" -#include "math_cheatinset.h" -#include "math_charinset.h" #include "debug.h" @@ -99,19 +96,12 @@ void MathMacroTable::builtinMacros() createTemplate("perp", 0, "\\bot"); createTemplate("owns", 0, "\\ni"); createTemplate("to", 0, "\\rightarrow"); +#ifdef WITH_WARNINGS +#warning 9em looks like too much but it is somehow working on screen.. +#endif WITH_WARNINGS + createTemplate("ll", 0, "<\\kern-9em<"); + createTemplate("gg", 0, ">\\kern-9em>"); //createTemplate("lint", 4, "\\int_#1^#2#3 d#4"); //createTemplate("silentmult", 0, "\\cdot"); //createTemplate("binom", 2, "\\left(\\frac#1#2\\right)"); - - MathMacroTemplate ll("ll", 0); - ll.cell(0).push_back(new MathCharInset('<', LM_TC_CONST)); - ll.cell(0).push_back(new MathCheatInset(-0.9)); - ll.cell(0).push_back(new MathCharInset('<', LM_TC_CONST)); - insertTemplate(ll); - - MathMacroTemplate gg("gg", 0); - gg.cell(0).push_back(new MathCharInset('>', LM_TC_CONST)); - gg.cell(0).push_back(new MathCheatInset(-0.9)); - gg.cell(0).push_back(new MathCharInset('>', LM_TC_CONST)); - insertTemplate(gg); } diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 40f0824c22..5d2a69c248 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -31,6 +31,7 @@ #include "math_deliminset.h" #include "math_factory.h" #include "math_funcinset.h" +#include "math_kerninset.h" #include "math_macro.h" #include "math_macrotable.h" #include "math_macrotemplate.h" @@ -812,6 +813,24 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) lyxerr[Debug::MATHED] << "unknow math inset begin '" << name << "'\n"; } + else if (t.cs() == "kern") { +#ifdef WITH_WARNINGS +#warning A hack... +#endif + string s; + while (1) { + Token const & t = getToken(); + if (!good()) { + putback(); + break; + } + s += t.character(); + if (isValidLength(s)) + break; + } + array.push_back(new MathKernInset(s)); + } + else if (t.cs() == "label") { //MathArray ar; //parse_into(ar, FLAG_ITEM); diff --git a/src/mathed/math_parser.h b/src/mathed/math_parser.h index f1ad6a87b5..469a97f290 100644 --- a/src/mathed/math_parser.h +++ b/src/mathed/math_parser.h @@ -105,6 +105,8 @@ enum MathTokenEnum /// LM_TK_NOT, /// + LM_TK_KERN, + /// LM_TK_STACK };