From mboxrd@z Thu Jan 1 00:00:00 1970 From: Haochen Xie Subject: Re: Block level specification for tex code html export method Date: Tue, 11 Aug 2015 17:47:05 +0900 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11425c5267ae80051d052619 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZP5DS-0001RY-0F for emacs-orgmode@gnu.org; Tue, 11 Aug 2015 04:47:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZP5DN-0002JU-Om for emacs-orgmode@gnu.org; Tue, 11 Aug 2015 04:47:25 -0400 Received: from mail-ig0-f182.google.com ([209.85.213.182]:38604) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZP5DN-0002JC-HL for emacs-orgmode@gnu.org; Tue, 11 Aug 2015 04:47:21 -0400 Received: by igfj19 with SMTP id j19so67267047igf.1 for ; Tue, 11 Aug 2015 01:47:20 -0700 (PDT) Received: from mail-io0-f169.google.com (mail-io0-f169.google.com. [209.85.223.169]) by smtp.gmail.com with ESMTPSA id ii1sm7697970igb.10.2015.08.11.01.47.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Aug 2015 01:47:20 -0700 (PDT) Received: by ioeg141 with SMTP id g141so195210928ioe.3 for ; Tue, 11 Aug 2015 01:47:19 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Andreas Leha Cc: emacs-orgmode@gnu.org --001a11425c5267ae80051d052619 Content-Type: text/plain; charset=UTF-8 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 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 > > > > --001a11425c5267ae80051d052619 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
= Hi Andreas,

Thank you for your= reply. I've read the whole thread, and found your
example (the secon= d 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 imagemagi= ck is indeed a raster image, I don't see
any benefit using SVG over P= NG, and exporting to PNG works perfectly.

I think I've come cr= oss to the "by-backend" approach while searching
over the Inter= net, I found nothing about how by-backend is defined so
gave up. Even thi= s tutorial [1] mention the use of by-backend, but
giving no information o= n what it is. Maybe it would be nice if
somebody write a tutorial on it a= nd post on the website?

But in the other hand, I still think my pr= oposal is still valid, since
my proposing extension would make it much ea= sier and intuitive to
include advancedly typesetted contents to HTML wi= th great freedom,
which remain the same semantics for the exporting to la= tex forms. I'd
like know what others think about it.

Also, t= o help other org-mode newbies to achieving including a diagram
=
or other f= igures typesetted with latex codes in HTML exports, I'd like
to sum u= p what's needed here:

<= font face=3D"monospace, monospace">1) make sure you have a latex environmen= t and imagemagick installed on
=C2=A0 =C2=A0your system

2) defin= e the by-backend macro in ~/.emacs as

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

3) in the org f= ile you want to include a latex rendered figure, add
=C2=A0 =C2=A0latex p= reambles you need in the following format:

=C2=A0 =C2=A0#+LATEX_HE= ADER: \usepackage{tikz}

4) include the latex code for the figure i= n a SRC block like the
=C2=A0 =C2=A0following one:

=C2=A0 #+HEA= DER: :packages '(("" "tikz"))
=C2=A0 #+HEADER: :f= ile (by-backend (latex "example_diagram.tikz") (html "exampl= e_diagram.png")
=C2=A0 #+HEADER: :imagemagick yes :iminoptions -dens= ity 300
=C2=A0 #+HEADER: :results file raw
=C2=A0 #+HEADER: :fit yes
= =C2=A0 #+BEGIN_SRC latex=C2=A0
=C2=A0 =C2=A0 \begin{tikzpicture}
=C2=A0= =C2=A0 =C2=A0 \node[red!50!black] (a) {A};
=C2=A0 =C2=A0 =C2=A0 \node (b= ) [right of=3Da] {B};
=C2=A0 =C2=A0 =C2=A0 \draw[->] (a) -- (b);
= =C2=A0 =C2=A0 \end{tikzpicture}
=C2=A0 #+END_SRC

=C2=A0 Notes:= the first line is important for the case of tikz, but may or
<= div class=3D"gmail_default">=C2=A0 may = not needed for your use case. the size of the image file could
=
=C2=A0 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,
=C2=A0 =C2=A0 =C2= =A0 =C2=A0and if you like, add the following to your ~/.emacs to scale the = preview:

=C2=A0 =C2=A0 =C2=A0 =C2=A0(plist-put org-format-latex-op= tions :scale 1.5)


=
--

Mail from Haochen Xie
<= /div>

On Tue, Aug 11, 2015 at 7:56 AM, Andreas Leh= a <andreas.leha@med.uni-goettingen.de> wrot= e:
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 whe= n
> 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<= br> > 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 cur= rently
> 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<= br> > 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 blo= ck of TeX
> code; and "dvipng" and "imagemagick" will call &qu= ot;dvipng" or
> "imagemagick" to render a png file to be embedded in the HTM= L 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<= br> > 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.orgmo= de/95197

[3] http://permalink.gmane.org/gmane.emacs.orgmo= de/95297




--001a11425c5267ae80051d052619--