# babel, beamer and nag conflict

With the MWE below, I experience some problem. As shown, the MWE compiles fine. If I change from book to beamer, I receive the "TeX capacity exceeded" error. If I comment out either nag or babel, it compiles fine again. What is going on here?

%\documentclass{beamer}
\documentclass{book}
\RequirePackage[l2tabu, orthodox]{nag}      % Require syntax analyzis

%\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}
\usepackage{xkeyval}    % Allow to use key-value pairs in arguments of macros
\usepackage{listingsutf8}   % Use program listings

\usepackage[english,magyar]{babel}

\makeatletter
\define@key{MEMacros}{language}{\def\ME@language{#1}}
\define@key{MEMacros}{options}{\def\ME@options{#1}}
%%%Usage \MESourceFile[keys]{source file}{caption}{label}
\newcommand\MESourceFileNew[4][]{
\setkeys{MEMacros}{language={[ANSI]C},options={}, ,#1}%
\begingroup\edef\x{\endgroup\noexpand
\lstinputlisting[language={\ME@language},\ME@options,label=#4, name=#4]{#2}}
\x
}
\makeatother

\begin{document}

\MESourceFileNew[language={[ANSI]C}, options={numbers=left}
]{HelloWorld.c}{caption}{lst:HelloWorld.c}

\end{document}

#include <stdio.h>

int main()
{
printf("hello, world\n");
}

• Avoid nag; it does worse than it would solve. In any case, it should be loaded before \documentclass. May 25 '15 at 19:59
• @egreg Hmm. The intended functionality is OK. Thanks for the hint. May 25 '15 at 20:01
• In this case, nag hangs at the evaluation of caption, probably because it doesn't understand the redefinition made by beamer. I find nag useless in general even if it works. May 25 '15 at 20:07

The problem is in interaction with the magyar option: this is what I get if I add \errorcontextlines=100 to the example file

\nag@@warning@xliii  ->\nag@captioncheck
\nag@haslabeltrue
\@@magyar@orig@label ->\nag@@warning@xliii
\nag@@label@xliii
\@@magyar@labelb #1->\@@magyar@orig@label
{#1}\begingroup \c@page \@m \edef ...

\@@magyar@labelb #1->\@@magyar@orig@label {#1}
\begingroup \c@page \@m \edef ...

\@@magyar@labelb #1->\@@magyar@orig@label {#1}
\begingroup \c@page \@m \edef ...


So the problem is in how the label is checked in the case of listings and in the interaction with the redefinitions that both magyar.ldf and beamer do on \label.

I don't think there is a sensible way for solving this conflict; following all the juggles performed by magyar.ldf is very complicated.

The best is to forget about nag.