Akira Kyle <ak...@akirakyle.com> 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