]> git.lyx.org Git - features.git/commitdiff
- Add support for the align environment from amsmath
authorDekel Tsur <dekelts@tau.ac.il>
Sun, 11 Feb 2001 09:58:20 +0000 (09:58 +0000)
committerDekel Tsur <dekelts@tau.ac.il>
Sun, 11 Feb 2001 09:58:20 +0000 (09:58 +0000)
- RTL fixes.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1479 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
lib/ui/default.ui
src/ChangeLog
src/buffer.C
src/insets/ChangeLog
src/insets/insettext.C
src/lyxparagraph.h
src/mathed/ChangeLog
src/mathed/math_cursor.C
src/mathed/math_defs.h
src/mathed/math_inset.C
src/mathed/math_parser.C
src/mathed/math_write.C
src/paragraph.C
src/text.C

index 588929d489a95c249b73881dfeca220bcb168a11..def3d0ed7dcb00e365716dc6fc98462880922a60 100644 (file)
@@ -146,9 +146,11 @@ Menuset
     Menu "edit_math"
        Item "Make eqnarray|e" "break-line e"
        Item "Make multline|m" "break-line m"
-       Item "Make alignat 1 column|1"  "break-line 1"
-       Item "Make alignat 2 columns|2"  "break-line 2"
-       Item "Make alignat 3 columns|3"  "break-line 3"
+       Item "Make align 1 column|1"  "break-line 1"
+       Item "Make align 2 columns|2"  "break-line 2"
+       Item "Make align 3 columns|3"  "break-line 3"
+       Item "Make alignat 2 columns|2"  "break-line B"
+       Item "Make alignat 3 columns|3"  "break-line C"
        Separator
        Item "Toggle numbering|n" "math-number"
        Item "Toggle numbering of line|u" "math-nonumber"
index ea479d722b1898358a0962a22517e7d36cd53350..f910fa6b6163f081bf42653af65051d03cda7380 100644 (file)
@@ -1,3 +1,12 @@
+2001-02-10  Dekel Tsur  <dekelts@tau.ac.il>
+
+       * text.C (PrepareToPrint): RTL Fix.
+
+       * paragraph.C (GetUChar): New method.
+       (String):  Use GetUChar.
+
+       * buffer.C (asciiParagraph): Use GetUChar.
+
 2001-02-09  Dekel Tsur  <dekelts@tau.ac.il>
 
        * text.C (GetVisibleRow): Fix selection drawing for RTL text in tables.
index f4c92268c55ac14a94ba8324232beda8d5e3a976..c548ce5396fff193f2f1669c663f14ee4b5f619f 100644 (file)
@@ -1528,7 +1528,7 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
                } else {
                        islatex = 0;
                }
-               c = par->GetChar(i);
+               c = par->GetUChar(params, i);
                if (islatex)
                        continue;
                switch (c) {
index 5388b4e6ab2a07943cf6d81c1915732bc4c2d085..2ae1eb118558e60a9fac6c6ddf755b6f7d1c8ba1 100644 (file)
@@ -1,3 +1,8 @@
+2001-02-10  Dekel Tsur  <dekelts@tau.ac.il>
+
+       * insettext.C (LocalDispatch): Restore the language if the inset
+       becomes empty.
+
 2001-02-09  Dekel Tsur  <dekelts@tau.ac.il>
 
        * insettext.C (moveRightIntern): Update the selection cursor.
index ee26c8f475b0ee2973ad87297a621055fda3914f..1b16607f03356e07051ea6af340be1828028e625 100644 (file)
@@ -1101,6 +1101,15 @@ InsetText::LocalDispatch(BufferView * bv,
        result = UNDISPATCHED;
        break;
     }
+
+    /// If the action has deleted all text in the inset, we need to change the
+    // language to the language to the surronding text.
+    if (par->Last() == 0 && !par->next) {
+       LyXFont font(LyXFont::ALL_IGNORE);
+       font.setLanguage(bv->getParentLanguage(this));
+       SetFont(bv, font, false);
+    }
+
     if (result != FINISHED) {
        ShowInsetCursor(bv);
     } else
index 98e73a11ecef9a592dcf5b4209913ff512747709..69e956f2f0c3ea27492d56cc70c83bbcbce89e09 100644 (file)
@@ -441,6 +441,8 @@ public:
        LyXFont const getFont(BufferParams const &, size_type pos) const;
        ///
        value_type GetChar(size_type pos) const;
+       ///
+       value_type GetUChar(BufferParams const &, size_type pos) const;
        /// The position must already exist.
        void SetChar(size_type pos, value_type c) {
 #ifndef HAVE_ROPE
index da0505e9c4b497a9540fe8754be0775228f6973d..f71d92ee99edd3deaccf592ac7b32631176061f2 100644 (file)
@@ -1,3 +1,7 @@
+2001-02-10  Dekel Tsur  <dekelts@tau.ac.il>
+
+       * Many files: add support for the align environment from amsmath.
+
 2001-02-09  André Pönitz  <poenitz@htwm.de>
 
        * array.h: replace array buffer  'byte bf[]'  by 'std::vector<byte> bf'
index f525f2a964652886e91febc8db0407cf024f0c1a..5d6895338571cda4d550dc5a73e3483104ed1834 100644 (file)
@@ -337,6 +337,12 @@ MathMatrixInset * create_multiline(short int type, int cols)
                cols = 1;
 
        switch (type) {
+       case LM_OT_ALIGN:
+       case LM_OT_ALIGNN:
+               columns = 2*cols;
+               for (int i = 0; i < cols; ++i)
+                       align += "Rl";
+               break;
        case LM_OT_ALIGNAT:
        case LM_OT_ALIGNATN:
                columns = 2*cols;
@@ -377,8 +383,11 @@ void MathedCursor::Insert(byte c, MathedTextCodes t)
         short int type = LM_OT_MPAR;
         int cols = 1;
         if (c >= '1' && c <= '9') {
+                type = LM_OT_ALIGN;
+                cols = c - '1' + 1;
+        } else if (c >= 'A' && c <= 'I') {
                 type = LM_OT_ALIGNAT;
-                cols = c - '0';
+                cols = c - 'A' + 1;
         } else if (c == 'm')
                 type = LM_OT_MULTLINE;
         else if (c == 'e')
index 10e49d0e53926191d6f99e9c599063ac515d3cc3..0d1901d5d6b9e0b255bdc12993c6a0a7097fcfa3 100644 (file)
@@ -145,6 +145,10 @@ enum MathedInsetTypes  {
        /// A multiline numbered paragraph
        LM_OT_MPARN,
        ///
+       LM_OT_ALIGN,
+       ///
+       LM_OT_ALIGNN,
+       ///
        LM_OT_ALIGNAT,
        ///
        LM_OT_ALIGNATN,
@@ -683,7 +687,8 @@ bool is_singlely_numbered(short int type)
 inline
 bool is_multi_numbered(short int type)
 {
-       return type == LM_OT_MPARN || type == LM_OT_ALIGNATN;
+       return type == LM_OT_MPARN || type == LM_OT_ALIGNN
+               || type == LM_OT_ALIGNATN;
 }
 
 inline
@@ -695,7 +700,8 @@ bool is_numbered(short int type)
 inline
 bool is_multicolumn(short int type)
 {
-       return type == LM_OT_ALIGNAT || type == LM_OT_ALIGNATN;
+       return type == LM_OT_ALIGN || type == LM_OT_ALIGNN
+               || type == LM_OT_ALIGNAT || type == LM_OT_ALIGNATN;
 }
 
 #endif
index 3ab75b3f9862d6be5f2e3f3b40205aa80eef0c44..491a9d0d396c54554d3fc3eaa9d49361029ba526 100644 (file)
@@ -464,7 +464,11 @@ void MathMatrixInset::Metrics()
     }
     descent = h - ascent + 2;
     
-   
+    // Increase ws[i] for 'R' columns (except the first one)
+    for (i = 1; i < nc; ++i)
+       if (h_align[i] == 'R')
+           ws[i] += 10*df_width;
+
    // Adjust local tabs
     cxrow = row;
     width = MATH_COLSEP;
@@ -477,12 +481,18 @@ void MathMatrixInset::Metrics()
                isvoid = true;
            }
            switch (h_align[i]) {
-            case 'l': lf = 0; break;
-            case 'c': lf = (ws[i] - cxrow->getTab(i))/2; 
-                      break;
-            case 'r': lf = ws[i] - cxrow->getTab(i); break;
+           case 'l':
+               lf = 0;
+               break;
+           case 'c':
+               lf = (ws[i] - cxrow->getTab(i))/2; 
+               break;
+           case 'r':
+           case 'R':
+               lf = ws[i] - cxrow->getTab(i);
+               break;
            }
-           ww = (isvoid) ? lf: lf + cxrow->getTab(i);
+           ww = (isvoid) ? lf : lf + cxrow->getTab(i);
            cxrow->setTab(i, lf + rg);
            rg = ws[i] - ww + MATH_COLSEP;
            if (cxrow == row) width += ws[i] + MATH_COLSEP;
index 288496ffadb971cbddf2e30fcf232c317bab9664..45a0d5db1292d77314ebd95bbdc8499a8eb74fa1 100644 (file)
@@ -65,13 +65,15 @@ MathedInsetTypes mathed_env = LM_OT_MIN;
 string mathed_label;
 
 
-int const latex_mathenv_num = 10;
+int const latex_mathenv_num = 12;
 char const * latex_mathenv[latex_mathenv_num] = { 
    "math", 
    "displaymath", 
    "equation", 
    "eqnarray*",
    "eqnarray",
+   "align*",
+   "align",
    "alignat*",
    "alignat",
    "multline*",
@@ -809,6 +811,15 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * array,
                 if (is_multiline(mathed_env)) {
                     int cols = 1;
                     if (is_multicolumn(mathed_env)) {
+                        if (mathed_env != LM_OT_ALIGNAT &&
+                            mathed_env != LM_OT_ALIGNATN &&
+                            yyis->good()) {
+                            char c;
+                            yyis->get(c);
+                            if (c != '%')
+                                    lyxerr << "Math parse error: unexpected '"
+                                           << c << "'" << endl;
+                        }
                         LexGetArg('{');
                         cols = strToInt(string(yytext));
                     }
index 114584a2310566ae23f2f2851ba69efcf64252a7..233635402657db86006010b3bf9fd78a14ced960 100644 (file)
@@ -336,8 +336,12 @@ void mathed_write(MathParInset * p, ostream & os, int * newlines,
             os << "\\begin{"
                << latex_mathenv[mathed_env]
                << "}";
-            if (mathed_env == LM_OT_ALIGNAT || mathed_env == LM_OT_ALIGNATN)
+            if (is_multicolumn(mathed_env)) {
+                    if (mathed_env != LM_OT_ALIGNAT
+                        && mathed_env != LM_OT_ALIGNATN)
+                            os << "%";
                     os << "{" << p->GetColumns()/2 << "}";
+            }
             os << "\n";
      }
      ++number_of_newlines;
index 510b784b21c570adc3e7e35485fbc7fbacc9a8fb..363038a23166d9a5c31ad20489a4a925f8c00c1b 100644 (file)
@@ -1018,6 +1018,47 @@ LyXParagraph::GetChar(LyXParagraph::size_type pos) const
 }
 
 
+LyXParagraph::value_type
+LyXParagraph::GetUChar(BufferParams const & bparams,
+                      LyXParagraph::size_type pos) const
+{
+       value_type c = GetChar(pos);
+       if (!lyxrc.rtl_support)
+               return c;
+
+       value_type uc = c;
+       switch (c) {
+       case '(':
+               uc = ')';
+               break;
+       case ')':
+               uc = '(';
+               break;
+       case '[':
+               uc = ']';
+               break;
+       case ']':
+               uc = '[';
+               break;
+       case '{':
+               uc = '}';
+               break;
+       case '}':
+               uc = '{';
+               break;
+       case '<':
+               uc = '>';
+               break;
+       case '>':
+               uc = '<';
+               break;
+       }
+       if (uc != c && GetFontSettings(bparams, pos).isRightToLeft())
+               return uc;
+       else
+               return c;
+}
+
 // return an string of the current word, and the end of the word in lastpos.
 string const LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
 {
@@ -3995,7 +4036,7 @@ string const LyXParagraph::String(Buffer const * buffer,
                s += labelstring + ' ';
 
        for (LyXParagraph::size_type i = beg; i < end; ++i) {
-               value_type c = GetChar(i);
+               value_type c = GetUChar(buffer->params, i);
                if (IsPrintable(c))
                        s += c;
                else if (c == META_INSET) {
index b493a5498a61ad29ed4ed24181a09c1e2b35d076..64fa5b2615dca7444bec1a95e5f570577a28b255 100644 (file)
@@ -2196,21 +2196,18 @@ void LyXText::PrepareToPrint(BufferView * bview,
 
         bool const is_rtl =
                row->par()->isRightToLeftPar(bview->buffer()->params);
-#ifndef NEW_INSETS
-
        if (is_rtl) {
-               x = RightMargin(bview->buffer(), row);
+               x = (workWidth(bview) > 0)
+                       ? RightMargin(bview->buffer(), row) : 0;
+#ifndef NEW_INSETS
                if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
                        LyXFont font(LyXFont::ALL_SANE);
                        font.setSize(LyXFont::SIZE_SMALL);
                        x += lyxfont::width("Mwide-figM", font);
                }
-       } else
 #endif
-               if (workWidth(bview) > 0)
-               x = LeftMargin(bview, row);
-       else
-               x = 0;
+       } else
+               x = (workWidth(bview) > 0) ? LeftMargin(bview, row) : 0;
        
        // is there a manual margin with a manual label
        if (textclasslist.Style(bview->buffer()->params.textclass,