Skip to content

Commit 4a0d951

Browse files
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>
1 parent f77800c commit 4a0d951

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

doc/org-manual.org

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13546,10 +13546,12 @@ include:
1354613546
#+vindex: org-latex-default-table-mode
1354713547
The LaTeX export back-end wraps the table differently depending on
1354813548
the mode for accurate rendering of math symbols. Mode is either
13549-
=table=, =math=, =inline-math= or =verbatim=.
13549+
=table=, =math=, =inline-math=, =verbatim= or =tabbing=.
1355013550

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

etc/ORG-NEWS

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ produce results superior to Minted or Listings.
227227
The block type in ~org-structure-template-alist~ is not case-sensitive.
228228
When the block type starts from the upper case, structure template
229229
will now insert =#+BEGIN_TYPE=. Previously, lower-case =#+begin_type= was inserted unconditionally.
230+
*** New ox-latex tabbing support for tables.
231+
232+
Latex tables can now be exported to the latex tabbing environment
233+
tabbing environment]].
234+
This is done by adding =#+ATTR_LATEX: :mode tabbing= at the top
235+
of the table.
236+
The default column width is set to 1/n times the latex textwidth,
237+
where n is the number of columns.
238+
This behaviour can be changed by supplying a =:align= parameter.
239+
240+
The tabbing environment can be useful when generating simple tables which
241+
can be span multiple pages and when table cells are allowed to overflow.
230242

231243
** New functions and changes in function arguments
232244

lisp/ox-latex.el

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,7 +3640,8 @@ CONTENTS is the contents of the object."
36403640
;; `org-latex-table' is the entry point for table transcoding. It
36413641
;; takes care of tables with a "verbatim" mode. Otherwise, it
36423642
;; delegates the job to either `org-latex--table.el-table',
3643-
;; `org-latex--org-table' or `org-latex--math-table' functions,
3643+
;; `org-latex--org-table', `org-latex--math-table' or
3644+
;; `org-latex--org-tabbing' functions,
36443645
;; depending of the type of the table and the mode requested.
36453646
;;
36463647
;; `org-latex--align-string' is a subroutine used to build alignment
@@ -3664,8 +3665,10 @@ contextual information."
36643665
`(table nil ,@(org-element-contents table))))))
36653666
;; Case 2: Matrix.
36663667
((or (string= type "math") (string= type "inline-math"))
3667-
(org-latex--math-table table info))
3668-
;; Case 3: Standard table.
3668+
(org-latex--math-table table info))
3669+
;; Case 3: Tabbing
3670+
((string= type "tabbing") (org-table--org-tabbing table contents info))
3671+
;; Case 4: Standard table.
36693672
(t (concat (org-latex--org-table table contents info)
36703673
;; When there are footnote references within the
36713674
;; table, insert their definition just after it.
@@ -3702,6 +3705,34 @@ centered."
37023705
info)
37033706
(apply 'concat (nreverse align)))))
37043707

3708+
(defun org-latex--align-string-tabbing (table info)
3709+
"Return an appropriate LaTeX alignment string, for the
3710+
latex tabbing environment.
3711+
TABLE is the considered table. INFO is a plist used as
3712+
a communication channel."
3713+
(or (org-export-read-attribute :attr_latex table :align)
3714+
(let ((align "")
3715+
(count 0)
3716+
(separator ""))
3717+
;; Count the number of cells in the first row.
3718+
(setq count (length
3719+
(org-element-map
3720+
(org-element-map table 'table-row
3721+
(lambda (row)
3722+
(and (eq (org-element-property :type row) 'standard) row))
3723+
info 'first-match)
3724+
'table-cell
3725+
(lambda (cell) cell))))
3726+
;; Calculate the column width, using a proportion of the documets
3727+
;; textwidth.
3728+
(setq separator (format
3729+
"\\hspace{%s\\textwidth} \\= "
3730+
(- (/ 1.0 count) 0.01)))
3731+
(setq align (concat
3732+
(apply 'concat (make-list count separator))
3733+
"\\kill")))
3734+
))
3735+
37053736
(defun org-latex--decorate-table (table attributes caption above? info)
37063737
"Decorate TABLE string with caption and float environment.
37073738
@@ -3804,6 +3835,23 @@ This function assumes TABLE has `org' as its `:type' property and
38043835
table-env)))
38053836
(org-latex--decorate-table output attr caption above? info))))))
38063837

3838+
3839+
(defun org-table--org-tabbing (table contenst info)
3840+
"Return appropriate LaTeX code for an Org table, using the
3841+
latex tabbing syntax.
3842+
TABLE is the table type element to transcode. CONTENTS is its
3843+
contents, as a string. INFO is a plist used as a communication
3844+
channel.
3845+
This function assumes TABLE has `org' as its `:type' property and
3846+
`tabbing' as its `:mode' attribute."
3847+
(let ((output (format "\\begin{%s}\n%s\n%s\\end{%s}"
3848+
"tabbing"
3849+
(org-latex--align-string-tabbing table info )
3850+
contenst
3851+
"tabbing")))
3852+
output)
3853+
)
3854+
38073855
(defun org-latex--table.el-table (table info)
38083856
"Return appropriate LaTeX code for a table.el table.
38093857
@@ -3887,6 +3935,9 @@ This function assumes TABLE has `org' as its `:type' property and
38873935
"Transcode a TABLE-CELL element from Org to LaTeX.
38883936
CONTENTS is the cell contents. INFO is a plist used as
38893937
a communication channel."
3938+
(let (
3939+
(type (org-export-read-attribute :attr_latex (org-export-get-parent-table table-cell) :mode))
3940+
)
38903941
(concat
38913942
(let ((scientific-format (plist-get info :latex-table-scientific-notation)))
38923943
(if (and contents
@@ -3898,7 +3949,10 @@ a communication channel."
38983949
(match-string 1 contents)
38993950
(match-string 2 contents))
39003951
contents))
3901-
(when (org-export-get-next-element table-cell info) " & ")))
3952+
(when (org-export-get-next-element table-cell info)
3953+
(if (string= type "tabbing")
3954+
" \\> " " & ")
3955+
))))
39023956

39033957

39043958
;;;; Table Row

0 commit comments

Comments
 (0)