Skip to content

Instantly share code, notes, and snippets.

@kjhealy
Created February 3, 2011 14:12
Show Gist options
  • Save kjhealy/809512 to your computer and use it in GitHub Desktop.
Save kjhealy/809512 to your computer and use it in GitHub Desktop.
Current xelatex + minted + latexmk setup
(require 'org-latex)
;; Choose either listings or minted for exporting source code blocks.
;; Using minted (as here) requires pygments be installed. To use the
;; default listings package instead, use
;; (setq org-export-latex-listings t)
;; and change references to "minted" below to "listings"
(setq org-export-latex-listings 'minted)
;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
;; but adapted to use latexmk 4.22 or higher.
(defun my-auto-tex-cmd ()
"When exporting from .org with latex, automatically run latex,
pdflatex, or xelatex as appropriate, using latexmk."
(let ((texcmd)))
;; default command: pdflatex (could be changed to old-style latex -> dvi instead)
(setq texcmd "latexmk -pdflatex='pdflatex --shell-escape' -pdf %f")
;; pdflatex -> .pdf
(if (string-match "LATEX_CMD: pdflatex" (buffer-string))
(setq texcmd "latexmk -pdflatex='pdflatex --shell-escape' -pdf %f"))
;; xelatex -> .pdf
(if (string-match "LATEX_CMD: xelatex" (buffer-string))
(setq texcmd "latexmk -pdflatex='xelatex --shell-escape' -pdf %f"))
;; LaTeX compilation command
(setq org-latex-to-pdf-process (list texcmd)))
(add-hook 'org-export-latex-after-initial-vars-hook 'my-auto-tex-cmd)
;; Default packages included in /every/ tex file, latex, pdflatex or xelatex
(setq org-export-latex-packages-alist
'(("" "graphicx" t)
("" "longtable" nil)
("" "float" nil)
("" "minted" nil)))
;; Custom packages
(defun my-auto-tex-parameters ()
"Automatically select the tex packages to include."
;; default packages for ordinary latex or pdflatex export
(setq org-export-latex-default-packages-alist
'(("AUTO" "inputenc" t)
("T1" "fontenc" t)
("" "fixltx2e" nil)
("" "wrapfig" nil)
("" "soul" t)
("" "textcomp" t)
("" "marvosym" t)
("" "wasysym" t)
("" "latexsym" t)
("" "amssymb" t)
("" "hyperref" nil)))
;; Packages to include when xelatex is used
;; (see https://github.com/kjhealy/latex-custom-kjh for the
;; non-standard ones.)
(if (string-match "LATEX_CMD: xelatex" (buffer-string))
(setq org-export-latex-default-packages-alist
'(("" "fontspec" t)
("" "xunicode" t)
("" "url" t)
("" "rotating" t)
("" "memoir-article-styles" t)
("american" "babel" t)
("babel" "csquotes" t)
("svgnames" "xcolor" t)
("" "soul" t)
("xetex, colorlinks=true, urlcolor=FireBrick, plainpages=false, pdfpagelabels, bookmarksnumbered" "hyperref" nil)
)))
(if (string-match "LATEX_CMD: xelatex" (buffer-string))
(setq org-export-latex-classes
(cons '("article"
"\\documentclass[11pt,article,oneside]{memoir}
\\input{vc}
\\usepackage{etoolbox}
\\usepackage[style=authoryear-comp-ajs, abbreviate=true]{biblatex}
\\bibliography{socbib}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
org-export-latex-classes))))
(add-hook 'org-export-latex-after-initial-vars-hook 'my-auto-tex-parameters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment