From: emacs--- via "General discussions about Org-mode." <emacs-orgmode@gnu.org> To: emacs-orgmode@gnu.org Subject: ox-latex table tabbing support. Date: Mon, 28 Mar 2022 16:38:16 +0200 (CEST) [thread overview] Message-ID: <MzFxcjy--7-2@vergauwen.me> (raw) [-- Attachment #1.1: Type: text/plain, Size: 1713 bytes --] Dear all, I have implemented tabbing (http://www.ctex.org/documents/latex/latex2e-html/ltx-58.html) support for ox-latex. By setting #+ATTR_LATEX: :mode tabbingthe exporter will use the tabbing environment. The benefits of using tabbing over tabular: - Can span multiple pages (also possible with long tables). - Cell width is fixed and does not depend on the content. - Cells can overflow. Use cases of tabbing: - Generate letter headings with fixed layout - Generate tables on invoices - Can replace multi-columns (my personal use case) Example 1: #+ATTR_LATEX: :mode tabbing | A | B | | | C | is exported to \begin{tabbing} \hspace{0.49\textwidth} \= \hspace{0.49\textwidth} \= \kill A \> B\\ \> C\\ \end{tabbing} Example 2: #+ATTR_LATEX: :mode tabbing | *Address* | Some street 100, box 101 | | *GSM* | 00 000 00 00 00 | | | Country | | *Email* | mail@example.com | the exported pdf is attached to this mail. Example 3: #+ATTR_LATEX: :mode tabbing :align \hspace{2cm} \= \hspace{2cm} \= \kill | name: | A very long product name in this cell | | | options: | option 1 | 1 | | | option 2 | 1 | | | option 3 | 0 | the exported pdf is attached to this mail. Implementation details: - The table environment must be set to tabbing - The cell separators must be set to \> - The alignment string must be updated. Kind regards, Bob Vergauwen [-- Attachment #1.2: Type: text/html, Size: 3782 bytes --] [-- Attachment #2: 0001-ox-latex.el-Added-padding-support.patch --] [-- Type: application/octet-stream, Size: 5493 bytes --] 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) [-- Attachment #3: 0002-org-manual.org-Added-padding-feature-to-the-manual.patch --] [-- Type: application/octet-stream, Size: 1403 bytes --] From 95c5f19f98ee177f00a3d2389a5b96a667d71176 Mon Sep 17 00:00:00 2001 From: Bob Vergauwen <bob.vergauwen@gmail.com> Date: Mon, 28 Mar 2022 15:52:24 +0200 Subject: [PATCH 2/3] org-manual.org: Added padding feature to the manual * doc/org-manual.org (Tables in LaTeX export): Added the documentation of the padding feature to the documentation of the LaTeX table exporter. TINYCHANGE --- doc/org-manual.org | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 49d906c27..e3bd61bc8 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -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. -- 2.30.1 (Apple Git-130) [-- Attachment #4: 0003-ORG-NEWS-Added-padding-feature-to-version-9.6.patch --] [-- Type: application/octet-stream, Size: 1446 bytes --] From cec5c642fe1d2e6ffd8710bdf1edd2ad7018ce47 Mon Sep 17 00:00:00 2001 From: Bob Vergauwen <bob.vergauwen@gmail.com> Date: Mon, 28 Mar 2022 15:55:48 +0200 Subject: [PATCH 3/3] ORG-NEWS: Added padding feature to version 9.6 * etc/ORG-NEWS: (New features): Added the tabbing feature to the list of new features for the 9.6 release of org-mode. TINYCHANGE --- etc/ORG-NEWS | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index fd29d39d7..df0bf4778 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -77,6 +77,18 @@ Items in a description list that begin with =Function:=, =Variable:= or certain related prefixes are converted using Texinfo definition commands. +*** New ox-latex tabbing support for tables. + +Latex tables can now be exported to the latex tabbing environment [[https://latexref.xyz/tabbing.html][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 *** New function ~org-element-cache-map~ for quick mapping across Org elements -- 2.30.1 (Apple Git-130) [-- Attachment #5: padding-example.pdf --] [-- Type: application/pdf, Size: 37897 bytes --]
next reply other threads:[~2022-03-28 14:46 UTC|newest] Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-03-28 14:38 emacs--- via General discussions about Org-mode. [this message] 2022-04-04 10:33 ` Ihor Radchenko [not found] ` <87wng5nno3.fsf@localhost-Mzo7eKN----2> 2022-04-04 14:03 ` emacs--- via General discussions about Org-mode. 2022-06-21 4:43 ` Daniel Fleischer 2022-06-24 13:37 ` Robert Pluim 2022-06-24 14:20 ` Daniel Fleischer 2022-06-24 15:01 ` Robert Pluim 2022-06-24 15:50 ` Daniel Fleischer 2022-06-24 19:32 ` emacs--- via General discussions about Org-mode. 2022-06-25 3:32 ` Ihor Radchenko 2022-06-26 10:08 ` Robert Pluim 2022-06-26 13:47 ` [PATCH] describe how to override Author Robert Pluim 2022-06-26 14:04 ` Daniel Fleischer 2022-06-27 9:53 ` Ihor Radchenko 2022-06-28 12:07 ` Robert Pluim 2022-06-29 10:10 ` Ihor Radchenko 2022-06-30 8:18 ` Robert Pluim 2022-06-30 13:19 ` Ihor Radchenko 2022-06-30 15:17 ` Robert Pluim 2022-07-02 4:21 ` Ihor Radchenko 2022-06-26 1:54 ` ox-latex table tabbing support Ihor Radchenko 2022-06-26 3:49 ` Kyle Meyer 2022-06-26 14:46 ` [PATCH] " Daniel Fleischer 2022-06-26 18:18 ` Kyle Meyer 2022-06-26 18:48 ` Daniel Fleischer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://www.orgmode.org/ * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=MzFxcjy--7-2@vergauwen.me \ --to=emacs-orgmode@gnu.org \ --cc=emacs@vergauwen.me \ --subject='Re: ox-latex table tabbing support.' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this inbox: https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).