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: [patch] ox-latex.el: add `:options' LaTeX attribute to tables
Date: Wed, 27 Oct 2021 15:52:07 +0000	[thread overview]
Message-ID: <87a6iu79eg.fsf@posteo.net> (raw)
In-Reply-To: <20211027034448.ijd337kvnmd3fje2@dalkati> (Vikas Rawal's message of "Wed, 27 Oct 2021 09:14:48 +0530")

Hi Vikas,

Vikas Rawal writes:

> This is excellent. There is only one improvement that I would like you to consider. Is it possible to allow multiple ":options " lines that are appended when exported to
> +latex? Something like this:
> #+ATTR_LATEX: :environment longtblr
> #+ATTR_LATEX: :align colspec = {XXX}, width = 0.85\linewidth
> #+ATTR_LATEX: :options remark{Note} = {Lorem ipsum dolor sit amet}
> #+ATTR_LATEX: :options remark{Source} = {The source of data}
>  ==> \begin{longtblr}[remark{Note} = {Lorem ipsum dolor sit amet},
>                       remark{Source} = {The source of data}]{colspec = {XXX}, width = 0.85\linewidth}
> This would be more elegant since table notes can be elaborate and putting them all in one line would make them unwieldy.
> At the moment, only the last ":options" line is considered.

The normal behavior is that you cannot put more than one property
`:foo', because in that case only the value of the last one is added
when exporting to LaTeX (ther is a property list where each property has
a string value).

I can think of a somewhat tricky solution, in case you want to adapt it
to your use case:

First, you need to convert a plist to an alist (source:

#+begin_src emacs-lisp
(defun plist->alist (plist)
  (if (null plist)
     (list (car plist) (cadr plist))
     (plist->alist (cddr plist)))))

And this would be the modified function:

#+begin_src emacs-lisp
(defun 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

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))
	 ;; various `:options' props ;;;; <== modified from here
	 (attr-alist (plist->alist attr))
	 (options-str (progn
			(mapc (lambda (m)
				(when (eq (car m) :options)
				  (add-to-list 'options-list (cdr m))))
			(mapconcat (lambda (x) (mapconcat 'identity x "")) options-list " ")))
	 ;;;;;;;; < == to here
	 (table-env (or (plist-get attr :environment)
			(plist-get info :latex-default-table-environment)))
	  (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 ")
		  (t (format "{%s}" w)))))
	 (caption (org-latex--caption/label-string table info))
	 (above? (org-latex--caption-above-p table info)))
     ((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"))
		(and (not above?)
		     (org-string-nw-p caption)
		     (concat caption "\\\\\n"))
		(format "\\end{%s}" table-env)
		(and fontsize "}"))))
      (let ((output (format "\\begin{%s}%s%s{%s}\n%s\\end{%s}"
                            ;; modified here
			    (if options-list (format "[%s]" options-str) "")
	(org-latex--decorate-table output attr caption above? info))))))

Pleas tell me if it works for you.

Best regards,

Juan Manuel 

  reply	other threads:[~2021-10-27 16:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-26 16:05 Juan Manuel Macías
2021-10-27  3:44 ` Vikas Rawal
2021-10-27 15:52   ` Juan Manuel Macías [this message]
2021-10-28 16:10     ` Vikas Rawal
2021-10-28 18:02       ` Juan Manuel Macías
2021-10-28 19:39         ` Juan Manuel Macías
2021-10-29  1:13           ` Vikas Rawal
2021-10-29  1:07         ` Vikas Rawal
2021-10-29  1:08         ` Vikas Rawal
2021-11-03 16:32 ` Nicolas Goaziou
2021-11-03 17:38   ` Juan Manuel Macías
2021-11-03 18:33     ` Nicolas Goaziou
2021-11-04 20:59       ` Juan Manuel Macías
2021-11-06 13:51         ` Nicolas Goaziou

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:

  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=87a6iu79eg.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=vikasrawal@gmail.com \


* 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


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