I would like to use emacs to "render" text to an output file.

Is there a way to export the buffer with all font-locking to a file?

(The exact format may not matter HTML or terminal-escaped colors would both be fine).

Some options I'm aware of but aren't quite what I'm after.

  • Cairo SVG screenshot...

    • Being a screenshot makes this less useful for writing a whole text buffer, although in theory and off screen buffer could be made very tall I suppose.
    • SVG isn't so easy to manipulate (search, convert into other text format).
  • Terminal screenshot...

    • Again, it's limited to a "screen", not so convenient to dump an entire buffer.

.. Of course it's possible to do tricks like capturing regions and joining them together, this can work but isn't trivial and seems like a last resort.

Are there any solutions that export the entire buffer as it's displayed on-screen?

  • htmlize-buffer (That's in the elpa package htmlize.)
    – Tobias
    Oct 14, 2021 at 11:34
  • You can also export org buffers including source blocks to HTML.
    – Tobias
    Oct 14, 2021 at 11:52

1 Answer 1


There are several packages for this, including:

  • ps-print -- Renders a buffer as postscript for printing (standard package)
  • htmlfontify -- Convert a buffer to html (standard package)
  • htmlize -- Another package for converting a buffer to html. Even though this is not included in the standard Emacs distribution, it is widely used.
  • e2ansi -- Renders a buffer using ANSI sequences for display in a terminal (useful in batch mode, e.g. as highlighter for more).

If you plan to write your own package that export it to another format you can base it on face-explorer (which was developed as part of the e2ansi project). It handles all the hairy low-level details, and works in batch mode.

Note: I'm the author of e2ansi and face-explorer.

  • 1
    Thanks for the info! e2ansi is exactly what I was looking for (htmlfontify may come in handy too!)
    – ideasman42
    Oct 15, 2021 at 1:15

Your Answer

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

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