Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

1 Answer 1

up vote 6 down vote accepted

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}
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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