Use exams2pdf or a modified solution.tex template to print solutions not another answer list - latex

I am trying to create a solution pdf for an exam but all I need for it is a simple marked box and not the answer list that follows. For example, I just want the first page from the following compilation and nothing else.
library(exams)
exams2pdf(list(
"boxplots",
c("tstat", "ttest", "confint"),
c("regression", "anova"),
"scatterplot",
"relfreq"
), template = "solution"
)
I don't have a strong grasp of the Latex language so when I try removing for example
\newenvironment{answerlist}{\renewcommand{\labelenumi}{(\alph{enumi})}\begin{enumerate}}{\end{enumerate}}
or
% \exinput{exercises}
It doesn't compile and just complains about a missing item etc
Which part of solution.tex can I remove that retains just the first page?

Solution: You need to delete all of the following lines from your copy of solution.tex:
\newpage
\begin{enumerate}
%% \exinput{exercises}
\end{enumerate}
Details: This LaTeX code starts a new page and includes an enumerated list for the individual exercises. The \exinput{exercises} is replaced with each of the {question} (and optionally {solution}) environments which then produces an \item for each question. So if you just remove the \exinput line, LaTeX complains about missing items because the {enumerate} list is empty.
Documentation: More details for exams2pdf() and its LaTeX templates can be found in vignette("exams", package = "exams").

Related

Export tex document which uses the exam class (Part 2)

I would like to export a text document which uses the exam class to markdown. To do so, I am currently using a workaround which was suggested in this answer, which relies on pseudo-definitions which in turn overwrite the definitions of the exam class such that pandoc can produce a clean markdown file.
Although, the workaround works for the suggested multiple-choice questions, I cannot adopt the solution to work for text with “fillin gaps” such as the document below:
\documentclass[answers]{exam}
\usepackage{minted}
\let\oldpart\part
\renewcommand{\part}[1][]{\oldpart[#1]{}}
\begin{document}
\begin{questions}
\question Exercise 1
\begin{parts}
\part[1] This fills in the \fillin[blanks][3cm]
\end{parts}
\end{questions}
\end{document}
If I use the following pseudo-definitions in a separate file:
% ignore \part
\renewcommand{\part}[0][1]{}
% Treat checkboxes like an itemized list
\newenvironment{checkboxes}{\begin{itemize}}{\end{itemize}}
\renewcommand{\CorrectChoice}{\item ☒ }
\renewcommand{\choice}{\item ☐ }
\renewcommand\fillin[2][{}]{\textbf{#1}}
I get the following broken markdown output
This fills in the **blanks**3cm\]
Moreover is there a way for pandoc to ignore \begin{parts} and \end{parts} so that there are no ::: in the final Markdown file?
The \fillin problem can be solved with
\newcommand{\fillin}[1][1]{\textbf{#1}\noop}
whereas the parts div can be removed with
\newenvironment{parts}{}{}

natbib author-year citation - fallback to editor possible when author missing?

I'm having an issue with the natbib package. When the bib entry is missing an author I want to display the editor instead. However the second citation just takes the first three letters of the bib-key instead of the author.
Sample tex:
\documentclass{article}
\usepackage[authoryear,round]{natbib}
\bibliographystyle{abbrvnat}
\begin{document}
I need this \citet[S.~2]{Test1} to look like Surname (2022, S. 2).
and this \citep{Test1} like (Surname, 2022)
But also this \citet[S.~2]{Test2} to look like Editor (2022, S. 2).
and this \citep{Test2} like (Editor, 2022)
but it just prints (Tes, 2022)
\bibliography{refs}
\end{document}
The bib file could look like this:
#misc{Test1,
author={Surname, Name}
title = {Sometitle},
year = {2022}
}
#misc{Test2,
title = {Someothertitle},
editor={{Editor, Name}}
year = {2022}
}
Can anyone help with this? I'd also switch to another package than natbib, since I'm still early on the project. But at a first glance it seemed to meet my needs quite well.
Also I don't really know what I'm doing, it's been a while since I've been working with Latex. So sorry for that in advance!
Although the user posting the initial question here was able to switch to biblatex (which is good), not everyone has that freedom for some publishing venues. If this applies to you (that you have to stay with natbib and plainnat, you may be interested in a TeX Stack Exchange post that provides a description of how you can customize your BST file to modify your sorting, including configuring misc to sort by author then editor.
EDIT: A down-check for this answer being unhelpful inspired me to be more specific than my original answer above so the additional details specific to this case are below.
Since your provided code has natbib using abbrvnat (not plainnat as in the linked example that I initially provided), you can find abbrvnat.bst in your TeX repository and place a local copy with a different name (like abbrvnat-copy.bst) into your working directory. There are two steps in modifying your local copy of abbrvnat-copy.bst: First, update the calc.short.authors function to also look for an editor in the misc type. Second, have your TeX file use your newly customized BST file.
Note: I am using the 2007 version of abbrvnat.bst, which is the latest as of this posting in 2022.
In your local copy of abbrvnat-copy.bst, search for the calc.short.authors function. We'll need to add two lines of code to it:
type$ "misc" =
or
I show the new version here:
FUNCTION {calc.short.authors}
{ type$ "book" =
type$ "inbook" =
or
type$ "misc" =
or
'author.editor.key.label
{ type$ "proceedings" =
'editor.key.organization.label
{ type$ "manual" =
'author.key.organization.label
'author.key.label
if$
}
if$
}
if$
'short.list :=
}
In your TeX file, you'll need to change this line to account for your newly customized file: \bibliographystyle{abbrvnat-copy}. Other than this one line in your main .tex file and adding a couple missing commas in your .bib file, I did not change any code in your MWE.
Here's the output:
Other aspects that you may want to address (that you didn't ask about) include getting the editor(s) to appear in the bibliography (references list) for misc entries and sorting by editor for misc entries. The example that I provided here and the example provided in the other post that I previously linked should both be helpful in customizing your BST file to achieve your desired bibliography style.

Custom list of things in LaTeX?

I'm writing a script for college where I insert the date of a part of text apart from the chapters using a custom command (currently just displaying a marginpar), like:
\lesson{1}
\section{A}
\section{B}
\subsection{C}
\lesson{2}
\subsection{D}
Apart from the usual \listoffigures, \listoftables and \tableofcontents I want a list that allows access by lesson number. It should look like the \listoffigures except with a custom label (since the lessons don't have captions), for example:
Lesson 1 ..... Page 1
Lesson 2 ..... Page 5
Is there a package that allows me to define new lists like that as easy as creating new counters? Or do I have to dig into the source for the existing lists and hack my own?
(the memoir package documentation has a list of rendered examples at the beginning, that would be another example of a custom list like I need it)
Any keywords to google for are appreciated!
I would do the following:
1) Open a file at the beginning:
\newwrite\listoffoo
\immediate\openout\listoffoo=\jobname.foo
2) Each command like \lesson should put a line into the file:
\newcounter{lesson}
\def\lesson{%
...
\refstepcounter{lesson}%
\immediate\write\listoffoo{%
\string\lessonfooline{\ref{lesson}}{\pageref{lesson}}}
...
}
3) At the end of the processing, close the file and read it in:
\immediate\closeout\listoffoo
\input\jobname.foo
You'll have to define the commands like \lessonfooline.
Hope this outline helps.

LaTeX: Cite, but don't reference

I'm producing a set of documents in LaTeX, and I would like to provide a single, global bibliography page for the whole set. This is because each document is page-limited: I don't want to take up space with references at the bottom of each one.
This means in each case, I would like to cite in the text, but not produce a reference at the end. I am using bibtex/natbib to handle the referencing.
Simplest example:
\documentclass[]{article}
\bibliographystyle{/usr/share/texmf/bibtex/bst/natbib/plainnat.bst}
\usepackage{natbib}
\begin{document}
In \citet*{MEF2010} I described the method.
\bibliography{bibliography.bib}
\end{document}
How can I do this? Essentially I just want it to cite correctly:
In Bloggs, Blagg and Blog (2010) I described the method.
But not add a references section at the end. Any ideas?
Thanks,
David
Instead of using \bibliography{bibliography.bib} you can try \nobibliography{bibliography.bib}.
You still need to enter the path so it can make the cross-references.
It happens due to missing packages. If you want to resolve the problem then enable the automatic installation packet. After that,First, you run the BibTeX file and generate the Pdf file (instead of pdfLatex file) and then pdfLatex to Pdf

Incorrect hyperlinking in LaTeX

So far the hyperref package in LaTeX has automatically linked all the items in my report correctly. But there is one that did not get linked properly, possibly because I manually added it to the table of contents like this:
\addcontentsline{toc}{chapter}{Bibliography}
How do I fix this?
You have to use the \phantomsection macro just before or after the \addtocontentsline. This instructs hyperref to add an anchor at that point. Also, take into account that you have to run LaTeX several times to make this anchor to be in the exact place.
If you're using a standard LaTeX document class, such as report, you can use the tocbibind package, and then you won't need the \addcontentsline command and the hyperlinks should work correctly. From the documentation:
The tocbibind package enables the titles of the Table of Contents, the List of Figure, the List of Tables, the Bibliography and the Index all to be added to the Table of Contents.
I'd also suggest looking at the memoir class, which also solves this problem. It's intended to be a replacement for the standard report and book classes, and provides lots of options and commands for customisation.

Resources