3

Why does the following 'minimal working example' work

\documentclass[a4,german]{book}
\usepackage{framed}

\begin{document}

\newcommand{\myText}{Bliblibli!}

\begin{framed}
Blabla 
\end{framed}

\myText

\end{document}

but not this here, when defining the new command inside a "framed" block?

'Minimal non-working example':

\documentclass[a4,german]{book}
\usepackage{framed}

\begin{document}

\begin{framed}
    Blabla \newcommand{\myText}{Bliblibli!}
\end{framed}

\myText

\end{document}

Does the framed package simply not support this feature, or do I do something wrong?

8

There is nothing special about framed here you would see the same from

\begin{empty}
    Blabla \newcommand{\myText}{Bliblibli!}
\end{empty}

or just

{
    Blabla \newcommand{\myText}{Bliblibli!}
}

The brace group or environment provides a scope that limits all non-global definitions.

1

TeX is meant to be a typesetting tool. This is nice, unless you want to programm anything in it. These so called scopes, that are individual environments, like frames and basically anything embraced somehow, hold their own style.

For fonts is nice, since you can write some text {\itshape something in a different font} and with no extra command back to the old style.

For programming, this is less nice

\def\mynumber{3} because 
the number \mynumber
{\itshape might somehow be increased or changed \def\mynumer{6} to \mynumber}
and then changes back to \mynumber, even if you only wanted your font back.

gives the output

the number 3 might somehow be increased or changed to 6 and then changes back to 3, even if you only wanted your font back.

In the manual Notes on Programming in TeX by Christian Feuersänger (comes with pgfplots), he writes how he fiddled around with the command that closes an environment to sneak a result out.

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.