emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* breakage: Using self-defined Macro in macro definition
@ 2020-01-20 10:27 Robert Klein
  2020-01-20 19:04 ` Berry, Charles
  0 siblings, 1 reply; 2+ messages in thread
From: Robert Klein @ 2020-01-20 10:27 UTC (permalink / raw)
  To: emacs-orgmode


Hi,

when I use a self-defined macro in a macro definition, subsequent
macros in the same macro definition don't get expanded (tested with
org version 9.2.1 and tip of maint):

--- snip example ---
#+Macro: newline (eval "\n")
#+Macro: new $1 {{{newline}}}#+Index: $1 {{{newline}}}

Use the {{{new(format)}}}
command to format a string according to the
/format-string/ argument.
--- snip example ---


the output of which is:

--- snip resulting output ---
Use the format a 
\index{format {{{newline}}}}
command to format a string according to the
\emph{format-string} argument.
--- snip resulting output ---


The expected output would be:

--- snip expected output ---
Use the format a 
\index{format} 
command to format a string according to the
\emph{format-string} argument.
--- snip expected output ---


PS: leaving the second {{{newline}}} out is not a solution, as
paragraph reformatting will put the macro in the middle of the line.



The issue doesn't crop up, when using a predefined macro, e.g. ` date'
or `author'.


It also doesn't show up, when the first macro in the macro is e.g. the
predefined macro `date'.  That is the following example 2 works ok:

--- snip example 2 ---
#+Date: <2020-01-20 Mon>
#+Macro: old $1 {{{date}}} {{{newline}}} alpha {{{newline}}} beta

{{{old}}}
--- snip example 2 ---


Thanks for any hints/help.

Best regards
Robert

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: breakage: Using self-defined Macro in macro definition
  2020-01-20 10:27 breakage: Using self-defined Macro in macro definition Robert Klein
@ 2020-01-20 19:04 ` Berry, Charles
  0 siblings, 0 replies; 2+ messages in thread
From: Berry, Charles @ 2020-01-20 19:04 UTC (permalink / raw)
  To: Robert Klein; +Cc: emacs-orgmode



> On Jan 20, 2020, at 2:27 AM, Robert Klein <roklein@roklein.de> wrote:
> 
> 
> Hi,
> 
> when I use a self-defined macro in a macro definition, subsequent
> macros in the same macro definition don't get expanded (tested with
> org version 9.2.1 and tip of maint):


The expansions in your example follow the rules. 

The problem as explained below is that you have created a macro whose expansion cannot be further expanded.

> 
> --- snip example ---
> #+Macro: newline (eval "\n")

That will add a newline character.

> #+Macro: new $1 {{{newline}}}#+Index: $1 {{{newline}}}

This is a bit tricky. It adds a newline character before the hash `#'.

Then you have this line in the current buffer (see the `org-export-with-buffer-copy' docstring):

#+Index: $1 {{{newline}}} 

and org needs to do something with it, but as the manual says

Org recognizes macro references in following Org markup areas:
paragraphs, headlines, verse blocks, tables cells and lists.  Org also
recognizes macro references in keywords, such as ‘CAPTION’, ‘TITLE’,
‘AUTHOR’, ‘DATE’, and for some back-end specific export options.

and INDEX was not one of the keywords, so the reference is not recognized. 

So it is not expanded. This has nought to do with it being `self-defined'.

Of course, you see it on export if the exporter deals with INDEX (it looks like you are using 'latex).

> 
> Use the {{{new(format)}}}
> command to format a string according to the
> /format-string/ argument.
> --- snip example ---
> 
> 
> the output of which is:
> 
> --- snip resulting output ---
> Use the format a 
> \index{format {{{newline}}}}
> command to format a string according to the
> \emph{format-string} argument.
> --- snip resulting output ---
> 
> 

As expected.

> The expected output would be:
> 
> --- snip expected output ---
> Use the format a 
> \index{format} 
> command to format a string according to the
> \emph{format-string} argument.
> --- snip expected output ---
> 
> 
> PS: leaving the second {{{newline}}} out is not a solution, as
> paragraph reformatting will put the macro in the middle of the line.
> 
> 
> 
> The issue doesn't crop up, when using a predefined macro, e.g. ` date'
> or `author'.
> 
> 
> It also doesn't show up, when the first macro in the macro is e.g. the
> predefined macro `date'.  That is the following example 2 works ok:
> 
> --- snip example 2 ---
> #+Date: <2020-01-20 Mon>
> #+Macro: old $1 {{{date}}} {{{newline}}} alpha {{{newline}}} beta
> 
> {{{old}}}
> --- snip example 2 ---
> 
> 
> Thanks for any hints/help.
> 

None of those examples involve a macro that creates output in which further macros cannot be recognized.

Build an `eval' macro that does all the expansions within its own code without referring to other macros. The property API may help with this.

Or maybe try an idiom that does not use a macro, such as a custom link.

HTH,

Chuck

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-20 19:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-20 10:27 breakage: Using self-defined Macro in macro definition Robert Klein
2020-01-20 19:04 ` Berry, Charles

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).