We think about distributing an open-book exam as a fillable PDF form via exams2nops. The idea is that students do not print the PDF and mark their answers with a pen, but rather fill in their answers electronically in their PDF (e.g. with Acrobat Reader), and send back that PDF to us (or upload it via Moodle). Then, the PDF is "scanned" / the answers are extracted from the PDF.
Currently, the checkboxes for MC/SC answers are not clickable; also the textfields for free text answers could be fillable text input fields. The current PDF export does not do this.
Has anybody done this already? If I'd like to implement this, where is a good starting point? Maybe nops.tex?
(We are aware that exporting to an interactive quiz in Moodle is an alternative option).
TL;DR
exams2nops() does not support this and will not be extended in this direction because its focus is generating PDF exams for printing/scanning/etc.
exams2pdf() can be customized to use different LaTeX templates and you can try to set up a suitable template using the {hyperref} package.
The support for the resulting PDF forms differs a lot between PDF viewers, typically with Acrobat Reader being the only one with decent support.
My personal experience with the heterogeneity on students' systems plus sending solutions via e-mail is that this is not a very reliable solution but would be the source of a lot of problems. Personally, I would avoid going down this road.
If your university hosts a Moodle system, I would recommend generating exams via exams2moodle(). At least the responsibility for the stability of the system is then with the university.
Details:
By using the {hyperref} package you can use the {Form} environment with commands like \CheckBox{}, \TextEntry{}, etc. A brief overview is given here: https://tex.stackexchange.com/questions/14842/creating-fillable-pdfs
A more elaborate worked example is available at: https://martin-thoma.com/creating-pdf-forms-with-latex/
Based on these I adapted the exam.tex template provided within the R/exams package and set up a form.tex template. The full LaTeX code is included below. This tries to do the following:
Set up a form that can be submitted by e-mail when completed.
The form consists of "fixed" fields for name and student ID.
Then it sets up commands \exnum, \exstring, exmchoice etc. that can be used by exams2pdf(). See Section 3 in vignette("exams", package = "exams") for details. Thus, these commands are repeated as often as necessary for a given exam.
At the end there are buttons to "Submit" or "Clear" the form.
For illustration, try:
exams2pdf(
c("deriv.Rmd", "swisscapital.Rmd", "boxplots.Rmd", "ttest.Rmd", "function.Rmd", "lm.Rmd"),
template = "form.tex"
)
where form.tex from below needs to be in your current working directory.
The result is a form1.pdf displayed automatically in your default PDF viewer (see options(pdfviewer = ...)). Alternatively, you can also add an argument dir = "." to store the file in your current working directory.
For me on Debian GNU/Linux with TeXLive this works and produces a PDF file that can be viewed and filled in using the Evince PDF viewer. However, neither "Submit" nor "Clear" works.
When I open the same file under Acrobat Reader in Windows 10, then only the TextEntry fields for Name/ID work, the others don't. The check boxes work but all checkboxes for (a) are linked, as are all (b), etc.
My impression is that composing the {Form} on the fly like this does not work for Acrobat Reader. But I would appreciate pointers how this can be fixed. An alternative would be to exactly code the form you need for a specific exam with unique name tags in all form elements etc.
Bonus note:
The template below also activates the {attachfile} LaTeX package which can be used to embed files (e.g., data sets) into the PDF. This works for me but only under Acrobat Reader. To automatically convert all \url{} commands (as created for the lm exercise, used above) into \attachfile{} commands, the development version of exams2pdf() gained an argument attachfile = FALSE which can be set to TRUE. See this thread in the R/exams forum on R-Forge for more details:
https://R-Forge.R-project.org/forum/forum.php?thread_id=32091&forum_id=4377&group_id=1337
LaTeX template: form.tex
\documentclass[10pt,a4paper]{article}
%% packages
\usepackage[utf8]{inputenc}
\usepackage{a4wide,color,verbatim,Sweave,url,xargs,amsmath,booktabs,longtable,eurosym}
%%% %% optionally: two-column layout for exercise form
%%% \usepackage{multicol}
%% embed supplementary data files etc.
\usepackage{attachfile}
\attachfilesetup{color=0.5 0 0}
%% support PDF forms
\usepackage{hyperref}
%% new environments
\newenvironment{question}{\item}{}
\newenvironment{solution}{\comment}{\endcomment}
\newenvironment{answerlist}{\renewcommand{\labelenumi}{(\alph{enumi})}\begin{enumerate}}{\end{enumerate}}
%% paragraphs
\setlength{\parskip}{0.7ex plus0.1ex minus0.1ex}
\setlength{\parindent}{0em}
%% compatibility with pandoc
\providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setkeys{Gin}{keepaspectratio}
%% fonts: Helvetica
\usepackage{helvet}
\IfFileExists{sfmath.sty}{
\RequirePackage[helvet]{sfmath}
}{}
\renewcommand{\sfdefault}{phv}
\renewcommand{\rmdefault}{phv}
\newcommandx{\exmchoice}[9][2=-,3=-,4=-,5=-,6=-,7=-,8=-,9=-]{%
\CheckBox[name=a, width=1em]{(a)}~~%
\if #2- \else \CheckBox[name=b, width=1em]{(b)}~~ \fi%
\if #3- \else \CheckBox[name=c, width=1em]{(c)}~~ \fi%
\if #4- \else \CheckBox[name=d, width=1em]{(d)}~~ \fi%
\if #5- \else \CheckBox[name=e, width=1em]{(e)}~~ \fi%
\if #6- \else \CheckBox[name=f, width=1em]{(f)}~~ \fi%
\if #7- \else \CheckBox[name=g, width=1em]{(g)}~~ \fi%
\if #8- \else \CheckBox[name=h, width=1em]{(h)}~~ \fi%
\if #9- \else \CheckBox[name=i, width=1em]{(i)}~~ \fi%
}
\newcommandx{\exclozechoice}[9][2=-,3=-,4=-,5=-,6=-,7=-,8=-,9=-]{\setcounter{enumiii}{1}%
\CheckBox[name=ca, width=1em]{\roman{enumiii}.} \stepcounter{enumiii}%
\if #2- \else \CheckBox[name=cb, width=1em]{\roman{enumiii}.} \stepcounter{enumiii} \fi%
\if #3- \else \CheckBox[name=cc, width=1em]{\roman{enumiii}.} \stepcounter{enumiii} \fi%
\if #4- \else \CheckBox[name=cd, width=1em]{\roman{enumiii}.} \stepcounter{enumiii} \fi%
\if #5- \else \CheckBox[name=ce, width=1em]{\roman{enumiii}.} \stepcounter{enumiii} \fi%
\if #6- \else \CheckBox[name=cf, width=1em]{\roman{enumiii}.} \stepcounter{enumiii} \fi%
\if #7- \else \CheckBox[name=cg, width=1em]{\roman{enumiii}.} \stepcounter{enumiii} \fi%
\if #8- \else \CheckBox[name=ch, width=1em]{\roman{enumiii}.} \stepcounter{enumiii} \fi%
\if #9- \else \CheckBox[name=ci, width=1em]{\roman{enumiii}.} \fi%
}
\newcommand{\exnum}[9]{\TextField[name=num, width=4cm]{}}
\newcommand{\exstring}[1]{\TextField[name=string, width=4cm]{}}
%% new commands
\makeatletter
\newcommand{\ID}[1]{\def\#ID{#1}}
\newcommand{\Date}[1]{\def\#Date{#1}}
\ID{00001}
\Date{YYYY-MM-DD}
%% \exinput{header}
\newcommand{\myID}{\#ID}
\newcommand{\myDate}{\#Date}
\makeatother
%% headings
\markboth{\textnormal{\bf \large Statistics Exam: \myID}}%
{\textnormal{\bf \large Statistics Exam: \myID}}
\pagestyle{myheadings}
\begin{document}
%% title page
\thispagestyle{empty}
{\sf
\textbf{\LARGE{R University}}
\textbf{\large{Statistics Exam \myDate \hfill Exam ID \myID}}
\vspace*{2cm}
\begin{Form}[action=mailto:info#example.com,encoding=html,method=post]
\begin{tabular}{ll}
\textbf{Name} & \TextField[name=Name, width=10cm]{}\\
\textbf{Student ID} & \TextField[name=ID, width=10cm]{}\\
\end{tabular}
\vspace*{1cm}
%%% \begin{multicols}{2}
%% \exinput{questionnaire}
%%% \end{multicols}
\Submit{Submit} ~~ \Reset{Clear}
\end{Form}
}
\newpage
\begin{enumerate}
%% \exinput{exercises}
\end{enumerate}
\end{document}
we will structure our exam like this:
students download pdf created with exams2nops
students open pdfs with Adobe Acrobat Reader DC (free: https://get.adobe.com/de/reader/?promoid=P79NQR4R&mv=other) and mark the boxes with X via the "sign" option
students upload the first filled page of the exam back (via print to pdf). The advantage of this is that the set crosses can no longer be changed.
normal evaluation process of exams starts...
Related
I am using a latex template to create a beamer presentation in R markdown. Everything works fine, except that the page number is not showing in the foot line. I went through the latex template code and still cannot figure out what's wrong there. Any contributions are welcome.
You should be able to clone from my github. In the template code, I suspect the problem might be around the \defbeamertemplate*{footline}{my footline} code chunk. We might directly navigate to that code chunk and figure out the glitch.
As requested by one of contributors in the comment section, I uploaded the generated .tex file below.
\documentclass[10pt,ignorenonframetext,,aspectratio=149]{beamer}
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{caption label separator}{: }
\setbeamercolor{caption name}{fg=normal text.fg}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\else % if luatex or xelatex
\ifxetex
\usepackage{mathspec}
\else
\usepackage{fontspec}
\fi
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\newcommand{\euro}{€}
\fi
% 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
}{}
% Comment these out if you don't want a slide with just the
% part/section/subsection/subsubsection title:
\AtBeginPart{
\let\insertpartnumber\relax
\let\partname\relax
\frame{\partpage}
}
\AtBeginSection{
\let\insertsectionnumber\relax
\let\sectionname\relax
\frame{\sectionpage}
}
\AtBeginSubsection{
\let\insertsubsectionnumber\relax
\let\subsectionname\relax
\frame{\subsectionpage}
}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}
\title{Weekly GAMS Meeting}
\author{Yabin Da}
\date{2020-10-15}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{longtable}
\usepackage{threeparttable}
\usepackage{xcolor}
\usepackage{amsmath}
%% Here's everything I added.
%%--------------------------
\usepackage{graphicx}
\usepackage{rotating}
%\setbeamertemplate{caption}[numbered]
\usepackage{hyperref}
\usepackage{caption}
\usepackage[normalem]{ulem}
%\mode<presentation>
\usepackage{wasysym}
%\usepackage{amsmath}
% Get rid of navigation symbols.
%-------------------------------
\setbeamertemplate{navigation symbols}{}
% Optional institute tags and titlegraphic.
% Do feel free to change the titlegraphic if you don't want it as a Markdown field.
%----------------------------------------------------------------------------------
\institute{Department of Agricultural Economics}
% <-- Somehow, the if sentence below did not work for me. I, therefore, placed the absolute path below and it worked.
\titlegraphic{\includegraphics[width=0.4\paperwidth]{C:/work/Study/Y 2020/Ozone in China/report/tamu/tamu.png}}
% -----------------------------------------------------------------------------------------------------
%
% Some additional title page adjustments.
%----------------------------------------
\setbeamertemplate{title page}[empty]
%\date{}
\setbeamerfont{subtitle}{size=\small}
\setbeamercovered{transparent}
% Some optional colors. Change or add as you see fit.
%---------------------------------------------------
\definecolor{tamumaroon}{HTML}{500000}
\definecolor{tamuwhite}{HTML}{FFFFFF}
\definecolor{uiucblue}{HTML}{003C7D}
\definecolor{uiucorange}{HTML}{F47F24}
% Some optional color adjustments to Beamer. Change as you see fit.
%------------------------------------------------------------------
\setbeamercolor{frametitle}{fg=tamuwhite,bg=tamumaroon}
\setbeamercolor{title}{fg=tamuwhite,bg=tamumaroon}
\setbeamercolor{local structure}{fg=tamumaroon}
\setbeamercolor{section in toc}{fg=tamuwhite,bg=tamumaroon}
\setbeamercolor{subsection in toc}{fg=tamuwhite,bg=tamumaroon}
\setbeamercolor{footline}{fg=tamuwhite, bg=tamumaroon}
\setbeamercolor{block title}{fg=tamuwhite, bg=tamumaroon}
\let\Tiny=\tiny
% Sections and subsections should not get their own damn slide.
%--------------------------------------------------------------
\AtBeginPart{}
\AtBeginSection{}
\AtBeginSubsection{}
\AtBeginSubsubsection{}
% Suppress some of Markdown's weird default vertical spacing.
%------------------------------------------------------------
\setlength{\emergencystretch}{0em} % prevent overfull lines
\setlength{\parskip}{0pt}
% Allow for those simple two-tone footlines I like.
% Edit the colors as you see fit.
%--------------------------------------------------
\defbeamertemplate*{footline}{my footline}{%
\ifnum\insertpagenumber=1
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=.8ex,dp=1ex,center]{}%
% empty environment to raise height
\end{beamercolorbox}%
}%
\vskip0pt%
\else%
\Tiny{%
\hfill%
\vspace*{1pt}%
\insertframenumber/\inserttotalframenumber \hspace*{0.1cm}%
\newline%
\color{tamumaroon}{\rule{\paperwidth}{0.4mm}}\newline%
\color{tamumaroon}{\rule{\paperwidth}{.4mm}}%
}%
\fi%
}
% Various cosmetic things, though I must confess I forget what exactly these do and why I included them.
%-------------------------------------------------------------------------------------------------------
\setbeamercolor{structure}{fg=blue}
\setbeamercolor{local structure}{parent=structure}
\setbeamercolor{item projected}{parent=item,use=item,fg=tamumaroon,bg=white}
\setbeamercolor{enumerate item}{parent=item}
% Adjust some item elements. More cosmetic things.
%-------------------------------------------------
\setbeamertemplate{itemize item}{\color{tamumaroon}$\bullet$}
\setbeamertemplate{itemize subitem}{\color{tamumaroon}\scriptsize{$\bullet$}}
\setbeamertemplate{itemize/enumerate body end}{\vspace{.6\baselineskip}} % So I'm less inclined to use \medskip and \bigskip in Markdown.
% Automatically center images
% ---------------------------
% Note: this is for ![](image.png) images
% Use "fig.align = "center" for R chunks
% \usepackage{etoolbox}
%
% \AtBeginDocument{%
% \letcs\oig{#orig\string\includegraphics}%
% \renewcommand<>\includegraphics[2][]{%
% \only#3{%
% {\centering\oig[{#1}]{#2}\par}%
% }%
% }%
% }
% I think I've moved to xelatex now. Here's some stuff for that.
% --------------------------------------------------------------
% I could customize/generalize this more but the truth is it works for my circumstances.
\ifxetex
\setbeamerfont{title}{family=\fontspec{serif}}
\setbeamerfont{frametitle}{family=\fontspec{serif}}
\usepackage[font=small,skip=0pt]{caption}
\else
\fi
% Okay, and begin the actual document...
\begin{document}
\frame{\titlepage}
\hypertarget{meeting-on-october-15}{%
\section{Meeting on October 15}\label{meeting-on-october-15}}
\begin{frame}{Potential problems}
\protect\hypertarget{potential-problems}{}
\begin{itemize}
\item
The current optimization model is not easy to maximum over a set of
objectives. That is because we only have one single objective
function.
\item
Even though we include multiple envrionmental benefits into the
objective function, since the units are different, we cannot simply
sum over those benefits and then maximize the benefit.
\item
I guess the unit is pounds per acre for environmental losses and
dollars per acre for cost. The scale factor for unit is 1000.
\end{itemize}
\end{frame}
\section[]{}
\frame{\small \frametitle{Table of Contents}
\tableofcontents}
\end{document}
The frame numbers become visible if you set them in any other colour than white:
\documentclass[10pt,ignorenonframetext,,aspectratio=149]{beamer}
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{caption label separator}{: }
\setbeamercolor{caption name}{fg=normal text.fg}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\else % if luatex or xelatex
\ifxetex
\usepackage{mathspec}
\else
\usepackage{fontspec}
\fi
\defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\newcommand{\euro}{€}
\fi
% 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
}{}
% Comment these out if you don't want a slide with just the
% part/section/subsection/subsubsection title:
\AtBeginPart{
\let\insertpartnumber\relax
\let\partname\relax
\frame{\partpage}
}
\AtBeginSection{
\let\insertsectionnumber\relax
\let\sectionname\relax
\frame{\sectionpage}
}
\AtBeginSubsection{
\let\insertsubsectionnumber\relax
\let\subsectionname\relax
\frame{\subsectionpage}
}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}
\title{Weekly GAMS Meeting}
\author{Yabin Da}
\date{2020-10-15}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{longtable}
\usepackage{threeparttable}
\usepackage{xcolor}
\usepackage{amsmath}
%% Here's everything I added.
%%--------------------------
\usepackage{graphicx}
\usepackage{rotating}
%\setbeamertemplate{caption}[numbered]
\usepackage{hyperref}
\usepackage{caption}
\usepackage[normalem]{ulem}
%\mode<presentation>
\usepackage{wasysym}
%\usepackage{amsmath}
% Get rid of navigation symbols.
%-------------------------------
\setbeamertemplate{navigation symbols}{}
% Optional institute tags and titlegraphic.
% Do feel free to change the titlegraphic if you don't want it as a Markdown field.
%----------------------------------------------------------------------------------
\institute{Department of Agricultural Economics}
% <-- Somehow, the if sentence below did not work for me. I, therefore, placed the absolute path below and it worked.
\titlegraphic{\includegraphics[width=0.4\paperwidth]{example-image}}
% -----------------------------------------------------------------------------------------------------
%
% Some additional title page adjustments.
%----------------------------------------
\setbeamertemplate{title page}[empty]
%\date{}
\setbeamerfont{subtitle}{size=\small}
\setbeamercovered{transparent}
% Some optional colors. Change or add as you see fit.
%---------------------------------------------------
\definecolor{tamumaroon}{HTML}{500000}
\definecolor{tamuwhite}{HTML}{FFFFFF}
\definecolor{uiucblue}{HTML}{003C7D}
\definecolor{uiucorange}{HTML}{F47F24}
% Some optional color adjustments to Beamer. Change as you see fit.
%------------------------------------------------------------------
\setbeamercolor{frametitle}{fg=tamuwhite,bg=tamumaroon}
\setbeamercolor{title}{fg=tamuwhite,bg=tamumaroon}
\setbeamercolor{local structure}{fg=tamumaroon}
\setbeamercolor{section in toc}{fg=tamuwhite,bg=tamumaroon}
\setbeamercolor{subsection in toc}{fg=tamuwhite,bg=tamumaroon}
\setbeamercolor{footline}{fg=tamuwhite, bg=tamumaroon}
\setbeamercolor{block title}{fg=tamuwhite, bg=tamumaroon}
\let\Tiny=\tiny
% Sections and subsections should not get their own damn slide.
%--------------------------------------------------------------
\AtBeginPart{}
\AtBeginSection{}
\AtBeginSubsection{}
\AtBeginSubsubsection{}
% Suppress some of Markdown's weird default vertical spacing.
%------------------------------------------------------------
\setlength{\emergencystretch}{0em} % prevent overfull lines
\setlength{\parskip}{0pt}
% Allow for those simple two-tone footlines I like.
% Edit the colors as you see fit.
%--------------------------------------------------
\defbeamertemplate*{footline}{my footline}{%
\ifnum\insertpagenumber=1
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=.8ex,dp=1ex,center]{}%
% empty environment to raise height
\end{beamercolorbox}%
}%
\vskip0pt%
\else%
\color{tamumaroon}%
\Tiny{%
\hfill%
\vspace*{1pt}%
\insertframenumber/\inserttotalframenumber \hspace*{0.1cm}%
\newline%
\color{tamumaroon}{\rule{\paperwidth}{0.4mm}}\newline%
\color{tamumaroon}{\rule{\paperwidth}{.4mm}}%
}%
\fi%
}
% Various cosmetic things, though I must confess I forget what exactly these do and why I included them.
%-------------------------------------------------------------------------------------------------------
\setbeamercolor{structure}{fg=blue}
\setbeamercolor{local structure}{parent=structure}
\setbeamercolor{item projected}{parent=item,use=item,fg=tamumaroon,bg=white}
\setbeamercolor{enumerate item}{parent=item}
% Adjust some item elements. More cosmetic things.
%-------------------------------------------------
\setbeamertemplate{itemize item}{\color{tamumaroon}$\bullet$}
\setbeamertemplate{itemize subitem}{\color{tamumaroon}\scriptsize{$\bullet$}}
\setbeamertemplate{itemize/enumerate body end}{\vspace{.6\baselineskip}} % So I'm less inclined to use \medskip and \bigskip in Markdown.
% Automatically center images
% ---------------------------
% Note: this is for ![](image.png) images
% Use "fig.align = "center" for R chunks
% \usepackage{etoolbox}
%
% \AtBeginDocument{%
% \letcs\oig{#orig\string\includegraphics}%
% \renewcommand<>\includegraphics[2][]{%
% \only#3{%
% {\centering\oig[{#1}]{#2}\par}%
% }%
% }%
% }
% I think I've moved to xelatex now. Here's some stuff for that.
% --------------------------------------------------------------
% I could customize/generalize this more but the truth is it works for my circumstances.
\ifxetex
\setbeamerfont{title}{family=\fontspec{serif}}
\setbeamerfont{frametitle}{family=\fontspec{serif}}
\usepackage[font=small,skip=0pt]{caption}
\else
\fi
% Okay, and begin the actual document...
\begin{document}
\frame{\titlepage}
\hypertarget{meeting-on-october-15}{%
\section{Meeting on October 15}\label{meeting-on-october-15}}
\begin{frame}{Potential problems}
\protect\hypertarget{potential-problems}{}
\begin{itemize}
\item
The current optimization model is not easy to maximum over a set of
objectives. That is because we only have one single objective
function.
\item
Even though we include multiple envrionmental benefits into the
objective function, since the units are different, we cannot simply
sum over those benefits and then maximize the benefit.
\item
I guess the unit is pounds per acre for environmental losses and
dollars per acre for cost. The scale factor for unit is 1000.
\end{itemize}
\end{frame}
\section[]{}
\frame{\small \frametitle{Table of Contents}
\tableofcontents}
\end{document}
Some unrelated remarks:
\usepackage{amssymb,amsmath} is unnecessary, beamer loads this
\usepackage{fixltx2e}, \usepackage{microtype} and \usepackage[utf8]{inputenc} unnecessary if your tex distribution is reasonable new. That's default now
you don't need \usepackage{caption} with beamer, beamer has its own mechanism to deal with captions
xcolor, hyperref and graphicx is not necessary, beamer loads it
several package are loaded multiple times
first setting \AtBeginPart etc and clearing it later makes not much sense
\frame{} only works for lecagy reasons, use \begin{frame}...\end{frame} instead
I am unable to compile an Rmd file using tinytex via RStudio. I can compile the same file without issues on another computer that has a full LaTeX installation.
I have written my CV using the moderncv class in RMarkdown. I have a full LaTeX distribution installed on one of my computers and I can compile the CV without any problems. On my new computer I have installed TinyTex via the r package tinytex and use it to compile Rmd files to pdf via RStudio. For some reason I cannot compile the same document on my new computer when using tinytex. I have tried manually installing all of the packages I load in my preamble without luck. My preliminary searches have not uncovered in problems similar to this one. I am using the kjh-vita template provided by Kieran Healy, though it has been modified to work with Rmd.
I've noticed that if I set the keep_tex YAML argument to yes that the .tex file that is produced is escaping out all of the curly braces (see image). The green portion is how it should look (i.e., how it looks in my .Rmd file) and the red portion is what is produced in the .tex file after knitting the document.
I believe the solution to my problem involves getting tinytex to stop escaping all of the curly braces in the file. I have no idea why this is happening or how to get it to stop.
update: add minimal working example
% Basic preamble
\documentclass[11pt,letterpaper]{moderncv}
% Pull from header includes
% moderncv themes
\moderncvtheme[black]{classic} % optional argument are 'blue' (default),
% 'orange', 'green', 'red', 'purple',
% 'grey' and 'roman' (for roman fonts,
% instead of sans serif fonts)
%\usepackage{assets/tex/moderncvthemeclassic}
%\usepackage[utf8]{inputenc} %character encoding
%\usepackage{hyperref}
\usepackage{url,fancyhdr}
% needed for xelatex to work
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xcolor}
% my additions:
% include ipa and bib formatting
\let\sups\relax
\usepackage{tipa}
\usepackage{multicol}
\usepackage[spanish, english]{babel}
\usepackage{natbib}
\usepackage{bibentry}
\newcommand{\bibverse}[1]{\begin{verse} \bibentry{#1}. \end{verse}}
\usepackage{hanging}
\usepackage{fontawesome5}
\usepackage{academicons}
% adjust the page margins
\usepackage[scale=0.8]{geometry}
%\setlength{\hintscolumnwidth}{3cm} % if you want to change the
% width of the column with the
% dates
%\setlength{\maketitlenamewidth}{10cm}} % only for the classic theme,
% if you want to change the
% width of your name placeholder
% (to leave more space for your
% address details
% Personal data
\firstname{Person}
\familyname{Name}
\title{Assistant Professor}
\address{Some University \\
Department of Stuff}{City, State 08401}
% \mobile{}
\phone{(456) 921-6345}
%\fax{(456) 921-6345}
\email{anemail#mail.edu}
\homepage{www.page.com}
% \extrainfo{}
\def\mytitle{Professor}
\def\myphone{(456) 921-6345}
\def\myskype{myskype}
\def\myemail{jmymail#mail.edu}
\def\myweb{www.page.com}
\def\facweb{https://www.page.com}
\def\school{Some University}
\def\schoolweb{http://www.page.edu}
%\nopagenumbers{} % uncomment to suppress automatic page numbering for CVs
% longer than one page
\begin{document}
\bigskip
\vspace{.1in}
\noindent{\huge {\textsc{My Name}, Ph.D.}}
\reversemarginpar
\noindent
\rule{492pt}{1.5pt}
\vspace{-0.1in}
\begin{minipage}[t]{2.4in}
\flushleft
\href{\schoolweb}{\school} \\
My buildin \\
15 Street place \\
Street, \textsc{State} 08305
\end{minipage}
\hfill
\begin{minipage}[t]{1.7in}
\flushleft
\faUniversity \phantom{-}\href{\facweb}{Faculty page} \\
\faPhone \phantom{-}\myphone \\
\faPaperPlane \phantom{-}\href{\myemail}{\texttt{\myemail}} \\
\faHome \phantom{-}\href{https://www.page.com}{\texttt{\myweb}} \\
\end{minipage}
\hfill
\begin{minipage}[t]{1.7in}
\flushright
Google scholar: \href{http://www.page.com}{\aiGoogleScholar} \\
ResearchGate: \href{http://www.page.com}{\aiResearchGate} \\
#jvcasillas \href{https://www.github.com/}{\faGithub} \\
#jvcasill \href{https://www.twitter.com/}{\faTwitter}
\end{minipage}
\vspace{0.1in}
\section{Appointments}
\cventry{2016 -- Present}
{\mytitle}
{Some University, Place}
{}
{}
{Name of program,
Department of stuff}
\end{document}
After pandoc version 2.5 the \cventry{} lines are not correctly parsed into latex. Specifically, this was what was causing the problems:
\cventry{2016 -- Present}
{\mytitle}
{Some University, Place}
{}
{}
{Name of program,
Department of stuff}
I can knit the document that contains the above code with pandoc 2.5. Any version above 2.5 must be written as follows:
\cventry{2016 -- Present}{\mytitle}{Some University, Place}{}{}{Name of program, Department of stuff}
Pandoc inserts an escape character \{\} whenever there is blank space (as seen in the image above).
I am writing a paper in R markdown and need to format it with this .cls file supplied by an academic journal.
A minimal .tex file compiles perfectly well with the above cls file.
My .tex file (compiled on ShareLaTeX with clv3.cls saved in same directory):
\documentclass[shortpaper]{clv3}
\usepackage[utf8]{inputenc}
\title{Paper title}
\author{Name Surname}
\date{May 2018}
\begin{document}
\maketitle
\section{Introduction}
Some text.
\end{document}
However a comparable minimal document in R markdown, using the same cls file, fails to compile in Rstudio, with the following error: ! Package geometry Error: \paperwidth (0.0pt) too short.
My Rmd file (with clv3.cls file saved in same directory):
---
title: "Paper title"
author: "Name Surname"
documentclass: clv3
classoption: shortpaper
output: pdf_document
---
# Introduction
Some text.
Why is this error induced when I try to use this class file with an R markdown document and how may I fix it?
I've tried manually specifying a pagewidth setting in the YAML header, but I don't really know what I'm doing. This seems undesirable anyway, since the normal LaTeX document works fine without it (and surely page width is something that should be specified by a journal, not manually overwritten by an author).
I do not know where exactly the clv3.cls class and the default pandoc template clash. However, that template does so many things that do not make sense when writing with a specific style, that is best to use your own template. Using clv3-template.tex
\documentclass[shortpaper]{clv3}
\usepackage[utf8]{inputenc}
$if(title)$
\title{$title$}
$else$
\title{}
$endif$
$if(author)$
\author{$for(author)$$author$$sep$ \\ $endfor$}
$else$
\author{}
$endif$
\begin{document}
$if(title)$
\maketitle
$endif$
$body$
\end{document}
together with
---
title: "Paper title"
author: "Name Surname"
output:
pdf_document:
template:
clv3-template.tex
---
# Introduction
Some text.
should be a good starting point.
The accepted answer works perfectly for the minimal example presented. However it breaks again pretty quickly as the document is made more complex (for example, inserting a bibliography and in-text citations). I'd like to expand a little on my solution for the potential benefit of any future readers, as I found it a bit of steep learning curve:
The issue here is that Pandoc has a LaTeX template, which it uses to produce PDF documents. This is separate from a .cls class file, which defines a document class. Like Ralf Stubner says, something about my particular class file was not cooperating with Pandoc's default template. This is probably super basic and obvious to many, but I had not appreciated this extra step nor understood the distinction between these files.
If one does not wish to deal with raw LaTeX, it seems there are quite a few templates out there for various kinds of documents (see, for example, the rticle package). Using R Markdown to produce a PDF document in a particular custom format (such as for a particular journal) will require construction of a LaTeX template, however. This can be done by either of two ways:
Tinkering with an existing template until you get what you need, either by finding Pandoc's default template and starting from there (see comment by user2554330 for location) or by cloning someone else's template on Github etc.
Writing a template from scratch. In this case, Ralf Stubner's minimal example above plus this section of the Pandoc manual will be informative.
In my case, I went with the latter option. I have saved my eventual template as an R package which can be installed using devtools::install_github("JaydenM-C/CLtemplate"). So if anyone else would ever like to author a document for Computational Linguistics using this particular document style, this may save you some time.
I'd like to include an example of complete LaTeX code inside an Rnw document that is parsed using knitr.
My .Rnw file is shown here (I really want to include a bunch of R code as well but this minimal example shows my problem)
\documentclass{article}
\begin{document}
Recursiveness, see
\begin{verbatim}
\documentclass{article}
\begin{document}
Recursiveness
\end{document}
\end{verbatim}
\end{document}
When I run knitr test.Rnw I get a .tex file where the second documentclass is replaced (see below, where the top of the .tex file is shown). I'm pretty sure that this is knitr that replaces the litaral string \documentclass with its own macro that and it does not realize that it shouldn't be parsen when inside the verbatim environment.
\documentclass{article}
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\begin{document}
Recursiveness, see
\begin{verbatim}
\documentclass{article}\usepackage[]{graphicx}\usepackage[]{color}
%% maxwidth is the original width if it is less than linewidth
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
\ifdim\Gin#nat#width>\linewidth
\linewidth
\else
\Gin#nat#width
\fi
}
\makeatother
Is it possible to circumvent this? I tried to insert a zero-width space character in the middle of documentclass but that gave me a bunch of headaches with the parsing.
This is a bug and should be fixed in the current development version of knitr (>= 1.12.22) now.
I'm trying to transfer a LaTeX/LyX presentation into a Beamer markdown document.
On some slides I suspend the background image (which has logos of funding bodies on it) to make more space for code output.
I previously did this with the following command:
\bgroup
\usebackgroundtemplate{\includegraphics[width=\paperwidth]{background.png}}
\begin{frame}[plain]
Some text here!}
\end{frame}
\egroup
I have tried something like this (which doesn't work):
\bgroup
\pgfdeclareimage[width=\paperwidth]{empty}{Template_blank.png}
\usebackgroundtemplate{\pgfuseimage{empty}}
## New Slide
some text
\egroup
Any ideas?
Normally switching between different background templates is a piece of cake in beamer, based on https://tex.stackexchange.com/questions/173201/beamer-template-with-different-style-options-for-frames one can simply create a new frame option.
Unfortunately rmarkdown simply ignores user created frame options and only passes on a tiny list of predefined options. To trick rmarkdown one could repurpose a frame option which is normally not used by beamer, the standout frame option (it is only used by the metropolis theme)
---
output:
beamer_presentation:
keep_tex: true
includes:
header-includes: |
\usepackage{etoolbox}
\defbeamertemplate{background canvas}{mydefault}{%
\includegraphics[width=\paperwidth,height=\paperheight]{example-image-duck}
}
\defbeamertemplate{background canvas}{standout}{%
\includegraphics[width=\paperwidth,height=\paperheight,page=2]{example-image-duck}
}
\BeforeBeginEnvironment{frame}{%
\setbeamertemplate{background canvas}[mydefault]%
}
\makeatletter
\define#key{beamerframe}{standout}[true]{%
\setbeamertemplate{background canvas}[standout]%
}
\makeatother
---
# frametitle
test
# frametitle with different background {.standout}
test
# frametitle
test