From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id aOY3FZx8eWHBTQAAgWs5BA (envelope-from ) for ; Wed, 27 Oct 2021 18:21:48 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id IPz6EJx8eWFjOgAA1q6Kng (envelope-from ) for ; Wed, 27 Oct 2021 16:21:48 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id DDF438847 for ; Wed, 27 Oct 2021 18:21:46 +0200 (CEST) Received: from localhost ([::1]:48566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mflgO-0006zp-P3 for larch@yhetil.org; Wed, 27 Oct 2021 12:21:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40112) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mflDt-0008DO-B2 for emacs-orgmode@gnu.org; Wed, 27 Oct 2021 11:52:17 -0400 Received: from mout01.posteo.de ([185.67.36.65]:34715) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mflDn-0005dI-S7 for emacs-orgmode@gnu.org; Wed, 27 Oct 2021 11:52:15 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 499BB240026 for ; Wed, 27 Oct 2021 17:52:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1635349929; bh=Sx5bhMZD7urILF/8XabK27frkwq4wh9+8AqSLCZybYU=; h=From:To:Cc:Subject:Date:From; b=qnfK4GeZTZN7dt1MPxqUFWiN3DssEQrHpRiQKPJurudfyOOTpnLrvqSGwJQfUAjir kFJrCYchJ0yoamPr3toREojtMhQmusI+Pd6gYyNTqk4qwvMm72CofByd6D/wIOB66l Chk2Cim452aDr2tmbhimAYKzvqHBkCMZiiwMqES8aj5ydKUXV4cEuydnYqc8UzEak6 M38SfmIlEZuMbrJEGOXP2tLl6nR2y25SGnqAXm32mfbIL1xDq7nkz+P22p6Ws+ffFo gmwmkl/ALxqd8MwfZzXq8xToGywiImamt7yLD3PD0PH9HNIH5L1G/kPfkHK47mwmOs sZze+CCopgBMw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4HfY944rHyz6tmQ; Wed, 27 Oct 2021 17:52:08 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: Vikas Rawal Subject: Re: [patch] ox-latex.el: add `:options' LaTeX attribute to tables References: <87mtmvwz3m.fsf@posteo.net> <20211027034448.ijd337kvnmd3fje2@dalkati> Date: Wed, 27 Oct 2021 15:52:07 +0000 In-Reply-To: <20211027034448.ijd337kvnmd3fje2@dalkati> (Vikas Rawal's message of "Wed, 27 Oct 2021 09:14:48 +0530") Message-ID: <87a6iu79eg.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.65; envelope-from=maciaschain@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: orgmode Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1635351707; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=x9kWfDDLd0lqbL3Phg3BPsMCOcyj7owKsGtOsb1ASfQ=; b=NACdnRUFvgRDK1EGhyzwlaZGMOQ8V+rbAbiqHmaMGu+GVjQpjTjUhx38K/iIbbWpj0wRE2 96BXesfHobTwx0So4Pg49RjTuhVKfWg0VNRvuFEU9NFpwF4Ud2vaEpXTMpRxcuOc0zeD0f tU+fn1dfWk01DMQjkCC0NSfQMtfzqoxpgAnGBjYNwfFyrZCTXGACQHhPWra+z7mjZzs2VN oWndKkn0D/tNZBL0gSQc9JY7cysiuzAUnQ7bLPXrSFa6zGA3qDGY17zFN0NM2Syfx3DSlw CqJWf6sCg7wRe8F9yqDhq7BGvruFywgIO5IpGgwa2TyZ1ioGrI4jmadu//QuEg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635351707; a=rsa-sha256; cv=none; b=rZMtJBcITX54pxEJpHj+FJ+I+Xg5z6EbUC6xRSc9HmFTMhQr/HmNXqicNhSRqasdNJFcvw L6Ra98IzDBoHrTuvGziv3Fy9q2VeYMB/i/oAsLpFoMfEQm9M3gDK619WINuyXVNyLxahoR 8N51d5d/xnMlx9GEfMWwYRir4CSbFt9fFiR2nEG9DhX0s2e1wZLmFY0xu21OMc8lQ9k8Km pdwUIOFLIF8sZlvpIGSGXohoeQn0qozeOqi4MbZBkNP09h0rhLxNoYVjFtRHA4VKme6qRy V9f1loweW49ll1b0oRL+zNkiMq6ZISgnjakUiIgZZYiqvo7R/9+FIwxIeaqZMA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=qnfK4GeZ; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -1.63 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=qnfK4GeZ; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: DDF438847 X-Spam-Score: -1.63 X-Migadu-Scanner: scn0.migadu.com X-TUID: CNgzqPpNSeFQ 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