GeneralPackage incompatibility?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
LarsWa
Posts: 5
Joined: Fri Nov 07, 2014 12:36 am

Package incompatibility?

Post by LarsWa »

I have a 500 p textbook in LaTeX that I wrote a year ago. After migrating to a new computer (Win 7) I get the error message "!You can't use a prefix with '\begingroup'" on a line \Newassociation{hint}{Hint}{hint} related to the package Answers. When I created the minimal working example below, the error instead showed up at a later - but similar line - \Newassociation{solt}{SolutionTeacher}{solt}. The error seems to be related to what is discussed on tex.stackexchange.com/questions/112706/chemfig-package-compatibility: an incompatibility between different packages. In the stackexchange-post it was recommended to change the order of the different \usepackage-commands, but that does not help in my case. However, I still have a feeling that my problem is related to package incompatibility, as I do not get the error when I only use the Answers package; nor do I get it when I use the Answers package together with some other packages. The minimal problem seems to be a combination of the four un-commented packages below (answers, mchem, pdfpages, siunitx; found by trial and error).

Code: Select all

\documentclass[11pt,twocolumn,twoside]{book}
%---------- PACKAGES ------------------
\usepackage{answers}
%\usepackage{amsthm} %enhanced theorems
%\usepackage{graphicx,epstopdf} %insert graphics and convert eps to pdf
%\usepackage[format=plain,font=small,labelfont=bf,up]{caption} %,textfont=it,up
\usepackage[version=3]{mhchem} %chemical formula
%\usepackage{float} %improved placement of floats
%\usepackage{placeins} %makes it possible to prevent floats from floating past the end of a section
\usepackage{pdfpages} %facilitates the insertion of pdf-pages into document (is not needed when the whole text is in LaTeX)
%\usepackage{makeidx} %index processor
%\usepackage{enumerate} % to make it easy to use for example levels of A, B, C for enumerate
%  %\usepackage{dblfloatfix} %makes it possible to use [b] with double column floats
%\usepackage{fixltx2e} %amalgamates figure and table lists for single and double columns
%\usepackage{caption} %to customize captions
\usepackage{siunitx} %proper formatting of numbers and SI-units
%\usepackage{xspace} %used only for fixing spaces in \oC
%\usepackage{textgreek} %to write non-italic Greek letters (in Greek box in Thermodynamics chapter)
%---------- ANSWERS PACKAGE ------------------
%I here create four types of files (the exercises are written where they are given): answers, hints, solutions for the book, and %solutions for the teacher. The solutions for the teacher (those solutions that are not given in the book) are given in solt.txt to be %printed separately.
\newtheorem{Ex}{Exercise}
\Newassociation{ans}{Answer}{ans}
\Newassociation{hint}{Hint}{hint}
\Newassociation{sol}{Solution}{sol}
\Newassociation{solt}{SolutionTeacher}{solt}
\renewcommand{\Answerlabel}[1]{\bf{Answer #1.}}
\renewcommand{\Hintlabel}[1]{\bf{Hint #1.} }
\renewcommand{\Solutionlabel}[1]{\bf{Solution #1.} }
\renewcommand{\SolutionTeacherlabel}[1]{\bf{Solution #1.} }
\begin{document}
%---------- START UP USE OF ANSWERS PACKAGE ------------------
\Opensolutionfile{ans}[ans1] % file for answers
\Opensolutionfile{hint}[hint1] % file for hints
\Opensolutionfile{sol}[sol1] % file for solutions for book
\Opensolutionfile{solt}[sol1t] % file for solutions for teacher
\Writetofile{ans}{Here are  answers to the exercises.}
\Writetofile{hint}{Here are hints for the exercises.}
\Writetofile{sol}{Here are solutions to selected exercises.}
\Writetofile{solt}{Solutions for the teacher only.}
\chapter{Heat}
Here is the chapter text about heat.
\section{Exercises}
\Writetofile{ans}{\protect\subsection*{Heat}}
\Writetofile{hint}{\protect\subsection*{Heat}}
\Writetofile{sol}{\protect\subsection*{Heat}}
\begin{Ex}
Heat question X.
\begin{ans}Answer X.\end{ans}
\begin{hint}Hint X.\end{hint}
\begin{sol}Solution X.\end{sol}
\end{Ex}

\begin{Ex}
Heat question Y.
\begin{ans}Answer Y.\end{ans}
\begin{hint}Hint Y.\end{hint}
\begin{solt}Solution Y (for teacher only).\end{solt}
\end{Ex}

\chapter{Biology}
Here is the chapter text about biology.
\section{Exercises}
\Writetofile{ans}{\protect\subsection*{Biology}}
\Writetofile{hint}{\protect\subsection*{Biology}}
\Writetofile{sol}{\protect\subsection*{Biology}}

\begin{Ex} %-------------------
Biology question Z.
\begin{ans}Answer Z.\end{ans}
\begin{hint}Hint Z.\end{hint}
\begin{sol}Solution Z.\end{sol}
\end{Ex}

%---------- ANSWERS PACKAGE ------------------
\Closesolutionfile{ans} % answers
\Closesolutionfile{hint} % hints
\Closesolutionfile{sol} % solutions
\Closesolutionfile{solt} % solutions for teacher
\chapter{Answers}
\input{ans1}\newpage

\chapter{Hints}
\input{hint1}\newpage

\chapter{Solutions}
\input{sol1}

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10340
Joined: Mon Mar 10, 2008 9:44 pm

Package incompatibility?

Post by Stefan Kottwitz »

Hi Lars,

welcome to the forum!

Can you please post the .log file as attachment here? It would be good if you would add the command \listfiles to your preamble, so the log file would list the package names and versions in addition.

Stefan
LaTeX.org admin
User avatar
Stefan Kottwitz
Site Admin
Posts: 10340
Joined: Mon Mar 10, 2008 9:44 pm

Re: Package incompatibility?

Post by Stefan Kottwitz »

For information, the problem has been solved (cross-post site, link above).

It's caused by a bug which is not present in the newest LaTeX version, so an update would help. A workaround is defining a new dummy counter right before the line where the error happened, as egreg suggested.

Stefan
LaTeX.org admin
Post Reply