emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: Vikas Rawal <vikasrawal@gmail.com>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: Support for tabularray in LaTeX export
Date: Thu, 02 Sep 2021 08:36:55 +0000	[thread overview]
Message-ID: <87ilzjgyqg.fsf@posteo.net> (raw)
In-Reply-To: <CALtzAB1yM+uG_xHghCxTLRX5mgbzNvT5+PO=DuaBB28nCsVqEA@mail.gmail.com> (Vikas Rawal's message of "Thu, 2 Sep 2021 06:12:43 +0530")

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
>


  reply	other threads:[~2021-09-02  8:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-02  0:42 Vikas Rawal
2021-09-02  8:36 ` Juan Manuel Macías [this message]
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

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=87ilzjgyqg.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=vikasrawal@gmail.com \
    --subject='Re: Support for tabularray in LaTeX export' \
    /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).