emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Switch for exported file types when evaluating code blocks
@ 2013-07-17 22:08 Brett Viren
  2013-07-18  0:45 ` Cook, Malcolm
  0 siblings, 1 reply; 9+ messages in thread
From: Brett Viren @ 2013-07-17 22:08 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

I'm hitting on an old theme in a new way here.  

I want graphics files which are exported by evaluated code blocks to be
generated in a format best suited to their intended use.  For HTML I
want either PNG or SVG.  For LaTeX/PDF I almost always want PDF.  For
inline viewing in emacs I want either PNG or SVG.

To that end I went a'googling and found this idea:

  http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html#sec-4-3

It doesn't work with my copies[1] of emacs and org-mode but I was able
to adapt it.  I suck at elisp so this is probably more an accomplishment
to me than it appears to most of you!

In any case, here is a short org document based on the one I found above
in worg which shows what I ended up with:


* COMMENT setup
#+begin_src emacs-lisp :results silent
  (defmacro by-backend (&rest body)
    `(case (if (boundp 'backend) backend nil) ,@body))
#+end_src

* A graph
#+header: :file (by-backend (html "graph.png") (latex "graph.pdf") (t "graph.svg"))
#+header: :export results
#+begin_src dot
digraph Name {
        tail -> head;
}
#+end_src


I think the real learning experience for me was that I could put lisp
directly in a header like this!  Now, I just gotta learn elisp
better....

Also, I'd certainly be interested to hear of any better ways to
accomplish this.

Thanks,
-Brett.


[1] The versions I'm using are

 - Org-mode version 8.0.3 (8.0.3-elpa @ /home/bviren/.emacs.d/elpa/org-20130514/)

 - GNU Emacs 24.1.1 (i486-pc-linux-gnu, GTK+ Version 2.24.10) of 2012-07-20 on murphy, modified by Debian

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: Switch for exported file types when evaluating code blocks
  2013-07-17 22:08 Switch for exported file types when evaluating code blocks Brett Viren
@ 2013-07-18  0:45 ` Cook, Malcolm
  2013-07-18  2:02   ` Suvayu Ali
  0 siblings, 1 reply; 9+ messages in thread
From: Cook, Malcolm @ 2013-07-18  0:45 UTC (permalink / raw)
  To: 'Brett Viren', 'emacs-orgmode@gnu.org'

>I want graphics files which are exported by evaluated code blocks to be
 >generated in a format best suited to their intended use.  For HTML I
 >want either PNG or SVG.  For LaTeX/PDF I almost always want PDF.  For
 >inline viewing in emacs I want either PNG or SVG.
 >
 >To that end I went a'googling and found this idea:
 >
 >  http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html#sec-4-3
 >
 >It doesn't work with my copies[1] of emacs and org-mode but I was able
 >to adapt it.  I suck at elisp so this is probably more an accomplishment
 >to me than it appears to most of you!
 >
 >In any case, here is a short org document based on the one I found above
 >in worg which shows what I ended up with:
 >
 >
 >* COMMENT setup
 >#+begin_src emacs-lisp :results silent
 >  (defmacro by-backend (&rest body)
 >    `(case (if (boundp 'backend) backend nil) ,@body))
 >#+end_src
 >
 >* A graph
 >#+header: :file (by-backend (html "graph.png") (latex "graph.pdf") (t "graph.svg"))
 >#+header: :export results
 >#+begin_src dot
 >digraph Name {
 >        tail -> head;
 >}
 >#+end_src
[Cook, Malcolm] 

Brett,

Thanks for posting your findings.  They almost help me.

I am looking for a solution to a similar problem.

I tend to work with org-export-babel-evaluate set to nil.  Thus, my code blocks are not evaled in the context of an export.  Thus at eval time there is no way of knowing what the eventual backend is going to be.

I think I need an approach that auto converts svg to png on-demand/on-the-fly during export.

Has anyone come across a variation on this that works as I am suggesting?

Thanks!

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

* Re: Switch for exported file types when evaluating code blocks
  2013-07-18  0:45 ` Cook, Malcolm
@ 2013-07-18  2:02   ` Suvayu Ali
  2013-07-18  4:02     ` Nick Dokos
  0 siblings, 1 reply; 9+ messages in thread
From: Suvayu Ali @ 2013-07-18  2:02 UTC (permalink / raw)
  To: emacs-orgmode

Hello again Malcolm,

On Thu, Jul 18, 2013 at 12:45:36AM +0000, Cook, Malcolm wrote:
> 
> I tend to work with org-export-babel-evaluate set to nil.  Thus, my code blocks are not evaled in the context of an export.  Thus at eval time there is no way of knowing what the eventual backend is going to be.
> 
> I think I need an approach that auto converts svg to png on-demand/on-the-fly during export.

In that case just use another source block with shell source.  In that
block you can call inkscape to do the conversion.  For an example, see
here:
<http://ctan.mirrorcatalogs.com/info/svg-inkscape/InkscapePDFLaTeX.pdf#subsubsection.2.3.1>

Hope this helps,

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Switch for exported file types when evaluating code blocks
  2013-07-18  2:02   ` Suvayu Ali
@ 2013-07-18  4:02     ` Nick Dokos
  2013-07-18 19:06       ` Cook, Malcolm
  0 siblings, 1 reply; 9+ messages in thread
From: Nick Dokos @ 2013-07-18  4:02 UTC (permalink / raw)
  To: emacs-orgmode

Suvayu Ali <fatkasuvayu+linux@gmail.com> writes:

> Hello again Malcolm,
>
> On Thu, Jul 18, 2013 at 12:45:36AM +0000, Cook, Malcolm wrote:
>> 
>> I tend to work with org-export-babel-evaluate set to nil.  Thus, my
>> code blocks are not evaled in the context of an export.  Thus at
>> eval time there is no way of knowing what the eventual backend is
>> going to be.
>> 
>> I think I need an approach that auto converts svg to png on-demand/on-the-fly during export.
>
> In that case just use another source block with shell source.  In that
> block you can call inkscape to do the conversion.  For an example, see
> here:
> <http://ctan.mirrorcatalogs.com/info/svg-inkscape/InkscapePDFLaTeX.pdf#subsubsection.2.3.1>
>

OT for the OP (say that three times fast!) but maybe of some use to somebody:

For SVG, there is a latex package that is an evolutionary offshoot of
the above link. It does the inkscape dance so you don't have to:

   http://www.tex.ac.uk/ctan/graphics/svg/

-- 
Nick

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

* Re: Switch for exported file types when evaluating code blocks
  2013-07-18  4:02     ` Nick Dokos
@ 2013-07-18 19:06       ` Cook, Malcolm
  2013-07-19  1:02         ` Nick Dokos
  0 siblings, 1 reply; 9+ messages in thread
From: Cook, Malcolm @ 2013-07-18 19:06 UTC (permalink / raw)
  To: 'Nick Dokos', 'emacs-orgmode@gnu.org'

Hi Nick,  I'm not sure how to use this ctan package in concert with orgmode's export to tex->pdf.  

Perhaps there is a way to use orgmode's export filtering capability to swap in a up-to-date png when exporting to tex....

Hmmm....

Anyone?

Thx!

 >-----Original Message-----
 >From: emacs-orgmode-bounces+mec=stowers.org@gnu.org [mailto:emacs-orgmode-bounces+mec=stowers.org@gnu.org] On
 >Behalf Of Nick Dokos
 >Sent: Wednesday, July 17, 2013 11:02 PM
 >To: emacs-orgmode@gnu.org
 >Subject: Re: [O] Switch for exported file types when evaluating code blocks
 >
 >Suvayu Ali <fatkasuvayu+linux@gmail.com> writes:
 >
 >> Hello again Malcolm,
 >>
 >> On Thu, Jul 18, 2013 at 12:45:36AM +0000, Cook, Malcolm wrote:
 >>>
 >>> I tend to work with org-export-babel-evaluate set to nil.  Thus, my
 >>> code blocks are not evaled in the context of an export.  Thus at
 >>> eval time there is no way of knowing what the eventual backend is
 >>> going to be.
 >>>
 >>> I think I need an approach that auto converts svg to png on-demand/on-the-fly during export.
 >>
 >> In that case just use another source block with shell source.  In that
 >> block you can call inkscape to do the conversion.  For an example, see
 >> here:
 >> <http://ctan.mirrorcatalogs.com/info/svg-inkscape/InkscapePDFLaTeX.pdf#subsubsection.2.3.1>
 >>
 >
 >OT for the OP (say that three times fast!) but maybe of some use to somebody:
 >
 >For SVG, there is a latex package that is an evolutionary offshoot of
 >the above link. It does the inkscape dance so you don't have to:
 >
 >   http://www.tex.ac.uk/ctan/graphics/svg/
 >
 >--
 >Nick
 >

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

* Re: Switch for exported file types when evaluating code blocks
  2013-07-18 19:06       ` Cook, Malcolm
@ 2013-07-19  1:02         ` Nick Dokos
  2013-07-19 10:23           ` Suvayu Ali
  2013-07-19 15:22           ` Cook, Malcolm
  0 siblings, 2 replies; 9+ messages in thread
From: Nick Dokos @ 2013-07-19  1:02 UTC (permalink / raw)
  To: emacs-orgmode

"Cook, Malcolm" <MEC@stowers.org> writes:

> Hi Nick, I'm not sure how to use this ctan package in concert with
> orgmode's export to tex->pdf.
>

Here's a simplfied example of what I did with it. The source block uses
dot to produce an SVG file for illustration - if you already have one
then you can ignore it:

--8<---------------cut here---------------start------------->8---
#+LATEX_HEADER: \usepackage{svg}

* foo

#+name: foo
#+BEGIN_SRC dot :file foo.svg :exports results :results none
digraph foo {
  a -> b
}
#+END_SRC

#+BEGIN_LaTeX
\includesvg{foo}
#+END_LaTeX
--8<---------------cut here---------------end--------------->8---

> Perhaps there is a way to use orgmode's export filtering capability to
> swap in a up-to-date png when exporting to tex....

PNG is a raster format whereas SVG is a vector format. I was trying to
produce some slides and I did use PNG at first because it's easier to
fit into the pdflatex workflow. But when I made the slides full screen,
the PNG got fuzzy. Sticking with SVG got rid of the fuzzies for me.

>
> Hmmm....
>
> Anyone?
>
> Thx!
>
>  >-----Original Message-----
>  >From: emacs-orgmode-bounces+mec=stowers.org@gnu.org [mailto:emacs-orgmode-bounces+mec=stowers.org@gnu.org] On
>  >Behalf Of Nick Dokos
>  >Sent: Wednesday, July 17, 2013 11:02 PM
>  >To: emacs-orgmode@gnu.org
>  >Subject: Re: [O] Switch for exported file types when evaluating code blocks
>  >
>  >Suvayu Ali <fatkasuvayu+linux@gmail.com> writes:
>  >
>  >> Hello again Malcolm,
>  >>
>  >> On Thu, Jul 18, 2013 at 12:45:36AM +0000, Cook, Malcolm wrote:
>  >>>
>  >>> I tend to work with org-export-babel-evaluate set to nil.  Thus, my
>  >>> code blocks are not evaled in the context of an export.  Thus at
>  >>> eval time there is no way of knowing what the eventual backend is
>  >>> going to be.
>  >>>
>  >>> I think I need an approach that auto converts svg to png on-demand/on-the-fly during export.
>  >>
>  >> In that case just use another source block with shell source.  In that
>  >> block you can call inkscape to do the conversion.  For an example, see
>  >> here:
>  >> <http://ctan.mirrorcatalogs.com/info/svg-inkscape/InkscapePDFLaTeX.pdf#subsubsection.2.3.1>
>  >>
>  >
>  >OT for the OP (say that three times fast!) but maybe of some use to somebody:
>  >
>  >For SVG, there is a latex package that is an evolutionary offshoot of
>  >the above link. It does the inkscape dance so you don't have to:
>  >
>  >   http://www.tex.ac.uk/ctan/graphics/svg/
>  >
>  >--
>  >Nick
>  >
>
>
>

-- 
Nick

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

* Re: Switch for exported file types when evaluating code blocks
  2013-07-19  1:02         ` Nick Dokos
@ 2013-07-19 10:23           ` Suvayu Ali
  2013-07-19 15:19             ` Cook, Malcolm
  2013-07-19 15:22           ` Cook, Malcolm
  1 sibling, 1 reply; 9+ messages in thread
From: Suvayu Ali @ 2013-07-19 10:23 UTC (permalink / raw)
  To: emacs-orgmode

On Thu, Jul 18, 2013 at 09:02:41PM -0400, Nick Dokos wrote:
> 
> #+BEGIN_LaTeX
> \includesvg{foo}
> #+END_LaTeX

I believe even this can be integrated with Org using a filter.  How
about something like this:

(defun my-svg-graphics (contents backend info)
  (when (eq backend 'latex)
    (replace-regexp-in-string "\\`\\\\includegraphics.+\\({.+\.svg}\\)"
       "\\\\includesvg\1" contents)))

(add-to-list 'org-export-filter-link-functions 'my-svg-graphics)

Of course the above ignores the options since I do not know if
\includesvg takes the same options.  But that is a detail that can be
fixed by changing the regexp.

What do you think?

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Switch for exported file types when evaluating code blocks
  2013-07-19 10:23           ` Suvayu Ali
@ 2013-07-19 15:19             ` Cook, Malcolm
  0 siblings, 0 replies; 9+ messages in thread
From: Cook, Malcolm @ 2013-07-19 15:19 UTC (permalink / raw)
  To: Suvayu Ali, emacs-orgmode@gnu.org

Suvayu,

This is splendid news!  I will try it immediately upon return from "gone fishin" in a week...

 (erhm, that is, right after I figure out haw to migrate my orgmode SETUPFILE to comport with new export backend I just upgraded to.... my fancy TOC and org-export-html-table-tag javascript have "gone missin")

Future is looking bright!,

~ malcolm_cook@stowers.org

________________________________________
From: emacs-orgmode-bounces+mec=stowers.org@gnu.org [emacs-orgmode-bounces+mec=stowers.org@gnu.org] on behalf of Suvayu Ali [fatkasuvayu+linux@gmail.com]
Sent: Friday, July 19, 2013 5:23 AM
To: emacs-orgmode@gnu.org
Subject: Re: [O] Switch for exported file types when evaluating code blocks

On Thu, Jul 18, 2013 at 09:02:41PM -0400, Nick Dokos wrote:
>
> #+BEGIN_LaTeX
> \includesvg{foo}
> #+END_LaTeX

I believe even this can be integrated with Org using a filter.  How
about something like this:

(defun my-svg-graphics (contents backend info)
  (when (eq backend 'latex)
    (replace-regexp-in-string "\\`\\\\includegraphics.+\\({.+\.svg}\\)"
       "\\\\includesvg\1" contents)))

(add-to-list 'org-export-filter-link-functions 'my-svg-graphics)

Of course the above ignores the options since I do not know if
\includesvg takes the same options.  But that is a detail that can be
fixed by changing the regexp.

What do you think?


--
Suvayu

Open source is the future. It sets us free.


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

* Re: Switch for exported file types when evaluating code blocks
  2013-07-19  1:02         ` Nick Dokos
  2013-07-19 10:23           ` Suvayu Ali
@ 2013-07-19 15:22           ` Cook, Malcolm
  1 sibling, 0 replies; 9+ messages in thread
From: Cook, Malcolm @ 2013-07-19 15:22 UTC (permalink / raw)
  To: Nick Dokos, emacs-orgmode@gnu.org

Great Example, Nick, Thanks, will push on with this approach....

~ malcolm_cook@stowers.org

________________________________________
From: emacs-orgmode-bounces+mec=stowers.org@gnu.org [emacs-orgmode-bounces+mec=stowers.org@gnu.org] on behalf of Nick Dokos [ndokos@gmail.com]
Sent: Thursday, July 18, 2013 8:02 PM
To: emacs-orgmode@gnu.org
Subject: Re: [O] Switch for exported file types when evaluating code blocks

"Cook, Malcolm" <MEC@stowers.org> writes:

> Hi Nick, I'm not sure how to use this ctan package in concert with
> orgmode's export to tex->pdf.
>

Here's a simplfied example of what I did with it. The source block uses
dot to produce an SVG file for illustration - if you already have one
then you can ignore it:

--8<---------------cut here---------------start------------->8---
#+LATEX_HEADER: \usepackage{svg}

* foo

#+name: foo
#+BEGIN_SRC dot :file foo.svg :exports results :results none
digraph foo {
  a -> b
}
#+END_SRC

#+BEGIN_LaTeX
\includesvg{foo}
#+END_LaTeX
--8<---------------cut here---------------end--------------->8---

> Perhaps there is a way to use orgmode's export filtering capability to
> swap in a up-to-date png when exporting to tex....

PNG is a raster format whereas SVG is a vector format. I was trying to
produce some slides and I did use PNG at first because it's easier to
fit into the pdflatex workflow. But when I made the slides full screen,
the PNG got fuzzy. Sticking with SVG got rid of the fuzzies for me.

>
> Hmmm....
>
> Anyone?
>
> Thx!
>
>  >-----Original Message-----
>  >From: emacs-orgmode-bounces+mec=stowers.org@gnu.org [mailto:emacs-orgmode-bounces+mec=stowers.org@gnu.org] On
>  >Behalf Of Nick Dokos
>  >Sent: Wednesday, July 17, 2013 11:02 PM
>  >To: emacs-orgmode@gnu.org
>  >Subject: Re: [O] Switch for exported file types when evaluating code blocks
>  >
>  >Suvayu Ali <fatkasuvayu+linux@gmail.com> writes:
>  >
>  >> Hello again Malcolm,
>  >>
>  >> On Thu, Jul 18, 2013 at 12:45:36AM +0000, Cook, Malcolm wrote:
>  >>>
>  >>> I tend to work with org-export-babel-evaluate set to nil.  Thus, my
>  >>> code blocks are not evaled in the context of an export.  Thus at
>  >>> eval time there is no way of knowing what the eventual backend is
>  >>> going to be.
>  >>>
>  >>> I think I need an approach that auto converts svg to png on-demand/on-the-fly during export.
>  >>
>  >> In that case just use another source block with shell source.  In that
>  >> block you can call inkscape to do the conversion.  For an example, see
>  >> here:
>  >> <http://ctan.mirrorcatalogs.com/info/svg-inkscape/InkscapePDFLaTeX.pdf#subsubsection.2.3.1>
>  >>
>  >
>  >OT for the OP (say that three times fast!) but maybe of some use to somebody:
>  >
>  >For SVG, there is a latex package that is an evolutionary offshoot of
>  >the above link. It does the inkscape dance so you don't have to:
>  >
>  >   http://www.tex.ac.uk/ctan/graphics/svg/
>  >
>  >--
>  >Nick
>  >
>
>
>

--
Nick



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

end of thread, other threads:[~2013-07-19 15:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-17 22:08 Switch for exported file types when evaluating code blocks Brett Viren
2013-07-18  0:45 ` Cook, Malcolm
2013-07-18  2:02   ` Suvayu Ali
2013-07-18  4:02     ` Nick Dokos
2013-07-18 19:06       ` Cook, Malcolm
2013-07-19  1:02         ` Nick Dokos
2013-07-19 10:23           ` Suvayu Ali
2013-07-19 15:19             ` Cook, Malcolm
2013-07-19 15:22           ` Cook, Malcolm

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