Skip to content

Instantly share code, notes, and snippets.

@reinholdsson
Last active December 18, 2020 17:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reinholdsson/7426608 to your computer and use it in GitHub Desktop.
Save reinholdsson/7426608 to your computer and use it in GitHub Desktop.
RMarkdown to PDF with pandoc (using Makefile)
# On Mac OS install X11 support, e.g. XQuartz-2.7.5.dmg
library(pander)
# Evaluation options
evalsOptions("graph.output", "pdf")
evalsOptions('graph.unify', T) # OBS!
evalsOptions("cache", F)
# Plot options
panderOptions("graph.background", "white")
panderOptions("graph.grid", F)
panderOptions("graph.grid.minor", F)
panderOptions("graph.legend.position", "bottom")
template <- "tufte-handout.template"
brew <- "report.brew"
tex <- "temp.tex"
# brew -> tex
Pandoc.brew(
file = brew,
output = tex,
convert = 'tex',
options = paste0('--template=', template),
open = F
)
# Replace figure to marginfigure
system(paste("sed -i -e 's/figure}.*/marginfigure}/'", tex))
# tex -> pdf
system(paste("pdflatex", tex))
build:
Rscript build.r
clean:
rm -rf *.tex *.tex-e *.bbl *.blg *.aux *.out *.log *.spl plots/ cache/ *.gz\(busy\) *.gz *.pdf
% Thomas Reinholdsson
% Minimal report example
# Title
This is an R Markdown document. Markdown is a simple formatting syntax for authoring web pages (click the **Help** toolbar button for more details on using R Markdown).
When you click the **Knit HTML** button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
Pander option:
<%= panderOptions("graph.background") %>
<%= plot(cars) %>
You can also embed plots, for example:
<%=
if (require(ggplot2, quietly = TRUE)) {
ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar()
}
%>
% tufte-handout.tex - DESC
% Iago Mosqueira - JRC. 2013
%
\documentclass{tufte-handout}
% pdf graphs
\usepackage{epstopdf}
\usepackage{grffile}
% tables
\usepackage{longtable}
% ams
\usepackage{amssymb,amsmath}
% Set up the images/graphics package
\usepackage{graphicx}
\setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio}
\graphicspath{{graphics/}}
% natbib
\usepackage{natbib}
\bibliographystyle{plainnat}
% biblatex
$if(biblatex)$
\usepackage{biblatex}
$if(biblio-files)$
\bibliography{$biblio-files$}
$endif$
$endif$
% booktabs
\usepackage{booktabs}
% url
\usepackage{url}
% hyperref
\usepackage{hyperref}
% units.
\usepackage{units}
% fancyvrb
\usepackage{fancyvrb}
\fvset{fontsize=\normalsize}
\DefineShortVerb[commandchars=\\\{\}]{\|}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% multiplecol
\usepackage{multicol}
% lipsum
\usepackage{lipsum}
% These commands are used to pretty-print LaTeX commands
\newcommand{\doccmd}[1]{\texttt{\textbackslash#1}}% command name -- adds backslash automatically
\newcommand{\docopt}[1]{\ensuremath{\langle}\textrm{\textit{#1}}\ensuremath{\rangle}}% optional command argument
\newcommand{\docarg}[1]{\textrm{\textit{#1}}}% (required) command argument
\newenvironment{docspec}{\begin{quote}\noindent}{\end{quote}}% command specification environment
\newcommand{\docenv}[1]{\textsf{#1}}% environment name
\newcommand{\docpkg}[1]{\texttt{#1}}% package name
\newcommand{\doccls}[1]{\texttt{#1}}% document class name
\newcommand{\docclsopt}[1]{\texttt{#1}}% document class option name
% Shaded
\newenvironment{Shaded}{}{}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}}
\newcommand{\RegionMarkerTok}[1]{{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\NormalTok}[1]{{#1}}
$if(title)$
\title{$title$}
$endif$
$if(author)$
\author{$for(author)$$author$$sep$ \and $endfor$}
$endif$
$if(date)$
\date{$date$}
$endif$
\begin{document}
$if(title)$
\maketitle
$endif$
$body$
$if(natbib)$
$if(biblio-files)$
$if(biblio-title)$
$if(book-class)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
\bibliography{$biblio-files$}
\bibliographystyle{plainnat}
$endif$
$endif$
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
$endif$
$for(include-after)$
$include-after$
$endfor$
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment