Skip to content

Instantly share code, notes, and snippets.

@fernseed
Forked from dylan-k/story.latex
Last active July 18, 2022 05:49
Show Gist options
  • Save fernseed/5a98006371ca16fb88a5 to your computer and use it in GitHub Desktop.
Save fernseed/5a98006371ca16fb88a5 to your computer and use it in GitHub Desktop.
a pandoc template to make PDF files with standard manuscript formatting
% ------------------------------------------------------------------------------
%
% STANDARD MANUSCRIPT FORMAT LaTeX TEMPLATE FOR PANDOC
%
% This template was originally created by Dylan Kinnett:
% https://gist.github.com/dylan-k/c596ca65098ac3f61ce2
%
% This version has been tweaked to support the 'novel' manuscript format as
% well as the 'short story'.
%
% Given a markdown file, this will create a PDF document formatted according to
% 'standard manuscript format'. See: http://www.shunn.net/format/ for details.
%
% An example markdown document:
% https://gist.github.com/3d5225d175d53457917c.git
%
% USAGE
% Place a copy of this file in your pandoc templates directory or place it in
% the same directory as the file you'd like to convert (eg. story.md) and use a
% command such as:
%
% pandoc story.md --latex-engine=xelatex --template=story.latex
% --from=markdown_github+yaml_metadata_block --output=manuscript.pdf
%
% ------------------------------------------------------------------------------
%-------------------------------------------------------------------------------
% PREAMBLE
%-------------------------------------------------------------------------------
%!TEX TS-program = xelatex
\documentclass[12pt]{scrartcl}
% DOCUMENT CLASS----------------------------------------------------------------
% The first line is a pseudo-comment to use XeTeX. In general, LaTeX
% comments begin with % and end with linebreak. Next we have a simple
% document class declaration. Pandoc's own default latex.template file is more
% complex:
%
% \documentclass$if(fontsize)$[$fontsize$]$endif${scrartcl}
%
% With this you would have invented a 'variable', fontsize,
% and could write things like:
%
% markdown2pdf my.txt --xetex --variable=fontsize:12pt -o my.pdf
%
% Or:
%
% pandoc -r markdown -w html my.txt -s --xetex --variable=fontsize:24pt
% -o my.tex.
%
% If we specified --variable-fontsize:12, then template substitution would
% yield a LaTeX document beginning:
%
% \documentclass[12pt]{scrarcl}
%
% Which is just what we've specified anyway, since standard manuscript format
% will only ever use a 12pt font. See "VARIABLES" below for items which remain
% customisable in this template.
%
% We use the special 'komascript' article class "scrartcl"; the standard
% minimal LaTeX 'article' class declaration would be something like:
%
% \documentclass[12pt]{article}
%
% Or there's also a 'Memoir' class:
%
% \documentclass[11pt,article,oneside]{memoir}
%
% Which may be of interest to you.
% VARIABLES---------------------------------------------------------------------
% Either the YAML header of the markup file or the pandoc command-line
% interface can specify values for 'author', 'title', etc. Here we provide
% them as input to our LaTeX variables, if they exist. Otherwise the LaTeX
% variables will remain empty, but still defined so that use of the template
% does not cause an error.
%
% See also: http://stackoverflow.com/questions/2336007/setting-up-author-or-address-string-variables-in-latex
\def\title{$if(title)$$title$$endif$}
\def\runningtitle{$if(shorttitle)$$shorttitle$$endif$}
\def\author{$if(author)$$author$$endif$}
\def\forename{$if(forename)$$forename$$endif$}
\def\surname{$if(surname)$$surname$$endif$}
\def\wordcount{$if(wordcount)$$wordcount$$endif$}
\def\address{$if(street)$$street$\\$endif$$if(location)$$location$\\$endif$$if(country)$$country$$endif$\\\\$if(phone)$$phone$\\$endif$$if(email)$$email$$endif$}
% This template supports both short story and novel manuscripts. The default
% behaviour is to assume short story format, but setting the 'novel' variable
% to true will enable the alternative formatting.
%
% Novels also have cover pages which don't count for page numbering purposes,
% see: http://www.shunn.net/format/novel.html
%
% We'll use a new 'if' boolean to keep track of whether the manuscript is
% still on the cover page or not so that we can start counting pages
% correctly.
$if(novel)$
\newif\ifcover
\covertrue
$endif$
% PACKAGES----------------------------------------------------------------------
% The behaviour of LaTeX can be altered by loading "packages" using the
% \usepackage command. Each one gives us a particular feature to make life
% easier.
\usepackage{fontspec,xltxtra,xunicode,ifthen,fancyhdr,amsmath,alltt}
% 'fontspec' means we can specify pretty much any font (see "Fonts" below).
% Because we are using XeTeX, this template needs to be called with the
% `--xetex` flag. The 'ifthen' package is loaded to help make conditional
% content. 'fancyhdr' enables fancy headers and footers and 'amsmath' imports
% an extensive collection of mathematical symbols.
% CUSTOM COMMANDS---------------------------------------------------------------
% If bullet point lists are included:
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
% LANGUAGE----------------------------------------------------------------------
% The `babel` package, among other things, lets you determine what
% language you are using in a given stretch of text, so that typesetting will
% be performed correctly. Here we specify that we are speaking English:
\usepackage[english]{babel}
% GEOMETRY, MARGINS, PAGE FORMAT------------------------------------------------
% the `geometry` package makes for convenient adjusting of margins, etc.
% standard manuscript format prefers 1 inch margins
\usepackage[letterpaper,includeheadfoot,margin=1in,footskip=.5in]{geometry}
% Page Format 'fancy' allows for headers and footers:
\pagestyle{fancy}
% Standard manuscript format calls for 25 double spaced lines of text per page
% 25 text lines plus 25 space lines * 12pts per line equals 600pt:
\setlength{\textheight}{600pt}
% You can modify the margin spacing with:
%
% \setlength{\voffset}{-0.5in}
%
% To debug formatting info in the output, uncomment the line below and the
% associated '\layout' line in the document body:
%
% \usepackage{layout}
% FONTS-------------------------------------------------------------------------
% Here we set the main font for the manuscript. We default to Courier Prime
% but there are other options, see for example:
% http://www.candlerblog.com/2012/09/11/which-courier/
\setmainfont{Courier Prime}
\setromanfont{Courier Prime}
\setsansfont{Courier Prime}
\setmonofont{Courier Prime}
% Allow pandoc commands to override the defaults:
$if(mainfont)$
\setmainfont{$mainfont$}
$endif$
$if(sansfont)$
\setsansfont{$sansfont$}
$endif$
$if(monofont)$
\setmonofont[Mapping=tex-ansi]{$monofont$}
$endif$
$if(mathfont)$
\setmathfont(Digits,Latin,Greek){$mathfont$}
$endif$
% LINE SPACING------------------------------------------------------------------
% LaTex is a mad hatter who thinks "double" spacing equals 1.8! So here's a
% workaround. For more info:
% http://en.wikibooks.org/wiki/LaTeX/Text_Formatting#Line_Spacing
\usepackage{setspace}
\doublespacing
% Other options:
%
% \singlespacing
% \onehalfspacing
% HEADINGS----------------------------------------------------------------------
% The sectsty package is useful for setting our heading appearance correctly.
%
% sectsty manual: http://cs.brown.edu/about/system/managed/latex/doc/sectsty.pdf
% headings info: http://tex.stackexchange.com/questions/103286/how-to-change-section-subsection-font-size#comment225271_103286
% formatting info: http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/TextFonts.html
\usepackage{sectsty}
% We'll set each header level to keep the same 12pt unbolded font:
\allsectionsfont{\normalfont\selectfont}
% Then we'll treat the three primary header sections that pandoc gives us as:
%
% # Part x (\section)
% ## Chapter y (\subsection)
% ### Title For Chapter y (\subsubsection)
%
% Parts will always begin on a new page, spaced one third of the way from the
% top, as with the short story title page:
\sectionfont{\ifthenelse{\equal{\thepage}{1}}{}{\clearpage\vspace*{0.3\textheight}}\normalfont\fontsize{12}{12}\nohang\centering\selectfont}
% Chapter headings will be given two double-spaced lines between themselves
% and any preceding text:
\subsectionfont{\vspace*{48pt}\normalfont\fontsize{12}{12}\nohang\centering\selectfont}
% Chapter titles will be centered but otherwise given no special treatment:
\subsubsectionfont{\normalfont\fontsize{12}{12}\nohang\centering\selectfont}
% EMPHASIS----------------------------------------------------------------------
% Use underlines for emphasis instead of italics when working with monospace
% fonts:
\usepackage{ulem}
\ULforem
% FOOTNOTES---------------------------------------------------------------------
% If your manuscript has more complex footnotes, you can specify the below
% option to allow verbatim text. This may be more likely for novels than short
% stories, and note that \VerbatimFootnotes doesn't play well with some other
% packages.
$if(verbatim-in-note)$
\usepackage{fancyvrb}
\VerbatimFootnotes
$endif$
% LISTS-------------------------------------------------------------------------
% List styling options:
$if(fancy-enums)$
% -- Redefine labelwidth for lists; otherwise, the enumerate package will
% -- cause markers to extend beyond the left margin:
\makeatletter\AtBeginDocument{
\renewcommand{\@listi}
{\setlength{\labelwidth}{4em}}
}\makeatother
\usepackage{enumerate}
$endif$
% TABLE FORMATTING--------------------------------------------------------------
% If you have specified a Markdown table in your manuscript, pandoc will
% declare that its `table` variable is True and we will import a table
% package suitable for simple tables:
$if(tables)$
\usepackage{array}
% -- This is needed because raggedright in table elements redefines \\:
\newcommand{\PreserveBackslash}[1]{\let\temp=\\#1\let\\=\temp}
\let\PBS=\PreserveBackslash
$endif$
% SUBSCRIPTS--------------------------------------------------------------------
% pandoc remembers whether you used subscripts, assigning True to its
% `subscript` variable. We will adopt a default:
$if(subscript)$
\newcommand{\textsubscr}[1]{\ensuremath{_{\scriptsize\textrm{#1}}}}
$endif$
% LINKS-------------------------------------------------------------------------
% Markdown allows the use of links since our texts can be made into HTML. We
% will therefore need to accomodate them in manuscript format.
%
% Links such as 'http://example.com' are to be considered code and thus must
% not be broken across lines:
\usepackage[breaklinks=true]{hyperref}
\hypersetup{colorlinks,
citecolor=blue,
filecolor=blue,
linkcolor=blue,
urlcolor=blue}
$if(url)$
\usepackage
$endif$
% IMAGES------------------------------------------------------------------------
% Import our graphics handling libraries, although these may not be present
% in most manuscripts:
$if(graphics)$
\usepackage{graphicx}
% -- We will generate all images so they have a width \maxwidth. This means
% -- that they will get their normal width if they fit onto the page, but
% -- are scaled down if they would overflow the margins.
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}
$endif$
% SECTION NUMBERING-------------------------------------------------------------
% Numbered sections can be specified by the variable 'numbersections'. Eg:
% markdown2pdf my.txt --number-sections --xetex --template=/wherever/this/is -o my.pdf
$if(numbersections)$
% Do nothing, this is the default LaTeX behaviour.
$else$
\setcounter{secnumdepth}{0}
$endif$
% By default we will use a single centered '#' character for section breaks,
% eg. when you use ---- in Markdown:
\renewcommand{\rule}[2]{\#}
% HEADER INCLUDES---------------------------------------------------------------
% You can include custom content for the header from a file specified on the
% commane line:
$for(header-includes)$
$header-includes$
$endfor$
%-------------------------------------------------------------------------------
% DOCUMENT
%-------------------------------------------------------------------------------
\begin{document}
% To debug the page layout, uncomment this line:
%
% \layout
% FOOTER------------------------------------------------------------------------
% Standard Manuscript Format does not call for a footer, so it's blanked here:
\fancyfoot{}
% HEADER------------------------------------------------------------------------
% No header will be rendered for the first page of a short story, or the first
% two pages of a novel manuscript.
%
% On subsequent pages we put a header in the upper right corner containing
% your real surname, one or two important words from the title, and the
% current page number.
%
% The 'fancyhdr' package was defined above to enable nice headers and footers.
% The package uses the command \lhead, \chead, \rhead for headers and \lfoot,
% \cfoot and \rfoot for footers (left, centred and right, respectively).
%
% Standard manuscript format does not make use of ruled horizontal lines:
\renewcommand{\headrulewidth}{0pt}
% The left-hand header space is always blank:
\lhead{}
% The right-hand header space will be blank for the first page, or the cover
% page for novels, otherwise it will have:
% Surname / Short Title / Page Number
\rhead{
\ifthenelse{\equal{\thepage}{1}}
{
$if(novel)$
\ifcover \else \surname~/~\runningtitle~/~\thepage \fi
$endif$
}
{\surname~/~\runningtitle~/~\thepage}
}
% TITLE, AUTHOR-----------------------------------------------------------------
% If you specified title, author, date, address metadata they are presented
% first. Novels use the entirety of the first page, for short stories this
% space equals 204pt or 17 single-spaced lines, note:
% http://texhacks.blogspot.com/2010/12/vspace-is-broken.html
%
% No paragraph indentations for this section.
\setlength\parindent{0in}
$if(novel)$
\begin{singlespace}
\forename~\surname\\
\address
\end{singlespace}
% Leave a space of one-third page-height:
\vspace*{0.3\textheight}
% Then insert the title and by-line:
\begin{singlespace}\begin{center}
$if(title)$
\MakeUppercase{$title$}
\vspace{12pt}
$endif$
$if(author)$
a novel by $author$
$endif$
\end{center}\end{singlespace}
% Then we have blank lines until the bottom of the page:
\vfill
% And finally the wordcount is shown, centered:
\center \wordcount~words
% The second page of a novel manuscript will blank one-third of the page
% height before any content:
\clearpage\vspace*{0.3\textheight}
% At this point the true novel manuscript page count will begin:
\setcounter{page}{1}
\coverfalse
% Short stories display the metadata information along with word count at the
% top of the first page:
$else$
\begin{singlespace}
\forename~\surname \hfill \wordcount~words\\
\address
\end{singlespace}
% Then leave space of one-third page-height before the title and by-line:
\vspace*{0.3\textheight}
\begin{singlespace}\begin{center}
$if(title)$
\MakeUppercase{$title$}
\vspace{12pt}
$endif$
$if(author)$
by $author$
$endif$
\end{center}\end{singlespace}
% Space of 2 lines is given after the title and author before the content:
\vspace{24pt}
$endif$
% PARAGRAPH FORMAT--------------------------------------------------------------
% Standard Manuscript Format has half-inch indented paragraphs, each paragraph
% has a first-line indent and is not fully-justified.
\raggedright
\raggedbottom
\setlength\parindent{.5in}
% ... with no special spacing between paragraphs. If you want that you can
% try:
% \setlength{\parskip}{6pt plus 2pt minus 1pt}
% BODY--------------------------------------------------------------------------
% Finally, your actual manuscript content forms the body of the document:
$body$
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment