From: "Michaël Cadilhac" <michael@cadilhac.name>
To: emacs-orgmode@gnu.org
Subject: HTML export with LaTeX babel blocks
Date: Wed, 28 Aug 2019 19:59:12 -0500 [thread overview]
Message-ID: <CADt3fpNNwaUp-buQELofbUYvXExtaijZi9FW2tn7BXDNx4bEJA@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 1728 bytes --]
My goal is to export SVG files of TikZ drawings in HTML. Now, what follows
is a bit of a rant on `org-babel-execute:latex`; let's go through the
options:
- You're exporting to PNG without imagemagick:
This uses `org-create-formula-image` which works really well, but it
discards the options of the LaTeX block (fit, width, height, ...),
including headers. It also fails to *force* using 'dvipng as processing
type, so if `org-preview-latex-default-process` has been changed, it may be
confusing. Finally, it uses `in-buffer` to render LaTeX as if it were in
the buffer, which is not what the user would want since they are exporting
to html (as a result, I get a black background on my pictures, since my
buffer background is black).
- You're exporting to PNG with imagemagick or to PDF:
This may work. Sadly, "#+LATEX_HEADER:" is ignored, though it is in the
previous case.
- You're exporting to HTML. This uses htlatex—it's very rarely functional,
but eh, you asked for TeX to HTML, and pdf2htmlEX seems unmaintained, so
expect chaos.
- You're exporting to SVG.
This… uses htlatex? Why in paradise? org-create-formula-image would do
that *brilliantly. *In any case, I can't seem to make it work: my fonts
are always disappearing.
So what do I do? I use the attached patch, that bypasses `htlatex` and
uses the oh-so-working `org-create-formula-image`. This, of course, is not
a complete solution—this whole function is messy at best, buggy at
worst—but in the meantime, I can finally export my pictures to SVG (end
result: https://autoboz.org/open-problems/19.1-ccra/).
If anyone has an opinion on what to do with this situation, I'd be happy to
help.
Cheers,
M.
[-- Attachment #1.2: Type: text/html, Size: 2073 bytes --]
[-- Attachment #2: 0001-ob-latex-Use-org-create-formula-image-when-generatin.patch --]
[-- Type: text/x-patch, Size: 3040 bytes --]
From 7f2cbee0e45ba6a57c913ed49690262401e67f39 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20Cadilhac?= <michael@cadilhac.name>
Date: Thu, 15 Aug 2019 10:28:27 -0400
Subject: [PATCH] ob-latex: Use org-create-formula-image when generating SVG
* lisp/ob-latex.el (org-babel-execute:latex): Remove convoluted and
buggy htlatex based SVG generation, and use `org-create-formula-image`
---
lisp/ob-latex.el | 37 ++++++++++++++-----------------------
1 file changed, 14 insertions(+), 23 deletions(-)
diff --git a/lisp/ob-latex.el b/lisp/ob-latex.el
index adf83d460..02ddfa2a8 100644
--- a/lisp/ob-latex.el
+++ b/lisp/ob-latex.el
@@ -114,14 +114,13 @@ This function is called by `org-babel-execute-src-block'."
(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))
+ ;; 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.
+ ((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
- ;; 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}
@@ -143,23 +142,14 @@ This function is called by `org-babel-execute-src-block'."
(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) "-1.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) "-1.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")))))
+ (when (file-exists-p (concat (file-name-sans-extension tex-file) ".html"))
+ (shell-command "mv %s %s"
+ (concat (file-name-sans-extension tex-file)
+ ".html")
+ out-file)))
+ ((string= "svg" extension)
+ (org-create-formula-image
+ body out-file org-format-latex-options nil 'dvisvgm))
((or (string= "pdf" extension) imagemagick)
(with-temp-file tex-file
(require 'ox-latex)
--
2.22.0
next reply other threads:[~2019-08-29 0:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-29 0:59 Michaël Cadilhac [this message]
2019-08-29 18:13 ` HTML export with LaTeX babel blocks Berry, Charles
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADt3fpNNwaUp-buQELofbUYvXExtaijZi9FW2tn7BXDNx4bEJA@mail.gmail.com \
--to=michael@cadilhac.name \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).