From bddcf5a79c6fb14c6f0c9cd32e3c50d2fec26f9b Mon Sep 17 00:00:00 2001
From: Bob Vergauwen <bob.vergauwen@gmail.com>
Date: Mon, 28 Mar 2022 15:33:15 +0200
Subject: [PATCH 1/3] ox-latex.el: Added padding support

* lisp/ox-latex.el (org-latex-table): Tabbing support.

(org-latex--align-string-tabbing): This function generates
the LaTeX alignment string for the tabbing environment.  An
optional string can be passed to this command via the
`:align' parameter.

(org-table--org-tabbing): Generates the tabbing export
string for latex.

(org-latex-table-cell): This function now checks the type
of the parent table of the cell.  If the parrent type is
set to `padding', the cell separator is set to ` \> '
otherwise the default cell separator ` &- ' is used.

TINYCHANGE
---
 lisp/ox-latex.el | 61 ++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 57 insertions(+), 4 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 0edba9e52..ac710b574 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3194,7 +3194,7 @@ CONTENTS is the contents of the object."
 ;; `org-latex-table' is the entry point for table transcoding.  It
 ;; takes care of tables with a "verbatim" mode.  Otherwise, it
 ;; delegates the job to either `org-latex--table.el-table',
-;; `org-latex--org-table' or `org-latex--math-table' functions,
+;; `org-latex--org-table' or `org-latex--math-table' or `org-latex--org-tabbing' functions,
 ;; depending of the type of the table and the mode requested.
 ;;
 ;; `org-latex--align-string' is a subroutine used to build alignment
@@ -3218,8 +3218,10 @@ contextual information."
 			   `(table nil ,@(org-element-contents table))))))
        ;; Case 2: Matrix.
        ((or (string= type "math") (string= type "inline-math"))
-	(org-latex--math-table table info))
-       ;; Case 3: Standard table.
+        (org-latex--math-table table info))
+       ;; Case 3: Tabbing
+       ((string= type "tabbing") (org-table--org-tabbing table contents info))
+       ;; Case 4: Standard table.
        (t (concat (org-latex--org-table table contents info)
 		  ;; When there are footnote references within the
 		  ;; table, insert their definition just after it.
@@ -3256,6 +3258,34 @@ centered."
 	  info)
 	(apply 'concat (nreverse align)))))
 
+(defun org-latex--align-string-tabbing (table info &optional math?)
+  "Return an appropriate LaTeX alignment string, for the
+latex tabbing environment.
+TABLE is the considered table.  INFO is a plist used as
+a communication channel.  When optional argument MATH? is
+non-nil, TABLE is meant to be a matrix, where all cells are
+centered."
+    (or (org-export-read-attribute :attr_latex table :align)
+        (let ((align "")
+              (count 0)
+              (separator ""))
+          (progn
+            ;; Count the number of cells in the first row.
+            (setq count (length
+                  (org-element-map
+                      (org-element-map table 'table-row
+                        (lambda (row)
+                          (and (eq (org-element-property :type row) 'standard) row))
+                        info 'first-match)
+                      'table-cell
+                    (lambda (cell) cell))))
+            ;; Calculate the column width, using a proportion of the documets
+            ;; textwidth.
+            (setq separator (format "\\hspace{%s\\textwidth} \\= " (- (/  1.0 count) 0.01)))
+             (setq align (apply 'concat (make-list count separator)))
+             (setq align (concat align "\\kill")))
+            )))
+
 (defun org-latex--decorate-table (table attributes caption above? info)
   "Decorate TABLE string with caption and float environment.
 
@@ -3358,6 +3388,23 @@ This function assumes TABLE has `org' as its `:type' property and
 			    table-env)))
 	(org-latex--decorate-table output attr caption above? info))))))
 
+
+(defun org-table--org-tabbing (table contenst info)
+      "Return appropriate LaTeX code for an Org table, using the
+latex tabbing syntax.
+TABLE is the table type element to transcode.  CONTENTS is its
+contents, as a string.  INFO is a plist used as a communication
+channel.
+This function assumes TABLE has `org' as its `:type' property and
+`tabbing' as its `:mode' attribute."
+    (let ((output (format "\\begin{%s}\n%s\n%s\\end{%s}"
+                          "tabbing"
+                          (org-latex--align-string-tabbing table info )
+                          contenst
+                          "tabbing")))
+      output)
+    )
+
 (defun org-latex--table.el-table (table info)
   "Return appropriate LaTeX code for a table.el table.
 
@@ -3441,6 +3488,9 @@ This function assumes TABLE has `org' as its `:type' property and
   "Transcode a TABLE-CELL element from Org to LaTeX.
 CONTENTS is the cell contents.  INFO is a plist used as
 a communication channel."
+  (let (
+        (type (org-export-read-attribute :attr_latex (org-export-get-parent-table table-cell) :mode))
+        )
   (concat
    (let ((scientific-format (plist-get info :latex-table-scientific-notation)))
      (if (and contents
@@ -3452,7 +3502,10 @@ a communication channel."
 		 (match-string 1 contents)
 		 (match-string 2 contents))
        contents))
-   (when (org-export-get-next-element table-cell info) " & ")))
+   (when (org-export-get-next-element table-cell info)
+         (if (string= type "tabbing")
+             " \\> " " & ")
+         ))))
 
 
 ;;;; Table Row
-- 
2.30.1 (Apple Git-130)

