6

The following code throws the error

Incomplete \iffalse; all text was ignored after line 7

when I enable the babel package.

\documentclass[a4paper,12pt]{book}
\usepackage[latin1]{inputenc}
%\usepackage[italian]{babel} % uncomment me
\begin{document}
\label{testlabel}
\xdef\mytest{}
\xdef\mytest{\mytest \ref{testlabel}}
\end{document}

To provide a bit of context of what I'm trying to accomplish, see the more verbose example below:

\documentclass[a4paper,12pt]{book}
\usepackage[latin1]{inputenc}
%\usepackage[italian]{babel} % enabling this results in an error
\usepackage{enumerate}

\begin{document}

\xdef\myanswers{}
\newcommand{\myappend}[1]{\xdef\myanswers{\myanswers #1}}
\newcommand{\mycorrect}{\label{risp:\theqcnt}}

\newenvironment{questions}
{\section*{Questions}\vspace{2em}}
{\noindent\textbf{Answers: }\myanswers}

\newcounter{qcnt}
\setcounter{qcnt}{1}
\newenvironment{question}[3]
{\noindent\textbf{Question \theqcnt:}
\begin{enumerate}[(a)]
\item #1
\item #2
\item #3
\end{enumerate}
\myappend{\arabic{qcnt}\ref{risp:\theqcnt} }
}
{\vspace{2em}\stepcounter{qcnt}}

\begin{questions}
\begin{question}{first\mycorrect}{second}{third}\end{question}
\begin{question}{first}{second\mycorrect}{third}\end{question}
\begin{question}{first}{second}{third\mycorrect}\end{question}
\end{questions}

\end{document}
  • @DavidCarlisle true. I'll delete that comment (and alos this one). – Gonzalo Medina Apr 17 '13 at 15:05
3

You should never use \edef or \xdef on latex input, you can only use them in controlled situations when you know the tokens involved. You can use the \protected@edef or here where you are appending to a macro use

\makeatletter
\newcommand{\myappend}[1]{\g@addto@macro\myanswers{#1}}
\makeatother
1

You want to expand only \theqcnt; so use \protected@xdef to avoid problems with commands that don't survive \edef, but expand \myanswers only once and not \label.

\documentclass[a4paper,12pt]{book}
\usepackage[latin1]{inputenc}
\usepackage[italian]{babel} % enabling this results in an error
\usepackage{enumerate}

\begin{document}

\def\myanswers{}
\makeatletter
\newcommand{\myappend}[1]{%
  \protected@xdef\myanswers{\unexpanded\expandafter{\myanswers} #1}}
\makeatother
\newcommand{\mycorrect}{\protect\label{risp:\theqcnt}}

\newenvironment{questions}
  {\section*{Questions}\vspace{2em}}
  {\noindent\textbf{Answers: }\myanswers}

\newcounter{qcnt}
\setcounter{qcnt}{1}

\newenvironment{question}[3]
  {\noindent\textbf{Question \theqcnt:}
   \begin{enumerate}[(a)]
   \item #1
   \item #2
   \item #3
   \end{enumerate}
   \myappend{\arabic{qcnt}\ref{risp:\theqcnt} }%
  }
  {\vspace{2em}\stepcounter{qcnt}}

\begin{questions}
\begin{question}{first\mycorrect}{second}{third}\end{question}
\begin{question}{first}{second\mycorrect}{third}\end{question}
\begin{question}{first}{second}{third\mycorrect}\end{question}
\end{questions}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.