emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Support for tabularray in LaTeX export
@ 2021-09-02  0:42 Vikas Rawal
  2021-09-02  8:36 ` Juan Manuel Macías
  0 siblings, 1 reply; 6+ messages in thread
From: Vikas Rawal @ 2021-09-02  0:42 UTC (permalink / raw)
  To: org-mode mailing list

[-- Attachment #1: Type: text/plain, Size: 866 bytes --]

tabularray (CTAN: Package tabularray <https://ctan.org/pkg/tabularray>)
provides longtblr environment that is called as

---
\begin{longtblr}[various-table-options]{column and row specifications}

\end{longtblr}
---

Adding something like the following to orgmode tables makes them export
nicely as longtblr

---
#+ATTR_LATEX: :environment longtblr
#+ATTR_LATEX: :align
width=0.8\textwidth,colspec={lX[2,r]X[3,r]X[r,bg=gray9]}
#+ATTR_LATEX: :booktabs t
---

Everything seems to work very well with orgmode except that I cannot figure
out how to pass [various table options] from orgmode. These table options
include, most importantly, table notes.

I normally use threeparttable for table notes, but longtblr does not seem
to work with threeparttable and has its own syntax for table notes.

Any advice on how to pass [table-options] to longtblr environment?

Vikas

[-- Attachment #2: Type: text/html, Size: 1147 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Support for tabularray in LaTeX export
  2021-09-02  0:42 Support for tabularray in LaTeX export Vikas Rawal
@ 2021-09-02  8:36 ` Juan Manuel Macías
  2021-09-02 10:08   ` Vikas Rawal
  0 siblings, 1 reply; 6+ messages in thread
From: Juan Manuel Macías @ 2021-09-02  8:36 UTC (permalink / raw)
  To: Vikas Rawal; +Cc: orgmode

Hi Vikas,

You can define a modified version of `org-latex--org-table',
adding a new LaTeX attribute `:options'. Something like this:

#+begin_src emacs-lisp
(defun my/org-latex--org-table (table contents info)
  "Return appropriate LaTeX code for an Org table.

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
`table' as its `:mode' attribute."
  (let* ((attr (org-export-read-attribute :attr_latex table))
         (alignment (org-latex--align-string table info))
         (opt (org-export-read-attribute :attr_latex table :options))
         (table-env (or (plist-get attr :environment)
                        (plist-get info :latex-default-table-environment)))
         (width
          (let ((w (plist-get attr :width)))
            (cond ((not w) "")
                  ((member table-env '("tabular" "longtable")) "")
                  ((member table-env '("tabu" "longtabu"))
                   (format (if (plist-get attr :spread) " spread %s "
                             " to %s ")
                           w))
                  (t (format "{%s}" w)))))
         (caption (org-latex--caption/label-string table info))
         (above? (org-latex--caption-above-p table info)))
    (cond
     ((member table-env '("longtable" "longtabu"))
      (let ((fontsize (let ((font (plist-get attr :font)))
                        (and font (concat font "\n")))))
        (concat (and fontsize (concat "{" fontsize))
                (format "\\begin{%s}%s{%s}\n" table-env width alignment)
                (and above?
                     (org-string-nw-p caption)
                     (concat caption "\\\\\n"))
                contents
                (and (not above?)
                     (org-string-nw-p caption)
                     (concat caption "\\\\\n"))
                (format "\\end{%s}" table-env)
                (and fontsize "}"))))
     (t
      (let ((output (format "\\begin{%s}%s%s{%s}\n%s\\end{%s}"
                            table-env
                            (if opt opt "")
                            width
                            alignment
                            contents
                            table-env)))
        (org-latex--decorate-table output attr caption above? info))))))

(advice-add 'org-latex--org-table :override #'my/org-latex--org-table)
#+end_src

and then:

#+ATTR_LATEX: :environment longtblr
#+ATTR_LATEX: :align <align-options>
#+ATTR_LATEX: :booktabs t
#+ATTR_LaTeX: :options [<options>]

Best regards,

Juan Manuel

Vikas Rawal writes:

> tabularray (CTAN: Package tabularray) provides longtblr environment
> that is called as
>
> ---
> \begin{longtblr}[various-table-options]{column and row specifications}
>
> \end{longtblr}
> ---
>
> Adding something like the following to orgmode tables makes them
> export nicely as longtblr
>
> ---
> #+ATTR_LATEX: :environment longtblr
> #+ATTR_LATEX: :align width=0.8\textwidth,colspec={lX[2,r]X[3,r]X
> [r,bg=gray9]}
> #+ATTR_LATEX: :booktabs t
> ---
>
> Everything seems to work very well with orgmode except that I cannot
> figure out how to pass [various table options] from orgmode. These
> table options include, most importantly, table notes.
>
> I normally use threeparttable for table notes, but longtblr does not
> seem to work with threeparttable and has its own syntax for table
> notes.
>
> Any advice on how to pass [table-options] to longtblr environment?
>
> Vikas
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Support for tabularray in LaTeX export
  2021-09-02  8:36 ` Juan Manuel Macías
@ 2021-09-02 10:08   ` Vikas Rawal
  2021-10-25 14:04     ` Vikas Rawal
  0 siblings, 1 reply; 6+ messages in thread
From: Vikas Rawal @ 2021-09-02 10:08 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: orgmode

[-- Attachment #1: Type: text/plain, Size: 3992 bytes --]

This is perfect. Thank you, Juan Manuel.

Vikas

On Thu, 2 Sept 2021 at 14:06, Juan Manuel Macías <maciaschain@posteo.net>
wrote:

> Hi Vikas,
>
> You can define a modified version of `org-latex--org-table',
> adding a new LaTeX attribute `:options'. Something like this:
>
> #+begin_src emacs-lisp
> (defun my/org-latex--org-table (table contents info)
>   "Return appropriate LaTeX code for an Org table.
>
> 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
> `table' as its `:mode' attribute."
>   (let* ((attr (org-export-read-attribute :attr_latex table))
>          (alignment (org-latex--align-string table info))
>          (opt (org-export-read-attribute :attr_latex table :options))
>          (table-env (or (plist-get attr :environment)
>                         (plist-get info :latex-default-table-environment)))
>          (width
>           (let ((w (plist-get attr :width)))
>             (cond ((not w) "")
>                   ((member table-env '("tabular" "longtable")) "")
>                   ((member table-env '("tabu" "longtabu"))
>                    (format (if (plist-get attr :spread) " spread %s "
>                              " to %s ")
>                            w))
>                   (t (format "{%s}" w)))))
>          (caption (org-latex--caption/label-string table info))
>          (above? (org-latex--caption-above-p table info)))
>     (cond
>      ((member table-env '("longtable" "longtabu"))
>       (let ((fontsize (let ((font (plist-get attr :font)))
>                         (and font (concat font "\n")))))
>         (concat (and fontsize (concat "{" fontsize))
>                 (format "\\begin{%s}%s{%s}\n" table-env width alignment)
>                 (and above?
>                      (org-string-nw-p caption)
>                      (concat caption "\\\\\n"))
>                 contents
>                 (and (not above?)
>                      (org-string-nw-p caption)
>                      (concat caption "\\\\\n"))
>                 (format "\\end{%s}" table-env)
>                 (and fontsize "}"))))
>      (t
>       (let ((output (format "\\begin{%s}%s%s{%s}\n%s\\end{%s}"
>                             table-env
>                             (if opt opt "")
>                             width
>                             alignment
>                             contents
>                             table-env)))
>         (org-latex--decorate-table output attr caption above? info))))))
>
> (advice-add 'org-latex--org-table :override #'my/org-latex--org-table)
> #+end_src
>
> and then:
>
> #+ATTR_LATEX: :environment longtblr
> #+ATTR_LATEX: :align <align-options>
> #+ATTR_LATEX: :booktabs t
> #+ATTR_LaTeX: :options [<options>]
>
> Best regards,
>
> Juan Manuel
>
> Vikas Rawal writes:
>
> > tabularray (CTAN: Package tabularray) provides longtblr environment
> > that is called as
> >
> > ---
> > \begin{longtblr}[various-table-options]{column and row specifications}
> >
> > \end{longtblr}
> > ---
> >
> > Adding something like the following to orgmode tables makes them
> > export nicely as longtblr
> >
> > ---
> > #+ATTR_LATEX: :environment longtblr
> > #+ATTR_LATEX: :align width=0.8\textwidth,colspec={lX[2,r]X[3,r]X
> > [r,bg=gray9]}
> > #+ATTR_LATEX: :booktabs t
> > ---
> >
> > Everything seems to work very well with orgmode except that I cannot
> > figure out how to pass [various table options] from orgmode. These
> > table options include, most importantly, table notes.
> >
> > I normally use threeparttable for table notes, but longtblr does not
> > seem to work with threeparttable and has its own syntax for table
> > notes.
> >
> > Any advice on how to pass [table-options] to longtblr environment?
> >
> > Vikas
> >
>

[-- Attachment #2: Type: text/html, Size: 5197 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Support for tabularray in LaTeX export
  2021-09-02 10:08   ` Vikas Rawal
@ 2021-10-25 14:04     ` Vikas Rawal
  2021-10-25 14:18       ` Juan Manuel Macías
  0 siblings, 1 reply; 6+ messages in thread
From: Vikas Rawal @ 2021-10-25 14:04 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: orgmode


>
>     Hi Vikas,
>
>     You can define a modified version of `org-latex--org-table',
>     adding a new LaTeX attribute `:options'. Something like this:

Is there a case for incorporating this in orgmode itself? There is some general utility for this in my view.


Vikas


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Support for tabularray in LaTeX export
  2021-10-25 14:04     ` Vikas Rawal
@ 2021-10-25 14:18       ` Juan Manuel Macías
  2021-10-25 17:25         ` Thomas Dye
  0 siblings, 1 reply; 6+ messages in thread
From: Juan Manuel Macías @ 2021-10-25 14:18 UTC (permalink / raw)
  To: Vikas Rawal; +Cc: orgmode

Vikas Rawal writes:

>>
>>     Hi Vikas,
>>
>>     You can define a modified version of `org-latex--org-table',
>>     adding a new LaTeX attribute `:options'. Something like this:
>
> Is there a case for incorporating this in orgmode itself? There is some general utility for this in my view.

I can prepare a patch based on that code, if you consider it useful
(https://list.orgmode.org/87ilzjgyqg.fsf@posteo.net/)

Best regards,

Juan Manuel 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Support for tabularray in LaTeX export
  2021-10-25 14:18       ` Juan Manuel Macías
@ 2021-10-25 17:25         ` Thomas Dye
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Dye @ 2021-10-25 17:25 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: Vikas Rawal, orgmode


> On Oct 25, 2021, at 4:23 AM, Juan Manuel Macías <maciaschain@posteo.net> wrote:
> 
> Vikas Rawal writes:
> 
>>> 
>>>    Hi Vikas,
>>> 
>>>    You can define a modified version of `org-latex--org-table',
>>>    adding a new LaTeX attribute `:options'. Something like this:
>> 
>> Is there a case for incorporating this in orgmode itself? There is some general utility for this in my view.
> 
> I can prepare a patch based on that code, if you consider it useful
> (https://list.orgmode.org/87ilzjgyqg.fsf@posteo.net/)
> 
> Best regards,
> 
> Juan Manuel 
> 
+1

All the best,
Tom


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-25 17:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02  0:42 Support for tabularray in LaTeX export Vikas Rawal
2021-09-02  8:36 ` Juan Manuel Macías
2021-09-02 10:08   ` Vikas Rawal
2021-10-25 14:04     ` Vikas Rawal
2021-10-25 14:18       ` Juan Manuel Macías
2021-10-25 17:25         ` Thomas Dye

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).