From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id KMvdFRtSKmM7VgEAbAwnHQ (envelope-from ) for ; Wed, 21 Sep 2022 01:51:55 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id mCPuFBtSKmMUOQAAG6o9tA (envelope-from ) for ; Wed, 21 Sep 2022 01:51:55 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id B59453DB26 for ; Wed, 21 Sep 2022 01:51:54 +0200 (CEST) Received: from localhost ([::1]:33100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oan1s-0006uZ-FI for larch@yhetil.org; Tue, 20 Sep 2022 19:51:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oakFR-0005W6-AE for emacs-orgmode@gnu.org; Tue, 20 Sep 2022 16:53:44 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:45720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oakFO-0006i2-KK for emacs-orgmode@gnu.org; Tue, 20 Sep 2022 16:53:41 -0400 Received: by mail-wm1-x329.google.com with SMTP id d12-20020a05600c3acc00b003b4c12e47f3so2536036wms.4 for ; Tue, 20 Sep 2022 13:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date; bh=ru6C1OdCwJ8d8efp+yMYPL5+LXF29LaKd++R8XnfWOA=; b=F17Dkwhj66NwmG8EtVxxK4oeOQlYn8utasrCRAJ8Skp21NEYLptmxz/keZH30oERc9 vkZEXOncS3NHWzHguuY3l9s4VlucXQLRexkbhkPH1Tx9EoKwd9vb32tnkkH6CzTncXAo uVCCRrQaPRHnouQLhRCfzuSCsTcoRxEVq86784yarvzbNSFnNThqT9d7hpS6w6n2WT1M VjNd9nt1MK8cPyQaG52D1pARUG1VFd4nrYBDHbvOhdQQSq+tuCPVO01fJOD9vPMsVPtc YfkBBGny9rT8jWOVi0zRxe/XN0cBkB/E7WHsbHRN+foYFzKSx9AS9fq7BD5Lb8KZ0/VW 4l3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date; bh=ru6C1OdCwJ8d8efp+yMYPL5+LXF29LaKd++R8XnfWOA=; b=g9/fLtw0coFuP5bszz+1M4yStLZg6Sm6EYXMVA3s8LPyBBsCmZP/+PX5/m+gle066a MfPBAg4XDmkAPiEZDVp1QlWSUNo7+4Bi+20nYWoqMPg7IPcr94Kv1Ey01sx7A/zjI2Fv y2kmZ6L2Iz3Glkpo4a/ojZ6nkOsgaownBewko9zHNt5VMkxMbxBbzdTW3NlkJFd9d8JY JGBQu1ioldwpLUVjn7XVrGqRrkLWg78/V7JoUaXba/He9iIgUH2qttvXUkjfM1Fuy0BF koLpZjv1CuFTAJtH3EHk8h8RQYd3UNmbmp8qjfh8DoHaC6oNZ6TBtv+TUJwrcPJIqTwe lyMw== X-Gm-Message-State: ACrzQf16OPye1l6pbLcyoFJ/5+4APUPYre6XAFdeEkAHL0R1qXTATWYR 08jy4/R06YIkH6ABK/+ktleZP7pRktk= X-Google-Smtp-Source: AMsMyM4YIzKcZFCurJ0ICSo3I4vYtspU583Y4BVgNa7Wh3K2zwkYqrGKocpBApibE+budbAHmSKfSQ== X-Received: by 2002:a05:600c:3c95:b0:3b4:cd95:f436 with SMTP id bg21-20020a05600c3c9500b003b4cd95f436mr3834766wmb.199.1663707216139; Tue, 20 Sep 2022 13:53:36 -0700 (PDT) Received: from paquerette (176-136-230-16.abo.bbox.fr. [176.136.230.16]) by smtp.gmail.com with ESMTPSA id bt25-20020a056000081900b00228d52b935asm745152wrb.71.2022.09.20.13.53.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 13:53:35 -0700 (PDT) From: Edouard Debry To: reza Cc: "emacs-orgmode@gnu.org" Subject: Re: svg file from tikz picture In-Reply-To: <010201835a532739-08121085-5b99-4410-8f53-11b74f8d7dcc-000000@eu-west-1.amazonses.com> (reza@housseini.me's message of "Tue, 20 Sep 2022 09:55:42 +0000") References: <3bc47afb-0bac-f6e8-1097-13dcb6f2be1f@housseini.me> <01020182a2d7ed46-7be65254-b93a-4e52-b275-c7dde587f51b-000000@eu-west-1.amazonses.com> <87o7wk34oe.fsf@localhost> <964a4117-ef6c-8d41-a25d-00e61c0c93d8@housseini.me> <01020182a6195e86-02f458a1-9efa-47ba-9b77-5669dbf06c6a-000000@eu-west-1.amazonses.com> <0931497c-9075-c214-c7f2-6507340a6d74@housseini.me> <87h72c3397.fsf@localhost> <01020182a62a5d2f-30791667-55f9-45ac-ae47-82377defea68-000000@eu-west-1.amazonses.com> <6daeb56b-163c-f862-5866-da624b43edd9@housseini.me> <01020182a6556f7e-bc5439ea-e56f-4acb-953c-7f3535eaedad-000000@eu-west-1.amazonses.com> <878rno301p.fsf@localhost> <7dcd1348-6faf-8464-38b5-8efac7c69250@housseini.me> <01020182a6670908-78f84b7b-c05b-42db-a109-0b828f53dc45-000000@eu-west-1.amazonses.com> <010201835a532739-08121085-5b99-4410-8f53-11b74f8d7dcc-000000@eu-west-1.amazonses.com> Date: Tue, 20 Sep 2022 22:53:34 +0200 Message-ID: <8635clydgx.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (windows-nt) MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=edouard.debry@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1663717914; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=ru6C1OdCwJ8d8efp+yMYPL5+LXF29LaKd++R8XnfWOA=; b=ttWUtAHUZB/LQyc3DXreC4hLil4ORpSWJV6+Lz7IlwrbdxgWHOfxwyefSpbht7E24wka0n f50w/WZ8c0za/giAV4V1wlU3S2QegXg/xrszO3Ev5cNzTfKeQlPS1PaqJ0o30IEgVpa5Zq 3uweB2tPAHDq9NOCwPFmgvGEBTqOkyMnkKmrDZ7fpZSk6xXWRM3g5FpqC2pG8pIEt5wp9T pVUDv0HTrN8CFA12OCAiSfaJkZTge/gG9r/7G4Z6N/yNKr5r8Jeeigj6YoNYRzcixBThYR R60jSMEeXpy8dD4KsYt7AVFwPYmaNwmuiK5ixl/GKz4qzR13zvvFmjl3VjfYdw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1663717914; a=rsa-sha256; cv=none; b=L30hrM2uD42R4m12w/OMWid/BN/VKWXN5+PKSIitcK8hKEou3d5RCm55TXDo0lBlvlPAh1 3kSH5YPvy9D55lXlNNGXzK4dC/0KEnK2kWS020E+yZUyaByZF8MqvuVEaUOgaVLrYd6xH4 Sr69ZVQ8QaHwBtpXUKIEPDxekkas8EFYuyUVKEwAL675YWIl2diC1k00M+iQQReuff8N+O EfO6VhECrqWvDWbXiew2nWbX5oTXxI8qVuU9Wee96NFWSkWvatQb+5xuyAy+z2Qr5NDmYK Lm2cvWb3Lrow2JoLLTKgsfZCjB2NzzWcEfFGjn2iJ9P8udYBmvQJ3w3L1Lrsdg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=F17Dkwhj; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -5.33 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=F17Dkwhj; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: B59453DB26 X-Spam-Score: -5.33 X-Migadu-Scanner: scn0.migadu.com X-TUID: Ul+pLREpOcSJ 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 > 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