emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Choosing image format according to export backend
@ 2013-05-15 17:38 Vincent Beffara
  2013-05-15 17:59 ` Vincent Beffara
  2013-05-15 20:21 ` John Hendy
  0 siblings, 2 replies; 6+ messages in thread
From: Vincent Beffara @ 2013-05-15 17:38 UTC (permalink / raw)
  To: emacs-orgmode

Dear list,

I would like to have the same org file export to both PDF (through
LaTeX) and HTML. The problem I have is images: for printing, PDF images
would be best but for display in a browser, it is much better to have a
PNG file rather than a link to the PDF. So what I need is for the
exporter to choose the image differently according to the backend.

I found this piece of code on stackoverflow:

#+begin_src emacs-lisp :exports results :results value raw
(case (and (boundp 'backend) backend)
  (nil "")
  (latex "[[file:traps.pdf]]")
  (html "[[file:traps.png]]"))
#+end_src

That works, but I was not able to make it recognize captions and such
(except by pasting them in both options or otherwise modifying the lisp
code above). Plus the markup is a bit heavy. Is there a simpler way?

[One thing I thought about was to keep only one of them in the markup,
and modifying the output for the other backend. I kind of know how to
do that within LaTeX by redefining the \includegraphics command but it
feels ... well ... not elegant. Maybe using a hook during one of the
exports?]

Cheers,

-- 
Vincent

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

* Re: Choosing image format according to export backend
  2013-05-15 17:38 Choosing image format according to export backend Vincent Beffara
@ 2013-05-15 17:59 ` Vincent Beffara
  2013-05-15 20:21 ` John Hendy
  1 sibling, 0 replies; 6+ messages in thread
From: Vincent Beffara @ 2013-05-15 17:59 UTC (permalink / raw)
  To: emacs-orgmode

> I would like to have the same org file export to both PDF (through
> LaTeX) and HTML. The problem I have is images: for printing, PDF images
> would be best but for display in a browser, it is much better to have a
> PNG file rather than a link to the PDF. So what I need is for the
> exporter to choose the image differently according to the backend.

... my entry for the dirtiest piece of code possible (but it works for
now):

(defun vb-massage-includegraphics (str backend opts)
  (replace-regexp-in-string ".png}" ".pdf}" str))
(add-hook 'org-export-filter-final-output-functions
          'vb-massage-includegraphics)

Am I on the right track? Meaning, after adding a test on the backend,
possibly a file existence check and so on. Or am I missing a simpler
way?

Cheers,

-- 
Vincent

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

* Re: Choosing image format according to export backend
  2013-05-15 17:38 Choosing image format according to export backend Vincent Beffara
  2013-05-15 17:59 ` Vincent Beffara
@ 2013-05-15 20:21 ` John Hendy
  2013-08-09  9:49   ` Carsten Dominik
  1 sibling, 1 reply; 6+ messages in thread
From: John Hendy @ 2013-05-15 20:21 UTC (permalink / raw)
  To: Vincent Beffara; +Cc: emacs-orgmode

On Wed, May 15, 2013 at 12:38 PM, Vincent Beffara <vbeffara@ens-lyon.fr> wrote:
> Dear list,
>
> I would like to have the same org file export to both PDF (through
> LaTeX) and HTML. The problem I have is images: for printing, PDF images
> would be best but for display in a browser, it is much better to have a
> PNG file rather than a link to the PDF. So what I need is for the
> exporter to choose the image differently according to the backend.

I know this is more of a request for coding help, but just wanted to
add my vote that this would be great. I don't use html *that* much,
but having the option would be awesome, and the replacement of all
*.pdf links with *.png (and typically re-running R code to generate
.png version, or running imagemagick on the dir to create them) is
typically too much of a barrier so I just stick with PDF/Beamer.

I'd love something like this.


John

>
> I found this piece of code on stackoverflow:
>
> #+begin_src emacs-lisp :exports results :results value raw
> (case (and (boundp 'backend) backend)
>   (nil "")
>   (latex "[[file:traps.pdf]]")
>   (html "[[file:traps.png]]"))
> #+end_src
>
> That works, but I was not able to make it recognize captions and such
> (except by pasting them in both options or otherwise modifying the lisp
> code above). Plus the markup is a bit heavy. Is there a simpler way?
>
> [One thing I thought about was to keep only one of them in the markup,
> and modifying the output for the other backend. I kind of know how to
> do that within LaTeX by redefining the \includegraphics command but it
> feels ... well ... not elegant. Maybe using a hook during one of the
> exports?]
>
> Cheers,
>
> --
> Vincent
>
>

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

* Re: Choosing image format according to export backend
  2013-05-15 20:21 ` John Hendy
@ 2013-08-09  9:49   ` Carsten Dominik
  2013-08-09 10:26     ` Suvayu Ali
  2013-08-09 15:36     ` Eric Schulte
  0 siblings, 2 replies; 6+ messages in thread
From: Carsten Dominik @ 2013-08-09  9:49 UTC (permalink / raw)
  To: John Hendy; +Cc: Vincent Beffara, emacs-orgmode


On 15.5.2013, at 22:21, John Hendy <jw.hendy@gmail.com> wrote:

> On Wed, May 15, 2013 at 12:38 PM, Vincent Beffara <vbeffara@ens-lyon.fr> wrote:
>> Dear list,
>> 
>> I would like to have the same org file export to both PDF (through
>> LaTeX) and HTML. The problem I have is images: for printing, PDF images
>> would be best but for display in a browser, it is much better to have a
>> PNG file rather than a link to the PDF. So what I need is for the
>> exporter to choose the image differently according to the backend.
> 
> I know this is more of a request for coding help, but just wanted to
> add my vote that this would be great. I don't use html *that* much,
> but having the option would be awesome, and the replacement of all
> *.pdf links with *.png (and typically re-running R code to generate
> .png version, or running imagemagick on the dir to create them) is
> typically too much of a barrier so I just stick with PDF/Beamer.
> 
> I'd love something like this.

I think this should be possible using filters in the exporter.

- Carsten

> 
> 
> John
> 
>> 
>> I found this piece of code on stackoverflow:
>> 
>> #+begin_src emacs-lisp :exports results :results value raw
>> (case (and (boundp 'backend) backend)
>>  (nil "")
>>  (latex "[[file:traps.pdf]]")
>>  (html "[[file:traps.png]]"))
>> #+end_src
>> 
>> That works, but I was not able to make it recognize captions and such
>> (except by pasting them in both options or otherwise modifying the lisp
>> code above). Plus the markup is a bit heavy. Is there a simpler way?
>> 
>> [One thing I thought about was to keep only one of them in the markup,
>> and modifying the output for the other backend. I kind of know how to
>> do that within LaTeX by redefining the \includegraphics command but it
>> feels ... well ... not elegant. Maybe using a hook during one of the
>> exports?]
>> 
>> Cheers,
>> 
>> --
>> Vincent
>> 
>> 
> 

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

* Re: Choosing image format according to export backend
  2013-08-09  9:49   ` Carsten Dominik
@ 2013-08-09 10:26     ` Suvayu Ali
  2013-08-09 15:36     ` Eric Schulte
  1 sibling, 0 replies; 6+ messages in thread
From: Suvayu Ali @ 2013-08-09 10:26 UTC (permalink / raw)
  To: emacs-orgmode

On Fri, Aug 09, 2013 at 11:49:48AM +0200, Carsten Dominik wrote:
> 
> On 15.5.2013, at 22:21, John Hendy <jw.hendy@gmail.com> wrote:
> 
> > On Wed, May 15, 2013 at 12:38 PM, Vincent Beffara <vbeffara@ens-lyon.fr> wrote:
> >> Dear list,
> >> 
> >> I would like to have the same org file export to both PDF (through
> >> LaTeX) and HTML. The problem I have is images: for printing, PDF images
> >> would be best but for display in a browser, it is much better to have a
> >> PNG file rather than a link to the PDF. So what I need is for the
> >> exporter to choose the image differently according to the backend.
> > 
> > I know this is more of a request for coding help, but just wanted to
> > add my vote that this would be great. I don't use html *that* much,
> > but having the option would be awesome, and the replacement of all
> > *.pdf links with *.png (and typically re-running R code to generate
> > .png version, or running imagemagick on the dir to create them) is
> > typically too much of a barrier so I just stick with PDF/Beamer.
> > 
> > I'd love something like this.
> 
> I think this should be possible using filters in the exporter.

I posted a similar example recently.

<http://mid.gmane.org/20130719102315.GB9369@kuru.dyndns-at-home.com>

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Choosing image format according to export backend
  2013-08-09  9:49   ` Carsten Dominik
  2013-08-09 10:26     ` Suvayu Ali
@ 2013-08-09 15:36     ` Eric Schulte
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Schulte @ 2013-08-09 15:36 UTC (permalink / raw)
  To: Vincent Beffara; +Cc: emacs-orgmode

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

Carsten Dominik <carsten.dominik@gmail.com> writes:

> On 15.5.2013, at 22:21, John Hendy <jw.hendy@gmail.com> wrote:
>
>> On Wed, May 15, 2013 at 12:38 PM, Vincent Beffara <vbeffara@ens-lyon.fr> wrote:
>>> Dear list,
>>> 
>>> I would like to have the same org file export to both PDF (through
>>> LaTeX) and HTML. The problem I have is images: for printing, PDF images
>>> would be best but for display in a browser, it is much better to have a
>>> PNG file rather than a link to the PDF. So what I need is for the
>>> exporter to choose the image differently according to the backend.
>> 
>> I know this is more of a request for coding help, but just wanted to
>> add my vote that this would be great. I don't use html *that* much,
>> but having the option would be awesome, and the replacement of all
>> *.pdf links with *.png (and typically re-running R code to generate
>> .png version, or running imagemagick on the dir to create them) is
>> typically too much of a barrier so I just stick with PDF/Beamer.
>> 
>> I'd love something like this.
>

This was very recently discussed with respect to latex code, and
conditional pdf or svg export.  Could the following solution be adapted
to your R code blocks?

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

e.g. something like the following,


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: conditional-export.org --]
[-- Type: text/x-org, Size: 641 bytes --]

#+Title: Conditional export

* Conditional Export Test
Here's a tree, exported to both html and pdf.

#+name: rnorm
#+headers: :exports results
#+headers: :results graphics
#+begin_src R :file (by-backend (latex "rnorm.pdf") (t "rnorm.png"))
  plot(rnorm(100), rnorm(100))
#+end_src

#+Caption: Normal random data.
#+RESULTS: rnorm
[[file:rnorm.png]]

* COMMENT setup
This function could be added to the user's =.emacs= init file.

#+begin_src emacs-lisp :results silent
  (setq org-babel-latex-htlatex "htlatex")
  (defmacro by-backend (&rest body)
    `(case (if (boundp 'backend) (org-export-backend-name backend) nil) ,@body))
#+end_src

[-- Attachment #3: Type: text/plain, Size: 62 bytes --]


-- 
Eric Schulte
http://cs.unm.edu/~eschulte
PGP: 0x614CA05D

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

end of thread, other threads:[~2013-08-09 15:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-15 17:38 Choosing image format according to export backend Vincent Beffara
2013-05-15 17:59 ` Vincent Beffara
2013-05-15 20:21 ` John Hendy
2013-08-09  9:49   ` Carsten Dominik
2013-08-09 10:26     ` Suvayu Ali
2013-08-09 15:36     ` Eric Schulte

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