I have been googling and searching for the answer to this question for a while but cannot find a definitive solution. In fact I am more confused than ever. I have no doubt that I am not the first person to run in this problem - an abundance of of 'solutions' but nothing that solves my problem.

I ask for your forbearance since this question has been asked before in one way or another. In short I want to use Emacs as a writing platform. I have done some configuring but I am short of some essential features and cannot find a way to implement those features.

A bit of background, the short version: I'm a long time vi (vim, Gvim and currently MacVim) user. I'm not trying to switch to Emacs as a code editor. During my working life, I made several valiant efforts to switch to Emacs but I had to abandon those efforts because I had work to do and deadlines to meet. I'm now retired and so have the time to apply myself but since I only write small fragments of code these days, I'm happy to stick with vim. But for doing a bit of odd scribbling and blogging I would like to create a distraction free, simple word processor-cum-editor in the style of the early DOS applications like Wordstar and especially, Xywrite. Yes I'm that old.

I'm using Emacs for Mac 25.3 installed via Homebrew. After a lot of fiddling and googling I have set it up the way I like it, for now. This is my ~/emacs.d/init.el file:

(menu-bar-mode 1)
(tool-bar-mode -1)
(toggle-scroll-bar -1)
(set-frame-parameter nil 'internal-border-width 20)
(fringe-mode 100)
(set-face-attribute 'fringe nil :background nil)
;;(setq header-line-format "20")
(setq inhibit-startup-screen t)
(setq initial-scratch-message "")
(setq initial-major-mode 'text-mode)
(enriched-mode 1)
(setq-default word-wrap t)
(set-foreground-color "grey80")
(set-background-color "#2d3743")
(add-to-list 'default-frame-alist '(height . 60))
(add-to-list 'default-frame-alist '(width . 85))
(set-frame-position (selected-frame) 225 35)
(set-frame-font "Menlo 13") 
(setq ispell-program-name "/usr/local/bin/aspell")
(setq ispell-dictionary "en_GB-ise-w_accents")

I think it looks great and, it actually works quite well except for the issues in need of solutions. I can spell check, I can highlight, meaning bold, and underline and do italics. I've held off from implementing Flyspell for now because many people have said it slows things down and because one method of implementing it appears to require about 50 lines (or more) of Lisp code. BTW, you will notice on line 7 of my config file that I attempted to set a top border but could not get it to work. Instead I used "internal-border-width" which gives me a bigger space below the mode line but that doesn't bother me.

My current Emacs setup

So my question is: How do I export my prose to a PDF file and retain the simple formatting on the screen; i.e italics and underline etc. And margins. The screen margins and screen line wrap are not retained when printing. Also, it would be nice to be able to change output font size for chapter headings etc. And, I suppose I do need to set an output/print font for the PDF, but that could be a fixed default. One last thing, is it possible to get rid of the little curly arrows at the margins. They seem completely superfluous to me.

Markdown-mode seems overkill for my simple needs. So do the various HTML modes. And Latex would be mega overkill, in my opinion.

I have read "Emacs for Writers by Randall Wood," and watched the Jay Dixit YouTube video on the same subject; amongst others. They don't cover my issues.

I am interested in Org-mode, specifically for the outlining capability and I understand that it has various export capabilities but I'm hesitant to add such complexity when all I really want is just to be able to print; specifically to PDF.

I would be grateful for any suggestions.



1 Answer 1



I'm not sure what you've tried, but the best start would probably be ps-print-buffer-with-faces. This answer provides a convenient wrapper for generating a pdf file (copied below):

You can put the below in your init.el and bind the function to a binding of your choice.

The function prints the file in current buffer as a PDF in the same folder by default.

Here the function requires the binary ps2pdf for converting .ps to .pdf. But you can replace that with any available pdf generator on your system.

(require 'ps-print)
(when (executable-find "ps2pdf")
  (defun modi/pdf-print-buffer-with-faces (&optional filename)
    "Print file in the current buffer as pdf, including font, color, and
underline information.  This command works only if you are using a window system,
so it has a way to determine color values.

C-u COMMAND prompts user where to save the Postscript file (which is then
converted to PDF at the same location."
    (interactive (list (if current-prefix-arg
                           (ps-print-preprint 4)
                         (concat (file-name-sans-extension (buffer-file-name))
    (ps-print-with-faces (point-min) (point-max) filename)
    (shell-command (concat "ps2pdf " filename))
    (delete-file filename)
    (message "Deleted %s" filename)
    (message "Wrote %s" (concat (file-name-sans-extension filename) ".pdf"))))

Line wrap

Unfortunately, I don't think that there's any way to export the "soft"/visual line breaks (indicated by the curly arrows in the margins). I'd instead suggest using auto-fill-mode with the fill-column set to an appropriate value (with set-fill-column or (setq fill-column N)).


I don't think there's any in-built way to use the value of the fringes (in the display) to set the margins in the printed document. You can however set the printed margins manually; the relevant variables are: ps-top-margin, ps-left-margin, ps-right-margin, ps-bottom-margin, which you can set with setq or "customize" (M-x customize-variable RET NAME_OF_VARIABLE).

Print header

If the default print header annoys you, you can switch it off with (setq ps-print-header nil) or modify it (details in the docstring of the variable — C-h v ps-print-header).

Font sizes

You can set the font size, using the variable ps-font-size and the font family using ps-font-family (though in the case of the latter, if the font family is not in ps-font-info-database, you'll need to customise the latter — if you look at the default value of the variable, the format of the database is pretty self-explanatory).

However, I don't think that it's possible to set the size of chapter headings etc.


Using htmlize as suggested by this answer might also be an OK-ish solution — in particular it would deal better with font sizes, but it still can't export soft line breaks or the margins — though it depends on an external package.



As you can see, Emacs isn't too well adapted to being a WYSIWYG editor and the built-in printing facilities are also not great (though given that Emacs is primarily a coding editor they're not that bad). The advantage of using a format like markdown, org, TeX or the like, is that you can then rely on general (i.e. non-emacs-specific) tools, like pandoc, LaTeX etc. to do the conversion or printing for you. (FWIW people have also created nice interfaces to these tools from within Emacs.) In principle, text/enriched, which enriched-mode uses as its backend, is also an external standard, but in practice almost nobody uses it, so the tooling isn't very well developed.


  • Thank you very much aplaice for your comprehensive and thoughtful answer. You have given me a lot to work with.
    – Ptolemy
    Commented Jun 21, 2018 at 21:58
  • In the mean time, as a temporary workaround, I have disabled enriched-mode (it does strange things in combination with Markdown) and started using Markdown in a plain text file. I then use Pandoc to convert to HTML. This turns out to be a good way to proof read the work before committing it to the more permanent PDF format.
    – Ptolemy
    Commented Jun 21, 2018 at 21:58
  • I can then use the "Export as PDF" option in Safari to create a PDF. Or, if I want page numbers, I can print it and us the "Save as PDF" option. There is also a third option built into OS X (I'm still using El Capitan) called "cupsfilter" which can convert an HTML file to PDF.
    – Ptolemy
    Commented Jun 21, 2018 at 21:59
  • None of the above is a perfect solutions but all have great potential. One of the problems is that the HTML margins are not transferred to the PDF. I'm looking into Print CSS to deal with that. CSS is also the way I handle margins in the HTML file. One could conceivably automate the whole process and apply a key combination to it; either as a macro or perhaps a bit of elisp. I don't know how to do that as of now but, hey, I'm retired.
    – Ptolemy
    Commented Jun 21, 2018 at 22:00
  • @aplaice: Thanks a million for a great, clean,concise defun that works very well for me.
    – phs
    Commented Sep 21, 2020 at 11:17

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.