summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIhor Radchenko <yantar92@posteo.net>2023-12-23 12:03:36 +0100
committerIhor Radchenko <yantar92@posteo.net>2023-12-23 12:03:36 +0100
commit539728840f7acae3d8e4853af580b6d43baad1e3 (patch)
treeb3e8f015c1585636522c68a35717f47d2b90776e
parent872c1b99fb2ef8f847bd7de2087821049d7a8cb5 (diff)
downloadorg-mode-539728840.tar.gz
ox-latex: Fix exporting longtable with multiline header
* lisp/ox-latex.el (org-latex-table-row): Use all the rows when constructing header definition. * testing/lisp/test-ox-latex.el (test-ox-latex/longtable): Add new test. Reported-by: Brett Presnell <presnell@member.fsf.org> Link: https://orgmode.org/list/87mt9zywco.fsf@localhost
-rw-r--r--lisp/ox-latex.el14
-rw-r--r--testing/lisp/test-ox-latex.el35
2 files changed, 48 insertions, 1 deletions
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 41c2d39..1458ded 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -4046,6 +4046,18 @@ a communication channel."
(org-export-get-previous-element table-row info) info))
"")
(t "\\midrule"))
+ ;; Memorize table header in case it is multiline. We need this
+ ;; information to define contents before "\\endhead" in longtable environments.
+ (when (org-export-table-row-in-header-p table-row info)
+ (let ((table-head-cache (plist-get info :org-latex-table-head-cache)))
+ (unless (hash-table-p table-head-cache)
+ (setq table-head-cache (make-hash-table :test #'eq))
+ (plist-put info :org-latex-table-head-cache table-head-cache))
+ (if-let ((head-contents (gethash (org-element-parent table-row) table-head-cache)))
+ (puthash (org-element-parent table-row) (concat head-contents org-latex-line-break-safe "\n" contents)
+ table-head-cache)
+ (puthash (org-element-parent table-row) contents table-head-cache))))
+ ;; Return LaTeX string as the transcoder.
(concat
;; When BOOKTABS are activated enforce top-rule even when no
;; hline was specifically marked.
@@ -4075,7 +4087,7 @@ a communication channel."
"")
(booktabsp "\\toprule\n")
(t "\\hline\n"))
- contents
+ (gethash (org-element-parent table-row) (plist-get info :org-latex-table-head-cache))
(if booktabsp "\\midrule" "\\hline")
(if booktabsp "\\midrule" "\\hline")
columns
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 5c58cce..35e37e4 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -58,5 +58,40 @@ lorem ipsum dolor\\\\[0pt]
lorem ipsum dolor\\\\[0pt]
\\end{verse}"))))
+(ert-deftest test-ox-latex/longtable ()
+ "Test table export with longtable environment."
+ (org-test-with-exported-text
+ 'latex
+ "#+attr_latex: :environment longtable
+| First | Second |
+| Column | Column |
+|--------------+--------|
+| a | 1 |
+| b | 2 |
+| \\pagebreak c | 3 |
+| d | 4 |
+"
+ (goto-char (point-min))
+ (should
+ (search-forward
+ "\\begin{longtable}{lr}
+First & Second\\\\[0pt]
+Column & Column\\\\[0pt]
+\\hline
+\\endfirsthead"))
+ (goto-char (point-min))
+ (should
+ (search-forward
+ "First & Second\\\\[0pt]
+Column & Column \\\\[0pt]
+
+\\hline
+\\endhead"))
+ (goto-char (point-min))
+ (should
+ (search-forward
+ "\\hline\\multicolumn{2}{r}{Continued on next page} \\\\
+\\endfoot"))))
+
(provide 'test-ox-latex)
;;; test-ox-latex.el ends here