4a0d951c647fa9ddd7c2c9d896f5fb5c66fce42c — Daniel Fleischer 10 days ago f77800c
ox-latex tabbing environment support

* lisp/ox-latex.el: New `org-latex--align-string-tabbing',
`org-table--org-tabbing' functions.  Modified `org-latex-table-cell' to
use optional tabbing delimiters.

* etc/ORG-NEWS: support in ox-latex for tabbing environment.

* doc/org-manual.org: mention support for new environment.

Created-by: Bob Vergauwen <emacs@vergauwen.me>
3 files changed, 73 insertions(+), 5 deletions(-)

M doc/org-manual.org
M lisp/ox-latex.el
M doc/org-manual.org => doc/org-manual.org +3 -1
@@ 13546,10 13546,12 @@ include:
  #+vindex: org-latex-default-table-mode
  The LaTeX export back-end wraps the table differently depending on
  the mode for accurate rendering of math symbols.  Mode is either
  =table=, =math=, =inline-math= or =verbatim=.
  =table=, =math=, =inline-math=, =verbatim= or =tabbing=.

  For =math= or =inline-math= mode, LaTeX export back-end wraps the
  table in a math environment, but every cell in it is exported as-is.
  For =tabbing= the LaTeX tabbing environment is used and the correct
  tabbing delimiters =\>= are used.
  The LaTeX export back-end determines the default mode from
  ~org-latex-default-table-mode~.  The LaTeX export back-end merges
  contiguous tables in the same mode into a single environment.

M etc/ORG-NEWS => etc/ORG-NEWS +12 -0
@@ 227,6 227,18 @@ produce results superior to Minted or Listings.
The block type in ~org-structure-template-alist~ is not case-sensitive.
When the block type starts from the upper case, structure template
will now insert =#+BEGIN_TYPE=.  Previously, lower-case =#+begin_type= was inserted unconditionally.
*** New ox-latex tabbing support for tables.

Latex tables can now be exported to the latex tabbing environment
tabbing environment]].
This is done by adding =#+ATTR_LATEX: :mode tabbing= at the top
of the table.
The default column width is set to 1/n times the latex textwidth,
where n is the number of columns.
This behaviour can be changed by supplying a =:align= parameter.

The tabbing environment can be useful when generating simple tables which
can be span multiple pages and when table cells are allowed to overflow.

** New functions and changes in function arguments

M lisp/ox-latex.el => lisp/ox-latex.el +58 -4
@@ 3640,7 3640,8 @@ 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', `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

@@ 3664,8 3665,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.

@@ 3702,6 3705,34 @@ centered."
	(apply 'concat (nreverse align)))))

(defun org-latex--align-string-tabbing (table info)
    "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."
    (or (org-export-read-attribute :attr_latex table :align)
        (let ((align "")
              (count 0)
              (separator ""))
            ;; Count the number of cells in the first row.
            (setq count (length
                      (org-element-map table 'table-row
                        (lambda (row)
                          (and (eq (org-element-property :type row) 'standard) row))
                        info 'first-match)
                    (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 (concat
                         (apply 'concat (make-list count separator))

(defun org-latex--decorate-table (table attributes caption above? info)
  "Decorate TABLE string with caption and float environment.

@@ 3804,6 3835,23 @@ This function assumes TABLE has `org' as its `:type' property and
	(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
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}"
                          (org-latex--align-string-tabbing table info )

(defun org-latex--table.el-table (table info)
  "Return appropriate LaTeX code for a table.el table.

@@ 3887,6 3935,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))
   (let ((scientific-format (plist-get info :latex-table-scientific-notation)))
     (if (and contents

@@ 3898,7 3949,10 @@ a communication channel."
		 (match-string 1 contents)
		 (match-string 2 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