]> git.lyx.org Git - lyx.git/commitdiff
try to suppress unneeded spaces when writing
authorAndré Pönitz <poenitz@gmx.net>
Thu, 22 Aug 2002 10:04:11 +0000 (10:04 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 22 Aug 2002 10:04:11 +0000 (10:04 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5069 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/math_inset.C
src/mathed/math_mathmlstream.C
src/mathed/math_mathmlstream.h
src/mathed/math_nestinset.C
src/mathed/math_parser.C
src/mathed/math_spaceinset.C
src/mathed/math_symbolinset.C

index b31246e9d7388f1fabb996e6e6e2cb1f972a70d4..40193c8f4a1b7d36d9fd4d196964fc56c61f96f7 100644 (file)
@@ -209,7 +209,8 @@ void MathInset::drawT(TextPainter &, int, int) const
 
 void MathInset::write(WriteStream & os) const
 {
 
 void MathInset::write(WriteStream & os) const
 {
-       os << '\\' << name().c_str() << ' ';
+       os << '\\' << name().c_str();
+       os.pendingSpace(true);
 }
 
 
 }
 
 
index 0d5bfc35a497852be961f41624d6a3dfae3ea387..5a1f6017d8d06e7e048a52de4b5dfc71c260e317 100644 (file)
@@ -11,6 +11,77 @@ using std::ostream;
 using std::strlen;
 
 
 using std::strlen;
 
 
+WriteStream::WriteStream(ostream & os, bool fragile, bool latex)
+       : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
+         pendingspace_(false), line_(0)
+{}
+
+
+WriteStream::WriteStream(ostream & os)
+       : os_(os), fragile_(false), firstitem_(false), latex_(false),
+         pendingspace_(false), line_(0)
+{}
+
+
+void WriteStream::addlines(unsigned int n)
+{
+       line_ += n;
+}
+
+
+WriteStream & operator<<(WriteStream & ws, MathAtom const & at)
+{
+       at->write(ws);
+       return ws;
+}
+
+
+WriteStream & operator<<(WriteStream & ws, MathArray const & ar)
+{
+       write(ar, ws);
+       return ws;
+}
+
+
+WriteStream & operator<<(WriteStream & ws, char const * s)
+{
+       ws.os() << s;
+       ws.addlines(int(lyx::count(s, s + strlen(s), '\n')));
+       return ws;
+}
+
+
+WriteStream & operator<<(WriteStream & ws, char c)
+{
+       if (ws.pendingSpace()) {
+               if (isalpha(c))
+                       ws.os() << ' ';
+               ws.pendingSpace(false);
+       }
+       ws.os() << c;
+       if (c == '\n')
+               ws.addlines(1);
+       return ws;
+}
+
+
+WriteStream & operator<<(WriteStream & ws, int i)
+{
+       ws.os() << i;
+       return ws;
+}
+
+
+WriteStream & operator<<(WriteStream & ws, unsigned int i)
+{
+       ws.os() << i;
+       return ws;
+}
+
+
+//////////////////////////////////////////////////////////////////////
+
+
 MathMLStream::MathMLStream(ostream & os)
        : os_(os), tab_(0), line_(0), lastchar_(0)
 {}
 MathMLStream::MathMLStream(ostream & os)
        : os_(os), tab_(0), line_(0), lastchar_(0)
 {}
@@ -228,63 +299,3 @@ NormalStream & operator<<(NormalStream & ns, int i)
 
 //////////////////////////////////////////////////////////////////////
 
 
 //////////////////////////////////////////////////////////////////////
 
-
-WriteStream::WriteStream(ostream & os, bool fragile, bool latex)
-       : os_(os), fragile_(fragile), latex_(latex), firstitem_(false), line_(0)
-{}
-
-
-WriteStream::WriteStream(ostream & os)
-       : os_(os), fragile_(false), latex_(false), firstitem_(false), line_(0)
-{}
-
-
-void WriteStream::addlines(unsigned int n)
-{
-       line_ += n;
-}
-
-
-WriteStream & operator<<(WriteStream & ws, MathAtom const & at)
-{
-       at->write(ws);
-       return ws;
-}
-
-
-WriteStream & operator<<(WriteStream & ws, MathArray const & ar)
-{
-       write(ar, ws);
-       return ws;
-}
-
-
-WriteStream & operator<<(WriteStream & ws, char const * s)
-{
-       ws.os() << s;
-       ws.addlines(int(lyx::count(s, s + strlen(s), '\n')));
-       return ws;
-}
-
-
-WriteStream & operator<<(WriteStream & ws, char c)
-{
-       ws.os() << c;
-       if (c == '\n')
-               ws.addlines(1);
-       return ws;
-}
-
-
-WriteStream & operator<<(WriteStream & ws, int i)
-{
-       ws.os() << i;
-       return ws;
-}
-
-
-WriteStream & operator<<(WriteStream & ws, unsigned int i)
-{
-       ws.os() << i;
-       return ws;
-}
index 0163b65a092aa0ddf6263c80718849e58fa87582..9f1ac9fed24646523888050a6b6349a8d51cedaa 100644 (file)
@@ -14,6 +14,61 @@ class MathArray;
 class MathInset;
 class MathAtom;
 
 class MathInset;
 class MathAtom;
 
+//
+// LaTeX/LyX
+//
+
+class WriteStream {
+public:
+       ///
+       WriteStream(std::ostream & os, bool fragile, bool latex);
+       ///
+       explicit WriteStream(std::ostream & os_);
+       ///
+       int line() const { return line_; }
+       ///
+       bool fragile() const { return fragile_; }
+       ///
+       bool latex() const { return latex_; }
+       ///
+       std::ostream & os() { return os_; }
+       ///
+       bool & firstitem() { return firstitem_; }
+       ///
+       void addlines(unsigned int);
+       /// writes space if next thing is isalpha()
+       void pendingSpace(bool how) { pendingspace_ = how; }
+       /// writes space if next thing is isalpha()
+       bool pendingSpace() const { return pendingspace_; }
+private:
+       ///
+       std::ostream & os_;
+       /// do we have to write \\protect sometimes
+       bool fragile_;
+       /// are we at the beginning of an MathArray?
+       bool firstitem_;
+       /// are we writing to .tex?
+       int latex_;
+       /// do we have a space pending?
+       bool pendingspace_;
+       ///
+       int line_;
+};
+
+///
+WriteStream & operator<<(WriteStream &, MathAtom const &);
+///
+WriteStream & operator<<(WriteStream &, MathArray const &);
+///
+WriteStream & operator<<(WriteStream &, char const *);
+///
+WriteStream & operator<<(WriteStream &, char);
+///
+WriteStream & operator<<(WriteStream &, int);
+///
+WriteStream & operator<<(WriteStream &, unsigned int);
+
+
 
 //
 //  MathML
 
 //
 //  MathML
@@ -189,52 +244,4 @@ OctaveStream & operator<<(OctaveStream &, int);
 
 
 
 
 
 
-//
-// LaTeX/LyX
-//
-
-class WriteStream {
-public:
-       ///
-       WriteStream(std::ostream & os, bool fragile, bool latex);
-       ///
-       explicit WriteStream(std::ostream & os_);
-       ///
-       int line() const { return line_; }
-       ///
-       bool fragile() const { return fragile_; }
-       ///
-       bool latex() const { return latex_; }
-       ///
-       std::ostream & os() { return os_; }
-       ///
-       bool & firstitem() { return firstitem_; }
-       ///
-       void addlines(unsigned int);
-private:
-       ///
-       std::ostream & os_;
-       ///
-       bool fragile_;
-       /// are we writing to .tex?
-       int latex_;
-       /// are we at the beginning of an MathArray?
-       bool firstitem_;
-       ///
-       int line_;
-};
-
-///
-WriteStream & operator<<(WriteStream &, MathAtom const &);
-///
-WriteStream & operator<<(WriteStream &, MathArray const &);
-///
-WriteStream & operator<<(WriteStream &, char const *);
-///
-WriteStream & operator<<(WriteStream &, char);
-///
-WriteStream & operator<<(WriteStream &, int);
-///
-WriteStream & operator<<(WriteStream &, unsigned int);
-
 #endif
 #endif
index c07486227617032cb4d6a5fb4f4aad899553b077..120462bfca9cfd22531f67f95bdcac068dc1f951 100644 (file)
@@ -293,10 +293,12 @@ void MathNestInset::write(WriteStream & os) const
        os << '\\' << name().c_str();
        for (unsigned i = 0; i < nargs(); ++i)
                os << '{' << cell(i) << '}';
        os << '\\' << name().c_str();
        for (unsigned i = 0; i < nargs(); ++i)
                os << '{' << cell(i) << '}';
-       if (lock_ && !os.latex())
-               os << "\\lyxlock ";
        if (nargs() == 0)
        if (nargs() == 0)
-               os << ' ';
+               os.pendingSpace(true);
+       if (lock_ && !os.latex()) {
+               os << "\\lyxlock";
+               os.pendingSpace(true);
+       }
 }
 
 
 }
 
 
index 36b279116822ce532967b89b9119fd5c3f855222..8eb6db23cb316cfa1f2fc4315bf3b2287a9464bc 100644 (file)
@@ -648,8 +648,10 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
                else if (t.cat() == catLetter)
                        cell->push_back(MathAtom(new MathCharInset(t.character())));
 
                else if (t.cat() == catLetter)
                        cell->push_back(MathAtom(new MathCharInset(t.character())));
 
-               else if (t.cat() == catSpace && mode != MathInset::MATH_MODE)
-                       cell->push_back(MathAtom(new MathCharInset(t.character())));
+               else if (t.cat() == catSpace && mode != MathInset::MATH_MODE) {
+                       if (cell->empty() || cell->back()->getChar() != ' ')
+                               cell->push_back(MathAtom(new MathCharInset(t.character())));
+               }
 
                else if (t.cat() == catNewline && mode != MathInset::MATH_MODE)
                        cell->push_back(MathAtom(new MathCharInset(t.character())));
 
                else if (t.cat() == catNewline && mode != MathInset::MATH_MODE)
                        cell->push_back(MathAtom(new MathCharInset(t.character())));
index 7f2461ba9467364b45ca7c1e5f605abb4c2f3c2c..3b4716b45434d79a7f358944145690f117199e20 100644 (file)
@@ -111,6 +111,8 @@ void MathSpaceInset::normalize(NormalStream & os) const
 
 void MathSpaceInset::write(WriteStream & os) const
 {
 
 void MathSpaceInset::write(WriteStream & os) const
 {
-       if (space_ >= 0 && space_ < nSpace)
-               os << '\\' << latex_mathspace[space_] << ' ';
+       if (space_ >= 0 && space_ < nSpace) {
+               os << '\\' << latex_mathspace[space_];
+               os.pendingSpace(true);
+       }
 }
 }
index 69d6f3c59381ac46ae4c1e461d0fb0a52e0d5406..65b36b8b8a7a78a5f441d252386f80c7b1414f35 100644 (file)
@@ -170,7 +170,8 @@ void MathSymbolInset::octavize(OctaveStream & os) const
 
 void MathSymbolInset::write(WriteStream & os) const
 {
 
 void MathSymbolInset::write(WriteStream & os) const
 {
-       os << '\\' << name() << ' ';
+       os << '\\' << name();
+       os.pendingSpace(true);
 }
 
 
 }