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 aHENAG0wWV8vSwAA0tVLHw (envelope-from ) for ; Wed, 09 Sep 2020 19:43: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 4KaWN2wwWV+VZAAAbx9fmQ (envelope-from ) for ; Wed, 09 Sep 2020 19:43:40 +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 5E3C79404C5 for ; Wed, 9 Sep 2020 19:43:40 +0000 (UTC) Received: from localhost ([::1]:53014 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kG60J-0007FI-6p for larch@yhetil.org; Wed, 09 Sep 2020 15:43:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kG5zo-0007Et-K6 for emacs-orgmode@gnu.org; Wed, 09 Sep 2020 15:43:08 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:35038) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kG5zl-0007RM-At; Wed, 09 Sep 2020 15:43:08 -0400 Received: by mail-pf1-x443.google.com with SMTP id o68so3207802pfg.2; Wed, 09 Sep 2020 12:43:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=xPVDOfujiIWv1nlgWJUirjvvxhDTaT9H2/59ypFE/rA=; b=X+WJjb8oOAIJWdO5UJ8e9OQqFZ3zs5EzrqM9LOCcGClNhMq7gLT4ARJqbhA7GHAodu DYKhlgYpDejVVz+3wqr6JVi6RVQpFf6udCqaNXNp9yV60GgMVP1MHt/eoLN80CEULwjc mWv7jSmuvOpBsDhi/VQsP3VeHjuH6Bt6pMV7dP92kws9MjlSF92HfY30OR17GTpN/6+S eVlU8z8UjXhOfpqvjo4rZK8wz4cUC6CB1SRNOLXrB35pTr3KSSOklKNrtimhKmsCbhmz /df8lHMDQoGvzcIi7FK0FNuqONXe05LnzE7wtpBQ9illjWV1B9pXCdKbFWlO3hAtCwys xTog== 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:cc:subject:in-reply-to:references :date:message-id:mime-version; bh=xPVDOfujiIWv1nlgWJUirjvvxhDTaT9H2/59ypFE/rA=; b=tcIf+cP+1bP/VbSuOpLJboIOMlYAu//IxG8MkRr0JuyhRNXWzEr7AessfM5RoK11Po 5xtXpZxNijzPL34ULp298AfJoEcXwc24nvldJTtYwNEAlXDv1vKfXrqRIUXqZmUaT2KM +vmUypHzfTWWsY17xtuu3TAWSsgrFgQRrHxbqmFLhtOYLdtGdlAYHybH4CKiSZgGKjlZ 8dkxxdMJZgk7ol6rluuCpKFgL7d4o53pui+0XmhM1DJkaMscgrlP2jbWLWlqZY6m5OoX 3/oGDO5dTmPyXINGaBs7Vdj2xVAdkW7zJbRrL92T7dnZIkmSwXNxPsdQLCmK0WBK/d0U E9Ag== X-Gm-Message-State: AOAM5336PkjKYIxHEFkjE/rHoSTPRT5NlRHtOoCCNCW3q5FZcb6BpRRh v8UiEc5/Ln5U8ABf7xiQqUI/P7hOC/5Gxg== X-Google-Smtp-Source: ABdhPJzzOfq9tYq3jcTS7Gmttgi0IDdAOR+ZqA0GdjpdKdzzPRAp+LWwHpC6twAUDb9ZBpnquCd81Q== X-Received: by 2002:a17:902:a40e:: with SMTP id p14mr2239969plq.4.1599680582694; Wed, 09 Sep 2020 12:43:02 -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 ev19sm43152pjb.42.2020.09.09.12.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 12:43:01 -0700 (PDT) From: Matt Huszagh To: Bastien Subject: Re: [PATCH] babel latex headers and image generation commands In-Reply-To: <874kobmnrc.fsf@gnu.org> References: <874kw6ztr9.fsf@gmail.com> <871rrayrsc.fsf@gmail.com> <87y2thylcb.fsf@gmail.com> <87r1z29abl.fsf@gnu.org> <87y2lynft3.fsf@gmail.com> <87zh685bl4.fsf@gmail.com> <87d034qacb.fsf@gmail.com> <874kobmnrc.fsf@gnu.org> Date: Wed, 09 Sep 2020 12:43:00 -0700 Message-ID: <87sgbqzqgr.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=huszaghmatt@gmail.com; helo=mail-pf1-x443.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: , Cc: , "emacs-orgmode@gnu.org" Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=gmail.com header.s=20161025 header.b=X+WJjb8o; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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: 0.09 X-TUID: nx4PCOD+dexG --=-=-= Content-Type: text/plain Bastien writes: > Prefer > > * lisp/ob-latex.el (org-babel-latex-preamble): New option for LaTeX > preamble customization. > > "New option" is quite standard, an "option" being a customizable > variable. In this case, "New option" would probably be enough, given > the name of the option is quite self-explanatory. Also, some find it > pedantic, but "LaTeX" is the correct spelling in a changelog I guess. Fixed in new patch (attached). > The first line of the docstring should contain a sentence, so you'd > need to have a new paragraph after "runtime to the LaTeX preamble." Also fixed. Making the first line a full sentence means that some lines are a little longer than 80 characters. Is this acceptable? > What for users who don't have inkscape? This is just a default, but I could use a dvisvgm command as the default instead? Either way, converting a PDF to SVG will require an executable outside Emacs, but I guess dvisvgm is more likely to be installed for people using a texlive installation. My personal preference for inkscape is because it should handle all PDF inputs, whereas there are some cases where dvisvgm may fail (see https://github.com/mgieseki/dvisvgm/issues/139) due to changes in ghostscript. Still, dvisvgm generally does a very good job with PDF inputs. Let me know your thoughts, I'd be happy to set the default to a dvisvgm command instead. Matt --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ob-latex.el-Make-latex-to-svg-compilation-very-custo.patch >From 1ff86f2267b653dff225837ccf13ebf417f7ed03 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): New option for LaTeX preamble customization. (org-babel-latex-begin-env): New option for LaTeX document environment begin customization. (org-babel-latex-end-env): New option for LaTeX document environment end customization. (org-babel-latex-pdf-svg-process): New option for converting a pdf to svg. (org-babel-execute:latex): Add specific case for svg generation from LaTeX block. --- lisp/ob-latex.el | 59 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el index 4b343dd14..6a4f7a6ba 100644 --- a/lisp/ob-latex.el +++ b/lisp/ob-latex.el @@ -66,7 +66,46 @@ "LaTeX-specific header arguments.") (defcustom org-babel-latex-htlatex "htlatex" - "The htlatex command to enable conversion of latex to SVG or HTML." + "The htlatex command to enable conversion of LaTeX to SVG or HTML." + :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) @@ -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 params) + body + (funcall org-babel-latex-end-env params)))) + (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 --=-=-=--