emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] limitation for macro expansion


From: Nicolas Goaziou
Subject: Re: [O] limitation for macro expansion
Date: Mon, 06 Mar 2017 09:22:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Hello,

Yasushi SHOJI <address@hidden> writes:

> Ah, you mean the parser is unable to distinguish the macro and
> subscript?

It's not the parser, but the syntax. Subscript is

  a_{...}

whereas macro is

  {{{macro(...)}}}

so, when you see

  a_{{{something}}}

there are two ways to interpret it: the one you expect and

  a_{CONTENTS} where CONTENTS is {{something}}.

Since subscript syntax started first, it has precedence over the macro.

> Doesn't seems to work.  When I export 'a_{{{{author}}}}', it
> generates:
>
>   a_{Yasushi SHOJI}
>
> I was expecting to see:
>
>   a_Yasushi SHOJI

This is correct if you use `ascii' back-end. How could you tell the
difference between

  a_{Yasushi SHOJI}

and

  a_Yasushi SHOJI

otherwise?

OTOH, `latex' back-end produces

  a\(_{\text{Yasushi SHOJI}}\)

which means the parser and the export process correctly handle it.

>> > - Link doesn't work like this: [[file:{{{input-file}}}][Bad link]]
>> 
>> Indeed. This kind of link is not supported as you cannot follow it
>> (macros are an export-only feature).
>
> Hmm, that's true that you can't follow it.
>
> Would it be OK to say that it's a design decision to ignore the macro
> expansion in the link field at export time?

It is. Actually, macros are not allowed in many places, as a design
decision. See

  (info "(org) Macro replacement")

for more details.

>> Feel free to provide a documentation patch if you think this needs to be
>> made explicit.
>
> Will do once I fully understand.
>
> Now, what I'm trying to achieve with a macro is to generate a
> filename-like string with a timestamp in it in my doc.
>
> ie)
>
>   #+MACRO: timestamp {{{date(%Y%m%d)}}}
>
>   Please open log_{{{timestamp}}}.txt
>
> Would it be possible for org to do this?

You could try

  #+MACRO: timestamp {{{time(%Y%m%d)}}}

  Please open log\under{}{{{timestamp()}}}.txt

> If not, would it be possible for me to modify the code to achieve this?
> My stupid idea is to:
>
>   - disable sub / superscript parser when org-use-sub-superscripts is nil

See `org-export-with-sub-superscripts'.

>   - reverse the precedence order of subscript and macro

This would only move the problem elsewhere.

Regards,

-- 
Nicolas Goaziou                                                0x80A93738



reply via email to

[Prev in Thread] Current Thread [Next in Thread]