branch: externals/org
commit 63e1165c0b785207bb1aaef84e206ee2244cc7bf
Author: Nick Dokos <[email protected]>
Commit: Ihor Radchenko <[email protected]>

    org-latex--table.el-table: Fix :rmlines behavior for table.el export
    
    * lisp/ox-latex.el (org-latex--table.el-table): If :rmlines is set,
    reverse the sense of the inequality for the end-of-ouput check and
    ensure preservation of the second `\hline'.
    
    * testing/lisp/test-ox-latex.el (test-ox-latex/table-el-table): Add
    test.
    
    See 
https://emacs.stackexchange.com/questions/85513/org-mode-export-to-latex-with-rmlines
    
    Reported-by: Marko
---
 lisp/ox-latex.el              |  6 ++++--
 testing/lisp/test-ox-latex.el | 28 ++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index d134b164f5..3db1903d0b 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -4120,10 +4120,12 @@ property."
        ;; When the "rmlines" attribute is provided, remove all hlines
        ;; but the one separating heading from the table body.
        (let ((n 0) (pos 0))
-         (while (and (< (length output) pos)
+         (while (and (> (length output) pos)
                      (setq pos (string-match "^\\\\hline\n?" output pos)))
            (cl-incf n)
-           (unless (= n 2) (setq output (replace-match "" nil nil output))))))
+           (if (= n 2)
+                (cl-incf pos)
+              (setq output (replace-match "" nil nil output))))))
       (org-latex--decorate-table output attr caption above? info))))
 
 (defun org-latex--math-table (table info)
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index de663c8e42..28ccfe7254 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -81,6 +81,7 @@ lorem ipsum dolor\\\\
 lorem ipsum dolor\\\\
 \\end{verse}")))
   ;; Footnotes inside verse blocks
+
   (org-test-with-exported-text
       'latex
       "#+begin_verse
@@ -143,6 +144,33 @@ Column & Column \\\\
       "\\hline\\multicolumn{2}{r}{Continued on next page} \\\\
 \\endfoot"))))
 
+(ert-deftest test-ox-latex/table-el-table ()
+  "Test table export with table.el table and :rmlines."
+  (org-test-with-exported-text
+      'latex
+      "#+attr_latex: :rmlines yes
++--------------------------+-----------+
+|   ... better than ...    | ... times |
++--------------+-----------+-----------+
+| PostgreSQL   | MySQL     |     2     |
++--------------+-----------+-----------+
+| PostgreSQL   | MongoDB   |     2     |
++--------------+-----------+-----------+
+| MongoDB      | MySQL     |     2     |
++--------------+-----------+-----------+
+"
+    (goto-char (point-min))
+    (should
+     (search-forward
+      "\\begin{tabular}{|l|l|l|}
+\\multicolumn{2}{|l|}{... better than ...} & ... times \\\\
+\\hline
+PostgreSQL & MySQL & 2 \\\\
+PostgreSQL & MongoDB & 2 \\\\
+MongoDB & MySQL & 2 \\\\
+\\end{tabular}"
+      ))))
+
 (ert-deftest test-ox-latex/inline-image ()
   "Test inline images."
   (org-test-with-exported-text

Reply via email to