emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Block level specification for tex code html export method
@ 2015-08-10  8:11 Haochen Xie
  2015-08-10 22:56 ` Andreas Leha
  0 siblings, 1 reply; 23+ messages in thread
From: Haochen Xie @ 2015-08-10  8:11 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

I'm trying to include a diagram drawn with tikz in a document, but
couldn't find an elegant way to conditionally export it as png when
generating HTML output and raw TeX code when generating PDF. It is
possible to use

#+OPTIONS: tex:imagemagick

to have tex blocks in the document exported as PNG in HTML, but since
I have other formulas which will render much better with MathJAX other
than embedded PNGs, i really don't want to do it. What I'm currently
doing is to use something like

#+BEGIN_SRC latex :file diagram.png :results value raw
\begin{tikzpicture}
  \draw (0,0) grid (7,5);
  \draw (0,0) node[below left] {$A$};
  \draw (7,5) node[above right] {$B$};
  \fill (0,0) circle (2pt);
  \fill (7,5) circle (2pt);
\end{tikzpicture}
#+END_SRC

#+RESULTS[da59bc402ce2d1055b5ff471ea7e398c4e0488f5]:
[[file:diagram.png]]

so that the diagram will be include in the HTML file as a png image,
and the pdf file will also include it as a raster image.

But this method is rather a workaround. I'd like to see a vector
diagram in the pdf file, which could be achieved if there is a way to
specify how a block of TeX source code should be handled when exported
to HTML regardless to the global settings. So I propose an extension
to #+BEGIN_LaTeX block so that a new header :html will control how the
specific block will be handled when exporting to HTML. The possible
values might be none, t, dvipng, or imagemagick. "none" will ignore
the whole block when exporting to HTML, just like the current
behavior; "t" will try to call MathJAX to interpret this block of TeX
code; and "dvipng" and "imagemagick" will call "dvipng" or
"imagemagick" to render a png file to be embedded in the HTML page.

If that extension is supported, we could then left the global option
tex:t while inline a tex powered figure with great convenience. For
example, in my use case, I could then just used the following code to
achieve what I want:

#+BEGIN_LaTeX :html imagemagick
\begin{tikzpicture}
  \draw (0,0) grid (7,5);
  \draw (0,0) node[below left] {$A$};
  \draw (7,5) node[above right] {$B$};
  \fill (0,0) circle (2pt);
  \fill (7,5) circle (2pt);
\end{tikzpicture}
#+END_LaTeX

As I'm new to org-mode, I may missed something that I could use
instead (although I searched the internet very hard). Please feel free
to disagree on me and point alternative ways to achieve my goal.

Thanks in advance.

Best regards,

Haochen

--

Mail from Haochen Xie

[-- Attachment #2: Type: text/html, Size: 7216 bytes --]

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

* Re: Block level specification for tex code html export method
  2015-08-10  8:11 Block level specification for tex code html export method Haochen Xie
@ 2015-08-10 22:56 ` Andreas Leha
  2015-08-11  8:47   ` Haochen Xie
  0 siblings, 1 reply; 23+ messages in thread
From: Andreas Leha @ 2015-08-10 22:56 UTC (permalink / raw)
  To: emacs-orgmode

Hi Haochen,


Haochen Xie <haochen@xie.name> writes:
> Hi,
>
> I'm trying to include a diagram drawn with tikz in a document, but
> couldn't find an elegant way to conditionally export it as png when
> generating HTML output and raw TeX code when generating PDF. It is
> possible to use
>
> #+OPTIONS: tex:imagemagick
>
> to have tex blocks in the document exported as PNG in HTML, but since
> I have other formulas which will render much better with MathJAX other
> than embedded PNGs, i really don't want to do it. What I'm currently
> doing is to use something like
>
> #+BEGIN_SRC latex :file diagram.png :results value raw
> \begin{tikzpicture}
> \draw (0,0) grid (7,5);
> \draw (0,0) node[below left] {$A$};
> \draw (7,5) node[above right] {$B$};
> \fill (0,0) circle (2pt);
> \fill (7,5) circle (2pt);
> \end{tikzpicture}
> #+END_SRC
>
> #+RESULTS[da59bc402ce2d1055b5ff471ea7e398c4e0488f5]:
> [[file:diagram.png]]
>
> so that the diagram will be include in the HTML file as a png image,
> and the pdf file will also include it as a raster image.
>
> But this method is rather a workaround. I'd like to see a vector
> diagram in the pdf file, which could be achieved if there is a way to
> specify how a block of TeX source code should be handled when exported
> to HTML regardless to the global settings. So I propose an extension
> to #+BEGIN_LaTeX block so that a new header :html will control how the
> specific block will be handled when exporting to HTML. The possible
> values might be none, t, dvipng, or imagemagick. "none" will ignore
> the whole block when exporting to HTML, just like the current
> behavior; "t" will try to call MathJAX to interpret this block of TeX
> code; and "dvipng" and "imagemagick" will call "dvipng" or
> "imagemagick" to render a png file to be embedded in the HTML page.
>
> If that extension is supported, we could then left the global option
> tex:t while inline a tex powered figure with great convenience. For
> example, in my use case, I could then just used the following code to
> achieve what I want:
>
> #+BEGIN_LaTeX :html imagemagick
> \begin{tikzpicture}
> \draw (0,0) grid (7,5);
> \draw (0,0) node[below left] {$A$};
> \draw (7,5) node[above right] {$B$};
> \fill (0,0) circle (2pt);
> \fill (7,5) circle (2pt);
> \end{tikzpicture}
> #+END_LaTeX
>
> As I'm new to org-mode, I may missed something that I could use
> instead (although I searched the internet very hard). Please feel free
> to disagree on me and point alternative ways to achieve my goal.
>
> Thanks in advance.
>
> Best regards,
>
> Haochen
>

There has been a thread on this list recently on this topic [1].
See [2] for an example and [3] for some further explanations.

Regards,
Andreas

[1] http://comments.gmane.org/gmane.emacs.orgmode/95174

[2] http://permalink.gmane.org/gmane.emacs.orgmode/95197

[3] http://permalink.gmane.org/gmane.emacs.orgmode/95297

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

* Re: Block level specification for tex code html export method
  2015-08-10 22:56 ` Andreas Leha
@ 2015-08-11  8:47   ` Haochen Xie
  2015-08-11  8:53     ` Fabrice Popineau
  0 siblings, 1 reply; 23+ messages in thread
From: Haochen Xie @ 2015-08-11  8:47 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

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

Hi Andreas,

Thank you for your reply. I've read the whole thread, and found your
example (the second link) very useful. Although for some reason, SVG
image is not working well on my machine (not being displayed in
chrome, nor on IE. I don't have firefox installed), but since the SVG
image generated by imagemagick is indeed a raster image, I don't see
any benefit using SVG over PNG, and exporting to PNG works perfectly.

I think I've come cross to the "by-backend" approach while searching
over the Internet, I found nothing about how by-backend is defined so
gave up. Even this tutorial [1] mention the use of by-backend, but
giving no information on what it is. Maybe it would be nice if
somebody write a tutorial on it and post on the website?

But in the other hand, I still think my proposal is still valid, since
my proposing extension would make it much easier and intuitive to
include advancedly typesetted contents to HTML with great freedom,
which remain the same semantics for the exporting to latex forms. I'd
like know what others think about it.

Also, to help other org-mode newbies to achieving including a diagram
or other figures typesetted with latex codes in HTML exports, I'd like
to sum up what's needed here:

1) make sure you have a latex environment and imagemagick installed on
   your system

2) define the by-backend macro in ~/.emacs as

   (defmacro by-backend (&rest body)
     `(case (if (boundp 'backend) (org-export-backend-name backend) nil)
,@body))

3) in the org file you want to include a latex rendered figure, add
   latex preambles you need in the following format:

   #+LATEX_HEADER: \usepackage{tikz}

4) include the latex code for the figure in a SRC block like the
   following one:

  #+HEADER: :packages '(("" "tikz"))
  #+HEADER: :file (by-backend (latex "example_diagram.tikz") (html
"example_diagram.png")
  #+HEADER: :imagemagick yes :iminoptions -density 300
  #+HEADER: :results file raw
  #+HEADER: :fit yes
  #+BEGIN_SRC latex
    \begin{tikzpicture}
      \node[red!50!black] (a) {A};
      \node (b) [right of=a] {B};
      \draw[->] (a) -- (b);
    \end{tikzpicture}
  #+END_SRC

  Notes: the first line is important for the case of tikz, but may or
  may not needed for your use case. the size of the image file could
  be adjusted with the -density option passed to imagemagick

Bonus) you can use C-c C-x C-l to preview the latex block output,
       and if you like, add the following to your ~/.emacs to scale the
preview:

       (plist-put org-format-latex-options :scale 1.5)

Regards,

Haochen

[1]: http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html



--

Mail from Haochen Xie

On Tue, Aug 11, 2015 at 7:56 AM, Andreas Leha <
andreas.leha@med.uni-goettingen.de> wrote:

> Hi Haochen,
>
>
> Haochen Xie <haochen@xie.name> writes:
> > Hi,
> >
> > I'm trying to include a diagram drawn with tikz in a document, but
> > couldn't find an elegant way to conditionally export it as png when
> > generating HTML output and raw TeX code when generating PDF. It is
> > possible to use
> >
> > #+OPTIONS: tex:imagemagick
> >
> > to have tex blocks in the document exported as PNG in HTML, but since
> > I have other formulas which will render much better with MathJAX other
> > than embedded PNGs, i really don't want to do it. What I'm currently
> > doing is to use something like
> >
> > #+BEGIN_SRC latex :file diagram.png :results value raw
> > \begin{tikzpicture}
> > \draw (0,0) grid (7,5);
> > \draw (0,0) node[below left] {$A$};
> > \draw (7,5) node[above right] {$B$};
> > \fill (0,0) circle (2pt);
> > \fill (7,5) circle (2pt);
> > \end{tikzpicture}
> > #+END_SRC
> >
> > #+RESULTS[da59bc402ce2d1055b5ff471ea7e398c4e0488f5]:
> > [[file:diagram.png]]
> >
> > so that the diagram will be include in the HTML file as a png image,
> > and the pdf file will also include it as a raster image.
> >
> > But this method is rather a workaround. I'd like to see a vector
> > diagram in the pdf file, which could be achieved if there is a way to
> > specify how a block of TeX source code should be handled when exported
> > to HTML regardless to the global settings. So I propose an extension
> > to #+BEGIN_LaTeX block so that a new header :html will control how the
> > specific block will be handled when exporting to HTML. The possible
> > values might be none, t, dvipng, or imagemagick. "none" will ignore
> > the whole block when exporting to HTML, just like the current
> > behavior; "t" will try to call MathJAX to interpret this block of TeX
> > code; and "dvipng" and "imagemagick" will call "dvipng" or
> > "imagemagick" to render a png file to be embedded in the HTML page.
> >
> > If that extension is supported, we could then left the global option
> > tex:t while inline a tex powered figure with great convenience. For
> > example, in my use case, I could then just used the following code to
> > achieve what I want:
> >
> > #+BEGIN_LaTeX :html imagemagick
> > \begin{tikzpicture}
> > \draw (0,0) grid (7,5);
> > \draw (0,0) node[below left] {$A$};
> > \draw (7,5) node[above right] {$B$};
> > \fill (0,0) circle (2pt);
> > \fill (7,5) circle (2pt);
> > \end{tikzpicture}
> > #+END_LaTeX
> >
> > As I'm new to org-mode, I may missed something that I could use
> > instead (although I searched the internet very hard). Please feel free
> > to disagree on me and point alternative ways to achieve my goal.
> >
> > Thanks in advance.
> >
> > Best regards,
> >
> > Haochen
> >
>
> There has been a thread on this list recently on this topic [1].
> See [2] for an example and [3] for some further explanations.
>
> Regards,
> Andreas
>
> [1] http://comments.gmane.org/gmane.emacs.orgmode/95174
>
> [2] http://permalink.gmane.org/gmane.emacs.orgmode/95197
>
> [3] http://permalink.gmane.org/gmane.emacs.orgmode/95297
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 12573 bytes --]

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

* Re: Block level specification for tex code html export method
  2015-08-11  8:47   ` Haochen Xie
@ 2015-08-11  8:53     ` Fabrice Popineau
  2015-08-11 16:24       ` Haochen Xie
  0 siblings, 1 reply; 23+ messages in thread
From: Fabrice Popineau @ 2015-08-11  8:53 UTC (permalink / raw)
  To: Haochen Xie; +Cc: Andreas Leha, emacs-orgmode@gnu.org

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

2015-08-11 10:47 GMT+02:00 Haochen Xie <haochenx@acm.org>:

> Hi Andreas,
>
> Thank you for your reply. I've read the whole thread, and found your
> example (the second link) very useful. Although for some reason, SVG
> image is not working well on my machine (not being displayed in
> chrome, nor on IE. I don't have firefox installed), but since the SVG
> image generated by imagemagick is indeed a raster image, I don't see
> any benefit using SVG over PNG, and exporting to PNG works perfectly.
>
>
Use dvisvgm instead of imagemagick to generate the svg file.

Fabrice

[-- Attachment #2: Type: text/html, Size: 1410 bytes --]

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

* Re: Block level specification for tex code html export method
  2015-08-11  8:53     ` Fabrice Popineau
@ 2015-08-11 16:24       ` Haochen Xie
  2015-08-12  8:50         ` Andreas Leha
  0 siblings, 1 reply; 23+ messages in thread
From: Haochen Xie @ 2015-08-11 16:24 UTC (permalink / raw)
  To: fabrice.popineau; +Cc: Andreas Leha, emacs-orgmode@gnu.org

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

Hi Fabrice,

Thank you for mentioning dvisvgm. I did some researches on it, and it seems
that as for now, the only way to invoke dvisvgm is to first export the
latex part to dvi, and call dvisvgm manually to convert it to svg, then
include it in the org file, which, is too troublesome for me. Is there any
plan to add dvisvgm as an alternative to dvipng and imagemagick? IMO svg
images will look much better than png (well, in browsers supporting it), so
that's a nice option to have.

Regards,

Haochen


--

Mail from Haochen Xie

On Tue, Aug 11, 2015 at 5:53 PM, Fabrice Popineau <
fabrice.popineau@supelec.fr> wrote:

>
>
> 2015-08-11 10:47 GMT+02:00 Haochen Xie <haochenx@acm.org>:
>
>> Hi Andreas,
>>
>> Thank you for your reply. I've read the whole thread, and found your
>> example (the second link) very useful. Although for some reason, SVG
>> image is not working well on my machine (not being displayed in
>> chrome, nor on IE. I don't have firefox installed), but since the SVG
>> image generated by imagemagick is indeed a raster image, I don't see
>> any benefit using SVG over PNG, and exporting to PNG works perfectly.
>>
>>
> Use dvisvgm instead of imagemagick to generate the svg file.
>
> Fabrice
>

[-- Attachment #2: Type: text/html, Size: 3202 bytes --]

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

* Re: Block level specification for tex code html export method
  2015-08-11 16:24       ` Haochen Xie
@ 2015-08-12  8:50         ` Andreas Leha
  2015-08-12 12:51           ` Haochen Xie
  2015-09-03 11:42           ` Alan Schmitt
  0 siblings, 2 replies; 23+ messages in thread
From: Andreas Leha @ 2015-08-12  8:50 UTC (permalink / raw)
  To: emacs-orgmode

Hi Haochen,

You can render svg from latex through org directly.  Here is a complete
example including a tikz diagram that that works on my system (once I
tackle a bug in PGF [1]).
It renders
- png by default (and for inlining the image into the org document)
- nothing for latex (directly include the tikz code into the tex document)
- svg for html


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

First execute the second code block, to define the convenience macro
and to set the required new variables in ob-latex.el.  Then export to
HTML and to pdf to see the tree exported as an SVG image and as
embedded tikz respectively.

* Tikz test
Here's a tree, exported to both html and pdf.

#+header: :file (by-backend (html "tree.svg") (latex "tree.tikz") (t "tree.png"))
#+header: :imagemagick :iminoptions -density 600 :imoutoptions -geometry 800
#+header: :results file raw
#+header: :fit yes
#+begin_src latex
  \usetikzlibrary{trees}
  \begin{tikzpicture}
    \node [circle, draw, fill=red!20] at (0,0) {1}
    child { node [circle, draw, fill=blue!30] {2}
      child { node [circle, draw, fill=green!30] {3} }
      child { node [circle, draw, fill=yellow!30] {4} }};
  \end{tikzpicture}
#+end_src

#+results:
[[file:tree.png]]

* COMMENT setup
#+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
--8<---------------cut here---------------end--------------->8---


Regards,
Andreas

[1] http://tex.stackexchange.com/a/232739


Haochen Xie <haochenx@acm.org> writes:
> Hi Fabrice,
>
> Thank you for mentioning dvisvgm. I did some researches on it, and it seems that as for now, the only way to invoke dvisvgm is to first export the latex part to dvi, and call dvisvgm
> manually to convert it to svg, then include it in the org file, which, is too troublesome for me. Is there any plan to add dvisvgm as an alternative to dvipng and imagemagick? IMO svg
> images will look much better than png (well, in browsers supporting it), so that's a nice option to have.
>
> Regards,
>
> Haochen
>
> --
>
> Mail from Haochen Xie
>
> On Tue, Aug 11, 2015 at 5:53 PM, Fabrice Popineau <fabrice.popineau@supelec.fr> wrote:
>
>
>  2015-08-11 10:47 GMT+02:00 Haochen Xie <haochenx@acm.org>:
>
>
>  Hi Andreas,
>
>  Thank you for your reply. I've read the whole thread, and found your
>  example (the second link) very useful. Although for some reason, SVG
>  image is not working well on my machine (not being displayed in
>  chrome, nor on IE. I don't have firefox installed), but since the SVG
>  image generated by imagemagick is indeed a raster image, I don't see
>  any benefit using SVG over PNG, and exporting to PNG works perfectly.
>
>  Use dvisvgm instead of imagemagick to generate the svg file.
>
>  Fabrice

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

* Re: Block level specification for tex code html export method
  2015-08-12  8:50         ` Andreas Leha
@ 2015-08-12 12:51           ` Haochen Xie
  2015-08-12 13:40             ` Andreas Leha
  2015-09-03 11:42           ` Alan Schmitt
  1 sibling, 1 reply; 23+ messages in thread
From: Haochen Xie @ 2015-08-12 12:51 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

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

Hi Andreas,

Thank you for your code example. I've tried almost the same code which
I saw from the thread you referred (with the htlatex initialization,
which I'm doing in my .emacs), and indeed got a svg file as
expected. But the problem is that when I try to browse the HTML page
in chrome, the image is shown as broken. I check the HTML source code,
the image is presented in an img tag, pointing to the svg file. My
first though was that the svg file isn't recognized because it's not
served by a HTTP server instead of being a filesystem link. I then
tried to use python SimpleHTTPServer, then python3 -m http.server (the
python2 SimpleHTTPServer was serving svg with a wrong Content-Type)
but without luck.

Today, I tried svg again, and finally figured out the problem: the svg
file generated doesn't contain a proper xmlns in the svg tag, so both
chrome and internet explorer is interpreting it as a plain xml file
instead of rendering it.

I guess this is a bug with imagemagick, but when I tried to do some
research on this problem I found nothing. Maybe I could find something
with more researches, but I don't have time now, and PNG is fine for
me.

Still, Andreas, thank you very much for helping.

Regards,

Haochen



--

Mail from Haochen Xie

On Wed, Aug 12, 2015 at 5:50 PM, Andreas Leha <
andreas.leha@med.uni-goettingen.de> wrote:

> Hi Haochen,
>
> You can render svg from latex through org directly.  Here is a complete
> example including a tikz diagram that that works on my system (once I
> tackle a bug in PGF [1]).
> It renders
> - png by default (and for inlining the image into the org document)
> - nothing for latex (directly include the tikz code into the tex document)
> - svg for html
>
>
> --8<---------------cut here---------------start------------->8---
> #+LATEX_HEADER: \usepackage{tikz}
>
> First execute the second code block, to define the convenience macro
> and to set the required new variables in ob-latex.el.  Then export to
> HTML and to pdf to see the tree exported as an SVG image and as
> embedded tikz respectively.
>
> * Tikz test
> Here's a tree, exported to both html and pdf.
>
> #+header: :file (by-backend (html "tree.svg") (latex "tree.tikz") (t
> "tree.png"))
> #+header: :imagemagick :iminoptions -density 600 :imoutoptions -geometry
> 800
> #+header: :results file raw
> #+header: :fit yes
> #+begin_src latex
>   \usetikzlibrary{trees}
>   \begin{tikzpicture}
>     \node [circle, draw, fill=red!20] at (0,0) {1}
>     child { node [circle, draw, fill=blue!30] {2}
>       child { node [circle, draw, fill=green!30] {3} }
>       child { node [circle, draw, fill=yellow!30] {4} }};
>   \end{tikzpicture}
> #+end_src
>
> #+results:
> [[file:tree.png]]
>
> * COMMENT setup
> #+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
> --8<---------------cut here---------------end--------------->8---
>
>
> Regards,
> Andreas
>
> [1] http://tex.stackexchange.com/a/232739
>
>
> Haochen Xie <haochenx@acm.org> writes:
> > Hi Fabrice,
> >
> > Thank you for mentioning dvisvgm. I did some researches on it, and it
> seems that as for now, the only way to invoke dvisvgm is to first export
> the latex part to dvi, and call dvisvgm
> > manually to convert it to svg, then include it in the org file, which,
> is too troublesome for me. Is there any plan to add dvisvgm as an
> alternative to dvipng and imagemagick? IMO svg
> > images will look much better than png (well, in browsers supporting it),
> so that's a nice option to have.
> >
> > Regards,
> >
> > Haochen
> >
> > --
> >
> > Mail from Haochen Xie
> >
> > On Tue, Aug 11, 2015 at 5:53 PM, Fabrice Popineau <
> fabrice.popineau@supelec.fr> wrote:
> >
> >
> >  2015-08-11 10:47 GMT+02:00 Haochen Xie <haochenx@acm.org>:
> >
> >
> >  Hi Andreas,
> >
> >  Thank you for your reply. I've read the whole thread, and found your
> >  example (the second link) very useful. Although for some reason, SVG
> >  image is not working well on my machine (not being displayed in
> >  chrome, nor on IE. I don't have firefox installed), but since the SVG
> >  image generated by imagemagick is indeed a raster image, I don't see
> >  any benefit using SVG over PNG, and exporting to PNG works perfectly.
> >
> >  Use dvisvgm instead of imagemagick to generate the svg file.
> >
> >  Fabrice
>
>
>

[-- Attachment #2: Type: text/html, Size: 8050 bytes --]

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

* Re: Block level specification for tex code html export method
  2015-08-12 12:51           ` Haochen Xie
@ 2015-08-12 13:40             ` Andreas Leha
  0 siblings, 0 replies; 23+ messages in thread
From: Andreas Leha @ 2015-08-12 13:40 UTC (permalink / raw)
  To: emacs-orgmode

Hi Haochen,

Sorry for not being clearer.  There is no imagemagick involved in the
svg generation if everything is setup correctly.  Instead the command
defined in org-babel-latex-htlatex is used.  My test file sets this to
to "htlatex" from tex4th [1].

At the time of the thread I linked to there was a bug in ob-latex,
though.  So, make sure to be on a "recent" version of org (containing at
least the commit 510e7037988d44151dea5b98631839fc8003dd57 from
2015-03-21)

Just for reference, here are the first lines of the svg that is produced
for me which look fine to me:
--8<---------------cut here---------------start------------->8---
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?> 
<?xml-stylesheet href="latex-28543ACk.css" type="text/css"?> 
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="60.55959pt" height="103.23871pt" viewBox="-30.27975 -94.29848 60.55959 103.23871 "> 
--8<---------------cut here---------------end--------------->8---


Regards,
Andreas


[1] https://www.tug.org/applications/tex4ht/mn-commands.html




Haochen Xie <haochenx@acm.org> writes:
> Hi Andreas,
>
> Thank you for your code example. I've tried almost the same code which
> I saw from the thread you referred (with the htlatex initialization,
> which I'm doing in my .emacs), and indeed got a svg file as
> expected. But the problem is that when I try to browse the HTML page
> in chrome, the image is shown as broken. I check the HTML source code,
> the image is presented in an img tag, pointing to the svg file. My
> first though was that the svg file isn't recognized because it's not
> served by a HTTP server instead of being a filesystem link. I then
> tried to use python SimpleHTTPServer, then python3 -m http.server (the
> python2 SimpleHTTPServer was serving svg with a wrong Content-Type)
> but without luck.
>
> Today, I tried svg again, and finally figured out the problem: the svg
> file generated doesn't contain a proper xmlns in the svg tag, so both
> chrome and internet explorer is interpreting it as a plain xml file
> instead of rendering it.
>
> I guess this is a bug with imagemagick, but when I tried to do some
> research on this problem I found nothing. Maybe I could find something
> with more researches, but I don't have time now, and PNG is fine for
> me.
>
> Still, Andreas, thank you very much for helping.
>
> Regards,
>
> Haochen
>
> --
>
> Mail from Haochen Xie
>
> On Wed, Aug 12, 2015 at 5:50 PM, Andreas Leha <andreas.leha@med.uni-goettingen.de> wrote:
>
>
>  Hi Haochen,
>
>  You can render svg from latex through org directly. Here is a complete
>  example including a tikz diagram that that works on my system (once I
>  tackle a bug in PGF [1]).
>  It renders
>  - png by default (and for inlining the image into the org document)
>  - nothing for latex (directly include the tikz code into the tex document)
>  - svg for html
>
>  --8<---------------cut here---------------start------------->8---
>  #+LATEX_HEADER: \usepackage{tikz}
>
>  First execute the second code block, to define the convenience macro
>  and to set the required new variables in ob-latex.el. Then export to
>  HTML and to pdf to see the tree exported as an SVG image and as
>  embedded tikz respectively.
>
>  * Tikz test
>  Here's a tree, exported to both html and pdf.
>
>  #+header: :file (by-backend (html "tree.svg") (latex "tree.tikz") (t "tree.png"))
>  #+header: :imagemagick :iminoptions -density 600 :imoutoptions -geometry 800
>  #+header: :results file raw
>  #+header: :fit yes
>  #+begin_src latex
>  \usetikzlibrary{trees}
>  \begin{tikzpicture}
>  \node [circle, draw, fill=red!20] at (0,0) {1}
>  child { node [circle, draw, fill=blue!30] {2}
>  child { node [circle, draw, fill=green!30] {3} }
>  child { node [circle, draw, fill=yellow!30] {4} }};
>  \end{tikzpicture}
>  #+end_src
>
>  #+results:
>  [[file:tree.png]]
>
>  * COMMENT setup
>  #+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
>  --8<---------------cut here---------------end--------------->8---
>
>  Regards,
>  Andreas
>
>  [1] http://tex.stackexchange.com/a/232739
>
>  Haochen Xie <haochenx@acm.org> writes:
>  > Hi Fabrice,
>  >
>  > Thank you for mentioning dvisvgm. I did some researches on it, and it seems that as for now, the only way to invoke dvisvgm is to first export the latex part to dvi, and call dvisvgm
>  > manually to convert it to svg, then include it in the org file, which, is too troublesome for me. Is there any plan to add dvisvgm as an alternative to dvipng and imagemagick? IMO svg
>  > images will look much better than png (well, in browsers supporting it), so that's a nice option to have.
>  >
>  > Regards,
>  >
>  > Haochen
>  >
>  > --
>  >
>  > Mail from Haochen Xie
>  >
>  > On Tue, Aug 11, 2015 at 5:53 PM, Fabrice Popineau <fabrice.popineau@supelec.fr> wrote:
>  >
>  >
>  > 2015-08-11 10:47 GMT+02:00 Haochen Xie <haochenx@acm.org>:
>  >
>  >
>  > Hi Andreas,
>  >
>  > Thank you for your reply. I've read the whole thread, and found your
>  > example (the second link) very useful. Although for some reason, SVG
>  > image is not working well on my machine (not being displayed in
>  > chrome, nor on IE. I don't have firefox installed), but since the SVG
>  > image generated by imagemagick is indeed a raster image, I don't see
>  > any benefit using SVG over PNG, and exporting to PNG works perfectly.
>  >
>  > Use dvisvgm instead of imagemagick to generate the svg file.
>  >
>  > Fabrice

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

* Re: Block level specification for tex code html export method
  2015-08-12  8:50         ` Andreas Leha
  2015-08-12 12:51           ` Haochen Xie
@ 2015-09-03 11:42           ` Alan Schmitt
  2015-09-03 12:30             ` Andreas Leha
  1 sibling, 1 reply; 23+ messages in thread
From: Alan Schmitt @ 2015-09-03 11:42 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 405 bytes --]

Hello Andreas,

I’m slowly catching up on the org mailing list, and I found your example
very interesting. I tried to run it and it does not seem to work here.
Here is what I did:
- I copied the code below to a file
- I evaluated the last block
- I made sure that latex was one of the org-babel-load-languages
  language
- I tried executing the first block, which generated this strange png
  

[-- Attachment #1.2: tree.png --]
[-- Type: image/png, Size: 298 bytes --]

[-- Attachment #1.3: Type: text/plain, Size: 1625 bytes --]

- I exported both to html and pdf, and in both cases I would have
  a reference to the png instead of the svg/tikz code.

I’m afraid I’m missing a step. Do you see what I’m doing wrong?

Thanks,

Alan

On 2015-08-12 10:50, Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> #+LATEX_HEADER: \usepackage{tikz}
>
> First execute the second code block, to define the convenience macro
> and to set the required new variables in ob-latex.el.  Then export to
> HTML and to pdf to see the tree exported as an SVG image and as
> embedded tikz respectively.
>
> * Tikz test
> Here's a tree, exported to both html and pdf.
>
> #+header: :file (by-backend (html "tree.svg") (latex "tree.tikz") (t "tree.png"))
> #+header: :imagemagick :iminoptions -density 600 :imoutoptions -geometry 800
> #+header: :results file raw
> #+header: :fit yes
> #+begin_src latex
>   \usetikzlibrary{trees}
>   \begin{tikzpicture}
>     \node [circle, draw, fill=red!20] at (0,0) {1}
>     child { node [circle, draw, fill=blue!30] {2}
>       child { node [circle, draw, fill=green!30] {3} }
>       child { node [circle, draw, fill=yellow!30] {4} }};
>   \end{tikzpicture}
> #+end_src
>
> #+results:
> [[file:tree.png]]
>
> * COMMENT setup
> #+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

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Last week athmospheric CO₂ average (Updated August 31, 2015, Mauna Loa Obs.):
377.82 ppm

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

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

* Re: Block level specification for tex code html export method
  2015-09-03 11:42           ` Alan Schmitt
@ 2015-09-03 12:30             ` Andreas Leha
  2015-09-03 13:03               ` Haochen Xie
  2015-09-03 20:33               ` Eric S Fraga
  0 siblings, 2 replies; 23+ messages in thread
From: Andreas Leha @ 2015-09-03 12:30 UTC (permalink / raw)
  To: emacs-orgmode

Hi Alan,

Glad you like the example.

Three things:
1. It still works for me ;-)
2. The distorted png might come from the bug in htlatex I mentioned in
this thread [1].
3. It seems that the by-backend does not work properly for you.  I am
not sure about the reason for that.  What org-mode version do you run?

HTH,
Andreas


[1] http://tex.stackexchange.com/a/232739



Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Hello Andreas,
>
> I’m slowly catching up on the org mailing list, and I found your example
> very interesting. I tried to run it and it does not seem to work here.
> Here is what I did:
> - I copied the code below to a file
> - I evaluated the last block
> - I made sure that latex was one of the org-babel-load-languages
>   language
> - I tried executing the first block, which generated this strange png
>   
>
>
> - I exported both to html and pdf, and in both cases I would have
>   a reference to the png instead of the svg/tikz code.
>
> I’m afraid I’m missing a step. Do you see what I’m doing wrong?
>
> Thanks,
>
> Alan
>
> On 2015-08-12 10:50, Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> #+LATEX_HEADER: \usepackage{tikz}
>>
>> First execute the second code block, to define the convenience macro
>> and to set the required new variables in ob-latex.el.  Then export to
>> HTML and to pdf to see the tree exported as an SVG image and as
>> embedded tikz respectively.
>>
>> * Tikz test
>> Here's a tree, exported to both html and pdf.
>>
>> #+header: :file (by-backend (html "tree.svg") (latex "tree.tikz") (t "tree.png"))
>> #+header: :imagemagick :iminoptions -density 600 :imoutoptions -geometry 800
>> #+header: :results file raw
>> #+header: :fit yes
>> #+begin_src latex
>>   \usetikzlibrary{trees}
>>   \begin{tikzpicture}
>>     \node [circle, draw, fill=red!20] at (0,0) {1}
>>     child { node [circle, draw, fill=blue!30] {2}
>>       child { node [circle, draw, fill=green!30] {3} }
>>       child { node [circle, draw, fill=yellow!30] {4} }};
>>   \end{tikzpicture}
>> #+end_src
>>
>> #+results:
>> [[file:tree.png]]
>>
>> * COMMENT setup
>> #+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

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

* Re: Block level specification for tex code html export method
  2015-09-03 12:30             ` Andreas Leha
@ 2015-09-03 13:03               ` Haochen Xie
  2015-09-03 20:39                 ` Andreas Leha
  2015-09-03 20:33               ` Eric S Fraga
  1 sibling, 1 reply; 23+ messages in thread
From: Haochen Xie @ 2015-09-03 13:03 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: Andreas Leha, emacs-orgmode

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

​Hello
 Alan,

I'm not 100% sure, but I think the distorted PNG file is generated by
dvipng. It seems that dvipng cannot handle tikz blocks very well, and one
must use imagemagick for those blocks. I think this line:

#+header: :imagemagick :iminoptions -density 600 :imoutoptions -geometry 800

should be

#+header: :imagemagick yes :iminoptions -density 600 :imoutoptions
-geometry 800

so that imagemagick would be used instead of dvipng, which is the global
default.

As said by Andreas,
​it's probably that ​
your
​​
by
​​
-backend
​​
macro
​​
​is not working​
 properly, or, maybe you are not using a recent enough version of org-mod
​​
e
​​
. This
​​
​​
magic
​, if I remember correctly,​
​​
​​
is
​​
​​
​​
act
​​
​​
uall
​​
​​
​​
​​
​​
​​
​​
​​
​​
​​
​​
​​
​​
​​
​y​
​​
done
​​
by
​​
a
​​
special
​​
case
​​
added
​​
to
​​
some
​​
latex
​​
babel
​​
export
​​
function
​​
, wh
​​
ich is contributed by Andreas somehow recently. You may want to try upgrade
your org-mode and try again.

Also please follow this link [1] to fix a
​bug
 in htlatex as mentioned in Andreas's mail, or your html export will fail
silently (showing success on emacs, but no images generated).

[1] http://tex.stackexchange.com/a/232739




--

Mail from Haochen Xie

On Thu, Sep 3, 2015 at 9:30 PM, Andreas Leha <
andreas.leha@med.uni-goettingen.de> wrote:

> Hi Alan,
>
> Glad you like the example.
>
> Three things:
> 1. It still works for me ;-)
> 2. The distorted png might come from the bug in htlatex I mentioned in
> this thread [1].
> 3. It seems that the by-backend does not work properly for you.  I am
> not sure about the reason for that.  What org-mode version do you run?
>
> HTH,
> Andreas
>
>
> [1] http://tex.stackexchange.com/a/232739
>
>
>
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> > Hello Andreas,
> >
> > I’m slowly catching up on the org mailing list, and I found your example
> > very interesting. I tried to run it and it does not seem to work here.
> > Here is what I did:
> > - I copied the code below to a file
> > - I evaluated the last block
> > - I made sure that latex was one of the org-babel-load-languages
> >   language
> > - I tried executing the first block, which generated this strange png
> >
> >
> >
> > - I exported both to html and pdf, and in both cases I would have
> >   a reference to the png instead of the svg/tikz code.
> >
> > I’m afraid I’m missing a step. Do you see what I’m doing wrong?
> >
> > Thanks,
> >
> > Alan
> >
> > On 2015-08-12 10:50, Andreas Leha <andreas.leha@med.uni-goettingen.de>
> writes:
> >
> >> #+LATEX_HEADER: \usepackage{tikz}
> >>
> >> First execute the second code block, to define the convenience macro
> >> and to set the required new variables in ob-latex.el.  Then export to
> >> HTML and to pdf to see the tree exported as an SVG image and as
> >> embedded tikz respectively.
> >>
> >> * Tikz test
> >> Here's a tree, exported to both html and pdf.
> >>
> >> #+header: :file (by-backend (html "tree.svg") (latex "tree.tikz") (t
> "tree.png"))
> >> #+header: :imagemagick :iminoptions -density 600 :imoutoptions
> -geometry 800
> >> #+header: :results file raw
> >> #+header: :fit yes
> >> #+begin_src latex
> >>   \usetikzlibrary{trees}
> >>   \begin{tikzpicture}
> >>     \node [circle, draw, fill=red!20] at (0,0) {1}
> >>     child { node [circle, draw, fill=blue!30] {2}
> >>       child { node [circle, draw, fill=green!30] {3} }
> >>       child { node [circle, draw, fill=yellow!30] {4} }};
> >>   \end{tikzpicture}
> >> #+end_src
> >>
> >> #+results:
> >> [[file:tree.png]]
> >>
> >> * COMMENT setup
> >> #+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 #2: Type: text/html, Size: 10209 bytes --]

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

* Re: Block level specification for tex code html export method
  2015-09-03 12:30             ` Andreas Leha
  2015-09-03 13:03               ` Haochen Xie
@ 2015-09-03 20:33               ` Eric S Fraga
  2015-09-03 21:11                 ` Andreas Leha
  1 sibling, 1 reply; 23+ messages in thread
From: Eric S Fraga @ 2015-09-03 20:33 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

On Thursday,  3 Sep 2015 at 13:30, Andreas Leha wrote:
> Hi Alan,
>
> Glad you like the example.
>
> Three things:
> 1. It still works for me ;-)

Andreas,

the example doesn't work for me with a quite recent org (updated within
the past week) and with -Q.

By the way, with emacs -Q, I need to "(required 'cl)" for the by-backend
macro although this is probably done by one of the export files?

> 2. The distorted png might come from the bug in htlatex I mentioned in
> this thread [1].

The solution has been pointed out by Haochen Xie in this thread
(":imagemagick yes").  I needed this fix as well to get the png creation
to work.

> 3. It seems that the by-backend does not work properly for you.  I am
> not sure about the reason for that.  What org-mode version do you run?

And it doesn't work for me either.  I recently ran into this problem
myself with a document (long book chapter with many tikz figures) that I
wrote about 4 months ago.  I had a deadline so couldn't track down what
was wrong but it is all about the by-backend macro.  No matter what the
target for export is, the by-backend macro doesn't work.  I tried to fix
it but no luck, mostly due to my lack of emacs lisp funess...

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3.1-188-g410ea6

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

* Re: Block level specification for tex code html export method
  2015-09-03 13:03               ` Haochen Xie
@ 2015-09-03 20:39                 ` Andreas Leha
  0 siblings, 0 replies; 23+ messages in thread
From: Andreas Leha @ 2015-09-03 20:39 UTC (permalink / raw)
  To: emacs-orgmode

Hi Haochen,

Thanks for following that up!

Haochen Xie <haochenx@acm.org> writes:
> ​Hello
> Alan,
>
> I'm not 100% sure, but I think the distorted PNG file is generated by dvipng. It seems that dvipng cannot handle tikz blocks very well, and one must use imagemagick for those blocks. I
> think this line:
>
> #+header: :imagemagick :iminoptions -density 600 :imoutoptions -geometry 800
>
> should be
>
> #+header: :imagemagick yes :iminoptions -density 600 :imoutoptions -geometry 800
>
> so that imagemagick would be used instead of dvipng, which is the global default.

Thanks for that!  I'll keep that in mind.

Regards,
Andreas




>
> As said by Andreas, 
> ​it's probably that ​
> your
> ​​ by
> ​​-backend
> ​​ macro
> ​​ 
> ​is not working​
> properly, or, maybe you are not using a recent enough version of org-mod
> ​​e
> ​​. This
> ​​ 
> ​​magic
> ​, if I remember correctly,​
> ​​ 
> ​​is
> ​​​​ 
> ​​act
> ​​​​uall
> ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​y​
> ​​ done
> ​​ by
> ​​ a
> ​​ special
> ​​ case
> ​​ added
> ​​ to
> ​​ some
> ​​ latex
> ​​ babel
> ​​ export
> ​​ function
> ​​, wh
> ​​ich is contributed by Andreas somehow recently. You may want to try upgrade your org-mode and try again.
>
> Also please follow this link [1] to fix a 
> ​bug
> in htlatex as mentioned in Andreas's mail, or your html export will fail silently (showing success on emacs, but no images generated).
>
> [1] http://tex.stackexchange.com/a/232739
>
> --
>
> Mail from Haochen Xie
>
> On Thu, Sep 3, 2015 at 9:30 PM, Andreas Leha <andreas.leha@med.uni-goettingen.de> wrote:
>
>
>  Hi Alan,
>
>  Glad you like the example.
>
>  Three things:
>  1. It still works for me ;-)
>  2. The distorted png might come from the bug in htlatex I mentioned in
>  this thread [1].
>  3. It seems that the by-backend does not work properly for you. I am
>  not sure about the reason for that. What org-mode version do you run?
>
>  HTH,
>  Andreas
>
>  [1] http://tex.stackexchange.com/a/232739
>
>  Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>  > Hello Andreas,
>  >
>  > I’m slowly catching up on the org mailing list, and I found your example
>  > very interesting. I tried to run it and it does not seem to work here.
>  > Here is what I did:
>  > - I copied the code below to a file
>  > - I evaluated the last block
>  > - I made sure that latex was one of the org-babel-load-languages
>  > language
>  > - I tried executing the first block, which generated this strange png
>  >
>  >
>  >
>  > - I exported both to html and pdf, and in both cases I would have
>  > a reference to the png instead of the svg/tikz code.
>  >
>  > I’m afraid I’m missing a step. Do you see what I’m doing wrong?
>  >
>  > Thanks,
>  >
>  > Alan
>  >
>  > On 2015-08-12 10:50, Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>  >
>  >> #+LATEX_HEADER: \usepackage{tikz}
>  >>
>  >> First execute the second code block, to define the convenience macro
>  >> and to set the required new variables in ob-latex.el. Then export to
>  >> HTML and to pdf to see the tree exported as an SVG image and as
>  >> embedded tikz respectively.
>  >>
>  >> * Tikz test
>  >> Here's a tree, exported to both html and pdf.
>  >>
>  >> #+header: :file (by-backend (html "tree.svg") (latex "tree.tikz") (t "tree.png"))
>  >> #+header: :imagemagick :iminoptions -density 600 :imoutoptions -geometry 800
>  >> #+header: :results file raw
>  >> #+header: :fit yes
>  >> #+begin_src latex
>  >> \usetikzlibrary{trees}
>  >> \begin{tikzpicture}
>  >> \node [circle, draw, fill=red!20] at (0,0) {1}
>  >> child { node [circle, draw, fill=blue!30] {2}
>  >> child { node [circle, draw, fill=green!30] {3} }
>  >> child { node [circle, draw, fill=yellow!30] {4} }};
>  >> \end{tikzpicture}
>  >> #+end_src
>  >>
>  >> #+results:
>  >> [[file:tree.png]]
>  >>
>  >> * COMMENT setup
>  >> #+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

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

* Re: Block level specification for tex code html export method
  2015-09-03 20:33               ` Eric S Fraga
@ 2015-09-03 21:11                 ` Andreas Leha
  2015-09-03 21:38                   ` Nicolas Goaziou
  0 siblings, 1 reply; 23+ messages in thread
From: Andreas Leha @ 2015-09-03 21:11 UTC (permalink / raw)
  To: emacs-orgmode

Hi Eric,

Thanks for following that up!

Eric S Fraga <e.fraga@ucl.ac.uk> writes:
> On Thursday,  3 Sep 2015 at 13:30, Andreas Leha wrote:
>> Hi Alan,
>>
>> Glad you like the example.
>>
>> Three things:
>> 1. It still works for me ;-)
>
> Andreas,
>
> the example doesn't work for me with a quite recent org (updated within
> the past week) and with -Q.

I see.  Another reason for me not to upgrade?   My org is quite old.
(8.3beta (release_8.3beta-1264-g365c19))

>
> By the way, with emacs -Q, I need to "(required 'cl)" for the by-backend
> macro although this is probably done by one of the export files?
>
>> 2. The distorted png might come from the bug in htlatex I mentioned in
>> this thread [1].
>
> The solution has been pointed out by Haochen Xie in this thread
> (":imagemagick yes").  I needed this fix as well to get the png creation
> to work.
>

Good to know!  Thanks for the confirmation.  I missed that.

Note also that it might be necessary to include

 #+header: :headers '("\\usepackage{tikz}")

to the latex block.  This I only need when testing with emacs -Q.  Not
sure why, though.  I was under the impression that global
#+latex_headers should apply in latex source blocks as well?



>> 3. It seems that the by-backend does not work properly for you.  I am
>> not sure about the reason for that.  What org-mode version do you run?
>
> And it doesn't work for me either.  I recently ran into this problem
> myself with a document (long book chapter with many tikz figures) that I
> wrote about 4 months ago.  I had a deadline so couldn't track down what
> was wrong but it is all about the by-backend macro.  No matter what the
> target for export is, the by-backend macro doesn't work.  I tried to fix
> it but no luck, mostly due to my lack of emacs lisp funess...

This macro is from Eric Schulte initially.  And I guess I would be out
of luck adapting it to new Org mode versions as well.

I'd vote for a macro like this to be included in Org mode.  I think it
is quite useful to have and somehow extends the @@latex: ...@ constructs
to babel.  That way updates to org breaking this would be less probable.

Unfortunately, I don't have the time right now to even upgrade Org mode.
So, I cannot offer any testing/bisecting, I am afraid.

Best,
Andreas

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

* Re: Block level specification for tex code html export method
  2015-09-03 21:11                 ` Andreas Leha
@ 2015-09-03 21:38                   ` Nicolas Goaziou
  2015-09-04  6:15                     ` Eric S Fraga
  2015-09-04 12:08                     ` Andreas Leha
  0 siblings, 2 replies; 23+ messages in thread
From: Nicolas Goaziou @ 2015-09-03 21:38 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

Hello,

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> This macro is from Eric Schulte initially.  And I guess I would be out
> of luck adapting it to new Org mode versions as well.

What about

  (defmacro by-backend (&rest body)
    `(case org-export-current-backend ,@body))
?

Regards,

-- 
Nicolas Goaziou

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

* Re: Block level specification for tex code html export method
  2015-09-03 21:38                   ` Nicolas Goaziou
@ 2015-09-04  6:15                     ` Eric S Fraga
  2015-09-04  6:23                       ` Haochen Xie
  2015-09-04 12:08                     ` Andreas Leha
  1 sibling, 1 reply; 23+ messages in thread
From: Eric S Fraga @ 2015-09-04  6:15 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

On Thursday,  3 Sep 2015 at 23:38, Nicolas Goaziou wrote:

[...]

> What about
>
>   (defmacro by-backend (&rest body)
>     `(case org-export-current-backend ,@body))

Nicolas,

this seems to work!  I thought I had tried something like this but I
must have got one of the ,@` wrong along the way...

I do have a problem in that the svg file doesn't get created but that
problem lies elsewhere methinks...

Many thanks.

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3.1-188-g410ea6

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

* Re: Block level specification for tex code html export method
  2015-09-04  6:15                     ` Eric S Fraga
@ 2015-09-04  6:23                       ` Haochen Xie
  2015-09-04  7:07                         ` Eric S Fraga
  2015-09-04  7:10                         ` Alan Schmitt
  0 siblings, 2 replies; 23+ messages in thread
From: Haochen Xie @ 2015-09-04  6:23 UTC (permalink / raw)
  To: Fabrice Popineau; +Cc: emacs-orgmode

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

Hi Eric,

It's very likely due to this problem as both Andreas and I mentioned in
earlier mails:

Also please follow this link [1] to fix a
> ​bug
>  in htlatex as mentioned in Andreas's mail, or your html export will fail
> silently (showing success on emacs, but no images generated).
>
> ​​
> [1] http://tex.stackexchange.com/a/232739

​​
​Also, please make sure you have htlatex in your emacs' $PATH​.
​​
​Regards,

Haochen​



--

Mail from Haochen Xie

On Fri, Sep 4, 2015 at 3:15 PM, Eric S Fraga <e.fraga@ucl.ac.uk> wrote:

> On Thursday,  3 Sep 2015 at 23:38, Nicolas Goaziou wrote:
>
> [...]
>
> > What about
> >
> >   (defmacro by-backend (&rest body)
> >     `(case org-export-current-backend ,@body))
>
> Nicolas,
>
> this seems to work!  I thought I had tried something like this but I
> must have got one of the ,@` wrong along the way...
>
> I do have a problem in that the svg file doesn't get created but that
> problem lies elsewhere methinks...
>
> Many thanks.
>
> --
> : Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3.1-188-g410ea6
>
>

[-- Attachment #2: Type: text/html, Size: 3560 bytes --]

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

* Re: Block level specification for tex code html export method
  2015-09-04  6:23                       ` Haochen Xie
@ 2015-09-04  7:07                         ` Eric S Fraga
  2015-09-04  7:10                         ` Alan Schmitt
  1 sibling, 0 replies; 23+ messages in thread
From: Eric S Fraga @ 2015-09-04  7:07 UTC (permalink / raw)
  To: Haochen Xie; +Cc: emacs-orgmode

On Friday,  4 Sep 2015 at 15:23, Haochen Xie wrote:
> Hi Eric,
>
> It's very likely due to this problem as both Andreas and I mentioned in
> earlier mails:

Thanks.  I did notice the bits about htlatex but didn't pay much
attention.  I don't actually need svg as I use png for my web pages!

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3.1-188-g410ea6

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

* Re: Block level specification for tex code html export method
  2015-09-04  6:23                       ` Haochen Xie
  2015-09-04  7:07                         ` Eric S Fraga
@ 2015-09-04  7:10                         ` Alan Schmitt
  1 sibling, 0 replies; 23+ messages in thread
From: Alan Schmitt @ 2015-09-04  7:10 UTC (permalink / raw)
  To: Haochen Xie; +Cc: Fabrice Popineau, emacs-orgmode

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

Thanks to everyone, I now have this working. Here is the final version.

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

First execute the second code block, to define the convenience macro
and to set the required new variables in ob-latex.el.  Then export to
HTML and to pdf to see the tree exported as an SVG image and as
embedded tikz respectively.

* Tikz test
Here's a tree, exported to both html and pdf.

#+header: :file (by-backend (html "tree.svg") (latex "tree.tikz") (t "tree.png"))
#+header: :imagemagick yes :iminoptions -density 600 :imoutoptions -geometry 800
#+header: :results file raw
#+header: :fit yes
#+header: :headers '("\\usepackage{tikz}")
#+begin_src latex
  \usetikzlibrary{trees}
  \begin{tikzpicture}
    \node [circle, draw, fill=red!20] at (0,0) {1}
    child { node [circle, draw, fill=blue!30] {2}
      child { node [circle, draw, fill=green!30] {3} }
      child { node [circle, draw, fill=yellow!30] {4} }};
  \end{tikzpicture}
#+end_src

#+results:
[[file:tree.png]]

* COMMENT setup
#+begin_src emacs-lisp :results silent
  (setq org-babel-latex-htlatex "htlatex")
  (defmacro by-backend (&rest body)
    `(case org-export-current-backend ,@body))
#+end_src
--8<---------------cut here---------------end--------------->8---

The header line that says to use the package tikz right before the
source block is only necessary to generate the png when evaluating the
block (“C-c C-c” on it), but as it does not prevent the export to work,
I leave it there.

I had to change my systems pgfsys-tex4ht.def as described in
http://tex.stackexchange.com/questions/185349/error-using-pgfsysdriver-with-tex4ht-only-shows-up-with-texlive-2014-ok-with-t/232739#232739
(having a local copy and modifying it as suggested on the site did not
work).

Thanks again,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Last week athmospheric CO₂ average (Updated August 31, 2015, Mauna Loa Obs.):
377.82 ppm

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

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

* Re: Block level specification for tex code html export method
  2015-09-03 21:38                   ` Nicolas Goaziou
  2015-09-04  6:15                     ` Eric S Fraga
@ 2015-09-04 12:08                     ` Andreas Leha
  2015-09-04 12:48                       ` Nicolas Goaziou
  1 sibling, 1 reply; 23+ messages in thread
From: Andreas Leha @ 2015-09-04 12:08 UTC (permalink / raw)
  To: emacs-orgmode

Hi Nicolas,

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Hello,
>
> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> This macro is from Eric Schulte initially.  And I guess I would be out
>> of luck adapting it to new Org mode versions as well.
>
> What about
>
>   (defmacro by-backend (&rest body)
>     `(case org-export-current-backend ,@body))
> ?
>
> Regards,

Thanks for this!  One reason less not to upgrade Org mode.

Seems to work fine!

Just note, that it works for me only after exporting
 (when tested under emacs -Q).

What about including that into org?

Regards,
Andreas

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

* Re: Block level specification for tex code html export method
  2015-09-04 12:08                     ` Andreas Leha
@ 2015-09-04 12:48                       ` Nicolas Goaziou
  2015-09-04 13:42                         ` Andreas Leha
  0 siblings, 1 reply; 23+ messages in thread
From: Nicolas Goaziou @ 2015-09-04 12:48 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> Seems to work fine!
>
> Just note, that it works for me only after exporting
>  (when tested under emacs -Q).

`org-export-current-backend' is set when exporting a document, much like
`backend'.

> What about including that into org?

Wrong namespace. It should be prefixed with "org". 

Also, it might be better to include it directly in :file directive
handling if that is its sole purpose.


Regards,

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

* Re: Block level specification for tex code html export method
  2015-09-04 12:48                       ` Nicolas Goaziou
@ 2015-09-04 13:42                         ` Andreas Leha
  2015-09-05  8:58                           ` Nicolas Goaziou
  0 siblings, 1 reply; 23+ messages in thread
From: Andreas Leha @ 2015-09-04 13:42 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> Seems to work fine!
>>
>> Just note, that it works for me only after exporting
>>  (when tested under emacs -Q).
>
> `org-export-current-backend' is set when exporting a document, much like
> `backend'.
>

The same protection as in the previous version seems to take effect
here:

  (defmacro by-backend (&rest body)
    `(case (if (boundp 'org-export-current-backend) org-export-current-backend nil) ,@body))

Are there any issues with this?

>> What about including that into org?
>
> Wrong namespace. It should be prefixed with "org". 
>

Easy to fix.

> Also, it might be better to include it directly in :file directive
> handling if that is its sole purpose.

Could you elaborate why that might be better?  Including it as a macro
like this has the up-side to be more general.n

I think that also other header arguments would benefit from such a
(org-)by-backend switch.

In former versions (pre-dating the handling of *.tikz 'images' by
ox-latex) of the tikz code in this thread, for example, the :results
argument needed to be set according to the backend as well


Regards,
Andreas

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

* Re: Block level specification for tex code html export method
  2015-09-04 13:42                         ` Andreas Leha
@ 2015-09-05  8:58                           ` Nicolas Goaziou
  0 siblings, 0 replies; 23+ messages in thread
From: Nicolas Goaziou @ 2015-09-05  8:58 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> The same protection as in the previous version seems to take effect
> here:
>
>   (defmacro by-backend (&rest body)
>     `(case (if (boundp 'org-export-current-backend) org-export-current-backend nil) ,@body))
>
> Are there any issues with this?

Not really, but

  (if (boundp 'org-export-current-backend) org-export-current-backend nil)

->

  (org-bound-and-true-p org-export-current-backend)

It should also be documented. In particular, outside any export process,
you need to use ((nil) ...) or (t ...).

> Could you elaborate why that might be better?  Including it as a macro
> like this has the up-side to be more general.

Of course. I'm just pointing out that /if/ its only use is for :file
directive, it might be better to include it there.

Regards,

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

end of thread, other threads:[~2015-09-05  8:57 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-10  8:11 Block level specification for tex code html export method Haochen Xie
2015-08-10 22:56 ` Andreas Leha
2015-08-11  8:47   ` Haochen Xie
2015-08-11  8:53     ` Fabrice Popineau
2015-08-11 16:24       ` Haochen Xie
2015-08-12  8:50         ` Andreas Leha
2015-08-12 12:51           ` Haochen Xie
2015-08-12 13:40             ` Andreas Leha
2015-09-03 11:42           ` Alan Schmitt
2015-09-03 12:30             ` Andreas Leha
2015-09-03 13:03               ` Haochen Xie
2015-09-03 20:39                 ` Andreas Leha
2015-09-03 20:33               ` Eric S Fraga
2015-09-03 21:11                 ` Andreas Leha
2015-09-03 21:38                   ` Nicolas Goaziou
2015-09-04  6:15                     ` Eric S Fraga
2015-09-04  6:23                       ` Haochen Xie
2015-09-04  7:07                         ` Eric S Fraga
2015-09-04  7:10                         ` Alan Schmitt
2015-09-04 12:08                     ` Andreas Leha
2015-09-04 12:48                       ` Nicolas Goaziou
2015-09-04 13:42                         ` Andreas Leha
2015-09-05  8:58                           ` Nicolas Goaziou

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