Export Beautiful PDFs in Emacs

Posted on by on September 15th, 2013 | 0 Comments »



I've always been used to org-mode helping me easily generate PDFs, webpages, and documentation.  I use it to combine math (embedded latex math segments) and code blocks. To configure the math portion look up the documentation for cdlatex. As for producing PDFs, I've not been the biggest fan of org-modes article format.  There was an article posted on Emacs-FU on how to make beautiful PDFs.  It recently broke on my mint distribution, but I have it working again.  This page includes all the packages I needed to install to get it working.  I've also added code so that source code blocks will be colourized.  


After installing all the packages below, and adding the code to your .emacs, just export in org-mode as you normally would (C-e d) or (C-e p).


Add the following code to your .emacs and restart emacs.
;; -------------------------------------
;; -- PDF
;; -------------------------------------
;; 'djcb-org-article' for export org documents to the LaTex 'article', using
;; XeTeX and some fancy fonts; requires XeTeX (see org-latex-to-pdf-process)
;; -----------------------------------------------------------------------------
;; http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html
;; http://comments.gmane.org/gmane.emacs.orgmode/40221
;; -----------------------------------------------------------------------------
;; Install Packages:
;; + texlive-all  
;; + texlive-xetex
;; + ttf-sil-gentium
;; + ttf-sil-gentium-basic
;; + ttf-sil-charis
;; + ttf-dejavu
;; -----------------------------------------------------------------------------
;; Make sure to include the latex class in you header:
;; #+LaTeX_CLASS: djcb-org-article
;; -----------------------------------------------------------------------------
(eval-after-load 'org-export-latex
     (add-to-list 'org-export-latex-classes
                     \\setromanfont [BoldFont={Gentium Basic Bold},
                                     ItalicFont={Gentium Basic Italic}]{Gentium Basic}
                     \\setsansfont{Charis SIL}
                     \\setmonofont[Scale=0.8]{DejaVu Sans Mono}
                     \\geometry{a4paper, textwidth=6.5in, textheight=10in,
                                 marginparsep=7pt, marginparwidth=.6in}
            ("\\section{%s}" . "\\section*{%s}")
            ("\\subsection{%s}" . "\\subsection*{%s}")
            ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
            ("\\paragraph{%s}" . "\\paragraph*{%s}")
            ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))))
;; -----------------------------------------------------------------------------
;; Added Syntax Highlighting Support
;; http://orgmode.org/worg/org-tutorials/org-latex-export.html
;; #+LaTeX_HEADER: \usepackage{minted}
;; #+LaTeX_HEADER: \usemintedstyle{emacs}
;; #+LaTeX_HEADER: \newminted{common-lisp}{fontsize=\footnotesize}
;; -----------------------------------------------------------------------------
;; Install Packages:
;; + python-pygments
;; -----------------------------------------------------------------------------
(setq org-export-latex-listings 'minted)
(setq org-export-latex-custom-lang-environments
    (emacs-lisp "common-lispcode")
(setq org-export-latex-minted-options
      '(("frame" "lines")
        ("fontsize" "\\scriptsize")
    ("linenos" "")
(setq org-latex-to-pdf-process 
      '("xelatex --shell-escape -interaction nonstopmode %f"
    "xelatex --shell-escape -interaction nonstopmode %f")) ;; for multiple passes
;; Not sure if this is actually setting the export class correctly.
(setq org-export-latex-class "djcb-org-article")
Linux Mint Debian MATE Easily Splitting Windows
My .emacs

Categorized Under


About Nick Guthrie

» has written 38 posts