emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
@ 2020-11-21 10:56 Bruno BEAUFILS
  2020-11-21 13:18 ` Tim Cross
  2020-11-23 10:19 ` Eric S Fraga
  0 siblings, 2 replies; 9+ messages in thread
From: Bruno BEAUFILS @ 2020-11-21 10:56 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Bruno BEAUFILS

[-- Attachment #1: Type: text/plain, Size: 1584 bytes --]

I have a *lot* of org files with a macro =if-backend= which enables me
to decide what to export depending on the backend :

#+begin_src org
  #+macro: if-backend (eval (if (org-export-derived-backend-p org-export-current-backend '$1) "$2"))
#+end_src

For instance, I use it to include =\hfill= in LaTeX family export
engines but not in others (html for instance) :

#+begin_src org
  #+macro: hfill {{{if-backend(latex, \\hfill{} )}}}
#+end_src

I generally use emacs 26.3 as distributed by Debian bullseyes (which
offer org-mode version 9.1.9).

On another box I need to work with a more recent org-mode, precisely
9.4.

In that environment, due to an incompatible change introduced by
[[https://orgmode.org/Changes_old.html#outline-container-org003add6][release 9.2]] the same macro has to be written in a different way :

#+begin_src org
  #+macro: if-backend (eval (if (org-export-derived-backend-p org-export-current-backend (intern $1)) $2))
#+end_src

And thus I need to change also the macro using it, for instance the
=hfill= macro has to be written that way :

#+begin_src org
  #+macro: hfill {{{if-backend(latex, \hfill{} )}}}
#+end_src

For now I need to work on the same files in these two different environment.

Do anyone have an idea on how to be able whether to define the
=if-backend= in a way that it can work in both org versions or if
there is a way to define these macro in different ways depending on
org version?

I would like to let the definitions in org files and not in emacs init
files.

-- 
Bruno BEAUFILS

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-21 10:56 looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test Bruno BEAUFILS
@ 2020-11-21 13:18 ` Tim Cross
  2020-11-22 20:49   ` Bruno BEAUFILS
  2020-11-23 10:19 ` Eric S Fraga
  1 sibling, 1 reply; 9+ messages in thread
From: Tim Cross @ 2020-11-21 13:18 UTC (permalink / raw)
  To: emacs-orgmode


Bruno BEAUFILS <bruno@boulgour.com> writes:

> I have a *lot* of org files with a macro =if-backend= which enables me
> to decide what to export depending on the backend :
>
> #+begin_src org
>   #+macro: if-backend (eval (if (org-export-derived-backend-p org-export-current-backend '$1) "$2"))
> #+end_src
>
> For instance, I use it to include =\hfill= in LaTeX family export
> engines but not in others (html for instance) :
>
> #+begin_src org
>   #+macro: hfill {{{if-backend(latex, \\hfill{} )}}}
> #+end_src
>
> I generally use emacs 26.3 as distributed by Debian bullseyes (which
> offer org-mode version 9.1.9).
>
> On another box I need to work with a more recent org-mode, precisely
> 9.4.
>
> In that environment, due to an incompatible change introduced by
> [[https://orgmode.org/Changes_old.html#outline-container-org003add6][release 9.2]] the same macro has to be written in a different way :
>
> #+begin_src org
>   #+macro: if-backend (eval (if (org-export-derived-backend-p org-export-current-backend (intern $1)) $2))
> #+end_src
>
> And thus I need to change also the macro using it, for instance the
> =hfill= macro has to be written that way :
>
> #+begin_src org
>   #+macro: hfill {{{if-backend(latex, \hfill{} )}}}
> #+end_src
>
> For now I need to work on the same files in these two different environment.
>
> Do anyone have an idea on how to be able whether to define the
> =if-backend= in a way that it can work in both org versions or if
> there is a way to define these macro in different ways depending on
> org version?
>
> I would like to let the definitions in org files and not in emacs init
> files.

Hmm, I just use backend specific blocks for this purpose. e.g.

#+begin_export latex
  \hfil{}
#+end_export

Pretty sure 9.1 supports the same (there was a change, which used
#+EXPORT_LATEX instead of #+begin_export, but I think the old version
still works in 9.4, can't remember which version the change was
introduced). So if 9.1 only supports EXPORT_LATEX, you should still be
able to use it under 9.4

IMO the org #+MACRO is really just a text substitution mechanism (like
C), not a 'real' macro (like elisp has) and as is the case with C, you
really need to keep them pretty simple. Once you start using them to
evaluate code, it isn't hard to find yourself in a mine field.

--
Tim Cross


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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-21 13:18 ` Tim Cross
@ 2020-11-22 20:49   ` Bruno BEAUFILS
  0 siblings, 0 replies; 9+ messages in thread
From: Bruno BEAUFILS @ 2020-11-22 20:49 UTC (permalink / raw)
  To: Tim Cross; +Cc: Bruno BEAUFILS, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 743 bytes --]

On Sun, Nov 22, 2020 at 12:18:07AM +1100, Tim Cross wrote:
> Hmm, I just use backend specific blocks for this purpose. e.g.
> 
> #+begin_export latex
>   \hfil{}
> #+end_export

Yes but it is what I try to avoid in order to let the file as simple
and readable as possible.

> IMO the org #+MACRO is really just a text substitution mechanism (like
> C), not a 'real' macro (like elisp has) and as is the case with C, you
> really need to keep them pretty simple. Once you start using them to
> evaluate code, it isn't hard to find yourself in a mine field.

I agree but as the possibility was offered I used it ;-)

The only trouble is that this eval feature changed in a hard way
between 9.1 and 9.2.

-- 
Bruno BEAUFILS

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-21 10:56 looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test Bruno BEAUFILS
  2020-11-21 13:18 ` Tim Cross
@ 2020-11-23 10:19 ` Eric S Fraga
  2020-11-23 13:02   ` Bruno BEAUFILS
  1 sibling, 1 reply; 9+ messages in thread
From: Eric S Fraga @ 2020-11-23 10:19 UTC (permalink / raw)
  To: Bruno BEAUFILS; +Cc: emacs-orgmode

Maybe define your macro like this:

#+macro: hfill @@latex:\hfill@@

HTH,
eric

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.4-118-g2a4578.dirty


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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-23 10:19 ` Eric S Fraga
@ 2020-11-23 13:02   ` Bruno BEAUFILS
  2020-11-23 13:12     ` Eric S Fraga
  0 siblings, 1 reply; 9+ messages in thread
From: Bruno BEAUFILS @ 2020-11-23 13:02 UTC (permalink / raw)
  To: Bruno BEAUFILS, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 259 bytes --]

On Mon, Nov 23, 2020 at 10:19:16AM +0000, Eric S Fraga wrote:
> Maybe define your macro like this:
> 
> #+macro: hfill @@latex:\hfill@@

Very good idea indeed.

I blame myself not having it in the first place.

Thank's a lot!

-- 
Bruno BEAUFILS

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-23 13:02   ` Bruno BEAUFILS
@ 2020-11-23 13:12     ` Eric S Fraga
  2020-11-29 17:30       ` Bruno BEAUFILS
  0 siblings, 1 reply; 9+ messages in thread
From: Eric S Fraga @ 2020-11-23 13:12 UTC (permalink / raw)
  To: Bruno BEAUFILS; +Cc: emacs-orgmode

On Monday, 23 Nov 2020 at 14:02, Bruno BEAUFILS wrote:
> I blame myself not having it in the first place.

Don't be too hard on yourself! :-)

Org, just like Emacs, has so many different ways of accomplishing
anything that sometimes the easiest is overlooked!

Glad I could help.

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.4-118-g2a4578.dirty


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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-23 13:12     ` Eric S Fraga
@ 2020-11-29 17:30       ` Bruno BEAUFILS
  2020-11-29 17:45         ` Eric S Fraga
  0 siblings, 1 reply; 9+ messages in thread
From: Bruno BEAUFILS @ 2020-11-29 17:30 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Bruno BEAUFILS

[-- Attachment #1: Type: text/plain, Size: 561 bytes --]

On Mon, Nov 23, 2020 at 01:12:45PM +0000, Eric S Fraga wrote:
> Don't be too hard on yourself! :-)

:-)

Any way this nice clean solution works well for almost all my cases
but one: when I include image I want them to be in pdf format in LaTeX
export and in original svg source when exporting in HTML.

I tried different way without any success without my old eval-fueled
=if-backend= MACRO, which I used that way {{{svg(myimage)}}}
(extension being added correctly depending of the backend).

Any idea how to achieve this?

-- 
Bruno BEAUFILS

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-29 17:30       ` Bruno BEAUFILS
@ 2020-11-29 17:45         ` Eric S Fraga
  2020-11-29 20:55           ` Tom Gillespie
  0 siblings, 1 reply; 9+ messages in thread
From: Eric S Fraga @ 2020-11-29 17:45 UTC (permalink / raw)
  To: Bruno BEAUFILS; +Cc: emacs-orgmode

On Sunday, 29 Nov 2020 at 18:30, Bruno BEAUFILS wrote:
> Any way this nice clean solution works well for almost all my cases
> but one: when I include image I want them to be in pdf format in LaTeX
> export and in original svg source when exporting in HTML.

I used to do this the same way you are trying, using the backend
information, but I was never entirely happy with what I achieved.  Since
then, I simply avoid having documents that will be exported to more than
one target... yes, I chickened out! ;-)

Hopefully somebody else can chime in.

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.4-143-g9a1549


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

* Re: looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test
  2020-11-29 17:45         ` Eric S Fraga
@ 2020-11-29 20:55           ` Tom Gillespie
  0 siblings, 0 replies; 9+ messages in thread
From: Tom Gillespie @ 2020-11-29 20:55 UTC (permalink / raw)
  To: Bruno BEAUFILS; +Cc: emacs-orgmode

Not sure if this helps, but the example that I came up with for the
quickstart https://orgmode.org/quickstart.html#macros has an example
(see below) of using multiple @@ export snippets in a single macro. If
you have consistent naming conventions for pdf vs svg you might be
able to write a variant #+macro: image that works like
{{{image(file-name-without-extension)}}}. Not sure this will get you
what you want though since I imagine that you want to modify how links
such as [[file:file-name.ext]] are exported. One alternative would be
to define a custom link type
https://orgmode.org/manual/Adding-Hyperlink-Types.html that would do
the type setting for you. If you want those definitions to live in the
org file you could use Eric's eval: (org-sbe startup) local variable
approach to ensure that the elisp definitions are always available.
Best,
Tom

The example from the quickstart:
#+MACRO: red @@html:<span class="red">$1</span>@@@@latex:\textcolor{red}{$1}@@


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

end of thread, other threads:[~2020-11-29 20:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-21 10:56 looking for a macro eval workaround (9.1 vs 9.2 and +) for export backend test Bruno BEAUFILS
2020-11-21 13:18 ` Tim Cross
2020-11-22 20:49   ` Bruno BEAUFILS
2020-11-23 10:19 ` Eric S Fraga
2020-11-23 13:02   ` Bruno BEAUFILS
2020-11-23 13:12     ` Eric S Fraga
2020-11-29 17:30       ` Bruno BEAUFILS
2020-11-29 17:45         ` Eric S Fraga
2020-11-29 20:55           ` Tom Gillespie

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