> On May 7, 2026, at 02:03, Christian Moe <[email protected]> wrote:
>
> Perry Smith <[email protected]> writes:
>> It appears that if the conditional text is itself a call to a macro, the
>> output gets confused. For example:
>>
>> #+MACRO: bold +$1+
>> #+MACRO: device1
>> {{{device1({{{bold(blah)}}})}}}
>>
>> results in the tailing )}}} being emitted.
>
> This is because you haven't defined the device1 macro. You need to add
> the argument.
>
> #+MACRO: device1 $1
>
> For conditional snippets that are separate paragraphs (or bigger), you
> can use drawers. Selecting which to include/exclude is straightforward.
>
> :DEVICE1:
> Text relevant to device 1.
> :END:
>
> :DEVICE2:
> Text relevant to device 2.
> :END:
>
> To export only the drawers for device 2, use
>
> #+OPTIONS: d:("DEVICE2”)
So I developed include-if and omit-if macros and thought I would share what I
did:
> #+OPTIONS: tags:nil
> #+EXCLUDE_TAGS: excluded boo
> #+SELECT_TAGS: selected blah
>
> # Useful for debugging and prototyping
> #+MACRO: selected (eval (prin1-to-string (plist-get
> (org-export--get-inbuffer-options) :select-tags)))
> #+MACRO: excluded (eval (prin1-to-string (plist-get
> (org-export--get-inbuffer-options) :exclude-tags)))
>
> # A macro to incude the second argument if the first argument is a
> # selected tag.
> #+MACRO: include-if (eval (if (member $1 (plist-get
> (org-export--get-inbuffer-options) :select-tags)) $2))
>
> # A macro to omit the second argument if the first argument is an
> # excluded tag.
> #+MACRO: omit-if (eval (unless (member $1 (plist-get
> (org-export--get-inbuffer-options) :exclude-tags)) $2))
>
> # Arguments to macros can be macros but must not have arguments of
> # their own. Thus a macro must be defined to produce the desired text
> # without any arguments. e.g.
> #+MACRO: bold *$1*
> #+MACRO: bold-happy {{{bold(happy)}}}
>
> # Results: excluded ("excluded" "boo")
> excluded {{{excluded}}}
>
> # Results: selected ("selected" "blah")
> selected {{{selected}}}
>
> # Results: include-if *happy* after
> # Since blah is selected, this results in a bold happy being exported
> include-if {{{include-if(blah, {{{bold-happy}}})}}} after
>
> # Results: include-if after2
> # Since boo is not selected, the bold happy is not exported
> include-if {{{include-if(boo, {{{bold-happy}}})}}} after2
>
> # Results: omit-if *happy* after
> # Since blah is not excluded, a bold happy being exported
> omit-if {{{omit-if(blah, {{{bold-happy}}})}}} after
>
> # Result: omit-if after2
> # Since boo is excluded, the bold happy is not exported
> omit-if {{{omit-if(boo, {{{bold-happy}}})}}} after2