Skip to content

Instantly share code, notes, and snippets.

@indraniel
Last active January 16, 2016 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indraniel/b788feb1b35f832be770 to your computer and use it in GitHub Desktop.
Save indraniel/b788feb1b35f832be770 to your computer and use it in GitHub Desktop.
An example of a LaTeX/knitr report setup containing a git commit revision number
.PHONY: clean
PRJDIR := /path/to/project
DOCS := $(PRJDIR)/docs
RLIBS := /gscmnt/gc2801/analytics/idas/jira/BIO-1465/rpkgs
REPORTDIR := $(DOCS)/writeups
PDFLATEX := /home/archive/texlive-2015/2015/bin/x86_64-linux/pdflatex
writeup: $(REPORTDIR)/report.pdf
$(REPORTDIR)/%.pdf: $(REPORTDIR)/revision.tex $(REPORTDIR)/%.tex
cd $(REPORTDIR) && $(PDFLATEX) $(REPORTDIR)/$*.tex
cd $(REPORTDIR) && $(PDFLATEX) $(REPORTDIR)/$*.tex
$(REPORTDIR)/%.tex: $(REPORTDIR)/%.Rtex
cd $(REPORTDIR) && R_LIBS=$(RLIBS) $(BIO_1597)/bin/knit-latex.r $<
$(REPORTDIR)/revision.tex:
echo "% Autogenerated, do not edit" > $(REPORTDIR)/revision.tex
echo "\\\\newcommand{\\\\revisiondate}{`git log -1 --format=\"%ad\" --date=short`}" >> $(REPORTDIR)/revision.tex
echo "\\\\newcommand{\\\\revision}{`git log -1 --format=\"%h\"`}" >> $(REPORTDIR)/revision.tex
clean:
bash -c "rm -fv $(REPORTDIR)/report.{aux,log,out,fff,ttt,tex,pdf}"
rm $(REPORTDIR)/revision.tex
\documentclass[10pt, letterpaper]{article}
% P R E A M B L E %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{parskip} % no-indentation with a space between paragraphs
\usepackage{booktabs} % for the tables
\usepackage[linkbordercolor={1 0 0}]{hyperref} % for url labels
\usepackage{xcolor} % for colors
\usepackage{fancyhdr} % for customized headers
%\usepackage{float} % for forcing figure placements in text
%\usepackage[nolists, nomarkers, tablesfirst]{endfloat} % for place all figures at the end of the document
\usepackage{tikz}
\usetikzlibrary{
positioning, % for the relative node positioning
shapes.multipart, % for the rectangle split
decorations.pathreplacing, % for the brace comments
calc % for the let command
}
\definecolor{pastelRed}{RGB}{251,180,174}
\definecolor{pastelBlue}{RGB}{179,205,227}
\definecolor{pastelGreen}{RGB}{204,235,197}
\definecolor{pastelPurple}{RGB}{222,203,228}
\definecolor{pastelYellow}{RGB}{254,217,166}
% setup an alternative font
\usepackage[T1]{fontenc}
\usepackage[sfdefault]{FiraSans}
% setup link colors
\hypersetup{
colorlinks,
linkcolor={red!80!black},
citecolor={blue!50!black},
urlcolor={blue!60!black}
}
% include git revision info
\input{revision}
% header/footer style on the front page
\fancypagestyle{titlepage}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\bfseries \thepage} % except the center
\fancyfoot[R]{\scriptsize{revision: \revision}} % except the right
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
% setup document headers and footers (for body pages)
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{\thepage}
\lfoot{}
\cfoot{}
%\rfoot{\scriptsize{\revisiondate \quad (\revision)}}
\rfoot{\scriptsize{revision: \revision}}
% C O M M A N D S %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\renewcommand{\abstractname}{Goal}
%% for inline R code: if the inline code is not correctly parsed, you will see a message
\newcommand{\rinline}[1]{SOMETHING WRONG WITH knitr}
% H E A D E R %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{Example Report}
\author{}
\date{\today}
% K N I T R S E T U P %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% begin.rcode setup, include=FALSE
% opts_chunk$set(fig.path='figure/latex-', cache.path='cache/latex-')
%% end.rcode
% D O C U M E N T %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\maketitle
\thispagestyle{titlepage}
\begin{abstract}
Blah. Blah.
\end{abstract}
\section{Overview}
The good stuff goes here.
\begin{figure}[h]
\begin{center}
\begin{tikzpicture}[scale=0.5]
% ----- Reference Set -----
% main chromosome line
\draw [thick] (0,5) -- (10,5);
% exon ``boxes''
\path [fill=pastelRed!60] (1,4.5) rectangle (3, 5.5);
\path [fill=pastelRed!70] (5,4.5) rectangle (7, 5.5);
\path [fill=pastelRed!90] (8,4.5) rectangle (9.5, 5.5);
% labels
\node at (2,5) {1};
\node at (6,5) {2};
\node at (8.75,5) {3};
\node [right] at (11,5) {Gene Blah};
% ----- Target Set (Nimblegen) -----
% main chromosome line
\draw [thick] (0,3) -- (10,3);
% exon ``boxes''
\path [fill=pastelRed!60] (1,2.5) rectangle (3, 3.5);
\path [fill=pastelRed!70] (5,2.5) rectangle (7, 3.5);
\path [fill=pastelRed!90] (8,2.5) rectangle (9.5, 3.5);
% labels
\node at (2,3) {1};
\node at (6,3) {2};
\node at (8.75,3) {3};
\node [right] at (11,3) {Gene Blah (Nimblegen Targets)};
% ----- Target Set (IDT) -----
% main chromosome line
\draw [thick] (0,1) -- (10,1);
% exon ``boxes''
\path [fill=pastelRed!60] (1,0.5) rectangle (3, 1.5);
\path [fill=pastelRed!90] (8,0.5) rectangle (9.5, 1.5);
% labels
\node at (2,1) {1};
\node at (8.75,1) {3};
\node [right] at (11,1) {Gene Blah (Target)};
\end{tikzpicture}
\end{center}
\caption{An Example of Incomplete Chromosome Coverage}
\label{fig:ChromFig}
\end{figure}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment