0

With the following .emacs (on bleeding-edge GNU Emacs 30.0.50 and Org mode 9.6.1 in 2023)

;; Org -> LaTeX
(require 'ox-latex)
(add-to-list 'org-latex-packages-alist '("" "minted"))
(setq org-latex-listings 'minted)
(setq org-latex-pdf-process '("latexmk -shell-escape -f -pdf %f"))
;; Org -> HTML
(setq org-src-fontify-natively t)

I can see both the effect of font-lock-fontify-buffer in Emacs (left) and the result of minted in the LaTeX/PDF export (center), but no fontification following exporting to HTML.

Org, LaTeX, and HTML

How do I export font-lock from Org to HTML?

Related: 1, 2, 3, 4, ...

Here is the sample source file.

#+LATEX_HEADER: \usemintedstyle{default}

#+BEGIN_SRC c++
// Mean == (Sum / Count)
template<typename Sample>
struct mean_accumulator : accumulator_base
{
    typedef Sample result_type;
    mean_accumulator(dont_care) {}

    template<typename Args>
    result_type result(Args const &args) const
    {
        return sum(args[accumulator]) /
               count(args[accumulator]);
    }
};
#+END_SRC
1
  • 3
    Make sure that htmlize is installed. Search the Org manual for htmlize and/or search the package list for it.
    – NickD
    Apr 5 at 20:43

2 Answers 2

0

If you recall this worked at some point, but it no longer does, install htmlize (thanks to NickD for the pointer).

You will then duly get the requisite output.

code fontified in HTML from Org

If you've wiped out your ~/.emacs.d/elpa directory, a good way to not forget one package or another is to rely on package-install.

0

If that fails and you need a workaround, there's this code to turn an entire buffer into SVG (but only on X11 !).

;; useful trick from https://www.reddit.com/r/emacs/comments/idz35e/emacs_27_can_take_svg_screenshots_of_itself/
(defun screenshot-svg ()
  "Save a screenshot of the current frame as an SVG image.
Saves to a temp file and puts the filename in the kill ring."
  (interactive)
  (let* ((filename (make-temp-file "Emacs" nil ".svg"))
     (data (x-export-frames nil 'svg)))
    (with-temp-file filename
      (insert data))
    (kill-new filename)
    (message filename)))
(define-key global-map [(super s)]  'screenshot-svg)

1
  • x-export-frames seems clever, but x-anything is too niche a solution. Forget about the Mac; it wouldn't even work on Linux flavors built with Qt; is that right?
    – Sam7919
    Apr 6 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.