1

I've got some code, which is mainly based on the solution of this: Other question I asked The code looks like this and it works so far, except for the \\-stuff:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage{environ}
\usepackage{etoolbox}


%%Environments
%Liederbuchumgebung
\newenvironment{Liederbuch}[1]
  {\def\liederbuchtmp{#1}\csgdef{LH#1}##1##2{\csuse{lied;#1;##1;##2}}}
  {}
%Liedumgebung
\NewEnviron{Lied}[2]{\csxdef{lied;\liederbuchtmp;#1;#2}{\BODY}}

%Forward to Environments
\newcommand*\LHsong[3][n]{\csuse{lied;#2;#1;#3}}


%use of Liederbuchenv.
\begin{Liederbuch}{Test}
%use of Liederbuchenv.
\begin{Lied}{t}{1}
%content begins here.
Lied Nummer 1, Format t
%Problem occurs here. If you delete the \\ it seems to throw a exhaustive expansion error (which I don't understand)
Hänschen klein, %\\
ging allein %\linebreak
in die weite Welt hinein. %\newline
Stock und Hut, 
steht im gut. 
Ist gar wohlgemut.
\end{Lied}
\begin{Lied}{nt}{2}
Lied Nummer 2, Format nt
\end{Lied}
\begin{Lied}{n}{336}
Lied Nummer 336, Format n
\end{Lied}
\end{Liederbuch}

\begin{document}
\LHsong[t]{Test}{1}
\end{document}

How can I get \\ to work?

MaestroGlanz
  • 2,348
  • most latex commands are not safe in an `\xdef`` why do you need edef expansion here? Note the comments on the referenced question already explain that such commands will fail in an xdef. – David Carlisle May 03 '16 at 18:35
  • @DavidCarlisle If I use \csdef, it does't work, because it's out of scope. If I use \csgdef or \global\csdef I get an error, saying, it doesn't know \BODY. – MaestroGlanz May 03 '16 at 18:46

1 Answers1

1

Most latex commands are not safe in \xdef (which is why latex has a \protect mechanism and \protected@edef) but here you just want \let I think and don't need to expand \BODY at all.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage{environ}
\usepackage{etoolbox}


%%Environments
%Liederbuchumgebung
\newenvironment{Liederbuch}[1]
  {\def\liederbuchtmp{#1}\csgdef{LH#1}##1##2{\csuse{lied;#1;##1;##2}}}
  {}
%Liedumgebung
\NewEnviron{Lied}[2]{\global\cslet{lied;\liederbuchtmp;#1;#2}\BODY}

%Forward to Environments
\newcommand*\LHsong[3][n]{\csuse{lied;#2;#1;#3}}


%use of Liederbuchenv.
\begin{Liederbuch}{Test}
%use of Liederbuchenv.
\begin{Lied}{t}{1}
%content begins here.
Lied Nummer 1, Format t
%Problem occurs here. If you delete the \\ it seems to throw a exhaustive expansion error (which I don't understand)
Hänschen klein, \\
ging allein %\linebreak
in die weite Welt hinein. %\newline
Stock und Hut, 
steht im gut. 
Ist gar wohlgemut.
\end{Lied}
\begin{Lied}{nt}{2}
Lied Nummer 2, Format nt
\end{Lied}
\begin{Lied}{n}{336}
Lied Nummer 336, Format n
\end{Lied}
\end{Liederbuch}

\begin{document}
\LHsong[t]{Test}{1}
\end{document}
David Carlisle
  • 757,742