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.

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?

share|improve this question
4  
The \newcommand is available on in the framed environment due to scoping. See for example \global\renewcommand equivalent of \global\def. So using \global\def\myText{Bliblibli!} should work. –  Peter Grill Jan 17 '13 at 23:13
    
Thanks, Peter! Works great! –  InfinitelyInquisitive Jan 17 '13 at 23:23
    
Welcome to TeX.SE! –  cmhughes Jan 18 '13 at 0:20

2 Answers 2

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.

share|improve this answer

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.

share|improve this answer

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.