emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: emacs--- via "General discussions about Org-mode." <emacs-orgmode@gnu.org>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: Emacs Orgmode <emacs-orgmode@gnu.org>
Subject: Re: ox-latex table tabbing support.
Date: Mon, 4 Apr 2022 16:03:22 +0200 (CEST)	[thread overview]
Message-ID: <MzosmTn--3-2@vergauwen.me> (raw)
In-Reply-To: <87wng5nno3.fsf@localhost-Mzo7eKN----2>


[-- Attachment #1.1: Type: text/plain, Size: 2810 bytes --]

Hi Ihor,
Thanks for the response. I updated my patched and mailed the requested copyright form to assign@gnu.org

Kind regards,
Bob 

-- 
 Sent with Tutanota, the secure & ad-free mailbox. 



Apr 4, 2022, 12:33 by yantar92@gmail.com:

> emacs--- via "General discussions about Org-mode."
> <emacs-orgmode@gnu.org> writes:
>
>> 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. 
>>
>
> Looks useful. Marking your message as a patch to be tracked at
> updated.orgmode.org
>
> Some comments are below.
>
>> TINYCHANGE
>>
>
> Note that your patch >15 LOC and cannot be applied without copyright
> assignment. See https://orgmode.org/worg/org-contribute.html#copyright
>
>> -;; `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,
>>
>
> We generally try to keep all the text in source files narrower than 70
> characters (default value of fill-column). You can use fill-region to
> make Emacs autofill the comment lines.
>
>> +(defun org-latex--align-string-tabbing (table info &optional math?)
>>
>
> It looks like math? argument is unused. Is it intentional?
>
>> +  "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
>>
>
> You do not need an extra progn inside let.
>
>> +(defun org-table--org-tabbing (table contenst info)
>>
>
> ^contents
>
>> +      "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
>>
>
> ^contents
>
>
> Best,
> Ihor
>


[-- Attachment #1.2: Type: text/html, Size: 4124 bytes --]

[-- Attachment #2: padding-feature.patch --]
[-- Type: application/octet-stream, Size: 6413 bytes --]

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.
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index fd29d39d7..9bcc9fabf 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -77,6 +77,19 @@ 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
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 0edba9e52..50dc4bb1e 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3194,7 +3194,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' 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 +3219,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 +3259,34 @@ centered."
 	  info)
 	(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
+                      (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 (concat
+                         (apply 'concat (make-list count separator))
+                         "\\kill")))
+            ))
+
 (defun org-latex--decorate-table (table attributes caption above? info)
   "Decorate TABLE string with caption and float environment.
 
@@ -3358,6 +3389,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 +3489,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 +3503,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

  parent reply	other threads:[~2022-04-04 14:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-28 14:38 ox-latex table tabbing support emacs--- via General discussions about Org-mode.
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. [this message]
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=MzosmTn--3-2@vergauwen.me \
    --to=emacs-orgmode@gnu.org \
    --cc=emacs@vergauwen.me \
    --cc=yantar92@gmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).