|
From: | Max Nikulin |
Subject: | Re: question about links, macros + org-publish and "parametrization" |
Date: | Fri, 31 May 2024 17:29:16 +0700 |
User-agent: | Mozilla Thunderbird |
On 30/05/2024 23:33, Ihor Radchenko wrote:
Max Nikulin writes:I can not figure out if it is possible with some trick to expand {{{year}}} before file:... is parsed.Not possible. Macros are not recognized in verbatim contexts like link path.
I had in mind some technique like \expandafter in TeX or intermediate macro in the case of C preprocessor.
---- 8< ---- #+macro: mend }}} #+macro: year 24 #+macro: source [[file:./$1/t.org][for the year $1]] #+macro: target {{{source({{{year}}}){{{mend}}} {{{source(24)}}} {{{target}}} {{{source({{{year}}}){{{mend}}} ---- >8 ---- It signals (error "Undefined Org macro: source; aborting") during processing source code blocks. Export buffer content at this step: ---- 8< ---- #+macro: mend }}} #+macro: year 24 #+macro: source [[file:./$1/t.org][for the year $1]] #+macro: target {{{source({{{year}}}){{{mend}}} [[file:./24/t.org][for the year 24]] {{{source(24)}}} {{{source(24)}}} ---- >8 ----So I have almost achieved the goal despite the approach is rather fragile. I might work with additional pass of macro processing added as an extra export filter.
However I believe it is better to use either a custom link type or an eval macro instead of set of kludges with postponing expansion.
It is not intuitive that macro parameters are not eagerly expanded like function arguments in most common procedural programming languages. Macro languages have their own shortcomings.
[Prev in Thread] | Current Thread | [Next in Thread] |