]> git.lyx.org Git - lyx.git/commitdiff
Georg Baum's vspace change
authorAndré Pönitz <poenitz@gmx.net>
Wed, 10 Dec 2003 08:33:37 +0000 (08:33 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 10 Dec 2003 08:33:37 +0000 (08:33 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8219 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ChangeLog
lib/reLyX/syntax.default
src/mathed/math_cursor.C
src/tex2lyx/ChangeLog
src/tex2lyx/Makefile.am
src/tex2lyx/text.C

index bf7a8aac68fdfef80737ad9833423f0587fd8346..ffac647c0babf680fdf9969b16f6c3b22e98ca2e 100644 (file)
@@ -1,3 +1,7 @@
+2003-12-08  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * reLyX/syntax.default: add \psfrag and \psfrag*
+
 2003-12-08  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * CREDITS: add Ronald Florence
index 94aba3a1b3664959429b42f611ce9e782a58bc1d..41e238b9ae0656be44bea806be02cb0fa738dec8 100644 (file)
@@ -545,6 +545,8 @@ $$
 \providecommand{}[][]{}
 \providecommand*{}[][]{}
 \ps
+\psfrag{}[][][][]{translate}
+\psfrag*{}[][][][]{translate}
 \pushtabs
 % \put(,){}     %picture
 % \qbezier[](,)(,)(,)     %picture
index 118aefd0b47e98cb967e9fccdb9ecb98c4f2b3fc..2d3400a699c5ea23095d0320112874d657b13960 100644 (file)
@@ -436,8 +436,14 @@ bool MathCursor::backspace()
                }
        }
 
-       --pos();
-       plainErase();
+       if (hasPrevAtom() && prevAtom()->nargs() > 0) {
+               // let's require two backspaces for 'big stuff' and
+               // highlight on the first
+               left(true);
+       } else {
+               --pos();
+               plainErase();
+       }
        return true;
 }
 
index 4c3903e79eb96e4bf41e48ac4ef099061ac078bd..539481f9d854c8777b18ab0f8234dc03ecf0a381 100644 (file)
@@ -1,3 +1,9 @@
+2003-12-08  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+
+       * text.C: Use the new VSpace inset (fixes a bug with added_space top)
+       * text.C: Fix \= in tabbing env again
+       * text.C: Fix invocation of parse_command()
+
 2003-11-18  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
        * tex2lyx.C:
index 7b22fe5f49bbae3ff5eec195f01608d655c69169..f58491d10b0e63786b128bdc95a02c6edd954673 100644 (file)
@@ -18,6 +18,7 @@ BUILT_SOURCES = \
        FloatList.C \
        Floating.C \
        counters.C \
+       lengthcommon.C \
        lyxlayout.h \
        lyxlayout.C \
        lyxtextclass.C \
index ee65ecaa3f26ec3817bfd1b0f38df0c17e66f7be..57ccbd30c280d564b7abfb03078455a791348113 100644 (file)
@@ -16,6 +16,7 @@
 #include "tex2lyx.h"
 #include "context.h"
 #include "FloatList.h"
+#include "lengthcommon.h"
 #include "support/lstrings.h"
 #include "support/tostr.h"
 #include "support/filetools.h"
@@ -103,45 +104,80 @@ map<string, string> split_map(string const & s)
        return res;
 }
 
-// A simple function to translate a latex length to something lyx can
-// understand. Not perfect, but rather best-effort.
-string translate_len(string const & len)
+
+/*!
+ * Split a LaTeX length into value and unit.
+ * The latter can be a real unit like "pt", or a latex length variable
+ * like "\textwidth". The unit may contain additional stuff like glue
+ * lengths, but we don't care, because such lengths are ERT anyway.
+ * \return true if \param value and \param unit are valid.
+ */
+bool splitLatexLength(string const & len, string & value, string & unit)
 {
-       const string::size_type i = len.find_first_not_of(" -0123456789.,");
+       if (len.empty())
+               return false;
+       const string::size_type i = len.find_first_not_of(" -+0123456789.,");
        //'4,5' is a valid LaTeX length number. Change it to '4.5'
        string const length = lyx::support::subst(len, ',', '.');
-       // a normal length
-       if (i == string::npos || len[i]  != '\\')
-               return length;
-       double val;
+       if (i == string::npos)
+               return false;
        if (i == 0) {
-               // We had something like \textwidth without a factor
-               val = 100;
+               if (len[0] == '\\') {
+                       // We had something like \textwidth without a factor
+                       value = "1.0";
+               } else {
+                       return false;
+               }
        } else {
-               istringstream iss(string(length, 0, i));
-               iss >> val;
-               val = val * 100;
+               value = trim(string(length, 0, i));
        }
+       if (value == "-")
+               value = "-1.0";
+       // 'cM' is a valid LaTeX length unit. Change it to 'cm'
+       if (lyx::support::contains(len, '\\'))
+               unit = trim(string(len, i));
+       else
+               unit = lyx::support::lowercase(trim(string(len, i)));
+       return true;
+}
+
+
+// A simple function to translate a latex length to something lyx can
+// understand. Not perfect, but rather best-effort.
+string translate_len(string const & length)
+{
+       string unit;
+       string valstring;
+       // If the input is invalid, return what we have.
+       if (!splitLatexLength(length, valstring, unit))
+               return length;
+       // LyX uses percent values
+       double value;
+       istringstream iss(valstring);
+       iss >> value;
+       value *= 100;
        ostringstream oss;
-       oss << val;
-       string const valstring = oss.str();
-       const string::size_type i2 = length.find(" ", i);
-       string const unit = string(len, i, i2 - i);
-       string const endlen = (i2 == string::npos) ? string() : string(len, i2);
+       oss << value;
+       string const percentval = oss.str();
+       // a normal length
+       if (unit.empty() || unit[0] != '\\')
+               return valstring + unit;
+       const string::size_type i = unit.find(" ", i);
+       string const endlen = (i == string::npos) ? string() : string(unit, i);
        if (unit == "\\textwidth")
-               return valstring + "text%" + endlen;
+               return percentval + "text%" + endlen;
        else if (unit == "\\columnwidth")
-               return valstring + "col%" + endlen;
+               return percentval + "col%" + endlen;
        else if (unit == "\\paperwidth")
-               return valstring + "page%" + endlen;
+               return percentval + "page%" + endlen;
        else if (unit == "\\linewidth")
-               return valstring + "line%" + endlen;
+               return percentval + "line%" + endlen;
        else if (unit == "\\paperheight")
-               return valstring + "pheight%" + endlen;
+               return percentval + "pheight%" + endlen;
        else if (unit == "\\textheight")
-               return valstring + "theight%" + endlen;
+               return percentval + "theight%" + endlen;
        else
-               return length;
+               return valstring + unit;
 }
 
 
@@ -1151,8 +1187,11 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                // Problem: \= creates a tabstop inside the tabbing environment
                // and else an accent. In the latter case we really would want
                // \={o} instead of \= o.
+               else if (t.cs() == "=" && (flags & FLAG_TABBING))
+                       handle_ert(os, t.asInput(), context);
+
                else if (t.cs() == "H" || t.cs() == "c" || t.cs() == "^" || t.cs() == "'"
-                     || t.cs() == "~" || t.cs() == "." || (t.cs() == "=" && ! (flags & FLAG_TABBING))) {
+                     || t.cs() == "~" || t.cs() == "." || t.cs() == "=") {
                        // we need the trim as the LyX parser chokes on such spaces
                        context.check_layout(os);
                        os << "\n\\i \\" << t.cs() << "{"
@@ -1231,33 +1270,93 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        end_inset(os);
                }
 
-               else if ( t.cs() == "smallskip" ||
-                         t.cs() == "medskip" ||
-                         t.cs() == "bigskip" ||
-                         t.cs() == "vfill" ||
-                        (t.cs() == "vspace" && p.next_token().asInput() != "*")) {
-                       string arg;
-                       if (t.cs() == "vspace")
-                               arg = p.getArg('{', '}');
-                       else
-                               arg = t.cs();
-                       // We may only add the vspace to the current context if the
-                       // current paragraph is not empty.
-                       if (context.atParagraphStart()
-                           && (p.next_token().cat() != catNewline || p.next_token().cs().size() == 1)
-                           && (! (p.next_token().cat() == catEscape && p.next_token().cs() == "end"))
-                           && (! (p.next_token().cat() == catEscape && p.next_token().cs() == "par"))) {
-                               context.extra_stuff += "\\added_space_top " + arg + " ";
-                               p.skip_spaces();
+               else if (t.cs() == "smallskip" ||
+                        t.cs() == "medskip" ||
+                        t.cs() == "bigskip" ||
+                        t.cs() == "vfill") {
+                       context.check_layout(os);
+                       begin_inset(os, "VSpace ");
+                       os << t.cs();
+                       end_inset(os);
+               }
+
+               else if (t.cs() == "vspace") {
+                       bool starred = false;
+                       if (p.next_token().asInput() == "*") {
+                               p.get_token();
+                               starred = true;
+                       }
+                       string const length = p.verbatim_item();
+                       string unit;
+                       string valstring;
+                       bool valid = splitLatexLength(length, valstring, unit);
+                       bool known_vspace = false;
+                       bool known_unit = false;
+                       double value;
+                       if (valid) {
+                               istringstream iss(valstring);
+                               iss >> value;
+                               if (value == 1.0) {
+                                       if (unit == "\\smallskipamount") {
+                                               unit = "smallskip";
+                                               known_vspace = true;
+                                       } else if (unit == "\\medskipamount") {
+                                               unit = "medskip";
+                                               known_vspace = true;
+                                       } else if (unit == "\\bigskipamount") {
+                                               unit = "bigskip";
+                                               known_vspace = true;
+                                       } else if (unit == "\\fill") {
+                                               unit = "vfill";
+                                               known_vspace = true;
+                                       }
+                               } else {
+                                       switch (unitFromString(unit)) {
+                                       case LyXLength::SP:
+                                       case LyXLength::PT:
+                                       case LyXLength::BP:
+                                       case LyXLength::DD:
+                                       case LyXLength::MM:
+                                       case LyXLength::PC:
+                                       case LyXLength::CC:
+                                       case LyXLength::CM:
+                                       case LyXLength::IN:
+                                       case LyXLength::EX:
+                                       case LyXLength::EM:
+                                       case LyXLength::MU:
+                                               known_unit = true;
+                                               break;
+                                       default:
+                                               break;
+                                       }
+                               }
+                       }
+
+                       if (known_unit || known_vspace) {
+                               // Literal length or known variable
+                               context.check_layout(os);
+                               begin_inset(os, "VSpace ");
+                               if (known_unit)
+                                       os << value;
+                               os << unit;
+                               if (starred)
+                                       os << '*';
+                               end_inset(os);
                        } else {
-                               if (t.cs() == "vspace")
-                                       handle_ert(os, t.asInput() + '{' + arg + '}', context);
-                               else
-                                       handle_ert(os, t.asInput(), context);
+                               // LyX can't handle other length variables in Inset VSpace
+                               string name = t.asInput();
+                               if (starred)
+                                       name += '*';
+                               if (valid) {
+                                       if (value == 1.0)
+                                               handle_ert(os, name + '{' + unit + '}', context);
+                                       else if (value == -1.0)
+                                               handle_ert(os, name + "{-" + unit + '}', context);
+                                       else
+                                               handle_ert(os, name + '{' + valstring + unit + '}', context);
+                               } else
+                                       handle_ert(os, name + '{' + length + '}', context);
                        }
-                       // Would be nice to recognize added_space_bottom too...
-                       // At the moment this is parsed as added_space_top of the
-                       // next paragraph.
                }
 
                else {
@@ -1280,7 +1379,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                p.get_token();                          // Eat '*'
                                name += '*';
                        }
-                       if (! parse_command(t.asInput(), p, os, outer, context))
+                       if (! parse_command(name, p, os, outer, context))
                                handle_ert(os, name, context);
                }