Yikes, been longer than I intended between posts. Alas for the uneven free time of an academic. In my defense, I’m trying to start up a new project in my group and I have a very energetic dog.
In the last post, I discussed my use of pandoc as a tool for writing in plain text and outputting to a variety of different formats. I use it as much as I possibly can because I just prefer writing in the simplest format possible and then “compiling” my final documents for distribution. Here, I’d like to share a simple template that I use to produce letters on Miami’s letterhead. I use this primarily for letters of recommendation.
Here’s what one of my letters actually looks like.
--- size: 11pt draft: yes sig: include: yes (blank for no) sign: post: Associate Professor cc: --- \today | Someone | 123 Somewhere St. | Anywhere, OH **Re: The Topic** Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Links, for example [this one to the Hartley Group website](http://www.hartleygroup.org), are easily included. Note, for example, that items in the header are hyperlinked to the relevant urls. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
And here’s the output when pandoc applies the template to that file and produces a pdf. I have a trigger set up for this in Alfred so it’s a simple matter of highlighting the file, hitting a few keys, and waiting 3–4 s.
It may seem complicated if you’re used to a WYSIWYG editor, but it’s actually pretty automatic once you get used to doing things this way.
Here’s the actual template I use. This just sits in a Pandoc folder in Dropbox, and never needs to be changed unless I decide to fiddle with the fonts or something:
%!TEX program = xelatex % Scott's letterhead template. Requires that Miami logo and signature file be % installed within the LaTeX directory structure. The "letter" class is used % because it allows for spacing between paragraphs, but properly line breaks at % the end of paragraphs (the articles class tends to avoid full lines at the % ends of paragraphs, for some reason). \documentclass[$size$]{letter} \usepackage[letterpaper,margin=1in]{geometry} \usepackage{fixltx2e} % Adds microtypography features: character protrusion, for XeTeX. \usepackage{microtype} % Allows links. \usepackage[usenames,dvipsnames]{color} \usepackage[xetex, bookmarks, colorlinks, breaklinks]{hyperref} \hypersetup{colorlinks=true, urlcolor=NavyBlue, linkcolor=NavyBlue} \urlstyle{rm} \frenchspacing{} % Remove extra spaces after periods. \pagestyle{empty} % Remove page numbers. \usepackage{fontspec} \defaultfontfeatures{Mapping=tex-text} % Sets quotation marks. \setromanfont{Linux Libertine O} \setsansfont[BoldFont={Helvetica Neue Bold}]{Helvetica Neue} \setmonofont[Scale=MatchLowercase]{Inconsolata} % From default template \providecommand{\tightlist}{% \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} \newcommand\shyp{\-} \newcommand{\header}[0]{ {\hypersetup{hidelinks} \noindent \parbox[b][0.625in][t]{6.5in}{ \vspace{-0.375in} \parbox[b][0.625in][t]{3.74in} {\href{http://www.miamioh.edu} {\includegraphics{/Users/hartlecs/.pandoc/images/MiamiLogo.pdf}}}\hfill \parbox[b][0.625in][t]{1.72in}{ \setlength{\baselineskip}{9pt} \fontsize{7pt}{7pt}{ \fontspec{Helvetica} \href{http://www.hartleygroup.org}{\textbf{C.\ SCOTT HARTLEY}}\\ \href{http://chemistry.miamioh.edu}{Department of Chemistry % \& Biochemistry}\vspace{6pt}\\ 651 E. High St.\\ Oxford, Ohio 45056-1465\\ (513) 529-1731\\ (513) 529-5715 Fax\\ \href{mailto:scott.hartley@miamioh.edu}{scott.hartley@miamioh.edu} } } }} } $if(draft)$ \usepackage{draftwatermark} \SetWatermarkLightness{0.9} $endif$ \begin{document} \header $body$ $if(sig.include)$ \begin{minipage}[t]{6.5in} Sincerely,\\ $if(sig.sign)$ \vspace{-0.2in}\includegraphics{/Users/hartlecs/.pandoc/images/sig} $else$ \\ $endif$ \\ C. Scott Hartley\\ $sig.post$ \end{minipage} $endif$ $if(cc)$ cc: $for(cc)$$cc$$sep$, $endfor$ $endif$ $if(ps)$ $ps$ $endif$ \end{document}
The vast majority of the template is just setting up the fonts (I’m partial to Linux Libertine O) and the header piece with the Miami Logo. The logo itself is stored as a vector graphic (in pdf format), so it looks clean and doesn’t add any unnecessary bulk to the files.
Users of LaTeX will recognize this as a fairly rudimentary LaTeX file with a few weird statements thrown in (“$if(cc)$”, for example). These points are instructions to pandoc when it applies the template to the file. “$body$” is where the bulk of the letter goes. The rest is from various pieces of metadata that are stuck at the top of the input file. These let me control the font size (I prefer 11 pt, but sometimes it’s necessary to tweak this to keep from orphaning the signature on its own page), the appearance of the signature, and whether or not the letter gets the “Draft” watermark.
Why bother doing this instead of just using Word or Pages? Well, the final product, in my opinion, looks a lot better. LaTeX does a wonderful job of typography and hyphenation. On the rare occasions that I actually need to print one of these letters and mail it in, I’ve taken to just getting blank paper with Miami’s watermark and printing the header on it directly. There are some other small advantages as well: The final result is just two files, the final pdf (usually about 50kB) and a tiny plain text file, instead of a pdf and a bloated docx. It’s also possible to use a lot of simple command-line tools to manipulate plain text, which can be exploited to generate a series of customized letters as part of a mail merge, for example.
I was just searching around online for different approaches to using Pandoc for letterheaded documents, yours is very thorough. Thanks for sharing! (Also, fun to see you’re part of Miami University, a bunch of my family are Miami alumni)
Glad you like it!
HI, I tried to get this to work as a new rmarkdown template in Rstudio. Unfortunately I cannot get it to use the LaTeX file that it needs to provide the logo and so on. Do you have any instructions for Rmarkdown and Rstudio specifically?
thanks,
I’m afraid that I am not familiar with R markdown and R studio; I generally just use pandoc at the command line with a standard text editor.