emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Exporting images to different output formats
@ 2022-10-29 11:52 Michael Welle
  2022-10-30  4:37 ` Ihor Radchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Welle @ 2022-10-29 11:52 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I want to export to different output formats. Trouble is the way ox-gfm
exports images. So I thought, hm, why not utilise macros to abstract away
the differences. Well, that escalated quickly:

#+macro: img_gfm (eval (concat "#+begin_export md\n![img](" $1 " \"" $2  "\")\n*Abb.: " $2 "* (Quelle: " $3 ")\n#+end_export"))

#+macro: img_latex (eval "foobar")

# Image export for Github flavoured markdown
# $1 path to image
# $2 caption
# $3 source
#+macro: img (eval (cl-case org-export-current-backend ('gfm (concat "{{{img_gfm(" $1 "," $2 "," $3")}}}")) ('latex "{{{img_latex}}}") (t "barfoo")))


{{{img(./foo, foo, barfoo)}}}

That kind of works (and breaks if I want commas in the caption), but is
ugly as... and doesn't get better if I implement the other output formats.

Maybe syntax like @@latex: ...@@ would help. But no, I think that is
defined in the specific backends, not as a general mechanism.

So, how can I do it better?

All the best,
hmw


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

* Re: Exporting images to different output formats
  2022-10-29 11:52 Exporting images to different output formats Michael Welle
@ 2022-10-30  4:37 ` Ihor Radchenko
  2022-11-01  7:41   ` Michael Welle
  0 siblings, 1 reply; 3+ messages in thread
From: Ihor Radchenko @ 2022-10-30  4:37 UTC (permalink / raw)
  To: Michael Welle; +Cc: emacs-orgmode

Michael Welle <mwe012008@gmx.net> writes:

> I want to export to different output formats. Trouble is the way ox-gfm
> exports images. So I thought, hm, why not utilise macros to abstract away
> the differences. Well, that escalated quickly:
>
> #+macro: img_gfm (eval (concat "#+begin_export md\n![img](" $1 " \"" $2  "\")\n*Abb.: " $2 "* (Quelle: " $3 ")\n#+end_export"))
>
> #+macro: img_latex (eval "foobar")
>
> # Image export for Github flavoured markdown
> # $1 path to image
> # $2 caption
> # $3 source
> #+macro: img (eval (cl-case org-export-current-backend ('gfm (concat "{{{img_gfm(" $1 "," $2 "," $3")}}}")) ('latex "{{{img_latex}}}") (t "barfoo")))
>
>
> {{{img(./foo, foo, barfoo)}}}
>
> That kind of works (and breaks if I want commas in the caption)

Re: commas. See 13.5 Macro Replacement

   (1) Since commas separate the arguments, commas within arguments have
to be escaped with the backslash character.  So only those backslash
characters before a comma need escaping with another backslash
character.

> , but is
> ugly as... and doesn't get better if I implement the other output formats.

Agree. The proper way to implement this is special blocks + custom
export filter that will take care about backend selection.

Also, see https://list.orgmode.org/orgmode/87y1yr9gbl.fsf@gmail.com/
referring to https://github.com/alhassy/org-special-block-extras/

> Maybe syntax like @@latex: ...@@ would help. But no, I think that is
> defined in the specific backends, not as a general mechanism.

You can have multiple export blocks---one for each backend.

-- 
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] 3+ messages in thread

* Re: Exporting images to different output formats
  2022-10-30  4:37 ` Ihor Radchenko
@ 2022-11-01  7:41   ` Michael Welle
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Welle @ 2022-11-01  7:41 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

Ihor Radchenko <yantar92@posteo.net> writes:

> Michael Welle <mwe012008@gmx.net> writes:
[...]
>> {{{img(./foo, foo, barfoo)}}}
>>
>> That kind of works (and breaks if I want commas in the caption)
>
> Re: commas. See 13.5 Macro Replacement
I found that shortly after posting. Works as expected.


>    (1) Since commas separate the arguments, commas within arguments have
> to be escaped with the backslash character.  So only those backslash
> characters before a comma need escaping with another backslash
> character.
>
>> , but is
>> ugly as... and doesn't get better if I implement the other output formats.
>
> Agree. The proper way to implement this is special blocks + custom
> export filter that will take care about backend selection.
>
> Also, see https://list.orgmode.org/orgmode/87y1yr9gbl.fsf@gmail.com/
> referring to https://github.com/alhassy/org-special-block-extras/
Ah, that looks promising.

Thank you!

All the best
hmw


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

end of thread, other threads:[~2022-11-01  7:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-29 11:52 Exporting images to different output formats Michael Welle
2022-10-30  4:37 ` Ihor Radchenko
2022-11-01  7:41   ` Michael Welle

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