2

Compiling this file

\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage{answers}
\Newassociation{sol}{Solucao}{solucoes}
\newtheorem{exer}{Exercício}

\begin{document}

\section{Exercícios}
\Opensolutionfile{solucoes}
\Writetofile{solucoes}{\protect\section{Soluções}}

\begin{exer}
  Determina
  \begin{sol}
    O resultado é
  \end{sol}
\end{exer}

\Closesolutionfile{solucoes}
\input{solucoes}

\end{document}

I get the following in the log file

./exemplo.tex:12: Bad space factor (0).
<recently read> \@savsf 

l.12 ...le{solucoes}{\protect\section{Soluções}}

I allow only values in the range 1..32767 here.

In the output file it appears a \nobreak.

I'm using TeX Live 2020/W32TeX.

How can I solve this?

1
  • 1
    It's a bug appeared with the transition from TL2018 to TL2019. The problem seems to be that you're right after a section title.
    – egreg
    Commented Apr 10, 2020 at 16:21

1 Answer 1

2

It's a bug in answers.sty that does \let\protect\string in a wrong place.

Here's a fix.

\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage{answers}
\Newassociation{sol}{Solucao}{\jobname-solucoes}
\newtheorem{exer}{Exercício}

\makeatletter
\renewcommand{\Writetofile}[2]{%
   \@bsphack
   \Iffileundefined{#1}{}{%
      \Ifopen{#1}{%
         {%
            \begingroup
            %\let\protect\string %%% <----- removed
            \Ifanswerfiles{%
               \protected@iwrite{\@nameuse{#1@file}}{\afterassignment\let@protect@string}{#2}%
            }{}%
            \endgroup
         }%
      }{}%
   }%
   \@esphack
}
\def\let@protect@string{\let\protect\string}
\makeatother


\begin{document}

\section{Exercícios}
\Opensolutionfile{\jobname-solucoes}
\Writetofile{\jobname-solucoes}{\protect\section{Soluções}}

\begin{exer}
  Determina
  \begin{sol}
    O resultado é
  \end{sol}
\end{exer}

\Closesolutionfile{\jobname-solucoes}
\input{\jobname-solucoes}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .