Re: [O] shorter syntax for both latex and html export of a figure

2016-03-08 Thread Alan Schmitt
On 2016-03-08 11:33, Alan Schmitt  writes:

> Thank you for the suggestion. At the moment I use a macro (because I
> need to put the resulting figure in a figure environment, as I want a
> label and caption), but I will give this a try.

I'm fairly happy with what I ended up doing (using a macro as I need to
pass some extra arguments, and I don't know how to extend a source block
with custom arguments), so here is my solution.

I define this utility function that is lob-ingested:

#+name: wrap-res
#+BEGIN_SRC emacs-lisp :var link="" :var caption="" :var label="" :results raw 
:exports none
(concat "#+LABEL: " label "\n#+CAPTION: " caption "\n" link)
#+END_SRC

I also define a macro (it's on one line but for this email I'm wrapping
it)

#+macro: tikzfig #+header: :file (by-backend (latex "$1.tikz") (t
 "$1.png")) :imagemagick yes :iminoptions -density 600 :imoutoptions
 -geometry 300 :results file raw :fit yes :headers
 '("\\usepackage{tikz}") :post
 wrap-res(link=*this*,label="fig:$1",caption="$2")

I can then have the following that is exported both in tikz and png (I
do not use svg as I found htlatex lacking for text nodes):

{{{tikzfig(cnf-example,An ordinal in Cantor normal form)}}}
#+begin_src latex
\begin{tikzpicture}[scale=2, every node/.style={transform shape}]
\node[color=blue]{$\omega^{(\omega^\omega\,+\, \omega^2 \times 8 \,+\, 
\omega)}+ \omega^\omega + \omega^4+ 6$};
\end{tikzpicture}
#+end_src

The first argument of the macro is the label of the figure (with "fig:"
added automatically) as well as the file used to export the figure, the
second argument is the caption.

Hopefully this may be useful to others.

Best,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-02, Mauna Loa Obs.): 404.02


signature.asc
Description: PGP signature


Re: [O] shorter syntax for both latex and html export of a figure

2016-03-08 Thread Alan Schmitt
On 2016-03-07 17:34, "Charles C. Berry"  writes:

> On Mon, 7 Mar 2016, Alan Schmitt wrote:
>
>> Hello,
>>
>> I'm trying to adapt the example that allows to export a figure both to
>> tikz and to png so that I don't have to manually add all the header
>> lines.
>>
>
> Maybe this gets you a step closer
>
> #+begin_src emacs-lisp :results silent
>  (defmacro by-backend ( body)
>`(case (org-bound-and-true-p org-export-current-backend)
>,@body))
>
>  (org-babel-do-load-languages
>   'org-babel-load-languages
>   '((latex . t)))
>
>  (defalias 'org-babel-execute:tikz 'org-babel-execute:latex)
>  (defalias 'org-babel-expand-body:tikz 'org-babel-expand-body:latex)
>
>  (add-to-list 'org-src-lang-modes '("tikz" . latex))
>
>(defvar org-babel-default-header-args:tikz
>  '((:imagemagick . "yes")
>(:iminoptions . "-density 600")
>(:imoutoptions . "-geometry 800")
>(:results . "file raw")
>(:fit . "yes")
>(:headers . "(\\usepackage{tikz})")
>(:exports . "results")))
> #+end_src
>
>
> When I run your tikz src block  interactively I get two files created. Not 
> sure why and I haven't time to edebug step thru the code. But maybe you 
> can handle that bit.

Thank you for the suggestion. At the moment I use a macro (because I
need to put the resulting figure in a figure environment, as I want a
label and caption), but I will give this a try.

Thanks again,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-02, Mauna Loa Obs.): 404.02


signature.asc
Description: PGP signature


Re: [O] shorter syntax for both latex and html export of a figure

2016-03-07 Thread Charles C. Berry

On Mon, 7 Mar 2016, Alan Schmitt wrote:


Hello,

I'm trying to adapt the example that allows to export a figure both to
tikz and to png so that I don't have to manually add all the header
lines.



Maybe this gets you a step closer

#+begin_src emacs-lisp :results silent
(defmacro by-backend ( body)
  `(case (org-bound-and-true-p org-export-current-backend)
 ,@body))

(org-babel-do-load-languages
 'org-babel-load-languages
 '((latex . t)))

(defalias 'org-babel-execute:tikz 'org-babel-execute:latex)
(defalias 'org-babel-expand-body:tikz 'org-babel-expand-body:latex)

(add-to-list 'org-src-lang-modes '("tikz" . latex))

  (defvar org-babel-default-header-args:tikz
'((:imagemagick . "yes")
  (:iminoptions . "-density 600")
  (:imoutoptions . "-geometry 800")
  (:results . "file raw")
  (:fit . "yes")
  (:headers . "(\\usepackage{tikz})")
  (:exports . "results")))
#+end_src


When I run your tikz src block  interactively I get two files created. Not 
sure why and I haven't time to edebug step thru the code. But maybe you 
can handle that bit.


HTH,

Chuck




[O] shorter syntax for both latex and html export of a figure

2016-03-07 Thread Alan Schmitt
Hello,

I'm trying to adapt the example that allows to export a figure both to
tikz and to png so that I don't have to manually add all the header
lines.

Here is what I tried:
#+LATEX_HEADER: \usepackage{tikz}

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

#+header: :file (by-backend (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

The same, with shorter syntax

#+header: :file (by-backend (latex "tree2.tikz") (t "tree2.png"))
#+begin_src tikz
  \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

* COMMENT evaluate this first
#+begin_src emacs-lisp :results silent
(defmacro by-backend ( body)
  `(case org-export-current-backend ,@body))

(org-babel-do-load-languages
 'org-babel-load-languages
 '((latex . t)))

(defalias 'org-babel-execute:tikz 'org-babel-execute:latex)

(add-to-list 'org-src-lang-modes '("tikz" . latex))

(defvar org-babel-default-header-args:tikz
  '((:imagemagick . "yes")
(:iminoptions . "-density 600")
(:imoutoptions . "-geometry 300")
(:results . "file raw")
(:fit . "yes")
(:headers . "'(\"usepackage{tikz}\")")))
#+end_src

The first part, where all the headers line are there, works great, but
the second source block for a newly defined language tikz (an alias to
latex with some default headers) does not work unfortunately. In the
exported version, I get a minted source block and not a link.

Am I doing something wrong? Is it possible to have a shorter syntax for
these blocks, or do I have to put all the header lines all the time?

Thanks,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-01, Mauna Loa Obs.): 402.52


signature.asc
Description: PGP signature