I am trying to create an R Markdown Template on the basis of a LaTeX template I found on Overleaf. The template preamble uses many packages. I am trying to compile this latex file in RStudio using tinytex latex compiler, and during this process, I am getting error "Latex Error: Command \bibname unspecified. I am attaching both, the preamble from overleaf, and the YAML specification from R Markdown.
Overleaf Preamble
\documentclass[twoside]{report} %[twoside, 14pt]
% ==== MY BUNCH OF PACKAGES ====
\usepackage[a4paper,top=3cm,bottom=3cm,left=2.5cm,right=2.5cm,bindingoffset=5mm]{geometry}
\usepackage[english]{babel}
\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{multirow}
\usepackage{float}
\usepackage{amsmath}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{caption}
\captionsetup{font=footnotesize}
\usepackage{subcaption}
\usepackage{tabularx}
%\usepackage{mathabx}
\usepackage{subfiles}
\newcommand\quoteref[1]{\csname#1\endcsname}%
\usepackage{glossaries}
\usepackage[toc,page]{appendix}
\usepackage{rotating}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{changepage} % for the adjust width environment
\usepackage{setspace}
% ----------- code environment settings
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
% ---------------- chapter abstracts
\newenvironment{chapabstract}
{
\begin{center}
\noindent\makebox[0.8\linewidth]{\rule{0.8\paperwidth}{0.4pt}}
\end{center}
\vspace{2mm}
\list{}{
\setlength{\leftmargin}{1cm}
\setlength{\rightmargin}{\leftmargin}
}
\item\relax
}
{\par}
\makeatother
% ------------- hyperref
%\biboptions{authoryear,square,sort&compress}
\usepackage[colorlinks=true,linkcolor=blue,citecolor=blue]{hyperref}
% -------------- journals shortcuts
\newcommand{\aaa}{Anonymous Ambiguous Abstracts}
\newcommand{\bbb}{Boring Bibliographic Book}
% ----------- glossary entries for summary of acronyms
\makenoidxglossaries
\newglossaryentry{AAA}{name=AAA, description={Ambitious Amicable Ants}}
\newglossaryentry{BBB}{name=BBBB, description={Babbling Bumbling Band of Baboons}}
\newglossaryentry{CCC}{name=CCC, description={Condescending Critical Cucumber}}
\newglossaryentry{BFG}{name=BFG, description={Big Friendly Giant}}
% ==== TEMPLATE PACKAGES ====
\usepackage[utf8]{inputenc} % allow utf-8 input
\usepackage[T1]{fontenc} % use 8-bit T1 fonts
\usepackage{lmodern}
\usepackage{hyperref} % hyperlinks
\usepackage{url} % simple URL typesetting
\usepackage{booktabs} % professional-quality tables
\usepackage{amsfonts} % blackboard math symbols
\usepackage{nicefrac} % compact symbols for 1/2, etc.
\usepackage{microtype} % microtypography
\usepackage{lipsum} % fill with latin nonsense
YAML Specification in R Markdown
title: "Ambra2"
author: "Maulik Bhatt"
date: "`r Sys.Date()`"
output:
bookdown::pdf_document2:
template: Ambra.tex
keep_tex: true
Bibliography: references.bib
What am I doing wrong here?
I want to make a cover page for my thesis. Something like this would be great. It's there a way to do it in R Markdown? Or maybe in a .tex file and then add it to the .rmd? I'm knitting into a pdf.
You can try to put a LaTeX Preamble into the .Rmd document. Change test.tex to the file path of your preamble. The preamble should only contain LaTeX code that comes after your \documentclass{article} declaration and before your \begin{document} declaration.
Output:
pdf_document:
includes:
in_header: “test.tex”
in that preamble you can try this for a custom title page:
\usepackage{titling}
\title{\huge{<++>}}
\author{\href{mailto:your#email.com}{Author Name}}
\date{\today}
and to render the title page put this in the .Rmd towards the top of the document:
\begin{titlepage}
\maketitle
\thispagestyle{empty}
\clearpage
\end{titlepage}
You could also try TeX Stack Exchange for lots of LaTeX questions.
I always use the bable (french) package and it works fine when one Overleaf or MiKTex. However, when copy pasting my code to Rstudio (with Sweave etc), it just does not work properly.
Document with "é" when done with Sweave
Same document (code copy pasted) on MiKTex
I have following packages:
\documentclass[a4paper, parskip=full]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{array}
\usepackage{tensor}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{verbatim}
\usepackage{enumitem}
\usepackage[abbrev,backrefs]{amsrefs}
\usepackage{appendix}
Since I don't know much about Rstudio, I don't know what information you need about it. I will provide more info when asked for.
I followed a simple tutorial on youtube to get sweave working.
Thank you.
Edit:
Here is a minimal document.
(not sure how to link the whole pdf)
The code in Rstudio (Sweave) is following:
\documentclass[a4paper, parskip=full]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{array}
\usepackage{tensor}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{verbatim}
\usepackage{enumitem}
\usepackage[abbrev,backrefs]{amsrefs}
\usepackage{appendix}
\title{Année académique}
\date{}
\begin{document}
\SweaveOpts{concordance=TRUE}
\maketitle
This is a sentence with the characters é and è.
\end{document}
I use knitr::kable function to dynamicly print tables in pdf with latex.
the problem is that in the table there are polish signs, which are encoded for example:
'Galeria Mokotów' is encoded into 'Galeria MokotĂłw' and my '.Rnw' file fails.
how should I change the preamble to fix pdf printing?
\documentclass[10pt,a4paper]{res}
\usepackage{helvet}
\usepackage[cp1250]{inputenc}
\usepackage{fontenc}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage[table]{xcolor}
\usepackage[pdfstartview=FitB]{hyperref}
\usepackage{float}
\usepackage{polski}
\usepackage{layout} % show a page layout
\usepackage{blindtext} % dummy text
\begin{document}
\end{document}
I am using R's knitr and LaTeX to create a pdf. Technic Center gives "!Undefined control sequence" for Build Output errors. Technic Center indicates that lines with \begin{kframe} and \end{kframe} are the problematic lines.
Removing the kframe environment resolves the errors from the Build Output, but the document does not display a shadecolor for code chunks even when the kframe environment is removed.
I updated my MikTex packages and knitr. The document's preamble includes \usepackage{framed}; \usepackage{xcolor} does not seem to influence the problem. Changing the knitr background option did not fix the problem.
Here is the preamble of my document in the Rnw file (knitr adds to this):
\documentclass{article}
\usepackage{Sweave}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage[margin = 0.5in]{geometry}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{marvosym}
\usepackage{paralist}
\usepackage{framed}
\usepackage{url}
\usepackage{xcolor}
\usepackage{array}
\renewcommand\qedsymbol{\Squarepipe}
\title{title changed for question}
\author{author changed for question}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\newenvironment{definition}[1][Definition]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}
\newenvironment{conjecture}[1][Conjecture]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}
\begin{document}
Thank you!
The kframe environment should be defined in your latex preamble. It is defined for example in the example visible in help(knit)
library(knitr)
(f = system.file("examples", "knitr-minimal.Rnw", package = "knitr"))
knit(f) # compile to tex
Looking at the generated document knitr-minimal.tex you can see the definition of the kframe environment:
\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
\def\at#end#of#kframe{}%
\ifinner\ifhmode%
\def\at#end#of#kframe{\end{minipage}}%
\begin{minipage}{\columnwidth}%
\fi\fi%
\def\FrameCommand##1{\hskip\#totalleftmargin \hskip-\fboxsep
\colorbox{shadecolor}{##1}\hskip-\fboxsep
% There is no \\#totalrightmargin, so:
\hskip-\linewidth \hskip-\#totalleftmargin \hskip\columnwidth}%
\MakeFramed {\advance\hsize-\width
\#totalleftmargin\z# \linewidth\hsize
\#setminipage}}%
{\par\unskip\endMakeFramed%
\at#end#of#kframe}
\makeatother
Adding this to your latex preamble might solve the issue. This is of course taken care of when you generate complete pdf documents from knitr. It is only an issue when you use knitr to generate Latex fragments, later reused in larger Latex documents.