3

I'm using both the answers package for an exercise book and Cyrillic symbols for 2nd level items. Here is my .tex code.

\documentclass[10pt, a4paper, openany]{report}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage{answers}

\begin{document}

\renewcommand{\theenumii}{\asbuk{enumii}}

\Newassociation{otv}{Otvet}{ans}
\Opensolutionfile{ans}[C1.ans6]

\begin{enumerate}
    \item 
        \begin{enumerate}
            \item Excercise 1a)
                \begin{otv}
                    answer 1a)  \end{otv}
            \item Excercise 1b)
                \begin{otv}
                    answer 1a)  \end{otv}
        \end{enumerate}
\end{enumerate}

\Closesolutionfile{ans}

Answers:
\input{c1.ans6}

\end{document}

and this error occurs

...\c1.ans6.tex:1: Undefined control sequence. [\begin{Otvet}{1.1.\T2A\cyra )}]

Answers file contains the following:

\begin{Otvet}{1\T2A\cyra }
                answer 1a)  
\end{Otvet}
\begin{Otvet}{1\T2A\cyrb }
                answer 1a)  
\end{Otvet}

Could anyone help me to deal with this problem?

Ilya Y.
  • 53
  • Welcome to TeX.SX! Please help us to help you and provide a full (but minimal) compilable document. It's difficult or often impossible to help someone with just some snippets. Reduce your document as much as possible while still getting this error. Thanks. – LaRiFaRi Aug 04 '14 at 13:06

1 Answers1

3

You need an \immediate version of \protected@write, because commands such as \cyra, produced by \asbuk don't survive \write.

The code is like in Replacing some macro tokens in a list before \write ing, then I also patch \Newassociation to use \protected@iwrite instead of \immediate\write.

\documentclass[10pt, a4paper, openany]{report}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage{answers}
\usepackage{xpatch}
\makeatletter
% get a copy of `\protected@write
\let\protected@iwrite\protected@write
% patch the copy to add \immediate
\xpatchcmd{\protected@iwrite}{\write}{\immediate\write}{}{}

\xpatchcmd{\Newassociation}
  {\immediate\write\@nameuse{#3@file}}
  {\protected@iwrite{\@nameuse{#3@file}}{}}
  {}{}
\makeatother

\begin{document}

\renewcommand{\theenumii}{\asbuk{enumii}}

\Newassociation{otv}{Otvet}{ans}
\Opensolutionfile{ans}[\jobname.ans6]

\begin{enumerate}
\item 
  \begin{enumerate}
  \item Excercise 1a)
    \begin{otv}
    answer 1a)
    \end{otv}
  \item Excercise 1b)
    \begin{otv}
    answer 1b)
    \end{otv}
  \end{enumerate}
\end{enumerate}

\Closesolutionfile{ans}

Answers:
\input{\jobname.ans6}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Note that the current version of answers.sty (that is, v2.16 released 2014/08/24) implements the change, so there's no need for the patch any more. – egreg Mar 28 '15 at 20:21