First things first I just wanted to say I’m a long time reader but first time poster so hopefully I can present my question clearly. I have a fair amount of experience with R (near daily use for about 3 years) but only recently took up Quarto/Markdown (~4 weeks now) and so am still learning the ropes. Onto the issue at hand:
I am working on a Quarto pdf output document, yesterday everything was fine but today when I went to render the document (no changes made*) it threw an error:
compilation failed- error
LaTeX Error: Loading a class or package in a group.See the LaTeX manual or LaTeX Companion for explanation.
Type H for immediate help.l.90 …ageloaded{caption}{}{usepackage{caption}}
I have been able to get my document to render now. After some tense (unhelpful) conversation with chatgpt I concluded the problem was related to the loading of the packages in my YAML header-includes section though I can’t understand why.
I was able to just copy the header-includes section from another doc I was working on that was rendering fine and lo and behold my document is fine now; but I want to understand why I got this error so I can avoid it in the future!
*at least no changes made consciously, I have a 2 month old and so am a bit sleep deprived. Anything that would have changed would have to be an errant keystroke nothing substantial and again I’m not sold that I did anything
Here is the offending YAML
---
title: "Teaching Portfolio"
author: "me"
format:
pdf:
documentclass: article
papersize: letterpaper
fontsize: 12pt
indent: true
number-sections: false
margin-top: 1in
margin-left: 1in
margin-right: 1in
margin-bottom: 1in
toc: true
editor: visual
header-includes:
- usepackage{pdfpages}
- usepackage{hyperref}
- hypersetup{colorlinks=true, linkcolor=blue, filecolor=magenta, urlcolor=cyan,}
- urlstyle{same}
- usepackage{amsmath}
- usepackage{amsfonts}
- usepackage{amssymb}
- usepackage[version=4]{mhchem}
- usepackage{stmaryrd}
- usepackage{indentfirst}
- usepackage{setspace}
- usepackage{float}
- doublespace
---
*Side note: this version produces the error but originally pdfpages was called just before double space command and I also had - usepackage[utf8]{inputenc}
as the first package.
and here is the YAML that worked
---
title: "Teaching Portfolio"
author: "me"
format:
pdf:
documentclass: article
papersize: letterpaper
fontsize: 12pt
indent: true
number-sections: false
margin-top: 1in
margin-left: 1in
margin-right: 1in
margin-bottom: 1in
toc: true
editor: visual
header-includes:
- usepackage[utf8]{inputenc}
- usepackage{indentfirst}
- usepackage{hyperref}
- hypersetup{colorlinks=true, linkcolor=blue, filecolor=magenta, urlcolor=cyan,}
- urlstyle{same}
- usepackage{amsmath}
- usepackage{amsfonts}
- usepackage{amssymb}
- usepackage[version=4]{mhchem}
- usepackage{stmaryrd}
- usepackage{setspace}
- usepackage{float}
- usepackage{pdfpages}
---
What gives? And how can I avoid this issue in the future? Thanks for your consideration!
I tried shuffling the order of the packages, removing some extraneous ones, I even commented out my figure caption, I also tried explicitly loading the “caption” package but then a new error that was basically the same but now with “subcaption” package. Also each time I change the number of packages the error remains but the number before “…ageloaded{caption}{}{usepackage{caption}}” changes e.g. l.91 then l.90 then l.89 etc
Tyler Clarke is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.