math_sizeinset.h \
math_spaceinset.C \
math_spaceinset.h \
+ math_specialcharinset.C \
+ math_specialcharinset.h \
math_sqrtinset.C \
math_sqrtinset.h \
math_stackrelinset.C \
MathCharInset::MathCharInset(char c)
- : char_(c), code_(nativeCode(c)), needbs_(false)
+ : char_(c), code_(nativeCode(c))
{
//lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
}
MathCharInset::MathCharInset(char c, MathTextCodes t)
- : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t), needbs_(false)
-{
-//lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
-}
-
-
-MathCharInset::MathCharInset(char c, MathTextCodes t, bool needbs)
- : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t), needbs_(needbs)
+ : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
{
//lyxerr << "creating char '" << char_ << "' with code " << int(code_) << endl;
}
{
if (isalpha(c))
return LM_TC_VAR;
- if (strchr("#$%{|}", c))
- return LM_TC_SPECIAL;
//if (strchr("0123456789;:!|[]().,?+/-*<>=", c)
return LM_TC_CONST;
}
void MathCharInset::writeRaw(std::ostream & os) const
{
- if (needbs_)
- os << "\\";
os << char_;
}
void MathCharInset::writeNormal(std::ostream & os) const
{
- if (needbs_)
- os << "\\";
os << char_;
}
///
MathCharInset(char c, MathTextCodes t);
///
- MathCharInset(char c, MathTextCodes t, bool needbs);
- ///
MathInset * clone() const;
///
MathTextCodes nativeCode(char c) const;
char char_;
/// the font to be used on screen
MathTextCodes code_;
- /// do wee need a backslash when writing LaTeX?
- bool needbs_;
};
#endif
#include "math_matrixinset.h"
#include "math_scriptinset.h"
#include "math_spaceinset.h"
+#include "math_specialcharinset.h"
#include "math_parser.h"
using std::endl;
return;
}
+ if (lastcode_ != LM_TC_TEX && strchr("#$%{|}", c)) {
+ insert(new MathSpecialCharInset(c));
+ return;
+ }
+
if (lastcode_ == LM_TC_TEX) {
if (macroName().empty()) {
insert(c, LM_TC_TEX);
return;
}
- if (c == '{' || c == '}') {
- niceInsert(new MathCharInset(c, LM_TC_SPECIAL));
- return;
- }
-
if (isalpha(c) && (lastcode_ == LM_TC_GREEK || lastcode_ == LM_TC_GREEK1)) {
static char const greek[26] =
{'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 ,
LM_TC_TEXTRM,
/// Math mode TeX characters ",;:{}"
LM_TC_TEX,
- /// Special characters "{}&#_%"
- LM_TC_SPECIAL,
/// Internal code when typing greek
LM_TC_GREEK,
/// Internal code when typing a single greek character
#include "math_notinset.h"
#include "math_rootinset.h"
#include "math_spaceinset.h"
+#include "math_specialcharinset.h"
#include "math_sqrtinset.h"
#include "math_symbolinset.h"
#include "math_stackrelinset.h"
return new MathBigopInset(l);
case LM_TK_FUNCLIM:
return new MathFuncLimInset(l);
+ case LM_TK_SPECIAL:
+ return new MathSpecialCharInset(l->id);
case LM_TK_SYM:
return new MathSymbolInset(l);
case LM_TK_STACK:
#include "math_rootinset.h"
#include "math_sqrtinset.h"
#include "math_scriptinset.h"
+#include "math_specialcharinset.h"
#include "math_sqrtinset.h"
#include "debug.h"
#include "support.h"
}
else if (t.cat() == catBegin) {
- array.push_back(new MathCharInset('{', LM_TC_SPECIAL));
+ array.push_back(new MathCharInset('{', LM_TC_TEX));
}
else if (t.cat() == catEnd) {
if (flags & FLAG_BRACE_LAST)
return;
- array.push_back(new MathCharInset('}', LM_TC_SPECIAL));
+ array.push_back(new MathCharInset('}', LM_TC_TEX));
}
else if (t.cat() == catAlign) {
lyxerr << "found tab unexpectedly, array: '" << array << "'\n";
- array.push_back(new MathCharInset('&', LM_TC_SPECIAL));
+ array.push_back(new MathCharInset('&', LM_TC_TEX));
}
else if (t.cat() == catSuper)
break;
else LM_TK_SPECIAL:
- array.push_back(new MathCharInset(ival_, LM_TC_SPECIAL));
+ array.push_back(new MathCharInset(ival_, LM_TC_TEX));
break;
*/
int pos;
for (pos = array.size() - 1; pos >= 0; --pos) {
MathInset * q = array.nextInset(pos);
- if (q->getChar() == '{' && q->code() == LM_TC_SPECIAL)
+ if (q->getChar() == '{')
break;
}
if (pos >= 0) {
--- /dev/null
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_specialcharinset.h"
+#include "support/LOstream.h"
+#include "support.h"
+
+
+MathSpecialCharInset::MathSpecialCharInset(char c)
+ : char_(c)
+{}
+
+
+MathInset * MathSpecialCharInset::clone() const
+{
+ return new MathSpecialCharInset(*this);
+}
+
+
+int MathSpecialCharInset::ascent() const
+{
+ return mathed_char_ascent(LM_TC_CONST, size(), char_);
+}
+
+
+int MathSpecialCharInset::descent() const
+{
+ return mathed_char_descent(LM_TC_CONST, size(), char_);
+}
+
+
+int MathSpecialCharInset::width() const
+{
+ return mathed_char_width(LM_TC_CONST, size(), char_);
+}
+
+
+void MathSpecialCharInset::metrics(MathStyles st) const
+{
+ size_ = st;
+}
+
+
+void MathSpecialCharInset::draw(Painter & pain, int x, int y) const
+{
+ xo(x);
+ yo(y);
+ drawChar(pain, LM_TC_CONST, size_, x, y, char_);
+}
+
+
+void MathSpecialCharInset::write(std::ostream & os, bool) const
+{
+ os << "\\" << char_;
+}
+
+
+void MathSpecialCharInset::writeNormal(std::ostream & os) const
+{
+ os << "\\" << char_;
+}
--- /dev/null
+// -*- C++ -*-
+#ifndef MATH_SPECIALCHARINSET_H
+#define MATH_SPECIALCHARINSET_H
+
+#include "math_inset.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+/** An inset for characters like {, #, and $ that need to be escaped
+ when written out, but can be inserted by a single keystroke
+ \author André Pönitz
+ */
+
+class MathSpecialCharInset : public MathInset {
+public:
+ ///
+ explicit MathSpecialCharInset(char c);
+ ///
+ MathInset * clone() const;
+ ///
+ void metrics(MathStyles st) const;
+ ///
+ void draw(Painter &, int x, int y) const;
+ ///
+ void write(std::ostream &, bool fragile) const;
+ ///
+ void writeNormal(std::ostream &) const;
+ ///
+ int ascent() const;
+ ///
+ int descent() const;
+ ///
+ int width() const;
+
+private:
+ /// the character
+ char char_;
+};
+#endif
f = Math_Fonts[5];
break;
- case LM_TC_SPECIAL: //f = Math_Fonts[0]; break;
case LM_TC_TEXTRM:
case LM_TC_CONST:
case LM_TC_TEX: