]> git.lyx.org Git - features.git/commitdiff
tex2lyx: support decimal alignment in tables
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 26 Aug 2018 14:17:54 +0000 (16:17 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 11 Sep 2018 06:03:23 +0000 (08:03 +0200)
(cherry picked from commit 8ef2558dc23a44185b246d3f66e1384a6144caa2)

src/tex2lyx/TODO.txt
src/tex2lyx/table.cpp
src/tex2lyx/test/beamer.lyx.lyx
src/tex2lyx/test/test-insets-basic.lyx.lyx
src/tex2lyx/test/test-insets.lyx.lyx
status.23x

index a68cc375fab6823a566ccf77a89dfafab915ae0e..a5f4f8ac3e9a5b1fe0f4c337661eb31ffc5f5f19 100644 (file)
@@ -28,7 +28,6 @@ Format LaTeX feature                        LyX feature
 364    branch file name suffix              \filename_suffix
 371    automatic mhchem loading             \use_mhchem
 390    forward/reverse search               \forward_search, \forward_macro
-391    decimal alignment in tables          InsetTabular
 399    automatic mathdots loading           \use_mathdots
 411    support for polyglossia              \language_package (the cases of no package, of babel and of custom package is supported)
 415    automatic undertilde loading         \use_package undertilde
index d3392b007774f1b2226097137d66fe2e9de189b1..98f3e03e3a7a37c87aad13758b3e677d901f032b 100644 (file)
@@ -37,7 +37,8 @@ namespace {
 
 class ColInfo {
 public:
-       ColInfo() : align('n'), valign('n'), rightlines(0), leftlines(0) {}
+       ColInfo() : align('n'), valign('n'), rightlines(0), leftlines(0),
+               decimal_point('\0') {}
        /// column alignment
        char align;
        /// vertical alignment
@@ -50,6 +51,8 @@ public:
        int rightlines;
        /// number of lines on the left
        int leftlines;
+       /// decimal separator
+       char decimal_point;
 };
 
 
@@ -177,6 +180,8 @@ inline char const * verbose_align(char c)
                return "right";
        case 'l':
                return "left";
+       case 'd':
+               return "decimal";
        default:
                return "none";
        }
@@ -264,6 +269,17 @@ void ci2special(ColInfo & ci)
                // this case.
                return;
 
+       if (ci.decimal_point != '\0') {
+               // we only support decimal point natively
+               // with 'l' alignment in or 'n' alignment
+               // with width in second row
+               if (ci.align != 'l' && ci.align != 'n') {
+                       ci.decimal_point = '\0';
+                       return;
+               } else
+                       ci.special.clear();
+       }
+
        if (!ci.width.empty()) {
                switch (ci.align) {
                case 'l':
@@ -338,8 +354,17 @@ void handle_colalign(Parser & p, vector<ColInfo> & colinfo,
                        case 'r':
                                // new column, horizontal aligned
                                next.align = t.character();
-                               if (!next.special.empty())
+                               if (!next.special.empty()) {
                                        ci2special(next);
+                                       // handle decimal separator
+                                       if (next.decimal_point != '\0') {
+                                               if (!colinfo.empty() && colinfo.back().align == 'r') {
+                                                       colinfo.back().align = 'd';
+                                                       colinfo.back().decimal_point = next.decimal_point;
+                                               } else
+                                                       next.decimal_point = '\0';
+                                       }
+                               }
                                colinfo.push_back(next);
                                next = ColInfo();
                                break;
@@ -349,8 +374,17 @@ void handle_colalign(Parser & p, vector<ColInfo> & colinfo,
                                // new column, vertical aligned box
                                next.valign = t.character();
                                next.width = p.verbatim_item();
-                               if (!next.special.empty())
+                               if (!next.special.empty()) {
                                        ci2special(next);
+                                       // handle decimal separator
+                                       if (next.decimal_point != '\0') {
+                                               if (!colinfo.empty() && colinfo.back().align == 'r') {
+                                                       colinfo.back().align = 'd';
+                                                       colinfo.back().decimal_point = next.decimal_point;
+                                               } else
+                                                       next.decimal_point = '\0';
+                                       }
+                               }
                                colinfo.push_back(next);
                                next = ColInfo();
                                break;
@@ -426,11 +460,16 @@ void handle_colalign(Parser & p, vector<ColInfo> & colinfo,
                        }
                        case '@':
                                // text instead of the column spacing
-                       case '!':
+                       case '!': {
                                // text in addition to the column spacing
+                               string const arg =  p.verbatim_item();
                                next.special += t.character();
-                               next.special += '{' + p.verbatim_item() + '}';
+                               next.special += '{' + arg + '}';
+                               string const sarg = arg.size() > 2 ? arg.substr(0, arg.size() - 1) : string();
+                               if (t.character() == '@' && sarg == "\\extracolsep{0pt}")
+                                       next.decimal_point = arg.back();
                                break;
+                       }
                        default: {
                                // try user defined column types
                                // unknown column types (nargs == -1) are
@@ -1131,7 +1170,12 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
                                     << cells[cell] << "'." << endl;
                                continue;
                        }
-                       Parser p(cells[cell]);
+                       string cellcont = cells[cell];
+                       // For decimal cells, ass the content of the second one to the first one
+                       // of a pair.
+                       if (colinfo[col].decimal_point != '\0' && colinfo[col].align == 'd' && cell < cells.size() - 1)
+                               cellcont += colinfo[col].decimal_point + cells[cell + 1];
+                       Parser p(cellcont);
                        p.skip_spaces();
                        //cells[cell] << "'\n";
                        if (p.next_token().cs() == "multirow") {
@@ -1401,8 +1445,13 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
        //cerr << "// output what we have\n";
        // output what we have
        string const rotate = "0";
+       size_type cols = colinfo.size();
+       for (size_t col = 0; col < colinfo.size(); ++col) {
+               if (colinfo[col].decimal_point != '\0' && colinfo[col].align != 'd')
+                       --cols;
+       }
        os << "\n<lyxtabular version=\"3\" rows=\"" << rowinfo.size()
-          << "\" columns=\"" << colinfo.size() << "\">\n";
+          << "\" columns=\"" << cols << "\">\n";
        os << "<features"
           << write_attribute("rotate", rotate)
           << write_attribute("booktabs", booktabs)
@@ -1427,9 +1476,13 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
 
        //cerr << "// after header\n";
        for (size_t col = 0; col < colinfo.size(); ++col) {
+               if (colinfo[col].decimal_point != '\0' && colinfo[col].align != 'd')
+                       continue;
                os << "<column alignment=\""
-                  << verbose_align(colinfo[col].align) << "\""
-                  << " valignment=\""
+                          << verbose_align(colinfo[col].align) << "\"";
+               if (colinfo[col].decimal_point != '\0')
+                       os << " decimal_point=\"" << colinfo[col].decimal_point << "\"";
+               os << " valignment=\""
                   << verbose_valign(colinfo[col].valign) << "\""
                   << write_attribute("width", translate_len(colinfo[col].width))
                   << write_attribute("special", colinfo[col].special)
@@ -1455,9 +1508,13 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
                   << ">\n";
                for (size_t col = 0; col < colinfo.size(); ++col) {
                        CellInfo const & cell = cellinfo[row][col];
+                       if (colinfo[col].decimal_point != '\0' && colinfo[col].align != 'd')
+                               // These are the second columns in a salign pair. Skip.
+                               continue;
                        os << "<cell";
-                       if (cell.multi == CELL_BEGIN_OF_MULTICOLUMN
-                           || cell.multi == CELL_PART_OF_MULTICOLUMN)
+                       if ((cell.multi == CELL_BEGIN_OF_MULTICOLUMN
+                                   || cell.multi == CELL_PART_OF_MULTICOLUMN)
+                                  && colinfo[col].align != 'd')
                                os << " multicolumn=\"" << cell.multi << "\"";
                        if (cell.multi == CELL_BEGIN_OF_MULTIROW
                            || cell.multi == CELL_PART_OF_MULTIROW)
index f3ba80fc5c93b9c0cd3e10f69b4090ca6c2da047..dab5c1d6afc682b572a18d9d629d52ce4ea5ebfb 100644 (file)
@@ -108,6 +108,22 @@ Version
 2.3
 \end_layout
 
+\begin_layout Standard
+
+\begin_inset ERT
+status collapsed
+
+\begin_layout Plain Layout
+
+\backslash
+maketitle
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
 \begin_layout Frame
 
 \end_layout
index 540c80c5d6128c06224268e2a4429c57a04119a9..cee0d2c6086465a0de21822f87fe08e4da9b7859 100644 (file)
@@ -5020,16 +5020,13 @@ status open
 \begin_layout Standard
 
 \begin_inset Tabular 
-<lyxtabular version="3" rows="4" columns="8">
+<lyxtabular version="3" rows="4" columns="5">
 <features rotate="0" tabularvalignment="middle" tabularwidth="0pt">
 <column alignment="center" valignment="top">
 <column alignment="center" valignment="top">
-<column alignment="right" valignment="top">
-<column alignment="none" valignment="top" special="@{\extracolsep{0pt}.}l">
-<column alignment="right" valignment="top">
-<column alignment="none" valignment="top" special="@{\extracolsep{0pt}.}l">
-<column alignment="right" valignment="top">
-<column alignment="none" valignment="top" special="@{\extracolsep{0pt}.}l">
+<column alignment="decimal" decimal_point="." valignment="top">
+<column alignment="decimal" decimal_point="." valignment="top">
+<column alignment="decimal" decimal_point="." valignment="top">
 <row>
 <cell alignment="center" valignment="top" usebox="none">
 \begin_inset Text
@@ -5049,7 +5046,7 @@ Two
 
 \end_inset
 </cell>
-<cell multicolumn="1" alignment="none" valignment="top" usebox="none" special="c">
+<cell alignment="none" valignment="top" usebox="none" special="c">
 \begin_inset Text
 
 \begin_layout Standard
@@ -5058,12 +5055,7 @@ Three
 
 \end_inset
 </cell>
-<cell multicolumn="2" alignment="center" valignment="top" usebox="none">
-\begin_inset Text
-
-\end_inset
-</cell>
-<cell multicolumn="1" alignment="none" valignment="top" usebox="none" special="c">
+<cell alignment="none" valignment="top" usebox="none" special="c">
 \begin_inset Text
 
 \begin_layout Standard
@@ -5072,23 +5064,13 @@ Four
 
 \end_inset
 </cell>
-<cell multicolumn="2" alignment="center" valignment="top" usebox="none">
-\begin_inset Text
-
-\end_inset
-</cell>
-<cell multicolumn="1" alignment="none" valignment="top" usebox="none" special="c">
+<cell alignment="none" valignment="top" usebox="none" special="c">
 \begin_inset Text
 
 \begin_layout Standard
 Five
 \end_layout
 
-\end_inset
-</cell>
-<cell multicolumn="2" alignment="center" valignment="top" usebox="none">
-\begin_inset Text
-
 \end_inset
 </cell>
 </row>
@@ -5111,7 +5093,7 @@ two
 
 \end_inset
 </cell>
-<cell multicolumn="1" alignment="none" valignment="top" topline="true" usebox="none" special="c">
+<cell alignment="none" valignment="top" topline="true" usebox="none" special="c">
 \begin_inset Text
 
 \begin_layout Standard
@@ -5120,12 +5102,7 @@ three
 
 \end_inset
 </cell>
-<cell multicolumn="2" alignment="center" valignment="top" topline="true" usebox="none">
-\begin_inset Text
-
-\end_inset
-</cell>
-<cell multicolumn="1" alignment="none" valignment="top" topline="true" usebox="none" special="c">
+<cell alignment="none" valignment="top" topline="true" usebox="none" special="c">
 \begin_inset Text
 
 \begin_layout Standard
@@ -5134,23 +5111,13 @@ four
 
 \end_inset
 </cell>
-<cell multicolumn="2" alignment="center" valignment="top" topline="true" usebox="none">
-\begin_inset Text
-
-\end_inset
-</cell>
-<cell multicolumn="1" alignment="none" valignment="top" topline="true" usebox="none" special="c">
+<cell alignment="none" valignment="top" topline="true" usebox="none" special="c">
 \begin_inset Text
 
 \begin_layout Standard
 five
 \end_layout
 
-\end_inset
-</cell>
-<cell multicolumn="2" alignment="center" valignment="top" topline="true" usebox="none">
-\begin_inset Text
-
 \end_inset
 </cell>
 </row>
@@ -5173,52 +5140,29 @@ He
 
 \end_inset
 </cell>
-<cell alignment="right" valignment="top" usebox="none">
-\begin_inset Text
-
-\begin_layout Standard
-2
-\end_layout
-
-\end_inset
-</cell>
-<cell alignment="none" valignment="top" usebox="none">
+<cell alignment="decimal" valignment="top" usebox="none">
 \begin_inset Text
 
 \begin_layout Standard
-77234 
+2.77234 
 \end_layout
 
 \end_inset
 </cell>
-<cell alignment="right" valignment="top" usebox="none">
+<cell alignment="decimal" valignment="top" usebox="none">
 \begin_inset Text
 
 \begin_layout Standard
-45672
+45672.
 \end_layout
 
 \end_inset
 </cell>
-<cell alignment="none" valignment="top" usebox="none">
-\begin_inset Text
-
-\end_inset
-</cell>
-<cell alignment="right" valignment="top" usebox="none">
+<cell alignment="decimal" valignment="top" usebox="none">
 \begin_inset Text
 
 \begin_layout Standard
-0
-\end_layout
-
-\end_inset
-</cell>
-<cell alignment="none" valignment="top" usebox="none">
-\begin_inset Text
-
-\begin_layout Standard
-69 
+0.69 
 \end_layout
 
 \end_inset
 
 \end_inset
 </cell>
-<cell alignment="right" valignment="top" usebox="none">
+<cell alignment="decimal" valignment="top" usebox="none">
 \begin_inset Text
 
 \begin_layout Standard
-12537
+12537.64 
 \end_layout
 
 \end_inset
 </cell>
-<cell alignment="none" valignment="top" usebox="none">
+<cell alignment="decimal" valignment="top" usebox="none">
 \begin_inset Text
 
 \begin_layout Standard
-64 
+37.66345 
 \end_layout
 
 \end_inset
 </cell>
-<cell alignment="right" valignment="top" usebox="none">
-\begin_inset Text
-
-\begin_layout Standard
-37
-\end_layout
-
-\end_inset
-</cell>
-<cell alignment="none" valignment="top" usebox="none">
-\begin_inset Text
-
-\begin_layout Standard
-66345 
-\end_layout
-
-\end_inset
-</cell>
-<cell alignment="right" valignment="top" usebox="none">
-\begin_inset Text
-
-\begin_layout Standard
-86
-\end_layout
-
-\end_inset
-</cell>
-<cell alignment="none" valignment="top" usebox="none">
+<cell alignment="decimal" valignment="top" usebox="none">
 \begin_inset Text
 
 \begin_layout Standard
-37 
+86.37 
 \end_layout
 
 \end_inset
index cebb68e2d9d6cf543f655e491065469514b1c00f..d59a043064ad5f1d422d67198ef08d69db0332fa 100644 (file)
@@ -5413,16 +5413,13 @@ status open
 \begin_layout Standard
 
 \begin_inset Tabular 
-<lyxtabular version="3" rows="4" columns="8">
+<lyxtabular version="3" rows="4" columns="5">
 <features rotate="0" tabularvalignment="middle" tabularwidth="0pt">
 <column alignment="center" valignment="top">
 <column alignment="center" valignment="top">
-<column alignment="right" valignment="top">
-<column alignment="none" valignment="top" special="@{\extracolsep{0pt}.}l">
-<column alignment="right" valignment="top">
-<column alignment="none" valignment="top" special="@{\extracolsep{0pt}.}l">
-<column alignment="right" valignment="top">
-<column alignment="none" valignment="top" special="@{\extracolsep{0pt}.}l">
+<column alignment="decimal" decimal_point="." valignment="top">
+<column alignment="decimal" decimal_point="." valignment="top">
+<column alignment="decimal" decimal_point="." valignment="top">
 <row>
 <cell alignment="center" valignment="top" usebox="none">
 \begin_inset Text
@@ -5442,7 +5439,7 @@ Two
 
 \end_inset
 </cell>
-<cell multicolumn="1" alignment="none" valignment="top" usebox="none" special="c">
+<cell alignment="none" valignment="top" usebox="none" special="c">
 \begin_inset Text
 
 \begin_layout Standard
@@ -5451,12 +5448,7 @@ Three
 
 \end_inset
 </cell>
-<cell multicolumn="2" alignment="center" valignment="top" usebox="none">
-\begin_inset Text
-
-\end_inset
-</cell>
-<cell multicolumn="1" alignment="none" valignment="top" usebox="none" special="c">
+<cell alignment="none" valignment="top" usebox="none" special="c">
 \begin_inset Text
 
 \begin_layout Standard
@@ -5465,23 +5457,13 @@ Four
 
 \end_inset
 </cell>
-<cell multicolumn="2" alignment="center" valignment="top" usebox="none">
-\begin_inset Text
-
-\end_inset
-</cell>
-<cell multicolumn="1" alignment="none" valignment="top" usebox="none" special="c">
+<cell alignment="none" valignment="top" usebox="none" special="c">
 \begin_inset Text
 
 \begin_layout Standard
 Five
 \end_layout
 
-\end_inset
-</cell>
-<cell multicolumn="2" alignment="center" valignment="top" usebox="none">
-\begin_inset Text
-
 \end_inset
 </cell>
 </row>
@@ -5504,7 +5486,7 @@ two
 
 \end_inset
 </cell>
-<cell multicolumn="1" alignment="none" valignment="top" topline="true" usebox="none" special="c">
+<cell alignment="none" valignment="top" topline="true" usebox="none" special="c">
 \begin_inset Text
 
 \begin_layout Standard
@@ -5513,12 +5495,7 @@ three
 
 \end_inset
 </cell>
-<cell multicolumn="2" alignment="center" valignment="top" topline="true" usebox="none">
-\begin_inset Text
-
-\end_inset
-</cell>
-<cell multicolumn="1" alignment="none" valignment="top" topline="true" usebox="none" special="c">
+<cell alignment="none" valignment="top" topline="true" usebox="none" special="c">
 \begin_inset Text
 
 \begin_layout Standard
@@ -5527,23 +5504,13 @@ four
 
 \end_inset
 </cell>
-<cell multicolumn="2" alignment="center" valignment="top" topline="true" usebox="none">
-\begin_inset Text
-
-\end_inset
-</cell>
-<cell multicolumn="1" alignment="none" valignment="top" topline="true" usebox="none" special="c">
+<cell alignment="none" valignment="top" topline="true" usebox="none" special="c">
 \begin_inset Text
 
 \begin_layout Standard
 five
 \end_layout
 
-\end_inset
-</cell>
-<cell multicolumn="2" alignment="center" valignment="top" topline="true" usebox="none">
-\begin_inset Text
-
 \end_inset
 </cell>
 </row>
@@ -5566,52 +5533,29 @@ He
 
 \end_inset
 </cell>
-<cell alignment="right" valignment="top" usebox="none">
+<cell alignment="decimal" valignment="top" usebox="none">
 \begin_inset Text
 
 \begin_layout Standard
-2
-\end_layout
-
-\end_inset
-</cell>
-<cell alignment="none" valignment="top" usebox="none">
-\begin_inset Text
-
-\begin_layout Standard
-77234 
+2.77234 
 \end_layout
 
 \end_inset
 </cell>
-<cell alignment="right" valignment="top" usebox="none">
+<cell alignment="decimal" valignment="top" usebox="none">
 \begin_inset Text
 
 \begin_layout Standard
-45672
+45672.
 \end_layout
 
 \end_inset
 </cell>
-<cell alignment="none" valignment="top" usebox="none">
-\begin_inset Text
-
-\end_inset
-</cell>
-<cell alignment="right" valignment="top" usebox="none">
+<cell alignment="decimal" valignment="top" usebox="none">
 \begin_inset Text
 
 \begin_layout Standard
-0
-\end_layout
-
-\end_inset
-</cell>
-<cell alignment="none" valignment="top" usebox="none">
-\begin_inset Text
-
-\begin_layout Standard
-69 
+0.69 
 \end_layout
 
 \end_inset
 
 \end_inset
 </cell>
-<cell alignment="right" valignment="top" usebox="none">
+<cell alignment="decimal" valignment="top" usebox="none">
 \begin_inset Text
 
 \begin_layout Standard
-12537
-\end_layout
-
-\end_inset
-</cell>
-<cell alignment="none" valignment="top" usebox="none">
-\begin_inset Text
-
-\begin_layout Standard
-64 
-\end_layout
-
-\end_inset
-</cell>
-<cell alignment="right" valignment="top" usebox="none">
-\begin_inset Text
-
-\begin_layout Standard
-37
-\end_layout
-
-\end_inset
-</cell>
-<cell alignment="none" valignment="top" usebox="none">
-\begin_inset Text
-
-\begin_layout Standard
-66345 
+12537.64 
 \end_layout
 
 \end_inset
 </cell>
-<cell alignment="right" valignment="top" usebox="none">
+<cell alignment="decimal" valignment="top" usebox="none">
 \begin_inset Text
 
 \begin_layout Standard
-86
+37.66345 
 \end_layout
 
 \end_inset
 </cell>
-<cell alignment="none" valignment="top" usebox="none">
+<cell alignment="decimal" valignment="top" usebox="none">
 \begin_inset Text
 
 \begin_layout Standard
-37 
+86.37 
 \end_layout
 
 \end_inset
index fea862abe280ce22c03aa5b6af4709db6cde3ef1..81a153c0c115abd2421771b113fb53939f05d378 100644 (file)
@@ -41,6 +41,8 @@ What's new
 
 - Add support for btUnit (multibib).
 
+- Add support for decimal alignment in table cells.
+
 
 
 * USER INTERFACE