How to knitr beamer slides using Frankfurt theme without loosing navigation circles - r

After updating R and packages my beamer slides using Frankfurt theme no longer include the navigation circles at the top.
A mock Rmd file to demonstrate:
---
title: "Untitled"
output:
beamer_presentation:
theme: "Frankfurt"
# keep_tex: true
slide_level: 3
header-includes:
- \AtBeginSubsection{}
- \AtBeginSection{}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
# Intro
## .
### R Markdown
This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.
# Example
## .
### Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
### Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```
### Slide with Plot
```{r pressure}
plot(pressure)
```
Which gives ...
I can get the navigation circles to appear by setting keep_tex: true in the YAML and compiling the .tex file ...
... but this seems like an extra unnecessary step that was not previously required?
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] sessioninfo_1.1.1
loaded via a namespace (and not attached):
[1] compiler_3.6.1 assertthat_0.2.1 cli_1.1.0 htmltools_0.3.6 tools_3.6.1 withr_2.1.2
[7] rstudioapi_0.10 yaml_2.2.0 crayon_1.3.4 Rcpp_1.0.2 rmarkdown_1.15 knitr_1.25
[13] xfun_0.9 digest_0.6.20 packrat_0.5.0 evaluate_0.14
EDIT: As requested, the .tex file generated when setting keep_tex: true in the YAML
\PassOptionsToPackage{unicode=true}{hyperref} % options for packages loaded elsewhere
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
ignorenonframetext,
]{beamer}
\usepackage{pgfpages}
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{caption label separator}{: }
\setbeamercolor{caption name}{fg=normal text.fg}
\beamertemplatenavigationsymbolsempty
% Prevent slide breaks in the middle of a paragraph:
\widowpenalties 1 10000
\raggedbottom
\setbeamertemplate{part page}{
\centering
\begin{beamercolorbox}[sep=16pt,center]{part title}
\usebeamerfont{part title}\insertpart\par
\end{beamercolorbox}
}
\setbeamertemplate{section page}{
\centering
\begin{beamercolorbox}[sep=12pt,center]{part title}
\usebeamerfont{section title}\insertsection\par
\end{beamercolorbox}
}
\setbeamertemplate{subsection page}{
\centering
\begin{beamercolorbox}[sep=8pt,center]{part title}
\usebeamerfont{subsection title}\insertsubsection\par
\end{beamercolorbox}
}
\AtBeginPart{
\frame{\partpage}
}
\AtBeginSection{
\ifbibliography
\else
\frame{\sectionpage}
\fi
}
\AtBeginSubsection{
\frame{\subsectionpage}
}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provides euro and other symbols
\else % if luatex or xelatex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usetheme[]{Frankfurt}
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\#ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
pdftitle={Untitled},
pdfborder={0 0 0},
breaklinks=true}
\urlstyle{same} % don't use monospace font for urls
\newif\ifbibliography
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin#nat#width>\linewidth\linewidth\else\Gin#nat#width\fi}
\def\maxheight{\ifdim\Gin#nat#height>\textheight\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}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-2}
% set default figure placement to htbp
\makeatletter
\def\fps#figure{htbp}
\makeatother
\AtBeginSubsection{}
\AtBeginSection{}
\title{Untitled}
\date{}
\begin{document}
\frame{\titlepage}
\hypertarget{intro}{%
\section{Intro}\label{intro}}
\hypertarget{section}{%
\subsection{.}\label{section}}
\begin{frame}{R Markdown}
\protect\hypertarget{r-markdown}{}
This is an R Markdown presentation. Markdown is a simple formatting
syntax for authoring HTML, PDF, and MS Word documents. For more details
on using R Markdown see \url{http://rmarkdown.rstudio.com}.
When you click the \textbf{Knit} button a document will be generated
that includes both content as well as the output of any embedded R code
chunks within the document.
\end{frame}
\hypertarget{example}{%
\section{Example}\label{example}}
\hypertarget{section-1}{%
\subsection{.}\label{section-1}}
\begin{frame}{Slide with Bullets}
\protect\hypertarget{slide-with-bullets}{}
\begin{itemize}
\tightlist
\item
Bullet 1
\item
Bullet 2
\item
Bullet 3
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Slide with R Output}
\protect\hypertarget{slide-with-r-output}{}
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{summary}\NormalTok{(cars)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
\end{verbatim}
\end{frame}
\begin{frame}{Slide with Plot}
\protect\hypertarget{slide-with-plot}{}
\includegraphics{temp_files/figure-beamer/pressure-1.pdf}
\end{frame}
\end{document}

Related

RMarkdown and knitting in Armenian

Thanks in advance for the help. I am trying to parametrically knit an RMD file into PDFs and HTMLs of different languages; one of them is Armenian. Knitting the Armenian version to any kind of format always produces literal UTF entities, like <U+0553><U+0578><U+0580><U+0571><U+0561><U+057C><U+0578>.
The .tex files are rendered as follows: \textless U+0553\textgreater\textless U+0578\textgreater\textless U+0580\textgreater\textless U+0571\textgreater
I have also tried using XeLaTeX and setting the main font to DejaVu Sans (i.e. latex_engine: xelatex and mainfont: DejaVu Sans), but it still knits the Armenian characters as Unicode literals.
I edited the XeTex .tex output and put in Armenian characters, and it worked fine. If Pandoc/RMD/Knitr didn't convert the characters to literals, then everything would work pefectly fine.
Even the .knit.md file already has the Unicode literals, so the problem is high up in the knitting chain, and I am not sure why this might be.
Any help would be appreciated.
Here's my minimal document (LuaLaTeX):
---
title: "Test Doc"
author: "Document"
output:
html_fragment:
section_divs: no
pdf_document:
latex_engine: lualatex
geometry: margin = 2cm
params:
lang: yes
lang: "`r switch(params$lang, CY = 'cy-GB', EN = 'en-GB', HY = 'hy-AM')`"
knit: (function(inputFile, encoding){ files <- c("cv-cy", "cv-en", "cv-hy"); langs <- c(list(lang = "CY"), list(lang = "EN"), list(lang = "HY")); i <- 1; for(f in files){ rmarkdown::render(inputFile, output_format = c("html_fragment", "pdf_document"), encoding = encoding, params = langs[i], output_file = c(paste0(dirname(inputFile), "/", print(f)), paste0(dirname(inputFile), "/", print(f)))); i <- i +1 } })
---
```
{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
lswitch <- function(lang, ...){
switch(lang, ..., stop(""))
}
```
`r lswitch(params$lang,
CY = "# Enw",
EN = "# Name",
HY = "# Անում"
)
`
Here's the pertinent section in the .log for the LuaLaTeX build:
) (d:/texlive/texmf-dist/tex/generic/babel/babel.sty
Package: babel 2019/05/04 3.31 The Babel package
(d:/texlive/texmf-dist/tex/generic/babel/switch.def
File: switch.def 2019/05/04 3.31 Babel switching mechanism
) (d:/texlive/texmf-dist/tex/generic/babel/luababel.def
\l#dumylang=\language2
Package babel Info: Non-standard hyphenation setup on input line 114.
\l#nohyphenation=\language3
\l#german-x-2019-04-04=\language4
\l#ngerman-x-2019-04-04=\language5
\l#afrikaans=\language6
\l#ancientgreek=\language7
\l#ibycus=\language8
\l#arabic=\language9
\l#armenian=\language10
\l#basque=\language11
\l#belarusian=\language12
\l#bulgarian=\language13
\l#catalan=\language14
\l#pinyin=\language15
\l#churchslavonic=\language16
\l#coptic=\language17
\l#croatian=\language18
\l#czech=\language19
\l#danish=\language20
\l#dutch=\language21
\l#ukenglish=\language22
\l#usenglishmax=\language23
\l#esperanto=\language24
\l#estonian=\language25
\l#ethiopic=\language26
\l#farsi=\language27
\l#finnish=\language28
\l#french=\language29
\l#friulan=\language30
\l#galician=\language31
\l#georgian=\language32
\l#german=\language33
\l#ngerman=\language34
\l#swissgerman=\language35
\l#monogreek=\language36
\l#greek=\language37
\l#hungarian=\language38
\l#icelandic=\language39
\l#assamese=\language40
\l#bengali=\language41
\l#gujarati=\language42
\l#hindi=\language43
\l#kannada=\language44
\l#malayalam=\language45
\l#marathi=\language46
\l#oriya=\language47
\l#panjabi=\language48
\l#pali=\language49
\l#tamil=\language50
\l#telugu=\language51
\l#indonesian=\language52
\l#interlingua=\language53
\l#irish=\language54
\l#italian=\language55
\l#kurmanji=\language56
\l#latin=\language57
\l#classiclatin=\language58
\l#liturgicallatin=\language59
\l#latvian=\language60
\l#lithuanian=\language61
\l#mongolian=\language62
\l#mongolianlmc=\language63
\l#bokmal=\language64
\l#nynorsk=\language65
\l#occitan=\language66
\l#piedmontese=\language67
\l#polish=\language68
\l#portuguese=\language69
\l#romanian=\language70
\l#romansh=\language71
\l#russian=\language72
\l#sanskrit=\language73
\l#serbian=\language74
\l#serbianc=\language75
\l#slovak=\language76
\l#slovenian=\language77
\l#spanish=\language78
\l#swedish=\language79
\l#thai=\language80
\l#turkish=\language81
\l#turkmen=\language82
\l#ukrainian=\language83
\l#uppersorbian=\language84
\l#welsh=\language85
)
! Package babel Error: Unknown option `armenian'. Either you misspelled it
(babel) or the language definition file armenian.ldf was not fou
nd.
See the babel package documentation for explanation.
Type H <return> for immediate help.
...
l.533 \ExecuteOptions{\bbl#opt#main}
Session info:
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363), RStudio 1.2.5019
Locale:
LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
LC_TIME=English_United Kingdom.1252
Package version:
base64enc_0.1.3 digest_0.6.23 evaluate_0.14 glue_1.3.1 graphics_3.6.1 grDevices_3.6.1 highr_0.8
htmltools_0.4.0 jsonlite_1.6 knitr_1.26 magrittr_1.5 markdown_1.1 methods_3.6.1 mime_0.7
Rcpp_1.0.3 rlang_0.4.2 rmarkdown_1.18 stats_3.6.1 stringi_1.4.3 stringr_1.4.0 tinytex_0.17
tools_3.6.1 utils_3.6.1 xfun_0.11 yaml_2.2.0
Pandoc version: 2.7.2

Impossible to cross-referring figures and tables with `beamer_presentation` option in `knitr`

Why does \#ref() notation fail to operate with beamer-presentation?
The following question may remind you some questions on cross-reference when knitting PDF document, e.g. this, but the methods introduced in the answers have not help me when I make beamer-presentations.
Now I'm confused because \#ref(fig:label-to-refer-figure) and \#ref(tab:label-to-refer-table) notation to refer a figure/table does not work when I am knitting an .Rmd file with the option output: beamer_presentation. As shown in the following images, the raw codes for the cross-reference appear on the outputted PDF file and I cannot refer the figure/table number. Although the citations go well even in the listed environment as well as in plain text field, cross-reference for figure/table number does not properly take effect.
My environment
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)
knitr_1.20
rmarkdown_1.10
RStudio v1.2.1206 (Preview Version) <- I prefer this for this reason
MWEs
The MWE I post here is created from the following sources: test-beamer.Rmd and myref.bib.
test-beamer.Rmd
---
title: "Test"
subtitle: |
| subtitle,
| with a line break
author: |
| CLR
| Rafael
institute: |
| Now I'm here,
| Now I'm there
date: "`r format(Sys.time(), '%Y/%b/%d')`" #English
output:
beamer_presentation:
keep_tex: yes
latex_engine: lualatex
theme: "AnnArbor"
colortheme: "dolphin"
fonttheme: "structurebold"
toc: true
#toc_depth: 3
#number_sections: TRUE
fig_caption: TRUE
dev: cairo_pdf
#extra_dependencies: subfig
citation_package: natbib
slide_level: 2
bibliography: bibs/myref.bib
biblio-style: apa
always_allow_html: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## The only thing
With Table \#ref(tab:under-pressure-table), #test-master shows that Figure \#ref(fig:under-pressure) depicts...
## Slide with Bullets in which I want to refer a figure
- \#ref(fig:under-pressure)
- #test-master
- \#ref(tab:under-pressure-table)
## Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```
## Slide with Plot
```{r under-pressure, fig.cap='Under Pressure', fig.pos='h', out.width="0.75\\textwidth"}
plot(pressure)
```
## Slide with Table
```{r under-pressure-table, caption = "This is a table"}
knitr::kable(pressure)
```
## More extraordinary
With Table \#ref(tab:under-pressure-table), #test-master shows that Figure \#ref(fig:under-pressure) depicts...
EDIT: I added fig.cap='Under Pressure', fig.pos='h', out.width="0.75\\textwidth" to the figure chunk, and caption = "This is a table" to the knitr::kable(). Without these codes, neither the caption nor table/figure numbers appear at all... However, the problem persists even after giving them to the entire .Rmd file, unless you carry out #Yihui's answer.
myref.bib
#master{test-master,
author = {Freddie Mercury and Brian May and John Deacon and Roger Taylor},
title = {Bohemian {R}hapsody: {W}e are the champions},
school = {{Queen}},
year = {2018},
address = {London}
}
The \#ref() notation is a feature of bookdown only. To port this feature to general R Markdown documents, you may set the base_format option of a certain bookdown output format, e.g.,
output:
bookdown::pdf_book:
base_format: rmarkdown::beamer_presentation
See Section 3.4 of the bookdown book for details.
The completed yaml section which suits for the MWE of this question may be like this:
---
title: "Test"
subtitle: |
| subtitle,
| with a line break
author: |
| CLR
| Rafael
institute: |
| Now I'm here,
| Now I'm there
date: "`r format(Sys.time(), '%Y/%b/%d')`" #English
output:
bookdown::pdf_book:
base_format: "function(..., number_sections) rmarkdown::beamer_presentation(...)"
number_sections: true
keep_tex: yes
latex_engine: lualatex
theme: "AnnArbor"
colortheme: "dolphin"
fonttheme: "structurebold"
toc: true
fig_caption: TRUE
dev: cairo_pdf
#extra_dependencies: subfig
citation_package: natbib
slide_level: 2
bibliography: bibs/myref.bib
biblio-style: apa
always_allow_html: yes
---

knitr sanitize_fn warning incorporating plots into latex via knit2pdf

I am dynamically generating pdf reports in R using a driver script that calls knit2pdf. My report source is latex, in a .Rnw file, and the call is like this:
knit2pdf("source.Rnw",output=paste0(fname,".tex"),quiet=T)
fname does not contain any dots.
source.Rnw contains:
<<setup, echo=FALSE >>=
opts_chunk$set(fig.path=tempfile(tmpdir="work",pattern=fname,fileext=".pdf"))
#
<<custom-dev, echo=FALSE >>=
my_pdf<-function(file,width,height) {
pdf(file,width=5,height=2)
}
#
<<plot, echo=FALSE, results="asis", dev="my_pdf", fig.ext="pdf">>=
# A ggplot chart
print(g)
#
The reports are fine, but the following warning is generated from
knitr's sanitize_fn:
dots in figure paths replaced with _ ("work/fname_pdfplot")
Clearly, the offending . is coming from the fileext in opts_chunk. However, if I change that fileext to "_pdf", I don't get the plot in the report at all, and latex throws an error about the file (fname_pdfplot-1) not being found.
Ideas on how to (a) do this right so there's no warning, or (b) do this as I'm doing it but suppress this particular warning?
Edit 1:
Here is a working example of source.Rnw without using fileext. This does seem to be closer, because now it breaks with an error due to putting work\fname... in includegraphics rather than work/fname..., and if I change the backslash to a proper slash, it compiles cleanly.
tempfile is returning work\fname..., so perhaps my fix is just to re-escape those backslashes (or replace them with a forward slash). Is this something I should have known to do already?
\documentclass[titlepage]{article}
\usepackage[utf8]{inputenc}
\usepackage[headheight=36pt, foot=24pt, top=1in, bottom=1in, left=1in, right=1in, landscape]{geometry}
\usepackage{hyperref}
\usepackage{bookmark}
\usepackage{fancyhdr}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{float}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{microtype}
\usepackage{libertine}
\usepackage{parskip}
\usepackage{environ}
\usepackage{preview}
\usepackage[labelformat=empty]{caption}
\usepackage{amssymb}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{picture}
\usepackage{needspace}
\usepackage{adjustbox}
\usepackage{graphicx}
\pagestyle{fancy}
\raggedbottom
\renewcommand\familydefault{\sfdefault}
\newcommand{\helv}{%
\fontfamily{phv}\fontseries{m}\fontsize{8}{10}\selectfont}
\newcommand{\mycopyright}{\helv Copyright.}
\cfoot{\mycopyright}
\rhead{\textbf{\Sexpr{firstname} \Sexpr{lastname}} \\ \Sexpr{oafr} to \Sexpr{eoafr} \\ Page \thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\fancypagestyle{fancytitlepage}
{
\fancyhf{}
\cfoot{\mycopyright}
\rhead{}
\renewcommand{\headrulewidth}{0pt}
}
\linespread{1.2}
\usepackage{sectsty}
\allsectionsfont{\sffamily}
\partfont{\centering}
\makeatletter
\newcommand{\sectbox}[1]{%
\noindent\protect\colorbox{gray!40}{%
\#tempdima=\hsize
\advance\#tempdima by-2\fboxsep
\advance\#tempdima by-2\fboxrule
\protect\parbox{\#tempdima}{%
\smallskip
% extra commands here
\centering
#1\smallskip
}}}
\newcommand{\subsectbox}[1]{%
\noindent\protect\colorbox{gray!20}{%
\#tempdima=\hsize
\advance\#tempdima by-2\fboxsep
\advance\#tempdima by-2\fboxrule
\protect\parbox{\#tempdima}{%
\smallskip
% extra commands here
#1\smallskip
}}}
\makeatother
\sectionfont{\sectbox}
\subsubsectionfont{\subsectbox}
\makeatletter
\newcommand\cellwidth{\TX#col#width}
\makeatother
\newlength\foo
\NewEnviron{recipe}{%
\begin{adjustbox}{minipage=\linewidth,gstore totalheight=\foo, gobble}
\BODY
\end{adjustbox}
\needspace{\foo}
\BODY%
}
<<setup, echo=FALSE >>=
opts_chunk$set(fig.path = tempfile(tmpdir="work",pattern=fname))
#
\hyphenpenalty=100000
\begin{document}
\raggedbottom
\setlength{\parskip}{0pt}
<<custom-dev,echo=FALSE>>=
wkld_pdf<-function(file,width,height) {
pdf(file,width=5,height=2)
}
#
<<wkld, echo=FALSE, results='asis',fig.align="center",dev="wkld_pdf",fig.ext="pdf">>=
if (!is.na(wkld.team) | !is.na(wkld.res)) {
g<-pltr$workload.chart(wkld.team,wkld.res,firstname)
print(g)
}
#
\end{document}
In the above example, the file work\fname61c28cd1a0awkld-1.pdf is correctly created, but the tex generated has:
{\centering \includegraphics[width=\maxwidth]{work\fname61c28cd1a0awkld-1}
}
and thus doesn't find it.
It appears that leaving out fileext works (and likely setting it to _pdf would as well) to remove the warning.
It was also necessary to replace the \ generated by tempfile with a / to prevent another warning from the generated includegraphics call, as somewhere in the chain, the \ was evaluated down to . This worked:
opts_chunk$set(fig.path = gsub('\\\\','/',tempfile(tmpdir="work",pattern=fname)))
Thank you for helping me track that down.

No author details in pdf, from R-Markdown / LaTeX template

I'm trying to create an R-Markdown template based on the BioMed Central LaTeX template (bmc-article.tex).
The bmc template files are available for download here and needless to say, they work just fine: https://www.biomedcentral.com/authors/tex
In particular, the author, address and note definitions work and produce the desired outcome.
I have replaced the example author, adresse and note definitions in the bmc-article.tex file to use that as a tex template. I have also removed most of the example-content in that file.
The definition examples in the bmc-article.tex, I have replaced with:
$for(author)$
\author[%
addressref={$author.addressref$}, %
$if(author.corref)$corref={$author.corref$}, $endif$ %
$if(author.noteref)$noteref={$author.noteref$}, $endif$ %
email={$author.email$} %
]{\inits{$author.inits$}\fnm{$author.fnm$} \snm{$author.snm$}}
$endfor$
$for(address)$
\address[id=$address.id$]{ %
$if(address.orgname)$ \orgname{$address.orgname$}, $endif$ %
$if(address.street)$ \street{$address.street$}, $endif$ %
$if(address.postcode)$ \postcode{$address.postcode$}, $endif$ %
$if(address.city)$ \city{$address.city$}, $endif$ %
$if(address.cny)$ \cny{$address.cny$}$endif$ %
}
$endfor$
\begin{artnotes}
$for(notes)$
\note[id=$notes.id$]{$notes.text$} % note, connected to author
$endfor$
\end{artnotes}
When 'knitr'ing the Rmd file, it is (as far as I can tell), converted into meningful tex, and I have perused the resulting tex file again and again looking for tex-errors, but find none.
E.g.:
author:
- fnm: "Soren"
snm: "ONeill"
inits: "S"
addressref: "aff1"
email: "sorens mail"
corref: "aff1"
noteref: "n1"
..becomes:
\author[%
addressref={aff1}, %
corref={aff1}, %
noteref={n1}, %
email={sorens mail} %
]{\inits{S}\fnm{Soren} \snm{ONeill}}
The resulting pdf file however is not correct. The superscript numbers which associate names with addresses is displayed as questionmarks and author details at the end of the article is missing altogether.
I fail to see any significant difference between the tex file created by pandoc (based on my Rmd file) and the original bmx template tex file.
The following is rather lengthy I know.
The Rmd example file
title: "Template testing"
author:
- fnm: "Soren"
snm: "ONeill"
inits: "S"
addressref: "aff1"
email: "sorens mail"
corref: "aff1"
noteref: "n1"
- fnm: "Lotte"
snm: "ONeill"
inits: "L"
addressref: "aff2"
email: "lottes mail"
address:
- id: "aff1"
orgname: "University of Southern Denmark"
street: "Campusvej 55"
postcode: "DK 5500"
city: "Odense M"
cny: "Denmark"
- id: "aff2"
orgname: "University of Southern Denmark"
street: "Campusvej 55"
postcode: "DK 5500"
city: "Odense M"
cny: "Denmark"
notes:
- id: "n1"
text: "Equal contributor"
date: "2 jun 2017"
output:
pdf_document:
template: template.tex
keep_tex: TRUE
---
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see rmarkdown.rstudio.com.
This is the template.tex file, which I have adapted from the downloaded bmc-article.tex file
%% BioMed_Central_Tex_Template_v1.06
\documentclass{bmcart}
\usepackage[utf8]{inputenc} %unicode support
\def\includegraphic{}
\def\includegraphics{}
\begin{document}
\begin{frontmatter}
\begin{fmbox}
\dochead{Research}
\title{$title$}
$for(author)$
\author[%
addressref={$author.addressref$}, %
$if(author.corref)$corref={$author.corref$}, $endif$ %
$if(author.noteref)$noteref={$author.noteref$}, $endif$ %
email={$author.email$} %
]{\inits{$author.inits$}\fnm{$author.fnm$} \snm{$author.snm$}}
$endfor$
$for(address)$
\address[id=$address.id$]{ %
$if(address.orgname)$ \orgname{$address.orgname$}, $endif$ %
$if(address.street)$ \street{$address.street$}, $endif$ %
$if(address.postcode)$ \postcode{$address.postcode$}, $endif$ %
$if(address.city)$ \city{$address.city$}, $endif$ %
$if(address.cny)$ \cny{$address.cny$}$endif$ %
}
$endfor$
\begin{artnotes}
$for(notes)$
\note[id=$notes.id$]{$notes.text$} % note, connected to author
$endfor$
\end{artnotes}
\end{fmbox}% comment this for two column layout
\begin{abstractbox}
\begin{abstract} % abstract
\parttitle{First part title} %if any
Text for this section.
\parttitle{Second part title} %if any
Text for this section.
\end{abstract}
\begin{keyword}
\kwd{sample}
\kwd{article}
\kwd{author}
\end{keyword}
\end{abstractbox}
\end{frontmatter}
%$body$
\begin{backmatter}
\section*{Competing interests}
The authors declare that they have no competing interests.
\section*{Author's contributions}
Text for this section \ldots
\section*{Acknowledgements}
Text for this section \ldots
\bibliographystyle{bmc-mathphys} % Style BST file (bmc-mathphys, vancouver, spbasic).
\bibliography{bmc_article} % Bibliography file (usually '*.bib' )
\end{backmatter}
\end{document}
This produces the following tex file (I've instructed RStudio/pandoc to retain the tex file):
%% BioMed_Central_Tex_Template_v1.06
\documentclass{bmcart}
\usepackage[utf8]{inputenc} %unicode support
\def\includegraphic{}
\def\includegraphics{}
\begin{document}
\begin{frontmatter}
\begin{fmbox}
\dochead{Research}
\title{Template testing}
\author[%
addressref={aff1}, %
corref={aff1}, %
noteref={n1}, %
email={sorens mail} %
]{\inits{S}\fnm{Soren} \snm{ONeill}}
\author[%
addressref={aff2}, %
%
%
email={lottes mail} %
]{\inits{L}\fnm{Lotte} \snm{ONeill}}
\address[id=aff1]{ %
\orgname{University of Southern Denmark}, %
\street{Campusvej 55}, %
\postcode{DK 5500}, %
\city{Odense M}, %
\cny{Denmark} %
}
\address[id=aff2]{ %
\orgname{University of Southern Denmark}, %
\street{Campusvej 55}, %
\postcode{DK 5500}, %
\city{Odense M}, %
\cny{Denmark} %
}
\begin{artnotes}
\note[id=n1]{Equal contributor} % note, connected to author
\end{artnotes}
\end{fmbox}% comment this for two column layout
\begin{abstractbox}
\begin{abstract} % abstract
\parttitle{First part title} %if any
Text for this section.
\parttitle{Second part title} %if any
Text for this section.
\end{abstract}
\begin{keyword}
\kwd{sample}
\kwd{article}
\kwd{author}
\end{keyword}
\end{abstractbox}
\end{frontmatter}
%\subsection{R Markdown}\label{r-markdown}
This is an R Markdown document. Markdown is a simple formatting syntax
for authoring HTML, PDF, and MS Word documents. For more details on
using R Markdown see rmarkdown.rstudio.com.
\begin{backmatter}
\section*{Competing interests}
The authors declare that they have no competing interests.
\section*{Author's contributions}
Text for this section \ldots
\section*{Acknowledgements}
Text for this section \ldots
\bibliographystyle{bmc-mathphys} % Style BST file (bmc-mathphys, vancouver, spbasic).
\bibliography{bmc_article} % Bibliography file (usually '*.bib' )
\end{backmatter}
\end{document}
The latex log file is rather lengthy (lots of stuff about Unicode char's etc), but this is possibly helpful
LaTeX Warning: Reference `aff1thanks' on page 1 undefined on input line 19.
LaTeX Font Info: Try loading font information for OMS+cmss on input line 19.
LaTeX Font Info: No file OMScmss.fd. on input line 19.
LaTeX Font Warning: Font shape `OMS/cmss/m/n' undefined
(Font) using `OMS/cmsy/m/n' instead
(Font) for symbol `textdagger' on input line 19.
LaTeX Warning: Reference `aff2thanks' on page 1 undefined on input line 25.
\address#aff1=\toks21
\address#aff2=\toks22
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <7> on input line 46.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <5> on input line 46.
LaTeX Warning: Reference `aff1thanks' on page 1 undefined on input line 46.
No file template_test_1.bbl.
AED: lastpage setting LastPage
LaTeX Font Warning: Font shape `OT1/cmss/m/it' in size <8> not available
(Font) Font shape `OT1/cmss/m/sl' tried instead on input line 89.
Overfull \hbox (1.0pt too wide) has occurred while \output is active
[]
[]
[1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}
] (./template_test_1.aux)
LaTeX Font Warning: Size substitutions with differences
(Font) up to 1.0pt have occurred.
LaTeX Font Warning: Some font shapes were not available, defaults substituted.
LaTeX Warning: There were undefined references.
Of course, I have noticed the warning about "Reference `aff2thanks'", but find no such reference in the original bmx-article.tex
Again, I know this is long -- I apologize for that. I hope someone can make suggestions...

Error in getMetricsFromLatex(TeXMetrics, verbose = verbose)

When compiling R code within a child, I get the following error.
Error in getMetricsFromLatex(TeXMetrics, verbose = verbose) :
TeX was unable to calculate metrics for the following string
or character:
m
Common reasons for failure include:
* The string contains a character which is special to LaTeX unless
escaped properly, such as % or $.
* The string makes use of LaTeX commands provided by a package and
the tikzDevice was not told to load the package.
The file worked flawlessly until I changed one tiny detail that I cannot recall. The tikzDictionary is in the directory of the first child containing R-code. I removed the tikZDictionary to no avail. The file created is empty (0 Bytes). Taking the code and compiling it in a file with the appropriate headers works fine. I tried copying the contents of the whole thesis to a new folder and recompile it there, but the same problems occur there.
> sessionInfo()
> R version 3.4.0 (2017-04-21) Platform: x86_64-apple-darwin16.5.0 (64-bit) Running under: macOS Sierra 10.12.4
>
> Matrix products: default BLAS:
> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
> LAPACK:
> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib
>
> locale: [1]
> en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages: [1] stats graphics grDevices utils
> datasets methods base
>
> other attached packages: [1] tikzDevice_0.10-1 plyr_1.8.4
> xtable_1.8-2 knitr_1.15.1
>
> loaded via a namespace (and not attached): [1] compiler_3.4.0
> magrittr_1.5 tools_3.4.0 Rcpp_0.12.10 [5]
> codetools_0.2-15 filehash_2.4-1 stringi_1.1.5 highr_0.6
> [9] grid_3.4.0 digest_0.6.12 stringr_1.2.0 evaluate_0.10
Copying all relevant files to a new directory and trying to compile it throws the same error.
1) Can one try to force the tikZdevice to recalculate the metrics?!
2) Can I get the correct metrics from elsewhere?
Thank you so much for your help.
I got it to work after a total of about 6 hours. I put all the R-Code in the main file, it compiles flawlessly. The ´main-tikzDirectory´ is in the same directory as the ´main´.
However, it is about 1000 lines of R code (we're talking about the results party of my whole thesis...), which I would rather have in a separate file.
As soon as I place anything in a child I get the same error. Also, while the error had been thrown in the ´R´ console before and no tex file is produced, when using the minimal example below the error message is written to the tex-file.
I provide a minimal example:
\documentclass[10pt,a4paper]{book}
\usepackage{geometry} % Titelseite braucht eigene Margins.
%\usepackage[ngerman]{babel} % Trennungsregeln, Datumsangabe etc. in Deutsch
\usepackage[T1]{fontenc} % europäischer Zeichensatz (Sonderzeichen, etc.)
%\usepackage[bitstream-charter]{mathdesign} % Moderne, serifenbetonte und sachliche Schriftart
\usepackage[utf8]{inputenc} % utf8 Eingabezeichensatz
\usepackage{xstring} % Testen/Vergleichen von (Sub)Strings
\usepackage{totcount} % Zähle Seitenzahlen, Abbildungen etc.
\usepackage{siunitx} % SI Einheiten
\DeclareSIUnit{\molar}{M}
%\usepackage{natbib} % Naturwissenschaftliche Zitierungen
\usepackage[sorting=none, citestyle=nature, maxnames=99, minnames=99, backend=biber]{biblatex}
\addbibresource{bibliography/bibliography.bib}
\renewcommand*{\bibfont}{\small}
\usepackage[version=3]{mhchem} % chemische Summen- und Strukturformeln
\usepackage{eurosym} % Euro-Zeichen
\usepackage{hyperref} %
\usepackage[xindy,acronym,nonumberlist,nomain]{glossaries} % Abkürzung + Abkürzungsverzeichnis
\makeglossaries %
\usepackage{multicol}
% Grafiken
\usepackage{tikz}
\usepackage{epsfig}
\usepackage{graphics}
\usepackage{graphicx}
% Tabellen
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{tabu}
\usepackage{array}
\usepackage{rotating}
\usepackage{bigdelim}
\usepackage{multirow}
\usepackage{float}
\usepackage{colortbl}
\usepackage{xcolor}
\def\TReg{\textsuperscript{\textregistered}}
\def\TCop{\textsuperscript{\textcopyright}}
\def\TTra{\textsuperscript{\texttrademark}}
%% Nummerierung
\setcounter{secnumdepth}{4}
%% Eigene Makros
\input{config/config}
\input{macros/InOderAm}
\input{macros/HideIfZero}
\input{macros/citenumCounter}
\input{macros/totalfiguresCounter}
\input{macros/totalappendixCounter}
%% Floats erst ab 80% auf eigene Seite
\renewcommand{\floatpagefraction}{.8}%
%% Dokument
\begin{document}
%% Knitr-optionen
<<setup, echo = FALSE, results= 'hide', message = FALSE>>=
library(xtable)
library(plyr)
opts_chunk$set(fig.path='figure/graphics-', cache.path='cache/graphics-', fig.align='center', dev='tikz', external=TRUE, fig.width=5, fig.height=5, fig.show='hold', cache=TRUE, global.par=FALSE)
knit_hooks$set(par=function(before, options, envir){
if (before && options$fig.show!='none') par(mar=c(4,4,.1,.1),cex=1,cex.lab=.9,cex.axis=.9,mgp=c(2,.7,0),tcl=-.3)
}, crop=hook_pdfcrop)
#
<<results, child="content/main/results/results2.Rnw">>=
#
\end{document}
The child is located some folders below.
<<corruption>>=
plot(runif(100,0,1)^2)
#

Resources