1
0
mirror of https://github.com/eddelbuettel/binb synced 2024-12-22 04:29:59 +01:00

initial commit of bare-boned working package

This commit is contained in:
Dirk Eddelbuettel 2018-09-15 09:05:26 -05:00
commit bdcf979276
11 changed files with 656 additions and 0 deletions

4
.Rbuildignore Normal file
View File

@ -0,0 +1,4 @@
^.*\.Rproj$
^\.Rproj\.user$
^localTests
.*\.tar\.gz$

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata

11
ChangeLog Normal file
View File

@ -0,0 +1,11 @@
2018-09-15 Dirk Eddelbuettel <edd@debian.org>
* DESCRIPTION (Version, Date): Initial pre-release version
* binb.R (metropolis): Process Metropolis theme
* inst/rmarkdown/templates/metropolis/skeleton/skeleton.Rmd:
Example skeleton taken from my samples=rmarkdown-metropolis repo
* inst/rmarkdown/templates/metropolis/resources/template.tex):
Generic template for beamer presentations

19
DESCRIPTION Normal file
View File

@ -0,0 +1,19 @@
Package: binb
Type: Package
Title: 'binb' is not 'Beamer'
Version: 0.0.0
Author: Dirk Eddelbuettel
Maintainer: Dirk Eddelbuettel <edd@debian.org>
Description: A collection of 'LaTeX' styles using 'Beamer' customization for
pdf-based presentation slides in RMarkdown. At present it contains RMarkdown
adaptations of the LaTeX themes 'Metropolis' (formerly 'mtheme') theme by
Matthias Vogelgesang and others (now included in TeXLive), and the 'IQSS' by
Ista Zahn (which is included here). Additional (free) fonts may be required:
'Metropolis' prefers 'Fira', and 'IQSS' requires 'Libertinus'.
URL: https://github.com/eddelbuettel/binb
BugReports: https://github.com/eddelbuettel/binb/issues
Imports: rmarkdown, knitr
VignetteBuilder: knitr
License: GPL (>= 2)
Encoding: UTF-8
RoxygenNote: 6.0.1

3
NAMESPACE Normal file
View File

@ -0,0 +1,3 @@
export("metropolis")
import("knitr")
import("rmarkdown")

81
R/binb.R Normal file
View File

@ -0,0 +1,81 @@
##' A template for RMarkdown-based Beamer presentations in the \sQuote{Metropolis}
##' style by Matthias Vogelgesang and others.
##'
##' Not all options and customizations available at the LaTeX level are implemented
##' yet.
##' @title Binb is not Beamer - Metropolis-themed PDF Presentation
##' @param toc A logical variable defaulting to \code{FALSE}.
##' @param slide_level A numeric variable defaulting to two.
##' @param incremental A logical variable defaulting to \code{FALSE}.
##' @param fig_width A numeric variable defaulting to ten.
##' @param fig_height A numeric variable defaulting to seven.
##' @param fig_crop A logical variable defaulting to \code{TRUE}.
##' @param fig_caption A logical variable defaulting to \code{TRUE}.
##' @param dev A character variable defaulting to \dQuote{pdf}.
##' @param df_print A character variable defaulting to \dQuote{default}.
##' @param fonttheme A character variable defaulting to \dQuote{default}.
##' @param highlight A character variable defaulting to \dQuote{tango}.
##' @param keep_tex A logical variable defaulting to \code{FALSE}.
##' @param latex_engine A character variable defaulting to \dQuote{xelatex}.
##' @param citation_package An optional character variable with possible value
##' \dQuote{none} (the default), \dQuote{natbib} or \dQuote{biblatex}.
##' @param includes An optional character variable defaulting to \code{NULL}.
##' @param md_extensions An optional character variable defaulting to \code{NULL}.
##' @param pandoc_args An optional character variable defaulting to \code{NULL}.
##' @return RMarkdown content processed for rendering.
##' @author Dirk Eddelbuettel
metropolis <- function(toc = FALSE,
slide_level = 2,
incremental = FALSE,
fig_width = 10,
fig_height = 7,
fig_crop = TRUE,
fig_caption = TRUE,
dev = 'pdf',
df_print = "default",
fonttheme = "default",
highlight = "tango",
keep_tex = FALSE,
latex_engine = "xelatex",
citation_package = c("none", "natbib", "biblatex"),
includes = NULL,
md_extensions = NULL,
pandoc_args = NULL) {
template <- system.file("rmarkdown", "templates", "metropolis",
"resources", "template.tex",
package="binb")
rmarkdown::beamer_presentation(template = template,
toc = toc,
slide_level = slide_level,
incremental = incremental,
fig_width = fig_width,
fig_height = fig_height,
fig_crop = fig_crop,
fig_caption = fig_caption,
dev = dev,
df_print = df_print,
theme = "metropolis",
fonttheme = fonttheme,
highlight = highlight,
keep_tex = keep_tex,
latex_engine = latex_engine,
citation_package = citation_package,
includes = includes,
md_extensions = md_extensions,
pandoc_args = pandoc_args)
}
# Call rmarkdown::pdf_documet and mark the return value as inheriting pdf_document
inherit_pdf_document <- function(...) {
fmt <- rmarkdown::pdf_document(...)
fmt$inherits <- "pdf_document"
fmt
}
knitr_fun <- function(name) utils::getFromNamespace(name, 'knitr')
output_asis <- knitr_fun('output_asis')

19
binb.Rproj Normal file
View File

@ -0,0 +1,19 @@
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 4
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
BuildType: Package
PackageInstallArgs: --no-multiarch --with-keep.source

View File

@ -0,0 +1,350 @@
\PassOptionsToPackage{unicode=true}{hyperref} % options for packages loaded elsewhere
\PassOptionsToPackage{hyphens}{url}
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$babel-lang$,$endif$$if(handout)$handout,$endif$$if(colorlinks)$dvipsnames,$endif$$if(beamer)$ignorenonframetext,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{caption label separator}{: }
\setbeamercolor{caption name}{fg=normal text.fg}
\beamertemplatenavigationsymbols$if(navigation)$$navigation$$else$empty$endif$
$if(fontfamily)$
\usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$}
$else$
\usepackage{lmodern}
$endif$
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[$if(fontenc)$$fontenc$$else$T1$endif$]{fontenc}
\usepackage[utf8]{inputenc}
$if(euro)$
\usepackage{eurosym}
$endif$
\else % if luatex or xelatex
\ifxetex
\usepackage{mathspec}
\else
\usepackage{fontspec}
\fi
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
$for(fontfamilies)$
\newfontfamily{$fontfamilies.name$}[$fontfamilies.options$]{$fontfamilies.font$}
$endfor$
$if(euro)$
\newcommand{\euro}{}
$endif$
$if(mainfont)$
\setmainfont[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$]{$mainfont$}
$endif$
$if(sansfont)$
\setsansfont[$for(sansfontoptions)$$sansfontoptions$$sep$,$endfor$]{$sansfont$}
$endif$
$if(monofont)$
\setmonofont[Mapping=tex-ansi$if(monofontoptions)$,$for(monofontoptions)$$monofontoptions$$sep$,$endfor$$endif$]{$monofont$}
$endif$
$if(mathfont)$
\setmathfont(Digits,Latin,Greek)[$for(mathfontoptions)$$mathfontoptions$$sep$,$endfor$]{$mathfont$}
$endif$
$if(CJKmainfont)$
\usepackage{xeCJK}
\setCJKmainfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmainfont$}
$endif$
\fi
$if(theme)$
\usetheme[$for(themeoptions)$$themeoptions$$sep$,$endfor$]{$theme$}
$endif$
$if(colortheme)$
\usecolortheme{$colortheme$}
$endif$
$if(fonttheme)$
\usefonttheme{$fonttheme$}
$endif$
$if(mainfont)$
\usefonttheme{serif} % use mainfont rather than sansfont for slide text
$endif$
$if(innertheme)$
\useinnertheme{$innertheme$}
$endif$
$if(outertheme)$
\useoutertheme{$outertheme$}
$endif$
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
$if(lang)$
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[shorthands=off,$for(babel-otherlangs)$$babel-otherlangs$,$endfor$main=$babel-lang$]{babel}
$if(babel-newcommands)$
$babel-newcommands$
$endif$
\else
\usepackage{polyglossia}
\setmainlanguage[$polyglossia-lang.options$]{$polyglossia-lang.name$}
$for(polyglossia-otherlangs)$
\setotherlanguage[$polyglossia-otherlangs.options$]{$polyglossia-otherlangs.name$}
$endfor$
\fi
$endif$
\newif\ifbibliography
$if(natbib)$
\usepackage{natbib}
\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$}
$endif$
$if(biblatex)$
\usepackage[$if(biblio-style)$style=$biblio-style$,$endif$$for(biblatexoptions)$$biblatexoptions$$sep$,$endfor$]{biblatex}
$for(bibliography)$
\addbibresource{$bibliography$}
$endfor$
$endif$
$if(verbatim-in-note)$
\usepackage{fancyvrb}
$endif$
\hypersetup{
$if(title-meta)$
pdftitle={$title-meta$},
$endif$
$if(author-meta)$
pdfauthor={$author-meta$},
$endif$
$if(keywords)$
pdfkeywords={$for(keywords)$$keywords$$sep$, $endfor$},
$endif$
$if(colorlinks)$
colorlinks=true,
linkcolor=$if(linkcolor)$$linkcolor$$else$Maroon$endif$,
citecolor=$if(citecolor)$$citecolor$$else$Blue$endif$,
urlcolor=$if(urlcolor)$$urlcolor$$else$Blue$endif$,
$else$
pdfborder={0 0 0},
$endif$
breaklinks=true}
%\urlstyle{same} % Use monospace font for urls
$if(verbatim-in-note)$
\VerbatimFootnotes % allows verbatim text in footnotes
$endif$
$if(listings)$
\usepackage{listings}
$endif$
$if(lhs)$
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
$endif$
$if(highlighting-macros)$
$highlighting-macros$
$endif$
$if(tables)$
\usepackage{longtable,booktabs}
\usepackage{caption}
% These lines are needed to make table captions work with longtable:
\makeatletter
\def\fnum@table{\tablename~\thetable}
\makeatother
$endif$
$if(graphics)$
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight0.8\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
$endif$
% Prevent slide breaks in the middle of a paragraph:
\widowpenalties 1 10000
\raggedbottom
$if(section-titles)$
\AtBeginPart{
\let\insertpartnumber\relax
\let\partname\relax
\frame{\partpage}
}
\AtBeginSection{
\ifbibliography
\else
\let\insertsectionnumber\relax
\let\sectionname\relax
\frame{\sectionpage}
\fi
}
\AtBeginSubsection{
\let\insertsubsectionnumber\relax
\let\subsectionname\relax
\frame{\subsectionpage}
}
$endif$
$if(links-as-notes)$
% Make links footnotes instead of hotlinks:
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$
$if(strikeout)$
\usepackage[normalem]{ulem}
% avoid problems with \sout in headers with hyperref:
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
$endif$
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
$if(numbersections)$
\setcounter{secnumdepth}{$if(secnumdepth)$$secnumdepth$$else$5$endif$}
$else$
\setcounter{secnumdepth}{0}
$endif$
$if(dir)$
\ifxetex
% load bidi as late as possible as it modifies e.g. graphicx
$if(latex-dir-rtl)$
\usepackage[RTLdocument]{bidi}
$else$
\usepackage{bidi}
$endif$
\fi
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\TeXXeTstate=1
\newcommand{\RL}[1]{\beginR #1\endR}
\newcommand{\LR}[1]{\beginL #1\endL}
\newenvironment{RTL}{\beginR}{\endR}
\newenvironment{LTR}{\beginL}{\endL}
\fi
$endif$
$for(header-includes)$
$header-includes$
$endfor$
$if(title)$
\title[$shorttitle$]{$title$}
$endif$
$if(subtitle)$
\subtitle{$subtitle$}
$endif$
$if(author)$
\author[
$if(short-author)$
$for(short-author)$$short-author$$sep$ \and $endfor$
$else$
$for(author)$$author$$sep$ \and $endfor$
$endif$
]{$for(author)$$author$$sep$ \and $endfor$}
$endif$
$if(institute)$
\institute[
$if(short-institute)$
$for(short-institute)$$short-institute$$sep$ \and $endfor$
$endif$
]{
$if(department)$
$for(department)$$department$$sep$ \and $endfor$ \\
$endif$
$for(institute)$$institute$$sep$ \and $endfor$
$if(email)$
\\ $for(email)$ \href{mailto:$email$}{\nolinkurl{$email$}}$sep$ \and $endfor$
$endif$
}
$endif$
\date[
$if(short-date)$
$short-date$
$else$
$date$
$endif$]{
$if(date)$
$date$
$if(license)$
\\ \vspace{5mm}
$endif$
$endif$
$if(license)$
{\scriptsize $license$}
$endif$
}
\begin{document}
% Hide progress bar and footline on titlepage
$if(title)$
\begin{frame}[plain]
\titlepage
\end{frame}
$endif$
$for(include-before)$
$include-before$
$endfor$
$if(toc)$
\begin{frame}
\tableofcontents[hideallsubsections]
\end{frame}
$endif$
$body$
$if(natbib)$
$if(bibliography)$
$if(biblio-title)$
$if(book-class)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
\begin{frame}[allowframebreaks]{$biblio-title$}
\bibliographytrue
\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
\end{frame}
$endif$
$endif$
$if(biblatex)$
\begin{frame}[allowframebreaks]{$biblio-title$}
\bibliographytrue
\printbibliography[heading=none]
\end{frame}
$endif$
$for(include-after)$
$include-after$
$endfor$
\end{document}

View File

@ -0,0 +1,99 @@
---
author: Your Name Here and Some Other Person
title: "Something really clever here: \\newline And maybe a second line"
subtitle: You can also have a subtitle
date: 2018-09-15
output: binb::metropolis
---
```{r,setup, include=FALSE}
knitr::opts_chunk$set(cache=TRUE)
```
# A Section Header
## A Slide Header
### A Subtitle
- Point A
- Point B
- Point C
# Principal Resources
## Metropolis
### Main Repos
- [Official GitHub Repo of Metropolis](https://github.com/matze/mtheme)
(formerly mtheme); older version in TeXLive
- [My GitHub Repo for a local Ubuntu package of Metropolis](https://github.com/eddelbuettel/pkg-latex-metropolis) -- formerly mtheme
- [My GitHub Repo for a local Ubuntu package for the Fira font](https://github.com/eddelbuettel/pkg-fonts-fira)
## Ubuntu and Launchpad
### Briefly
- The packages which can be built (ie not Fira as it needs external fonts
which we cannot download during build) are
[in this repo](https://launchpad.net/~edd/+archive/ubuntu/misc/+packages)
- If you're not on Ubuntu, it is probably more work to get
- Metropolis into your \LaTeX environment
- the Fira font into your \LaTeX environment
- I *did* try without (on plain Ubuntu 16.04) and it _builds_ but looks less
crisp
- So for the time being you probably want these fresh from source, or via my
helpers. YMMV.
## Local Adaption
- mtheme and metropolis changed a bit since I first used them
- I started with a local modification I called m2; the package is still in
the launchpad repo
- I generally include a file `header.tex` from the YAML for color, font,
... tweaking at the \LaTeX level, but as these are presentation-specific I
didn't include any changes here.
_ _ _
\LARGE Breakout page
## Using LaTeX Parts: Equations
### Linear Model
$$ \hat{\beta} = \text{argmin}_{b \in \mathbb{R}} S(b) = \left( \frac{1}{n} \sum_{i=1}^n x_i x_i^T \right)^{-1} \cdot \frac{1}{n} \sum_{i=1}^n x_i y_i $$
or in matrix form
$$ \hat{\beta} = (X^TX)^{-1} X^T y $$
## Using LaTeX Parts: Blocks
As one example of falling back into \LaTeX, consider the example of
three different block environments are pre-defined and may be styled
with an optional background color.
<!-- this sets the background -->
\metroset{block=fill}
\begin{block}{Default}
Block content.
\end{block}
\begin{alertblock}{Alert}
Block content.
\end{alertblock}
\begin{exampleblock}{Example}
Block content.
\end{exampleblock}
## Finally
### Going Forward
- Questions etc: Open issue tickets [at the GitHub repo](https://github.com/eddelbuettel/samples-rmarkdown-metropolis/issues)
- Pull requests welcome for bug fixes, extensions, examples, ...

View File

@ -0,0 +1,3 @@
name: Binb is not Beamer - Metropolis (pdf)
description: A custom R Markdown Beamer presentation theme.
create_dir: true

63
man/metropolis.Rd Normal file
View File

@ -0,0 +1,63 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/binb.R
\name{metropolis}
\alias{metropolis}
\title{Binb is not Beamer - Metropolis-themed PDF Presentation}
\usage{
metropolis(toc = FALSE, slide_level = 2, incremental = FALSE,
fig_width = 10, fig_height = 7, fig_crop = TRUE, fig_caption = TRUE,
dev = "pdf", df_print = "default", fonttheme = "default",
highlight = "tango", keep_tex = FALSE, latex_engine = "xelatex",
citation_package = c("none", "natbib", "biblatex"), includes = NULL,
md_extensions = NULL, pandoc_args = NULL)
}
\arguments{
\item{toc}{A logical variable defaulting to \code{FALSE}.}
\item{slide_level}{A numeric variable defaulting to two.}
\item{incremental}{A logical variable defaulting to \code{FALSE}.}
\item{fig_width}{A numeric variable defaulting to ten.}
\item{fig_height}{A numeric variable defaulting to seven.}
\item{fig_crop}{A logical variable defaulting to \code{TRUE}.}
\item{fig_caption}{A logical variable defaulting to \code{TRUE}.}
\item{dev}{A character variable defaulting to \dQuote{pdf}.}
\item{df_print}{A character variable defaulting to \dQuote{default}.}
\item{fonttheme}{A character variable defaulting to \dQuote{default}.}
\item{highlight}{A character variable defaulting to \dQuote{tango}.}
\item{keep_tex}{A logical variable defaulting to \code{FALSE}.}
\item{latex_engine}{A character variable defaulting to \dQuote{xelatex}.}
\item{citation_package}{An optional character variable with possible value
\dQuote{none} (the default), \dQuote{natbib} or \dQuote{biblatex}.}
\item{includes}{An optional character variable defaulting to \code{NULL}.}
\item{md_extensions}{An optional character variable defaulting to \code{NULL}.}
\item{pandoc_args}{An optional character variable defaulting to \code{NULL}.}
}
\value{
RMarkdown content processed for rendering.
}
\description{
A template for RMarkdown-based Beamer presentations in the \sQuote{Metropolis}
style by Matthias Vogelgesang and others.
}
\details{
Not all options and customizations available at the LaTeX level are implemented
yet.
}
\author{
Dirk Eddelbuettel
}