diff --git a/R/stat_exercise.R b/R/stat_exercise.R index 35e50be..5b9a70e 100644 --- a/R/stat_exercise.R +++ b/R/stat_exercise.R @@ -15,6 +15,7 @@ stat_exercise <- function(...) { toc = FALSE, number_sections = FALSE, template = template, + citation_package = "biblatex", ... ) diff --git a/inst/rmarkdown/templates/stat_exercise/resources/template.tex b/inst/rmarkdown/templates/stat_exercise/resources/template.tex index cfc9482..b3026a2 100644 --- a/inst/rmarkdown/templates/stat_exercise/resources/template.tex +++ b/inst/rmarkdown/templates/stat_exercise/resources/template.tex @@ -1,88 +1,135 @@ \documentclass[a4paper, 11pt]{article} -$if(fontfamily)$ -\usepackage{$fontfamily$} + +\usepackage{lmodern} % Latin modern fonts +\usepackage[margin=2cm, bottom=2.5cm]{geometry} % Margins +\usepackage{amssymb,amsmath} % Math packages +\usepackage{fancyhdr} % For creating header +\usepackage{lastpage} % For page count +\usepackage{bm} % Bolded letters, e.g. for matrices and vectors +\usepackage{mathspec} +\usepackage{xltxtra, xunicode} +\usepackage{listings} +\usepackage{longtable,booktabs} +\usepackage{xcolor} + +\providecommand{\tightlist}{% + \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} + +% Create header +\pagestyle{fancy} +\setlength{\headheight}{35.10004pt} +\fancypagestyle{plain}{\pagestyle{fancy}} +\fancyhead[L]{$course-name$ \\ +$department$ \\ +$university$} +\fancyhead[R]{$lecturer$ / $assistant$ \\ +Fall 2023 \\ +\textbf{$exercise-name$}} + +% Create footer +\fancyfoot[R]{\thepage\ / \pageref*{LastPage}} +\fancyfoot[C]{} + +\usepackage{polyglossia} +\setmainlanguage{english} + +$if(csl-refs)$ +% Pandoc citation processing +$if(pandoc318)$ +%From Pandoc 3.1.8 +% definitions for citeproc citations +\NewDocumentCommand\citeproctext{}{} +\NewDocumentCommand\citeproc{mm}{% + \begingroup\def\citeproctext{#2}\cite{#1}\endgroup} +\makeatletter + % allow citations to break across lines + \let\@cite@ofmt\@firstofone + % avoid brackets around text for \cite: + \def\@biblabel#1{} + \def\@cite#1#2{{#1\if@tempswa , #2\fi}} +\makeatother +\newlength{\cslhangindent} +\setlength{\cslhangindent}{1.5em} +\newlength{\csllabelwidth} +\setlength{\csllabelwidth}{3em} +\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing + {\begin{list}{}{% + \setlength{\itemindent}{0pt} + \setlength{\leftmargin}{0pt} + \setlength{\parsep}{0pt} + % turn on hanging indent if param 1 is 1 + \ifodd #1 + \setlength{\leftmargin}{\cslhangindent} + \setlength{\itemindent}{-1\cslhangindent} + \fi + % set entry spacing + \setlength{\itemsep}{#2\baselineskip}}} + {\end{list}} +$else$$if(pandoc317)$ +% definitions for citeproc citations +\NewDocumentCommand\citeproctext{}{} +\NewDocumentCommand\citeproc{mm}{% + \begingroup\def\citeproctext{#2}\cite{#1}\endgroup} +% avoid brackets around text for \cite: +\makeatletter + \def\@biblabel#1{} + \def\@cite#1#2{{#1\if@tempswa , #2\fi}} +\makeatother +\newlength{\cslhangindent} +\setlength{\cslhangindent}{1.5em} +\newlength{\csllabelwidth} +\setlength{\csllabelwidth}{3em} +\newlength{\cslentryspacing} +\setlength{\cslentryspacing}{0em} +\usepackage{enumitem} +\newlist{CSLReferences}{itemize}{1} +\setlist[CSLReferences]{label={}, + leftmargin=\cslhangindent, + itemindent=-1\cslhangindent, + parsep=\parskip, + itemsep=\cslentryspacing} $else$ -\usepackage{lmodern} -$endif$ -$if(linestretch)$ -\usepackage{setspace} -\setstretch{$linestretch$} -$endif$ -\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} -$if(euro)$ - \usepackage{eurosym} -$endif$ -\else % if luatex or xelatex - \ifxetex - \usepackage{mathspec} - \usepackage{xltxtra,xunicode} - \else - \usepackage{fontspec} +\newlength{\cslhangindent} +\setlength{\cslhangindent}{1.5em} +\newlength{\csllabelwidth} +\setlength{\csllabelwidth}{3em} +\newlength{\cslentryspacingunit} % times entry-spacing +\setlength{\cslentryspacingunit}{\parskip} +% for Pandoc 2.8 to 2.10.1 +\newenvironment{cslreferences}% + {$if(csl-hanging-indent)$\setlength{\parindent}{0pt}% + \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces$endif$}% + {\par} +% For Pandoc 2.11+ +\newenvironment{CSLReferences}[2] % #1 hanging-ident, #2 entry spacing + {% don't indent paragraphs + \setlength{\parindent}{0pt} + % turn on hanging indent if param 1 is 1 + \ifodd #1 + \let\oldpar\par + \def\par{\hangindent=\cslhangindent\oldpar} \fi - \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase} - \newcommand{\euro}{€} -$if(mainfont)$ - \setmainfont{$mainfont$} -$endif$ -$if(sansfont)$ - \setsansfont{$sansfont$} -$endif$ -$if(monofont)$ - \setmonofont[Mapping=tex-ansi]{$monofont$} -$endif$ -$if(mathfont)$ - \setmathfont(Digits,Latin,Greek){$mathfont$} -$endif$ -\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 -}{} -$if(geometry)$ -\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry} -$endif$ -$if(lang)$ -\ifxetex - \usepackage{polyglossia} - \setmainlanguage{$mainlang$} -\else - \usepackage[shorthands=off,$lang$]{babel} -\fi -$endif$ -$if(natbib)$ -\usepackage{natbib} -\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$} -$endif$ -$if(biblatex)$ -\usepackage{biblatex} -$if(biblio-files)$ -\bibliography{$biblio-files$} -$endif$ -$endif$ -$if(listings)$ -\usepackage{listings} + % set entry spacing + \setlength{\parskip}{#2\cslentryspacingunit} + }% + {} +$endif$$endif$ +\usepackage{calc} +\newcommand{\CSLBlock}[1]{#1\hfill\break} +\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}} +\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break} +\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1} $endif$ -$if(lhs)$ -\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} + +$if(bibliography)$ +\usepackage[style=authoryear]{biblatex} +\bibliography{$bibliography$} $endif$ + $if(highlighting-macros)$ $highlighting-macros$ $endif$ -$if(verbatim-in-note)$ -\usepackage{fancyvrb} -\VerbatimFootnotes -$endif$ -$if(tables)$ -\usepackage{longtable,booktabs} -$endif$ + $if(graphics)$ \usepackage{graphicx} \makeatletter @@ -111,71 +158,17 @@ linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$, pdfborder={0 0 0}} \urlstyle{same} % don't use monospace font for urls -$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 + $if(numbersections)$ \setcounter{secnumdepth}{5} $else$ \setcounter{secnumdepth}{0} $endif$ -$if(verbatim-in-note)$ -\VerbatimFootnotes % allows verbatim text in footnotes -$endif$ - -%%% Use protect on footnotes to avoid problems with footnotes in titles -\let\rmarkdownfootnote\footnote% -\def\footnote{\protect\rmarkdownfootnote} - -$if(compact-title)$ -%%% Change title format to be more compact -\usepackage{titling} - -% Create subtitle command for use in maketitle -\newcommand{\subtitle}[1]{ - \posttitle{ - \begin{center}\large#1\end{center} - } -} - -\setlength{\droptitle}{-2em} -$endif$ - -\usepackage{fancyhdr} % For creating header -\usepackage{lastpage} % For page count - -% Create header -\pagestyle{fancy} -\setlength{\headheight}{35.10004pt} -\fancypagestyle{plain}{\pagestyle{fancy}} -\fancyhead[L]{$course-name$ \\ -$department$ \\ -$university$} -\fancyhead[R]{$lecturer$ / $assistant$ \\ -Fall 2023 \\ -\textbf{$exercise-name$}} - -% Create footer -\fancyfoot[R]{\thepage\ / \pageref{LastPage}} -\fancyfoot[C]{} - -\title{ -\noindent -\large\textbf{$title$} \hfill \textbf{$first-name$ $last-name$} \\ -\normalsize Module: $module$ \hfill Team members: $for(teammates)$$teammates$$sep$, $endfor$ \\ -Module Lead: $module-lead$ \hfill Lab Date: $lab-date$ \\ -Lab Lead: $TA$ \hfill Due Date: $due-date$ -} -\date{\vspace{-5ex}} $for(header-includes)$ $header-includes$ @@ -183,57 +176,18 @@ \begin{document} -$if(title)$ -\maketitle -$endif$ - -$if(abstract)$ -\begin{abstract} -$abstract$ -\end{abstract} -$endif$ - $for(include-before)$ $include-before$ - $endfor$ -$if(toc)$ -{ -\hypersetup{linkcolor=black} -\setcounter{tocdepth}{$toc-depth$} -\tableofcontents -} -$endif$ -$if(lot)$ -\listoftables -$endif$ -$if(lof)$ -\listoffigures -$endif$ - - $body$ -$if(natbib)$ -$if(biblio-files)$ -$if(biblio-title)$ -$if(book-class)$ -\renewcommand\bibname{$biblio-title$} -$else$ -\renewcommand\refname{$biblio-title$} -$endif$ -$endif$ -\bibliography{$biblio-files$} - -$endif$ +$if(bibliography)$ +\printbibliography[title=References] $endif$ -$if(biblatex)$ -\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$ -$endif$ $for(include-after)$ $include-after$ - $endfor$ + \end{document} diff --git a/inst/rmarkdown/templates/stat_exercise/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/stat_exercise/skeleton/skeleton.Rmd index fc31c48..8b48ab0 100644 --- a/inst/rmarkdown/templates/stat_exercise/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/stat_exercise/skeleton/skeleton.Rmd @@ -1,27 +1,45 @@ --- -title: "Untitled" course-name: Statistics Course exercise-name: Exercise Set 0 university: Aalto University department: Department of Mathematics and Systems Analysis -lecturer: M. Luennoitsija -assistant: M. Opettaja -first-name: FirstName -last-name: LastName -module: ModuleNumber -teammates: [student1, student2] -module-lead: Prof. Smith -lab-date: XX/XX/XX -due-date: XX/XX/XX -TA: John Smith +lecturer: Lecturer +assistant: Assistant +bibliography: sources.bib output: perejrmd::stat_exercise -geometry: margin=2cm --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` -## Adding an RMarkdown Template +# About -This file is what a user will see when they select your template. Make sure that you update the fields in the yaml header. In particular you will want to update the `output` field to whatever format your template requires. +R Markdown template for exercises of statistics courses in Aalto University. + +# Features + +Metadata related to the course can be given in the YAML header. Metadata can include the following fields: + +1. Course name +2. Exercise name +3. University +4. Department +5. Lecturer +6. Assistant + +This template also includes a bibliography file containing a single reference [@rmarkdown]. Template uses \texttt{bibtex} for managing references and the bibliography style is set to \texttt{authoryear}. + +The YAML header of this template looks like the following. +``` +--- +course-name: Statistics Course +exercise-name: Exercise Set 0 +university: Aalto University +department: Department of Mathematics and Systems Analysis +lecturer: Lecturer +assistant: Assistant +bibliography: sources.bib +output: perejrmd::stat_exercise +--- +``` diff --git a/inst/rmarkdown/templates/stat_exercise/skeleton/sources.bib b/inst/rmarkdown/templates/stat_exercise/skeleton/sources.bib new file mode 100644 index 0000000..f7993b8 --- /dev/null +++ b/inst/rmarkdown/templates/stat_exercise/skeleton/sources.bib @@ -0,0 +1,7 @@ +@Manual{rmarkdown, + title = {rmarkdown: Dynamic Documents for R}, + author = {JJ Allaire and Yihui Xie and Jonathan McPherson and Javier Luraschi and Kevin Ushey and Aron Atkins and Hadley Wickham and Joe Cheng and Winston Chang}, + year = {2018}, + note = {R package version 1.9}, + url = {https://CRAN.R-project.org/package=rmarkdown}, +}