Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-11-06 Thread Nicolas Goaziou
Hello,

Juan Manuel Macías  writes:

> Attached here the updated patch.

Applied. Thank you.

I added two spaces between sentences in org-manual.org.

Regards,
-- 
Nicolas Goaziou



Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-11-04 Thread Juan Manuel Macías
Hi Nicolas,

Nicolas Goaziou writes:

> Good idea. Thanks.

Attached here the updated patch.

Best regards,

Juan Manuel 
>From fc9062caf43956ac68b72f16afbd5584ec84e687 Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias 
Date: Thu, 4 Nov 2021 21:38:26 +0100
Subject: [PATCH] ox-latex.el: add `options' latex attribute to tables

* lisp/ox-latex.el (org-latex--org-table): The `:options' LaTeX
attribute allows adding an optional argument (`\begin{env}[opt]'),
since certain tabular environments, such as `longtblr', accept optional
arguments.
* doc/org-manual.org (Tables in LaTeX export): this feature in the manual.
* etc/ORG-NEWS (New :options attribute when exporting tables to
LaTeX): this feature in `ORG-NEWS'.
---
 doc/org-manual.org |  9 +
 etc/ORG-NEWS   | 14 ++
 lisp/ox-latex.el   |  4 +++-
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index af88b8506..50cdb9101 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -13572,6 +13572,14 @@ include:
   The LaTeX export back-end uses these attributes for regular tables
   to set their alignments, fonts, and widths.
 
+- =:options= ::
+
+  The =:options= attribute allows adding an optional argument with a
+  list of various table options (between brackets in LaTeX export),
+  since certain tabular environments, such as =longtblr= of the
+  =tabularray= LaTeX package, provides this structure. For example:
+  =:options remark{Note}={note},remark{Source}={source}=.
+
 - =:spread= ::
 
   When =:spread= is non-~nil~, the LaTeX export back-end spreads or
@@ -19770,6 +19778,7 @@ moves across a special context.
   (add-to-list 'org-tab-first-hook 'yas/org-very-safe-expand)
   (define-key yas/keymap [tab] 'yas/next-field)))
   #+end_src
+
 ** Using Org on a TTY
 :PROPERTIES:
 :DESCRIPTION: Using Org on a tty.
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index d73d0d3c3..626e19335 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -53,6 +53,13 @@ structures is supported.  Storing references between different
 variables is also supported (see =:inherit= key in
 ~org-persist-register~).
 
+*** New :options attribute when exporting tables to LaTeX 
+
+The =:options= attribute allows adding an optional argument with a
+list of various table options (between brackets in LaTeX export),
+since certain tabular environments, such as =longtblr= of the
+=tabularray= LaTeX package, provides this structure.
+
 ** New functions and changes in function arguments
 
 *** New function ~org-element-cache-map~ for quick mapping across Org elements
@@ -1555,6 +1562,7 @@ the headline to use for making the table of contents.
 ,* Another section
 ,#+TOC: headlines 1 :target "#TargetSection"
 #+end_example
+
 ** New functions
 *** ~org-dynamic-block-insert-dblock~
 
@@ -1845,6 +1853,7 @@ CIDER version which has not =sesman= integrated, only has
 (dissoc Clojure 'JVM)
 (conj clojurists "stardiviner")
 #+end_src
+
 *** Add ~:results link~ support for Babel
 
 With this output format, create a link to the file specified in
@@ -1863,14 +1872,17 @@ wget -c "https://ben.akrin.com/crackzor/crackzor_1.0.c.gz;
 #+begin_src js :session "*Javascript REPL*"
 console.log("stardiviner")
 #+end_src
+
 *** Add ~:session~ support of ob-js for Indium
 #+begin_src js :session "*JS REPL*"
 console.log("stardiviner")
 #+end_src
+
 *** Add ~:session~ support of ob-js for skewer-mode
 #+begin_src js :session "*skewer-repl*"
 console.log("stardiviner")
 #+end_src
+
 *** Add support for links to LaTeX equations in HTML export
 Use MathJax links when enabled (by ~org-html-with-latex~), otherwise
 add a label to the rendered equation.
@@ -1957,6 +1969,7 @@ you should expect to see something like:
 #+BEGIN_EXAMPLE
   ,#+STARTUP: shrink
 #+END_EXAMPLE
+
 *** Allow to filter by tags/property when capturing colview
 
 You can now use =:match= to filter entries using a todo/tags/properties
@@ -2339,6 +2352,7 @@ To use =vertica= in an sql =SRC_BLK= set the =:engine= like this:
   SELECT * FROM nodes;
   ,#+END_SRC
 #+END_EXAMPLE
+
  C++: New header ~:namespaces~
 
 The new ~:namespaces~ export option can be used to specify namespaces
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 3e3967033..409d92164 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3314,6 +3314,7 @@ 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
@@ -3343,8 +3344,9 @@ This function assumes TABLE has `org' as its `:type' property and
 		(format "\\end{%s}" table-env)
 		(and fontsize "}"
  (t
-  (let ((output (format "\\begin{%s}%s{%s}\n%s\\end{%s}"
+  (let ((output (format 

Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-11-03 Thread Nicolas Goaziou
Juan Manuel Macías  writes:

> Of course, tomorrow I will upload an updated version of the patch with
> the documentation in the manual. Should I also add an entry in ORG-NEWS,
> in "Version 9.6" node?

Good idea. Thanks.

Regards,



Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-11-03 Thread Juan Manuel Macías
Hi Nicolas,

Nicolas Goaziou writes:

> Thank you.
>
> Could you also document it in the manual?

Of course, tomorrow I will upload an updated version of the patch with
the documentation in the manual. Should I also add an entry in ORG-NEWS,
in "Version 9.6" node?

Best regards,

Juan Manuel 



Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-11-03 Thread Nicolas Goaziou
Hello,

Juan Manuel Macías  writes:

> The `:options' attr. allows adding an optional argument with various
> table options (between brackets in LaTeX export), since certain tabular
> environments, such as `longtblr' of the `tabularray' LaTeX package,
> provides this structure (see:
> https://list.orgmode.org/CALtzAB1yM+uG_xHghCxTLRX5mgbzNvT5+PO=duabb28ncsv...@mail.gmail.com/#r)
>
> Example:
>
> #+ATTR_LATEX: :environment longtblr
> #+ATTR_LATEX: :align colspec = {XXX}, width = 0.85\linewidth
> #+ATTR_LATEX: :options remark{Note} = {Lorem ipsum dolor sit amet}
>
> ==> \begin{longtblr}[remark{Note} = {Lorem ipsum dolor sit amet}]{colspec = 
> {XXX}, width = 0.85\linewidth}

Thank you.

Could you also document it in the manual?

Regards,
-- 
Nicolas Goaziou



Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-10-28 Thread Vikas Rawal
>
> Do you still keep this line in your init:
>
> (advice-add 'org-latex--org-table :override #'my/org-latex--org-table) ?

You were right. My bad.

I confirm, the new function works and is a significant improvement.

Vikas



Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-10-28 Thread Vikas Rawal
> > \begin{longtblr}[options 1 options 2 options 3 options 4]{align}
>
> PS: I think the options should be separated by commas. In this
> case, it's necessary to replace the line:
>
> (mapconcat (lambda (x) (mapconcat 'identity x "")) options-list " ")))
>
> by this line:
>
> (mapconcat (lambda (x) (mapconcat 'identity x "")) options-list ",")))

I think the user can just write the comma in the option lines. It
might be more flexible to leave it to the user. I am just thinking of
a possibility that some other package may require a different
delimiter between options.

But others may have a different view.

I think this modification is useful and an improvement, and should be 
incorporated in orgmode itself.

I expect Nicholas would have a sense of whether this is likely to conflict with 
anything, or if there are some other considerations. Would be great to know 
from him and others in the know.

Thank you very much.

Vikas



Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-10-28 Thread Vikas Rawal
> Do you still keep this line in your init:
>
> (advice-add 'org-latex--org-table :override #'my/org-latex--org-table) ?
>
> If so, rename the function from my previous email as
> `my/org-latex-org-table' and re-evaluate it. And comment the old
> `my/org-latex-org-table'.
>

You were right. My bad. I should have been more careful.

I confirm, the new function works and is a significant improvement.

Vikas



Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-10-28 Thread Juan Manuel Macías
Juan Manuel Macías writes:

> \begin{longtblr}[options 1 options 2 options 3 options 4]{align}

PS: I think the options should be separated by commas. In this
case, it's necessary to replace the line:

(mapconcat (lambda (x) (mapconcat 'identity x "")) options-list " ")))

by this line:

(mapconcat (lambda (x) (mapconcat 'identity x "")) options-list ",")))

Best regards,

Juan Manuel 



Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-10-28 Thread Juan Manuel Macías
Vikas Rawal writes:

> This still seems to exporting the second "options" value only.

Do you still keep this line in your init:

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

If so, rename the function from my previous email as
`my/org-latex-org-table' and re-evaluate it. And comment the old
`my/org-latex-org-table'.

The new function works well for me. E.g. this:

#+ATTR_LATEX: :environment longtblr
#+ATTR_LATEX: :align align
#+ATTR_LATEX: :options options 1
#+ATTR_LATEX: :options options 2
#+ATTR_LATEX: :options options 3
#+ATTR_LATEX: :options options 4
| lorem | lorem | lorem | lorem | lorem |
|---+---+---+---+---|
| ipsum | ipsum | ipsum | ipsum | ipsum |

produces in LaTeX this:

\begin{longtblr}[options 1 options 2 options 3 options 4]{align}
lorem & lorem & lorem & lorem & lorem\\
\hline
ipsum & ipsum & ipsum & ipsum & ipsum\\
\end{longtblr}



Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-10-28 Thread Vikas Rawal



>
> First, you need to convert a plist to an alist (source:
> https://caiorss.github.io/Emacs-Elisp-Programming/Elisp_Programming.html#sec-1-8-4):
>
>
> And this would be the modified function:
>


This still seems to exporting the second "options" value only.

Vikas



Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-10-27 Thread Juan Manuel Macías
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:
https://caiorss.github.io/Emacs-Elisp-Programming/Elisp_Programming.html#sec-1-8-4):

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

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
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))
 ;; various `:options' props  <== modified from here
 (attr-alist (plist->alist attr))
 (options-list)
 (options-str (progn
(mapc (lambda (m)
(when (eq (car m) :options)
  (add-to-list 'options-list (cdr m
  attr-alist)
(mapconcat (lambda (x) (mapconcat 'identity x "")) 
options-list " ")))
  < == to here
 (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
;; modified here
(if options-list (format "[%s]" options-str) "")
width
alignment
contents
table-env)))
(org-latex--decorate-table output attr caption above? info))
#+end_src

Pleas tell me if it works for you.

Best regards,

Juan Manuel 



Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables

2021-10-26 Thread Vikas Rawal


>
> Example:
>
> #+ATTR_LATEX: :environment longtblr
> #+ATTR_LATEX: :align colspec = {XXX}, width = 0.85\linewidth
> #+ATTR_LATEX: :options remark{Note} = {Lorem ipsum dolor sit amet}
>
> ==> \begin{longtblr}[remark{Note} = {Lorem ipsum dolor sit amet}]{colspec = 
> {XXX}, width = 0.85\linewidth}

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.

Thanks a lot.

Vikas