* question about links, macros + org-publish and "parametrization" @ 2024-05-28 10:02 Martin Steffen 2024-05-29 8:44 ` Fraga, Eric 2024-05-29 13:35 ` Ihor Radchenko 0 siblings, 2 replies; 10+ messages in thread From: Martin Steffen @ 2024-05-28 10:02 UTC (permalink / raw) To: emacs-orgmode Hi, I got a question whether the following is possible, when using org-publish. Concretely I generate with org-publish markdown-files (that ultimately are turned to HTML), but I guess the question is not specific for this choice of a ``publication-process''.' The whole content consists of quite a number of files, and in particular has quite many html-links, and the links change (each year, each semester) and they change in ``systematic ways'' What has been for instance https://www.gitpages.io/somelecture/fall23/exercises will have to be changed for the next round to https://www.gitpages.io/somelecture/fall24/exercises (and there are links for many things beside exercises, and also they have to be changed analogously). The way I make that smooth is I define #LINK: exercises-web https://www.gitpages.io/somelecture/fall23/exercises and then, When the semester comes, replace all occurrences of fall23 to fall24. Even if there are quite a number of such link definitions (for all kind of information), it's straightforward. It's systematically organized, and if all the link definitions are centralized in some file collectionoflinks.org or similar that is #INCLUDE:-ed into all the other files that work with this links, then ``porting'' of the whole set-up to a new semester is quite easy and robust. So I am happy with that, but I wonder if I could make it even more parametrized. Like combining macros with links like that "fall23" is an argument to a macros, which then builds up a link. But that does not to work in a naive way, like #+MACRO: semester fall24 #+LINK: https://www.gitpages.io/somelecture/{{{semester}}}/exercises since macros do replacement in "text" (not in those #+-"meta-commands"). I tried parametrized macros_ #+MACRO: parametricexercizes https://www.gitpages.io/somelecture/$1/exercises and that half-way works. I.e., if I do parametricexercizes(fall24) (*) it works in that it results in a page with a correct link, but that's not quite what I want, for 2 reasons. Really useful would the parametrization if one could do parametricexercizes(semester) where semester is a macro, not a literal "fall24". The second reason is that the use as in (*) is not really useful, what I am really after is something like [[parametricexercizes(fall24)][the exercises are here]] and the combination of macros inside [[ .... ]] does not work either. Maybe there are other ways to achieve ``parametrization'' (or maybe not, I have not worked much with macros in Org), any ideas? best, Martin ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: question about links, macros + org-publish and "parametrization" 2024-05-28 10:02 question about links, macros + org-publish and "parametrization" Martin Steffen @ 2024-05-29 8:44 ` Fraga, Eric 2024-05-30 3:52 ` Martin Steffen 2024-05-29 13:35 ` Ihor Radchenko 1 sibling, 1 reply; 10+ messages in thread From: Fraga, Eric @ 2024-05-29 8:44 UTC (permalink / raw) To: Martin Steffen; +Cc: emacs-orgmode@gnu.org Hello, I'm not entirely sure if I am missing something but, in case it helps, macros can themselves invoke other macros and macros can make use of [[target][desc]] syntax directly. Can you not build up a hierarchy of macros that would achieve what you want, along these lines: --8<---------------cut here---------------start------------->8--- #+macro: link [[file:t.org][$1]] #+macro: target {{{link($1)}}} This is some text where I can look at {{{target(blah)}}} --8<---------------cut here---------------end--------------->8--- HTH, eric -- : Eric S Fraga, with org release_9.6.19-1230-g407a55 in Emacs 30.0.50 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: question about links, macros + org-publish and "parametrization" 2024-05-29 8:44 ` Fraga, Eric @ 2024-05-30 3:52 ` Martin Steffen 2024-05-30 5:03 ` Martin Steffen 0 siblings, 1 reply; 10+ messages in thread From: Martin Steffen @ 2024-05-30 3:52 UTC (permalink / raw) To: Org Mode List >>>>> "Fraga," == Fraga, Eric <e.fraga@ucl.ac.uk> writes: Fraga,> Hello, Fraga,> I'm not entirely sure if I am missing something but, in case thanks, it was more that I was missing something. I tried to combine links and macros in a naive ways (without much studying the manual), so I thought perhaps nesting is not possible (or there is another way). Your suggestion solves my "problem" and makes the set-up a bit more "parametric" and easier to adapt, without that one forgets some bits, which is very nice. best, Martin Fraga,> it helps, macros can themselves invoke other macros and Fraga,> macros can make use of [[target][desc]] syntax directly. Fraga,> Can you not build up a hierarchy of macros that would Fraga,> achieve what you want, along these lines: Fraga,> #+macro: link [[file:t.org][$1]] Fraga,> #+macro: target {{{link($1)}}} Fraga,> This is some text where I can look at {{{target(blah)}}} Fraga,> HTH, eric Fraga,> -- : Eric S Fraga, with org release_9.6.19-1230-g407a55 in Fraga,> Emacs 30.0.50 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: question about links, macros + org-publish and "parametrization" 2024-05-30 3:52 ` Martin Steffen @ 2024-05-30 5:03 ` Martin Steffen 2024-05-30 8:40 ` Fraga, Eric 2024-05-30 16:28 ` Max Nikulin 0 siblings, 2 replies; 10+ messages in thread From: Martin Steffen @ 2024-05-30 5:03 UTC (permalink / raw) To: Org Mode List Hi, maybe my email was premature. The combination of macros and links you described is nice and useful for me (I did not much in the ways of macros in org before). However, one aspect I am after seems not to work. Your example was as follows, and it works: --8<---------------cut here---------------start------------->8--- #+macro: link [[file:t.org][$1]] #+macro: target {{{link($1)}}} This is some text where I can look at {{{target(blah)}}} --8<---------------cut here---------------end--------------->8--- There are 2 tweaks I had in mind in addition to your example, which I can't get to work. The first one is that the argument for the macro link should (also) occur in the first part, a part of the link, not the text: #+macro: source [[file:./$1/t.org][for the subdirectory $1]] That actually works, if one uses in the text {{{target(bla)}}} that's great, but it leaves me replacing in the text many occurrences of "bla" across many files. The second tweak is that "bla" is a macro as well (centrally defined). something like the following (modifing your example) --8<---------------cut here---------------start------------->8--- #+macro: year 24 #+macro: source [[file:./$1/t.org][for the year $1]] #+macro: target {{{source({{{year}}})}}} --8<---------------cut here---------------end--------------->8--- Then of I call the macros 1) {{{source(24)}}} : that works, $1 is replaced both times and the link points to file:./24/t.org 2) {{{source({{{year}}})}}}: that does not work 3) {{{target}}} : that does not work either In both cases 2) and 3), the result of the macro expansion is the following (I export to markdown) [for the year 24](./{{{year}}}/t.md) - [for the year 24](./{{{year}}}/t.md) i.e, the argument (intended to be 24) is properly replaced in ``text part'' but not in the `` link'' part. I don't know if I simply expect ``too much'' from the macro-expansion facilities.... best, Martin >>>>> "Martin" == Martin Steffen <msteffen@ifi.uio.no> writes: >>>>> "Fraga," == Fraga, Eric <e.fraga@ucl.ac.uk> writes: Martin> Fraga,> Hello, Martin> Fraga,> I'm not entirely sure if I am missing something Martin> but, in case Martin> thanks, it was more that I was missing something. I tried to Martin> combine links and macros in a naive ways (without much Martin> studying the manual), so I thought perhaps nesting is not Martin> possible (or there is another way). Martin> Your suggestion solves my "problem" and makes the set-up a Martin> bit more "parametric" and easier to adapt, without that one Martin> forgets some bits, which is very nice. Martin> best, Martin Martin> Fraga,> it helps, macros can themselves invoke other Martin> macros and Fraga,> macros can make use of [[target][desc]] Martin> syntax directly. Fraga,> Can you not build up a hierarchy Martin> of macros that would Fraga,> achieve what you want, along Martin> these lines: Martin> Fraga,> #+macro: link [[file:t.org][$1]] Martin> Fraga,> #+macro: target {{{link($1)}}} Martin> Fraga,> This is some text where I can look at Martin> {{{target(blah)}}} Martin> Fraga,> HTH, eric Martin> Fraga,> -- : Eric S Fraga, with org Martin> release_9.6.19-1230-g407a55 in Fraga,> Emacs 30.0.50 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: question about links, macros + org-publish and "parametrization" 2024-05-30 5:03 ` Martin Steffen @ 2024-05-30 8:40 ` Fraga, Eric 2024-05-30 11:25 ` Martin Steffen 2024-05-30 16:28 ` Max Nikulin 1 sibling, 1 reply; 10+ messages in thread From: Fraga, Eric @ 2024-05-30 8:40 UTC (permalink / raw) To: Martin Steffen; +Cc: Org Mode List On Thursday, 30 May 2024 at 07:03, Martin Steffen wrote: > [...] > #+macro: target {{{source({{{year}}})}}} So, the problem you are running into is that you cannot evaluate a macro with arguments that require evaluating a macro. Unless you can change the order in which you evaluate these macros, the only solution I can suggest is that you define elisp macros. See the info manual, specifically the second example in the macro replacement section. #+macro: complicated (eval ...) -- : Eric S Fraga, with org release_9.6.19-1230-g407a55 in Emacs 30.0.50 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: question about links, macros + org-publish and "parametrization" 2024-05-30 8:40 ` Fraga, Eric @ 2024-05-30 11:25 ` Martin Steffen 0 siblings, 0 replies; 10+ messages in thread From: Martin Steffen @ 2024-05-30 11:25 UTC (permalink / raw) To: Org Mode List >>>>> "Fraga," == Fraga, Eric <e.fraga@ucl.ac.uk> writes: Fraga,> On Thursday, 30 May 2024 at 07:03, Martin Steffen wrote: >> [...] #+macro: target {{{source({{{year}}})}}} Fraga,> So, the problem you are running into is that you cannot Fraga,> evaluate a macro with arguments that require evaluating a Fraga,> macro. Unless you can change the order in which you Fraga,> evaluate these macros, the only solution I can suggest is Fraga,> that you define elisp macros. See the info manual, Fraga,> specifically the second example in the macro replacement Fraga,> section. thanks, fair enough, I look into the elisp-option. Martin Fraga,> #+macro: complicated (eval ...) Fraga,> -- : Eric S Fraga, with org release_9.6.19-1230-g407a55 in Fraga,> Emacs 30.0.50 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: question about links, macros + org-publish and "parametrization" 2024-05-30 5:03 ` Martin Steffen 2024-05-30 8:40 ` Fraga, Eric @ 2024-05-30 16:28 ` Max Nikulin 2024-05-30 16:33 ` Ihor Radchenko 1 sibling, 1 reply; 10+ messages in thread From: Max Nikulin @ 2024-05-30 16:28 UTC (permalink / raw) To: emacs-orgmode On 30/05/2024 12:03, Martin Steffen wrote: > #+macro: year 24 > #+macro: source [[file:./$1/t.org][for the year $1]] > #+macro: target {{{source({{{year}}})}}} Custom link type might be more convenient (info "(org) Adding Hyperlink Types") https://orgmode.org/manual/Adding-Hyperlink-Types.html I can not figure out if it is possible with some trick to expand {{{year}}} before file:... is parsed. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: question about links, macros + org-publish and "parametrization" 2024-05-30 16:28 ` Max Nikulin @ 2024-05-30 16:33 ` Ihor Radchenko 2024-05-31 10:29 ` Max Nikulin 0 siblings, 1 reply; 10+ messages in thread From: Ihor Radchenko @ 2024-05-30 16:33 UTC (permalink / raw) To: Max Nikulin; +Cc: emacs-orgmode Max Nikulin <manikulin@gmail.com> 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. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92> ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: question about links, macros + org-publish and "parametrization" 2024-05-30 16:33 ` Ihor Radchenko @ 2024-05-31 10:29 ` Max Nikulin 0 siblings, 0 replies; 10+ messages in thread From: Max Nikulin @ 2024-05-31 10:29 UTC (permalink / raw) To: emacs-orgmode 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. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: question about links, macros + org-publish and "parametrization" 2024-05-28 10:02 question about links, macros + org-publish and "parametrization" Martin Steffen 2024-05-29 8:44 ` Fraga, Eric @ 2024-05-29 13:35 ` Ihor Radchenko 1 sibling, 0 replies; 10+ messages in thread From: Ihor Radchenko @ 2024-05-29 13:35 UTC (permalink / raw) To: Martin Steffen; +Cc: emacs-orgmode Martin Steffen <msteffen@ifi.uio.no> writes: > The way I make that smooth is I define > > #LINK: exercises-web https://www.gitpages.io/somelecture/fall23/exercises > > ... > So I am happy with that, but I wonder if I could make it even more > parametrized. Like > > > combining macros with links > > > like that "fall23" is an argument to a macros, which then builds up a > link. But that does not to work in a naive way, like > > > #+MACRO: semester fall24 > #+LINK: https://www.gitpages.io/somelecture/{{{semester}}}/exercises > ... > where semester is a macro, not a literal "fall24". The second reason is > that the use as in (*) is not really useful, what I am really after is > something like > > [[parametricexercizes(fall24)][the exercises are here]] The simplest thing you can use is #+LINK: exercises-web https://www.gitpages.io/somelecture/%s/exercises [[exercises-web:fall24][the exercises are here]] If you need something more complex, check out %(my-function) placeholder instead of %s as described in "Link Abbreviations" section of Org manual. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92> ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-05-31 10:30 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-05-28 10:02 question about links, macros + org-publish and "parametrization" Martin Steffen 2024-05-29 8:44 ` Fraga, Eric 2024-05-30 3:52 ` Martin Steffen 2024-05-30 5:03 ` Martin Steffen 2024-05-30 8:40 ` Fraga, Eric 2024-05-30 11:25 ` Martin Steffen 2024-05-30 16:28 ` Max Nikulin 2024-05-30 16:33 ` Ihor Radchenko 2024-05-31 10:29 ` Max Nikulin 2024-05-29 13:35 ` Ihor Radchenko
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).