Re: svg file from tikz picture

2023-10-19 Thread Ihor Radchenko
Akira Kyle  writes:

>> I've just checked and Akira's is a registered FSF contributor 
>> since
>> last may.
>
> Unfortunately I was informed that I am only allowed to make 
> "small" contributions. I wasn't given any explicit metric of what 
> qualifies as a "small" contribution, but was informed that patches 
> such as this one are okay for me to contribute.

(...after some checking with FSF off-list)
We have confirmation that the discussed patch should be OK.
Thus, we have no legal obstacles accepting the patches in this thread.

> ...
> It's been five years since I initially wrote this patch and two 
> years since I started my assignment processes so I haven't really 
> had the time or motivation to get this patch into a merge-able 
> state. I still use this code quite regularly myself so I'll 
> probably get around to working on it again and some point in the 
> future.

It has been a while since the last message in this thread.
Let us know if you are still interested to work on this patch.
In needed, we can provide help on the code or answer any questions.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: svg file from tikz picture

2023-08-05 Thread Bastien Guerry
Akira Kyle  writes:

> It's been five years since I initially wrote this patch and two years
> since I started my assignment processes 

More precisely: I'll double-check with the FSF legal team that having
your name in the FSF copyright registers means that you can contribute
to Emacs and Org-mode. Probably your university disclaimer was enough.

-- 
 Bastien Guerry



Re: svg file from tikz picture

2023-08-05 Thread Bastien Guerry
Hi Akira,

Akira Kyle  writes:

> I have been informed that this document my university has
> provided is queued with the FSF legal team for eventual review.

Thanks for your answer.

I suggest we take this off-list and try to sort it out with the FSF
legal team directly.

-- 
 Bastien Guerry



Re: svg file from tikz picture

2023-08-05 Thread Akira Kyle



On Sat, Aug 05, 2023 at 07:29 PM, Bastien Guerry  
wrote:



Ihor Radchenko  writes:


Akira, may I know if you managed to clear the FSF paperwork?


I've just checked and Akira's is a registered FSF contributor 
since

last may.


Unfortunately I was informed that I am only allowed to make 
"small" contributions. I wasn't given any explicit metric of what 
qualifies as a "small" contribution, but was informed that patches 
such as this one are okay for me to contribute.


This is due to my university being unwilling to sign the FSF 
copyright disclaimer without involvement from their legal team 
(although they did sign a standard letter they have saying the 
would never claim copyright over emacs, but that disclaimer does 
not name me personally). I have been informed that this document 
my university has provided is queued with the FSF legal team for 
eventual review.


It's been five years since I initially wrote this patch and two 
years since I started my assignment processes so I haven't really 
had the time or motivation to get this patch into a merge-able 
state. I still use this code quite regularly myself so I'll 
probably get around to working on it again and some point in the 
future.


Akira



Re: svg file from tikz picture

2023-08-05 Thread Bastien Guerry
Ihor Radchenko  writes:

> Akira, may I know if you managed to clear the FSF paperwork?

I've just checked and Akira's is a registered FSF contributor since
last may.

-- 
 Bastien Guerry



Re: svg file from tikz picture

2023-08-05 Thread Ihor Radchenko
Bastien Guerry  writes:

>>> The last message I received from them was over a month ago and my 
>>> last follow up email to them was ten days ago.
>>
>> Bastien, may you follow up with Craig about the status?
>
> I don't see the FSF copyright assignment status for
> ak...@akirakyle.com - please CC me if you write to Craig again so I
> can follow up directly there.

It has been a while since the last email in this thread.
Akira, may I know if you managed to clear the FSF paperwork?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: svg file from tikz picture

2023-04-19 Thread Bastien Guerry
Ihor Radchenko  writes:

> Akira Kyle  writes:
>
>>> Do note that FSF should reply within 5 working days.
>>> If not, please follow up and wait another 5 working days.
>>> They should reply by then, but if still not, let us know - we 
>>> will be
>>> able to push them further.
>>
>> The last message I received from them was over a month ago and my 
>> last follow up email to them was ten days ago.
>
> Bastien, may you follow up with Craig about the status?

I don't see the FSF copyright assignment status for
ak...@akirakyle.com - please CC me if you write to Craig again so I
can follow up directly there.

Thanks!

-- 
 Bastien Guerry



Re: svg file from tikz picture

2023-03-25 Thread Ihor Radchenko
Akira Kyle  writes:

>> Do note that FSF should reply within 5 working days.
>> If not, please follow up and wait another 5 working days.
>> They should reply by then, but if still not, let us know - we 
>> will be
>> able to push them further.
>
> The last message I received from them was over a month ago and my 
> last follow up email to them was ten days ago.

Bastien, may you follow up with Craig about the status?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: svg file from tikz picture

2023-03-25 Thread Akira Kyle



On Sat, Mar 25, 2023 at 06:13 PM, Ihor Radchenko 
 wrote:



Do note that FSF should reply within 5 working days.
If not, please follow up and wait another 5 working days.
They should reply by then, but if still not, let us know - we 
will be

able to push them further.


The last message I received from them was over a month ago and my 
last follow up email to them was ten days ago.





Re: svg file from tikz picture

2023-03-25 Thread Ihor Radchenko
Akira Kyle  writes:

> Unfortunately, I'm still waiting for my fsf copyright assignment 
> paperwork to go through, and I think I'm already at my maximum 
> allowed copyright-exempt contributions for emacs.

Do note that FSF should reply within 5 working days.
If not, please follow up and wait another 5 working days.
They should reply by then, but if still not, let us know - we will be
able to push them further.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: svg file from tikz picture

2023-03-24 Thread Akira Kyle



On Mon, Nov 14, 2022 at 05:52 AM, Ihor Radchenko 
 wrote:



Have you had a chance to look into my comments?


Sorry for the really slow replies, I do intend to follow up on 
this at some point.


Unfortunately, I'm still waiting for my fsf copyright assignment 
paperwork to go through, and I think I'm already at my maximum 
allowed copyright-exempt contributions for emacs.




Re: svg file from tikz picture

2022-11-14 Thread Ihor Radchenko
Ihor Radchenko  writes:

> Akira Kyle  writes:
>
>> I've been using the attached patch for the last few years and I've meaning 
>> to send it here/start a discussion about ob-latex.el since I used it pretty 
>> much daily to write tikz figures in org mode. So I'm glad to see this 
>> discussion has been started!

Hi Akira,

Have you had a chance to look into my comments?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: svg file from tikz picture

2022-09-25 Thread Ihor Radchenko
Akira Kyle  writes:

> I've been using the attached patch for the last few years and I've meaning to 
> send it here/start a discussion about ob-latex.el since I used it pretty much 
> daily to write tikz figures in org mode. So I'm glad to see this discussion 
> has been started!
>
> I've found it to be incredibly productive to use babel to develop tikz 
> diagrams as I can make come changes and quickly `org-ctrl-c-ctrl-c` to render 
> them in the same buffer.
>
> I think when I made this patch I had been caught by some of the quirks of the 
> svg export. For example, sometimes I would have some latex equation which I 
> use ~org-latex-preview~ on as I was writing it, but then it would fail to 
> render as mathjax upon html export since I would use some latex package that 
> isn't available under mathjax. So by using ob-latex I could easily fix this 
> by using the ~:file .svg~ header and get a nice html export. However due to 
> the different way of assembling the ~.tex~ file sometimes ~org-latex-preview~ 
> would work but ob-latex wouldn't. I think my use case may be fairly common 
> and so I think ob-latex really should be updated so svg uses the 
> ~org-latex-preview~ code. o

Thanks a lot for the patch!
I am not very familiar with the code here, but I will try to cross-check
things as much as possible as an initial feedback.

> Also I think the ~.tikz~ extension doesn't really make any sense since one 
> really can but arbitrary tex code in such a block, and I think that's why I 
> renamed it in my patch. However I'm now realizing that this evaluation method 
> probably doesn't make much since `:tangle` will already do this, with the 
> added benefit of handling noweb references correctly. So perhaps this should 
> be removed and document using tangling in lieu of ~:file *.tikz~?

This sounds reasonable, but we must not remove it just yet. Instead, we
need to support .tex extension _and_ .tikz extension as backwards
compatibility. For .tikz extension we may also display a warning that it
is obsolete.

> -(defcustom org-babel-latex-htlatex-packages
> -  '("[usenames]{color}" "{tikz}" "{color}" "{listings}" "{amsmath}")
> -  "Packages to use for htlatex export."
> -  :group 'org-babel
> -  :type '(repeat (string)))

Removing this defcustom will be a regression. Maybe we can instead
append it to org-latex-packages-alist? Note that {color} and {tikz} are
not loaded by default in `org-format-latex-header'.

> +  (org-format-latex-header
> +   (concat org-format-latex-header
> +   (mapconcat #'identity (cdr (assq :headers params)) "\n")
> +   (if fit "\n\\usepackage[active, tightpage]{preview}\n" "")

(concat "a" nil "b") is perfectly acceptable. There is no need to supply
empty strings as `concat' arguments.
Can simply use (when fit ...)

> +(defun org-babel-latex-format-tex (tex-file body)
> +  "Generate a temporary tex file from execute params."
> +  (with-temp-file tex-file
> +(insert
> + (org-latex-make-preamble
> +  (org-export-get-environment (org-export-get-backend 'latex))
> +  org-format-latex-header)
> + (concat "\n\\begin{document}\n" body "\n\\end{document}\n"

I note that `org-export-get-environment' will be ran inside a temporary
file. It means that Org buffer LaTeX export settings for the source
buffer will not affect the return value. I assume that it is
intentional. If so, it is worth adding a comment about it into the code.

>  
> -(defun org-babel-latex-tex-to-pdf (file)
> -  "Generate a pdf file according to the contents FILE."
> -  (require 'ox-latex)
> -  (org-latex-compile file))
> -

This is removing a non-private function. Even though this function is
nothing but trivial, we still cannot remove it without notice.
The function should be moved to org-compat.el and marked obsolete.

Finally, please note that we follow certain commit message standards in
Org mode. See https://orgmode.org/worg/org-contribute.html#commit-messages

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



Re: svg file from tikz picture

2022-09-23 Thread Akira Kyle

I've been using the attached patch for the last few years and I've meaning to 
send it here/start a discussion about ob-latex.el since I used it pretty much 
daily to write tikz figures in org mode. So I'm glad to see this discussion has 
been started!

I've found it to be incredibly productive to use babel to develop tikz diagrams 
as I can make come changes and quickly `org-ctrl-c-ctrl-c` to render them in 
the same buffer.

I think when I made this patch I had been caught by some of the quirks of the 
svg export. For example, sometimes I would have some latex equation which I use 
~org-latex-preview~ on as I was writing it, but then it would fail to render as 
mathjax upon html export since I would use some latex package that isn't 
available under mathjax. So by using ob-latex I could easily fix this by using 
the ~:file .svg~ header and get a nice html export. However due to the 
different way of assembling the ~.tex~ file sometimes ~org-latex-preview~ would 
work but ob-latex wouldn't. I think my use case may be fairly common and so I 
think ob-latex really should be updated so svg uses the ~org-latex-preview~ 
code. o

Also I think the ~.tikz~ extension doesn't really make any sense since one 
really can but arbitrary tex code in such a block, and I think that's why I 
renamed it in my patch. However I'm now realizing that this evaluation method 
probably doesn't make much since `:tangle` will already do this, with the added 
benefit of handling noweb references correctly. So perhaps this should be 
removed and document using tangling in lieu of ~:file *.tikz~?

PS: I'm not currently subbed to this mailing list, so please try to cc me

>From 5d94745dfbe0858d4fd7d6530b821445b06d5013 Mon Sep 17 00:00:00 2001
From: Akira Kyle 
Date: Tue, 4 Jan 2022 14:33:05 -0700
Subject: [PATCH] ob-latex: Create svg images the same way as png images

Also some cleanup of generation .html and .pdf files
---
 lisp/ob-latex.el | 161 +++
 1 file changed, 50 insertions(+), 111 deletions(-)

diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el
index a86699e22..71b01058c 100644
--- a/lisp/ob-latex.el
+++ b/lisp/ob-latex.el
@@ -39,7 +39,7 @@
 
 (declare-function org-create-formula-image "org" (string tofile options buffer  type))
 (declare-function org-latex-compile "ox-latex" (texfile  snippet))
-(declare-function org-latex-guess-inputenc "ox-latex" (header))
+(declare-function org-latex-make-preamble "ox-latex" (info  template snippet?))
 (declare-function org-splice-latex-header "org" (tpl def-pkg pkg snippets-p  extra))
 (declare-function org-at-heading-p "org" ( _))
 (declare-function org-back-to-heading "org" ( invisible-ok))
@@ -115,12 +115,6 @@ exporting the literal LaTeX source."
   :group 'org-babel
   :type 'string)
 
-(defcustom org-babel-latex-htlatex-packages
-  '("[usenames]{color}" "{tikz}" "{color}" "{listings}" "{amsmath}")
-  "Packages to use for htlatex export."
-  :group 'org-babel
-  :type '(repeat (string)))
-
 (defun org-babel-expand-body:latex (body params)
   "Expand BODY according to PARAMS, return the expanded body."
   (mapc (lambda (pair) ;; replace variables
@@ -142,132 +136,82 @@ This function is called by `org-babel-execute-src-block'."
 	 (extension (file-name-extension out-file))
 	 (tex-file (org-babel-temp-file "latex-" ".tex"))
 	 (border (cdr (assq :border params)))
-	 (imagemagick (cdr (assq :imagemagick params)))
-	 (im-in-options (cdr (assq :iminoptions params)))
-	 (im-out-options (cdr (assq :imoutoptions params)))
 	 (fit (or (cdr (assq :fit params)) border))
 	 (height (and fit (cdr (assq :pdfheight params
 	 (width (and fit (cdr (assq :pdfwidth params
 	 (headers (cdr (assq :headers params)))
 	 (in-buffer (not (string= "no" (cdr (assq :buffer params)
+	 (imagemagick (cdr (assq :imagemagick params)))
+	 (im-in-options (cdr (assq :iminoptions params)))
+	 (im-out-options (cdr (assq :imoutoptions params)))
 	 (org-latex-packages-alist
-	  (append (cdr (assq :packages params)) org-latex-packages-alist)))
+	  (append (cdr (assq :packages params)) org-latex-packages-alist))
+	 (org-format-latex-header
+	  (concat org-format-latex-header
+		  (mapconcat #'identity (cdr (assq :headers params)) "\n")
+		  (if fit "\n\\usepackage[active, tightpage]{preview}\n" "")
+		  (if border
+			  (format "\\setlength{\\PreviewBorder}{%s}" border) "")
+		  (if height
+			  (concat "\n" (format "\\pdfpageheight %s" height)) "")
+		  (if width
+			  (concat "\n" (format "\\pdfpagewidth %s" width)) "")))
+	 (body (if fit 
+		   (concat "\n\\begin{preview}\n" body "\n\\end{preview}\n")
+		 body)))
 (cond
  ((and (string-suffix-p ".png" out-file) (not imagemagick))
   (let ((org-format-latex-header
 		 (concat org-format-latex-header "\n"
 			 (mapconcat #'identity headers "\n"
-	(org-create-formula-image
-  

Re: svg file from tikz picture

2022-09-21 Thread Ihor Radchenko
reza  writes:

First of all, thanks a lot for digging into ob-latex!
This file has not been touched seriously since 7 years ago and the last
major change is 8 years ago (510e70379).

> When having a look at the code inside ob-latex.el I also encountered a 
> few stuff which made me wondering:
>
> 1. png generation is done with the preview code inside org.el 
> (org-create-formula-image), there is also a perfectly fine svg preview 
> function but this does not get used for the svg extension which does the 
> svg conversion without any external tools like inkscape (see 
> https://github.com/bzg/org-mode/blob/main/lisp/ob-latex.el#L156 and 
> https://github.com/bzg/org-mode/blob/main/lisp/org.el#L3181)

This, and many other oddities are likely related to the fact that org.el
preview code is more up-to-date, while ob-latex have not been changed,
including its assumptions about org.el's LaTeX preview.

I suspect that some features in org.el were implemented
separately, but did not get integrated with ob-latex.

> 2. there is a tikz extension switch which does insert the code verbatim, 
> which in my opinion does create a whole bunch of problems (backend 
> dependency issues). Not to mention that it also mimics behaviour which 
> is reserved for the header :results (see 
> https://github.com/bzg/org-mode/blob/main/lisp/ob-latex.el#L177).

Could you please elaborate?

> 3. there is a html extension switch with an unclear purpose to me (in 
> what scenario would you want to produce an html file?). It also has some 
> strange (and contradicting) checking if an svg or an html file got 
> produced. As far as I can tell this code never gets executed and is 
> therefore pointless (see 
> https://github.com/bzg/org-mode/blob/main/lisp/ob-latex.el#L181).

Well. We do not remove existing features unless there is strong
justifications. See https://bzg.fr/en/the-software-maintainers-pledge/

As for the contradicting checking, it is likely a classic copy-paste
error when html and svg branches of the code got split.

> 4. the whole pdf generation looks like duplicate code which is already 
> done in other parts of the code base (ox-latex.el and for the svg 
> extension) it ais also not using the variable org-babel-latex-begin-env 
> and org-babel-latex-end-env (see 
> https://github.com/bzg/org-mode/blob/main/lisp/ob-latex.el#L225).

Again, I am not sure here. It is a very old code. My best guess is that
it was developer prior to ox-latex.

The best hint I can provide is
https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html
that should document some details of the logic.

> I don't want to criticize anyone, I just want to find answers for in my 
> opinion some strange decisions.

Criticism is welcome as long as it is aiming to improve Org. No worries.

If you want to dig further, I can also suggest to use git blame and dig
into mailing list messages from Eric Schulte, the original author of
ob-latex.

> My propositions for refactoring is:
>
> 1. use the svg preview code for svg generation (and therefore ditching 
> the whole imagemagick headers)

Note that imagemagick argument does more than you may expect. For
example, one can apply various image effects on the generated file via
imagemagick:

https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html
>> :imagemagick
>> When not nil the source block is processed to pdf and the pdf is converted 
>> with ImageMagick to whatever is given as :file. Thus, the format is not 
>> limited to png.
>> :iminoptions
>> This is passed to ImageMagick before the pdf file.
>> :imoutoptions
>> This is passed to ImageMagick before the output file.

That said, I do agree that re-using svg preview generation sounds like
an improvement. But we need to be careful not to remove the existing
functionality.

> 2. remove the whole tikz generation completely
>
> 3. remove the whole html generation completely

I did not see justification why we need to do it other than lack of
ideas why they are useful. For now, I do not think that removing
tikz/html generation is a good idea.

According to
https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-LaTeX.html,
tikz generation can be useful during LaTeX export.

> 4. try to merge pdf generation with org.el and ox-latex.el or 
> incorporating it into he preview code and 
> org-preview-latex-process-alist (this is probably a whole project of it own)

This sounds like a very good idea. I'd merge the preview code from
org.el into ob-latex.

> WDYT?

Improving ob-latex is most welcome. I think that the first step is
incremental refactor. Let's not remove features until we have less
tangled code that is easier to understand.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



Re: svg file from tikz picture

2022-09-20 Thread Edouard Debry


Hi, I had this very same question to produce svg from latex src blocks.

First, consider this example :
#+HEADER: :file test1.png
#+HEADER: :exports results
#+HEADER: :results output silent graphics file
#+HEADER: :fit yes :noweb yes :headers '("\\usepackage{tikz}" 
"\\usetikzlibrary{backgrounds}")
#+begin_src latex
\begin{tikzpicture}[background rectangle/.style={fill=olive!30}, show 
background rectangle]
\draw[->] (-3,0) -- (-2,0) arc[radius=0.5cm,start angle=-180,end angle=0] 
(-1,0) -- (1,0) arc[radius=0.5cm,start angle=180,end angle=0] (2,0) -- (3,0);
\filldraw (-1.5,0) circle[radius=1mm];
\filldraw (1.5,0) circle[radius=3mm];
\end{tikzpicture}
#+end_src

When I run it, it does create a test1.png but, it is in fact a svg file
!! This is because, as you noticed, the `org-create-formula-image`
relies on `org-preview-latex-default-process` which is set to 'dvisvgm.
If you set it to 'dvipng, it creates again a regular png file.

Then, I changed the line :
((and (string-suffix-p ".png" out-file) (not imagemagick))
into
((and (or (string-suffix-p ".png" out-file) (string-suffix-p ".svg" out-file)) 
(not imagemagick))

so that I can correctly create a svg file when I want to and, to create
a real png file (or jpg one), I add the following line to the header :
#+HEADER: :imagemagick yes :iminoptions -density 600

There is also another way to create a svg file with `htlatex` with :

 ((and (string= "svg" extension)
   (executable-find org-babel-latex-htlatex))
  ;; TODO: this is a very different way of generating the
  ;; frame latex document than in the pdf case.  Ideally, both
  ;; would be unified.  This would prevent bugs creeping in
  ;; such as the one fixed on Aug 16 2014 whereby :headers was
  ;; not included in the SVG/HTML case.
  (with-temp-file tex-file
(insert (concat
 "\\documentclass[preview]{standalone}
\\def\\pgfsysdriver{pgfsys-dvisvgm4ht.def}
"
 (mapconcat (lambda (pkg)
  (concat "\\usepackage" pkg))
org-babel-latex-htlatex-packages
"\n")
 (if headers
 (concat "\n"
 (if (listp headers)
 (mapconcat #'identity headers "\n")
   headers) "\n")
   "")
 "\\begin{document}"
 body
 "\\end{document}")))
  (when (file-exists-p out-file) (delete-file out-file))
  (let ((default-directory (file-name-directory tex-file)))
(shell-command (format "%s %s" org-babel-latex-htlatex tex-file)))
  (cond
   ((file-exists-p (concat (file-name-sans-extension tex-file) 
"0x.svg"))
(if (string-suffix-p ".svg" out-file)
(progn
  (shell-command "pwd")
  (shell-command (format "mv %s %s"
 (concat (file-name-sans-extension 
tex-file) "0x.svg")
 out-file)))
  (error "SVG file produced but HTML file requested")))
   ((file-exists-p (concat (file-name-sans-extension tex-file) ".html"))
(if (string-suffix-p ".html" out-file)
(shell-command "mv %s %s"
   (concat (file-name-sans-extension tex-file)
   ".html")
   out-file)
  (error "HTML file produced but SVG file requested")

you will notice that this is a copy-paste from the html generation with
two major differences :
- for svg generation, do not use the driver
\\def\\pgfsysdriver{pgfsys-tex4ht.def}
but rather
\\def\\pgfsysdriver{pgfsys-dvisvgm4ht.def}
which handles better fonts and probably many other things
- the svg file produced to not have the same format with this driver
  ("0x.svg")

That would be great to reimplement ob-latex.el, at least correct the
first curious behavior when you end up with a svg file although you
wanted a png one.

Hope this helps.

Regards

reza  writes:

> By setting
>
>  (setq org-babel-latex-preamble (lambda (_) 
> "\\documentclass[preview]{standalone}\n")
>
> the tikz file svg generation does run fine. Obviously the part
>
>  \\def\\pgfsysdriver{pgfsys-tex4ht.def}
>
> inside `org-babel-latex-preamble` does not play well with the svg 
> generation.
>
>
> When having a look at the code inside ob-latex.el I also encountered a 
> few stuff which made me wondering:
>
> 1. png generation is done with the preview code inside org.el 
> (org-create-formula-image), there is also a perfectly fine svg preview 
> function but this does not get used for the svg extension which does the 
> svg conversion without any external tools like inkscape (see 
> 

Re: svg file from tikz picture

2022-09-20 Thread reza
By setting

 (setq org-babel-latex-preamble (lambda (_) 
"\\documentclass[preview]{standalone}\n")

the tikz file svg generation does run fine. Obviously the part

 \\def\\pgfsysdriver{pgfsys-tex4ht.def}

inside `org-babel-latex-preamble` does not play well with the svg 
generation.


When having a look at the code inside ob-latex.el I also encountered a 
few stuff which made me wondering:

1. png generation is done with the preview code inside org.el 
(org-create-formula-image), there is also a perfectly fine svg preview 
function but this does not get used for the svg extension which does the 
svg conversion without any external tools like inkscape (see 
https://github.com/bzg/org-mode/blob/main/lisp/ob-latex.el#L156 and 
https://github.com/bzg/org-mode/blob/main/lisp/org.el#L3181)

2. there is a tikz extension switch which does insert the code verbatim, 
which in my opinion does create a whole bunch of problems (backend 
dependency issues). Not to mention that it also mimics behaviour which 
is reserved for the header :results (see 
https://github.com/bzg/org-mode/blob/main/lisp/ob-latex.el#L177).

3. there is a html extension switch with an unclear purpose to me (in 
what scenario would you want to produce an html file?). It also has some 
strange (and contradicting) checking if an svg or an html file got 
produced. As far as I can tell this code never gets executed and is 
therefore pointless (see 
https://github.com/bzg/org-mode/blob/main/lisp/ob-latex.el#L181).

4. the whole pdf generation looks like duplicate code which is already 
done in other parts of the code base (ox-latex.el and for the svg 
extension) it ais also not using the variable org-babel-latex-begin-env 
and org-babel-latex-end-env (see 
https://github.com/bzg/org-mode/blob/main/lisp/ob-latex.el#L225).

I don't want to criticize anyone, I just want to find answers for in my 
opinion some strange decisions.

My propositions for refactoring is:

1. use the svg preview code for svg generation (and therefore ditching 
the whole imagemagick headers)

2. remove the whole tikz generation completely

3. remove the whole html generation completely

4. try to merge pdf generation with org.el and ox-latex.el or 
incorporating it into he preview code and 
org-preview-latex-process-alist (this is probably a whole project of it own)

WDYT?

Best,
Reza


OpenPGP_0xC375C6AF05125C52.asc
Description: application/pgp-keys


OpenPGP_signature
Description: PGP signature


Re: svg file from tikz picture

2022-08-16 Thread reza
> I do not think that ob-latex code has much to add into ox-latex.
> What I was referring to is the giant `cond' form in
> org-babel-execute:latex, which produces different LaTeX templates
> depending on the output file extension.
> 
> The ob-latex templates should probably remain specific to ob-latex since
> they are tailored to produce (usually one-page) documents from short
> LaTeX snippets.

Yes of course, sorry I confused stuff, the TODO item was referring to 
producing PDF vs SVG not ob-latex vs ox-latex




OpenPGP_0xC375C6AF05125C52.asc
Description: application/pgp-keys


OpenPGP_signature
Description: PGP signature


Re: svg file from tikz picture

2022-08-16 Thread Ihor Radchenko
reza  writes:

>> It is a part of the same infrastructure, but the LaTeX templates for 
>> html/pdf/svg/tiks export are different for some reason. There is even a 
>> TODO comment in the code saying that things should better be unified. Alas.
>> 
>> Patches improving the situation are always welcome.
>
> Where would I put combined code for ox-latex.el and ob-latex.el?

I do not think that ob-latex code has much to add into ox-latex.
What I was referring to is the giant `cond' form in
org-babel-execute:latex, which produces different LaTeX templates
depending on the output file extension.

The ob-latex templates should probably remain specific to ob-latex since
they are tailored to produce (usually one-page) documents from short
LaTeX snippets.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



Re: svg file from tikz picture

2022-08-16 Thread reza
> It is a part of the same infrastructure, but the LaTeX templates for 
> html/pdf/svg/tiks export are different for some reason. There is even a 
> TODO comment in the code saying that things should better be unified. Alas.
> 
> Patches improving the situation are always welcome.

Where would I put combined code for ox-latex.el and ob-latex.el?


OpenPGP_0xC375C6AF05125C52.asc
Description: application/pgp-keys


OpenPGP_signature
Description: PGP signature


Re: svg file from tikz picture

2022-08-16 Thread Ihor Radchenko
> why is this handled differently, should it at least use part of the same
infrastructure?

It is a part of the same infrastructure, but the LaTeX templates for
html/pdf/svg/tiks export are different for some reason. There is even a
TODO comment in the code saying that things should better be unified. Alas.

Patches improving the situation are always welcome.


On Tue, Aug 16, 2022 at 6:20 PM reza  wrote:

> > AFAIU, the news entry is about LaTeX export (ox-latex.el). Here, we are
> > talking about LaTeX babel backend, which is a different implementation
> > (ob-latex.el).
> >
> > In any case, I can reproduce on the latest main.
>
> why is this handled differently, should it at least use part of the same
> infrastructure?
> It seems to be a bug then...
>


Re: svg file from tikz picture

2022-08-16 Thread reza
> AFAIU, the news entry is about LaTeX export (ox-latex.el). Here, we are
> talking about LaTeX babel backend, which is a different implementation
> (ob-latex.el).
> 
> In any case, I can reproduce on the latest main.

why is this handled differently, should it at least use part of the same 
infrastructure?
It seems to be a bug then...


OpenPGP_0xC375C6AF05125C52.asc
Description: application/pgp-keys


OpenPGP_signature
Description: PGP signature


Re: svg file from tikz picture

2022-08-16 Thread Ihor Radchenko
reza  writes:

>> svg generation takes a completely different code branch compared to pdf
>> in ox-latex.el. I am not sure why. Hopefully, someone more familiar with
>> ox-latex and LaTeX in general can chime in.
>
> Just found this in the source [1], maybe it is already fixed?
> https://github.com/bzg/org-mode/blob/b428839f1b5b772d391c1e6bdd80e3f5e23b4441/etc/ORG-NEWS#L768

AFAIU, the news entry is about LaTeX export (ox-latex.el). Here, we are
talking about LaTeX babel backend, which is a different implementation
(ob-latex.el).

In any case, I can reproduce on the latest main.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



Re: svg file from tikz picture

2022-08-16 Thread reza
> svg generation takes a completely different code branch compared to pdf
> in ox-latex.el. I am not sure why. Hopefully, someone more familiar with
> ox-latex and LaTeX in general can chime in.

Just found this in the source [1], maybe it is already fixed?

[1] 
https://github.com/bzg/org-mode/blob/b428839f1b5b772d391c1e6bdd80e3f5e23b4441/etc/ORG-NEWS#L768


OpenPGP_0xC375C6AF05125C52.asc
Description: application/pgp-keys


OpenPGP_signature
Description: PGP signature


Re: svg file from tikz picture

2022-08-16 Thread Ihor Radchenko
reza  writes:

> when running the following code
>
> #+header: :file "absolute-distance.pdf"
> #+header: :results file drawer :exports results :fit yes :border 0cm
> #+header: :headers '("\\usepackage{tikz}")
> #+begin_src latex
>\usetikzlibrary{positioning}
>\begin{tikzpicture}
>  \node[circle,fill,label=above:$P_1$,node font=\Large] (point1) at 
> (0,0) {};
>  \node[circle,fill,label=above:$P_2$,node font=\Large] (point2) at 
> (3,0) {};
>  \draw[latex-latex] (point1) -- (point2);
>\end{tikzpicture}
> #+end_src
>
> everything runs fine and a pdf file gets produced. But when I change the 
> file header to "absolute-distance.svg" an error occurs and no output 
> gets produced. Find attached the tex file and the log of the compilation.

Confirmed.

svg generation takes a completely different code branch compared to pdf
in ox-latex.el. I am not sure why. Hopefully, someone more familiar with
ox-latex and LaTeX in general can chime in.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92