From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 8K+/MZzAH2WxiAAAauVa8A:P1 (envelope-from ) for ; Fri, 06 Oct 2023 10:09:00 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 8K+/MZzAH2WxiAAAauVa8A (envelope-from ) for ; Fri, 06 Oct 2023 10:09:00 +0200 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 3F2A351A4C for ; Fri, 6 Oct 2023 10:09:00 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=posteo.net header.s=2017 header.b=N870oCBj; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (strict)" header.from=posteo.net (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1696579740; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=JIHGu/wQXuDdfwWGI/5YR2CoMxHUBmHHKnk+KCf99jE=; b=tFCEIMQyfo5cT8n2ANifCElQl5t7Z9ezwhqmRWuryiXg9Wxulr/KDPx4LvL+esJyDdM0mo 98INP1h9SNLwfPzQZhcUehzudgcZafRk2JAhG0idas8xDcw/DfxAijF+L3OFdEybb0jAr/ Jq9eN+femjHKwvHXV3Ne5+MUCCr4snpZ7VpsCWc9CW7wia9LNmGoNFTPwy5xKxlLM2x3w5 0IA9ulpV/UaEir/4spYs6G7lUe38JU3fsXXnsZ+98M+LnnHA+s2RtCAgvOuJPVU18FiiaU sO/phecEjbOgQRQK20Ti1zxoSzqsP2wUVGPFjw8AJe45916cRRL8+HmN+wpctg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=posteo.net header.s=2017 header.b=N870oCBj; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (strict)" header.from=posteo.net (policy=none) ARC-Seal: i=1; s=key1; d=yhetil.org; t=1696579740; a=rsa-sha256; cv=none; b=Gria5zoWFSqaQSvC58Dt2nHhpVf0YrJfVr0cqnG6axaB1r80FveegUVdh4Ou6Sf2mM1TpW 3p4fb3UuN8CPV5REN0kkSAu8Wohu+FJmlH+xvyhCFk7hvAcJmuC4lG0zo/oWIsHpo9jXqD 2UQfodZNzBMEXQ1V3Uqsm1pWhbzkOl3f9ulPgRgSaQeQ3V+1lX8GrIFFVA2tf6FXSNbXTD AYOpzf3rFTQ3eC2gVIJq3dSiEtUDlTpoACE0lIGPUcv8IxwIYokNTK8+KpNCARKFigwLxN 3tmzvAEEQ1/JFhDX4en47OpQ07MtZXxICzRK5hxKeI7YnIkBj4LZK1TNdLhG4g== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qofsV-0005Nt-L1; Fri, 06 Oct 2023 04:08:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qofsT-0005La-Nl for emacs-orgmode@gnu.org; Fri, 06 Oct 2023 04:08:05 -0400 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qofsR-0003Fx-4M for emacs-orgmode@gnu.org; Fri, 06 Oct 2023 04:08:05 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id CAABC240103 for ; Fri, 6 Oct 2023 10:07:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1696579677; bh=Uul5LE9uu8j7CUHdCAlt7/dXQy7rJ2BCq4gEyxO2lRk=; h=From:To:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=N870oCBjNoVjZjqalLgjYxsrPUjpUkkRAOXLSxJDh+DawlYysXOe2SzTjn4olic8x 5k375eQnxWYoJ/RSQ3yQjM42EHWjzsaGmzMC/Mp/NasQx+riDvuyHld8aXH3ItJSoa LFZbykPWzmxEFqrOFgRPHZIPeukIUh+9qJ3b0GBNLCpGWEQ9ypQg+wf6wV0XSerP3W iX90jqiuxVw7wuklIujByAriijyQ3BKJDRsmOGK0RfnGvLk4OkOz58059afCXHNdqM ZdH0lPogqO6g9R0xpEMNl8Nn+LAm+1IF+OWILEXhh4mwI2k6R4Syr/EignGwyMEbuT Ggheym2oPOnWA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4S21JF2wcgz9rxG for ; Fri, 6 Oct 2023 10:07:57 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: [proof of concept, tip] 'Templates with arguments' using org src blocks Date: Fri, 06 Oct 2023 08:07:54 +0000 Message-ID: <87bkdc5g2t.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.67.36.66; envelope-from=maciaschain@posteo.net; helo=mout02.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_H5=0.001, RCVD_IN_MSPIKE_WL=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.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -5.22 X-Migadu-Scanner: mx2.migadu.com X-Migadu-Queue-Id: 3F2A351A4C X-Spam-Score: -5.22 X-TUID: 2ybWkqrwftPy Hi, this is a proof of concept of how a sort of 'templates with arguments' can be used within Org, just with Org=E2=80=99s own resources at= the user level. It occurred to me that org src blocks might be handy for this. For this test I just made a disguised format string using this function: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 (defun my-format-template (template vars) =E2=94=82 (format =E2=94=82"#+begin_src emacs-lisp :results raw :exports results :var templat= e =3D %s =E2=94=82 (format =E2=94=82 (format \"%%s\" template) =E2=94=82 %s) =E2=94=82 #+end_src" template vars)) =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 and a macro: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 #+MACRO: template (eval (my-format-template $1 $2)) =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 A simple example. We start from this template: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 #+NAME: template1 =E2=94=82 #+begin_src org :exports none =E2=94=82 ,*%s* =E2=94=82 %s =E2=94=82 #+end_src =E2=94=82=20 =E2=94=82 #+header: :var hello =3D "Hello World" =E2=94=82 #+header: :var str =3D "Lorem ipsum dolor" =E2=94=82 {{{template(template1,hello str)}}} =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 An example with a src block inside the template: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 #+NAME: template2 =E2=94=82 #+begin_src org :exports none =E2=94=82 ,#+begin_src emacs-lisp :exports results :results raw =E2=94=82 (let ((name "%s")) =E2=94=82 (format "/Hello, %%s/" name)) =E2=94=82 ,#+end_src =E2=94=82 #+end_src =E2=94=82=20 =E2=94=82 #+header: :var name =3D "World" =E2=94=82 {{{template(template2,name)}}} =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 And this example is somewhat more elaborate. We want a table in LaTeX with the threeparttable package. Template: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 #+NAME: tptable =E2=94=82 #+begin_src org :exports none =E2=94=82 ,#+begin_table =E2=94=82 ,#+ATTR_LaTeX: :options [b] =E2=94=82 ,#+begin_threeparttable =E2=94=82 %s =E2=94=82 ,#+begin_tablenotes =E2=94=82 %s =E2=94=82 ,#+end_tablenotes =E2=94=82 ,#+end_threeparttable =E2=94=82 ,#+end_table =E2=94=82 #+end_src =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 the table: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 #+NAME: table1 =E2=94=82 #+begin_src org :exports none =E2=94=82 ,#+ATTR_LaTeX: :center nil :booktabs t :float nil =E2=94=82 ,#+caption: Lorem ipsum dolor =E2=94=82 ,#+name: table1 =E2=94=82 |-------+--------------------------+-------| =E2=94=82 | lorem | ipsum@@latex:\tnote{1}@@ | dolor | =E2=94=82 | lorem | ipsum@@latex:\tnote{2}@@ | dolor | =E2=94=82 |-------+--------------------------+-------| =E2=94=82 #+end_src =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 And, finally: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 #+header: :var table =3D table1 =E2=94=82 #+header: :var notes =3D "\\item [1] First note\n\\item [2] Secon= d note" =E2=94=82 {{{template(tptable,table notes)}}} =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 Best regards, Juan Manuel --=20 Juan Manuel Mac=C3=ADas=20 https://juanmanuelmacias.com https://lunotipia.juanmanuelmacias.com https://gnutas.juanmanuelmacias.com