From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id IMU2DDnXT1+FawAA0tVLHw (envelope-from ) for ; Wed, 02 Sep 2020 17:32:41 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id eFznBznXT18fDQAAbx9fmQ (envelope-from ) for ; Wed, 02 Sep 2020 17:32:41 +0000 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 AAA2F940602 for ; Wed, 2 Sep 2020 17:32:40 +0000 (UTC) Received: from localhost ([::1]:49530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDWch-00022z-Kj for larch@yhetil.org; Wed, 02 Sep 2020 13:32:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDWcK-00022p-38 for emacs-orgmode@gnu.org; Wed, 02 Sep 2020 13:32:16 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:40741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kDWcI-0004Me-7U for emacs-orgmode@gnu.org; Wed, 02 Sep 2020 13:32:15 -0400 Received: by mail-pl1-x642.google.com with SMTP id z15so78443plo.7 for ; Wed, 02 Sep 2020 10:32:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=/UuzLEsNEeM4gU+svGkbEwQp1ciLevo4QUsdYCsfbRk=; b=kfRsXm2k7RBMnbo4N+w0ecJov4uiUEfnp8rthAPOgs2iom6AG8UwlGtzURA7zhJ/F5 udLQZIrDg27Zw8AXAkXvzYLtRgK86zzacFxcPWf+mE2C+/cKCHkiubOCldRjJVT1yixT zaRMxHB0teeefqOsO6t1Xs8qMkW6wn63DVtpo4J/j2IaWeVIVVZ01OT80vAyGWxxfmCx q7BW/Vr0un6WNRwblgAW7U12GQlEhFiTooAGrilP8OYuItA+osZ+7xINqhzlp0YrwkaD dZMbxPF4bLaEVBVo78eR1S8E3EhBLv8uXPj0vNxCZ+MmicXmHWOeo0zIYPY/5SZUq5P8 uYOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=/UuzLEsNEeM4gU+svGkbEwQp1ciLevo4QUsdYCsfbRk=; b=GwJ5LjlKKBZiL4mEvZfE2ZifbkYiEF/oW3rujJ4StWy98OyfiKATbk5/fgKROM7Zgw hUhoPaUxc90F90hxM7LBAU3c99far7h+qi8OBbYU01P6WVUtChh/L6fLXyiKAmAmkAXw 1LikI4SdOIVF9xw8J1TdynP2Zb4QWynlowZ9D/czuwNFUDW+xHadF9eT6POLJGuEYrQO WUDHhrSqXMP90hfa1JcMN4tdlBW/CiK7bfaBRudA7I/HPALBoaYd0+GCNeADeHXvrhna 4l34WjjAO/4j82gWRG5qGAFNpfC2Iva9eSoZZwg8nCImORdnOM/3DAZ2EaMwb+8g1l6p J/uQ== X-Gm-Message-State: AOAM5326IclKfvQomOC4Zs/sooeZGOvTejSEHxGrDRoaD5GPhEopm1QG KcJDyqRuOtEQ0eR7Dw6ohjN4H1h/zrgxaQ== X-Google-Smtp-Source: ABdhPJxvsMrIcNMs8tLK/VF305Xe0gtoQaC5fGB4vJLRycqX2ujPCkXtjDu8wWoUFe1SW8qZgycUJA== X-Received: by 2002:a17:902:bd42:: with SMTP id b2mr3043999plx.246.1599067932446; Wed, 02 Sep 2020 10:32:12 -0700 (PDT) Received: from ryzen3950 (c-73-71-89-135.hsd1.ca.comcast.net. [73.71.89.135]) by smtp.gmail.com with ESMTPSA id i1sm5945143pgq.41.2020.09.02.10.32.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2020 10:32:11 -0700 (PDT) From: Matt Huszagh To: "emacs-orgmode@gnu.org" Cc: Subject: Re: [PATCH] babel latex headers and image generation commands In-Reply-To: References: <874kw6ztr9.fsf@gmail.com> <871rrayrsc.fsf@gmail.com> <87y2thylcb.fsf@gmail.com> <87r1z29abl.fsf@gnu.org> <87y2lynft3.fsf@gmail.com> Date: Wed, 02 Sep 2020 10:32:07 -0700 Message-ID: <87zh685bl4.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::642; envelope-from=huszaghmatt@gmail.com; helo=mail-pl1-x642.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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.23 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-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=kfRsXm2k; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.71 X-TUID: kOubqUql40e3 --=-=-= Content-Type: text/plain Matt Huszagh writes: > Ok, I've finally gotten around to taking a crack at this. The patch is > attached. Basically, it allows a lot more control when converting a > latex source block into an svg image file. I've added a few changes to the patch that additionally allow custom the begin and end document environments. The purpose here is to allow latex code within the document environment that is ignored by the body export. For instance, I can set the page color with {\color{some-color}...} and this doesn't mess up latex exports. Please comment with any questions/concerns/thoughts. Thanks! --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ob-latex.el-Make-latex-to-svg-compilation-very-custo.patch >From 6dbd5ae840f02333f83d40a9c27be06968279563 Mon Sep 17 00:00:00 2001 From: Matt Huszagh Date: Fri, 28 Aug 2020 22:26:05 -0700 Subject: [PATCH] ob-latex.el: Make latex to svg compilation very customizable * lisp/ob-latex.el (org-babel-latex-preamble): Add latex preamble customization. (org-babel-latex-begin-env): Add latex document environment begin customization. (org-babel-latex-end-env): Add latex document environment end customization. (org-babel-latex-pdf-svg-process): Add customization for converting a pdf to svg. (org-babel-execute:latex): Add specific case for svg generation from latex block. --- lisp/ob-latex.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el index 4b343dd14..359179476 100644 --- a/lisp/ob-latex.el +++ b/lisp/ob-latex.el @@ -70,6 +70,45 @@ :group 'org-babel :type 'string) +(defcustom org-babel-latex-preamble + (lambda (_) + "\\documentclass[preview]{standalone} +\\def\\pgfsysdriver{pgfsys-tex4ht.def} +") + "Closure which evaluates at runtime to the latex preamble. It +takes 1 argument which is the parameters of the source block." + :group 'org-babel + :type 'function) + +(defcustom org-babel-latex-begin-env + (lambda (_) + "\\begin{document}") + "Closure which evaluates at runtime to the begin part of the +document environment. It takes 1 argument which is the +parameters of the source block. This allows adding additional +code that will be ignored when exporting the literal latex +source." + :group 'org-babel + :type 'function) + +(defcustom org-babel-latex-end-env + (lambda (_) + "\\end{document}") + "Closure which evaluates at runtime to the end part of the +document environment. It takes 1 argument which is the +parameters of the source block. This allows adding additional +code that will be ignored when exporting the literal latex +source." + :group 'org-babel + :type 'function) + +(defcustom org-babel-latex-pdf-svg-process + "inkscape --pdf-poppler %f -T -l -o %O" + "Command used to convert a PDF file to an SVG file when +executing a latex source block." + :group 'org-babel + :type 'string) + (defcustom org-babel-latex-htlatex-packages '("[usenames]{color}" "{tikz}" "{color}" "{listings}" "{amsmath}") "Packages to use for htlatex export." @@ -114,12 +153,26 @@ This function is called by `org-babel-execute-src-block'." (mapconcat #'identity headers "\n")))) (org-create-formula-image body out-file org-format-latex-options in-buffer))) + ((string= "svg" extension) + (with-temp-file tex-file + (insert (concat (funcall org-babel-latex-preamble params) + (mapconcat #'identity headers "\n") + (funcall org-babel-latex-begin-env) + body + (funcall org-babel-latex-end-env)))) + (let ((tmp-pdf (org-babel-latex-tex-to-pdf tex-file))) + (let* ((log-buf (get-buffer-create "*Org Babel LaTeX Output*")) + (err-msg "org babel latex failed") + (img-out (org-compile-file + tmp-pdf + (list org-babel-latex-pdf-svg-process) + extension err-msg log-buf))) + (shell-command (format "mv %s %s" img-out out-file))))) ((string-suffix-p ".tikz" out-file) (when (file-exists-p out-file) (delete-file out-file)) (with-temp-file out-file (insert body))) - ((and (or (string= "svg" extension) - (string= "html" extension)) + ((and (string= "html" 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 -- 2.28.0 --=-=-=--