# How to use macros with parameters inside a \newenvironment?

I would like to define a new environment that changes the section titles via \titleformat. Obviously I have to "escape" the #1 somehow, so it is not considered to be an (undeclared) parameter to local_format_env, but a parameter to \titleformat. How do I do that?

(Omitting the [explicit] option to titlesec is not an option due to constraints not present in the example for simplicity of presentation.)

Minimal non-working example:

\documentclass{scrbook}
\usepackage[german]{babel}
\usepackage[utf8]{inputenc}
\usepackage[explicit]{titlesec}

\newenvironment{local_format_env}{
\titleformat{\section}{\normalfont\scshape\Large}{}{0pt}{#1} % <-- needs excaping
}{
\titleformat{\section}{\normalfont\Large}{}{0pt}{#1}         % <-- needs escaping
}

\begin{document}

\section{Global Format}

\begin{local_format_env}
\section{Local Format}
\end{local_format_env}

\end{document}

-

It's a case of replacing #1 with ##1.

\documentclass{scrbook}
\usepackage[german]{babel}
\usepackage[utf8]{inputenc}
\usepackage[explicit]{titlesec}

\newenvironment{local_format_env}{
\titleformat{\section}{\normalfont\scshape\Large}{}{0pt}{##1} % <-- needs excaping
}{
\titleformat{\section}{\normalfont\Large}{}{0pt}{##1}         % <-- needs escaping
}

\begin{document}

\section{Global Format}

\begin{local_format_env}
\section{Local Format}
\end{local_format_env}

\end{document}

-
Although I'm beginning to wonder whether just not using the explicit option wouldn't make more sense? –  Seamus Aug 22 '11 at 14:18
As I wrote in the question, it is not an option. The actual formatting done by the real document is somewhat more involved than the one in my example here. Probably most importantly, one of the formattings involved doesn't print the section title (by omitting the #1), which would be somewhat difficult without [explicit]. (Well, I guess I could set it in white, but...) –  DevSolar Aug 22 '11 at 14:55