[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [proof of concept, tip] 'Templates with arguments' using org src blo
From: |
Max Nikulin |
Subject: |
Re: [proof of concept, tip] 'Templates with arguments' using org src blocks |
Date: |
Fri, 13 Oct 2023 23:00:13 +0700 |
User-agent: |
Mozilla Thunderbird |
On 06/10/2023 15:07, Juan Manuel Macías wrote:
And, finally:
┌────
│ #+header: :var table = table1
│ #+header: :var notes = "\\item [1] First note\n\\item [2] Second note"
│ {{{template(tptable,table notes)}}}
└────
Usage is quite close to "#+call:", but it does not support specifying
arguments using "#+header:"
https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-org.html
I would still consider noweb (table1 is omitted):
--- 8< ---
#+property: header-args:org :exports results :results replace :noweb yes
#+NAME: tptable
#+begin_src org :exports none
,#+begin_table
,#+ATTR_LaTeX: :options [b]
,#+begin_threeparttable
$table
,#+begin_tablenotes
$notes
,#+end_tablenotes
,#+end_threeparttable
,#+end_table
#+end_src
#+header: :var table = table1
#+header: :var notes = "\\item [1] First note\n\\item [2] Second note"
#+begin_src org
<<tptable>>
#+end_src
--- >8 ---
or "%(param)s" substitutions in python (another variant f"""{param}"""
is inconvenient for LaTeX):
--- 8< ---
#+property: header-args:python :python python3 :results org :noweb yes
:exports results
#+property: header-args:org :exports results :results replace
#+NAME: tptable
#+begin_src python :exports none
return """\
,#+begin_table
,#+ATTR_LaTeX: :options [b]
,#+begin_threeparttable
%(table)s
,#+begin_tablenotes
%(notes)s
,#+end_tablenotes
,#+end_threeparttable
,#+end_table
""" % locals()
#+end_src
#+header: :var table = table1
#+header: :var notes = "\\item [1] First note\n\\item [2] Second note"
#+begin_src python
<<tptable>>
#+end_src
--- >8 ---