]> git.lyx.org Git - features.git/commitdiff
some support for TeX's \kern primitive in the parser.
authorAndré Pönitz <poenitz@gmx.net>
Tue, 21 Aug 2001 14:20:50 +0000 (14:20 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 21 Aug 2001 14:20:50 +0000 (14:20 +0000)
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

src/mathed/Makefile.am
src/mathed/math_cheatinset.C [deleted file]
src/mathed/math_cheatinset.h [deleted file]
src/mathed/math_factory.C
src/mathed/math_gridinset.C
src/mathed/math_hash.C
src/mathed/math_kerninset.C [new file with mode: 0644]
src/mathed/math_kerninset.h [new file with mode: 0644]
src/mathed/math_macrotable.C
src/mathed/math_parser.C
src/mathed/math_parser.h

index 61e5df60f5953ac8415402cce03940a2bb02625d..a0f324a8671b2cd2a062a95d4458bc415d433af8 100644 (file)
@@ -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 (file)
index f1b5da1..0000000
+++ /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 (file)
index 5569c5a..0000000
+++ /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
index 57ed1e1d97c7adf1cbea916a49fa0fb3c31e0092..342f1e50b7c0d92bdf90c20868dd95987d86b1bf 100644 (file)
@@ -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;
index 4f86b4be7af4a9491466791d56923f85bfd12642..ad0db48da83c522e2a14fe7b2bd8a143ddc54cd6 100644 (file)
@@ -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());
 }
index 65a59112dea4a3bbb895f77ffc50d39bb623d6d1..140231b76cd641abe824ecefd2ace21934ba76d2 100644 (file)
@@ -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 (file)
index 0000000..37e24e9
--- /dev/null
@@ -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<int>(wid_.value());
+}
diff --git a/src/mathed/math_kerninset.h b/src/mathed/math_kerninset.h
new file mode 100644 (file)
index 0000000..978dd10
--- /dev/null
@@ -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
index c7cc1a4819b6f1dfc49889e19dd30369ad6c95ef..854f99bd5c7f28e8dac5ba875638ae925622a80e 100644 (file)
@@ -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);
 }
index 40f0824c22dee359ac6902c80e8f6bc40ebb9cf6..5d2a69c2484c385b53f79f72bd38c15ed41b0870 100644 (file)
@@ -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);
index f1ad6a87b539fe10a7294acc43e216ee3890b8ae..469a97f29017a1ac70fc9ef15f133703784aabe1 100644 (file)
@@ -105,6 +105,8 @@ enum MathTokenEnum
        ///
        LM_TK_NOT,
        ///
+       LM_TK_KERN,
+       ///
        LM_TK_STACK
 };