3

Here a question also about my last topic. I want to create an environment that put a pretty box around my theorem and its title. Here is a code with the desired output :

\documentclass{report}


\usepackage[utf8]{inputenc}
\usepackage[english, arabic]{babel}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{tikz}

\usepackage{etoolbox}
\AtBeginEnvironment{tikzpicture}{\selectlanguage{english}}
\tikzset{font=\selectlanguage{arabic}}


\begin{document}


\tikzset{
    mybox/.style={
        draw=red, fill=blue!20, very thick,
        rectangle, rounded corners, inner sep=10pt, inner ysep=20pt
    },
    fancytitle/.style={
            draw=red, fill=blue!20, text=black, rectangle, rounded corners
    }
}
\begin{tikzpicture}
\node [mybox] (box){%
\begin{minipage}{.89\textwidth}

لتكن $f$ دالة مستمرة على المجال $[a,b]$ و قابلة للإشتقاق على $]a,b[$, 
حيث $f(a)=f(b)$.
إذن, يوجد عدد حقيقي $c \in ]a,b[$ حيث 
$$
f^\prime(c)=0.
$$
\end{minipage}
};
\node[fancytitle, left=10pt] at (box.north east) {\AR{نظـريـة}};
\node[fancytitle, rounded corners] at (box.east) {$\clubsuit$};
\end{tikzpicture}%


\end{document}

Now, if I create the environment tamtam to obtain a good looking box around my Arabic text, it doesn't do it

\documentclass{report}


\usepackage[utf8]{inputenc}
\usepackage[english, arabic]{babel}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{tikz}

\usepackage{etoolbox}
\AtBeginEnvironment{tikzpicture}{\selectlanguage{english}}
\tikzset{font=\selectlanguage{arabic}}


\newenvironment{tamtam}[1]{%
\tikzset{
    mybox/.style={
        draw=red, fill=blue!20, very thick,
        rectangle, rounded corners, inner sep=10pt, inner ysep=20pt
    },
    fancytitle/.style={
            draw=red, fill=blue!20, text=black, rectangle, rounded corners
    }
}
\begin{tikzpicture}
\node [mybox] (box){%
\begin{minipage}{.89\textwidth}
#1
\end{minipage}
};
\node[fancytitle, left=10pt] at (box.north east) {\AR{نظـريـة}};
\end{tikzpicture}%
}{}%


\begin{document}


\begin{tamtam}


لتكن $f$ دالة مستمرة على المجال $[a,b]$ و قابلة للإشتقاق على $]a,b[$, 
حيث $f(a)=f(b)$.
إذن, يوجد عدد حقيقي $c \in ]a,b[$ حيث 
$$
f^\prime(c)=0.
$$

\end{tamtam}

\end{document}

NB: you have to let 2 empty lines between \begin{tamtam} and the Arabic text to get a readable Arabic output !!??

4

This problem has nothing to do with the arabic text, but rather stems from misunderstanding of how \newenvironment works: Within a \newenvironment definition, #1 does not contain the body of the environment.

To define an environment that works as expected, you can use the approach from Defining a new environment whose contents go in a TikZ node:

\documentclass{report}


\usepackage[utf8]{inputenc}
\usepackage[english, arabic]{babel}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usepackage{tikz}
\usepackage{environ}

\usepackage{etoolbox}
\AtBeginEnvironment{tikzpicture}{\selectlanguage{english}}
\tikzset{font=\selectlanguage{arabic}}

\tikzset{
    mybox/.style={
        draw=red, fill=blue!20, very thick,
        rectangle, rounded corners, inner sep=10pt, inner ysep=20pt
    },
    fancytitle/.style={
            draw=red, fill=blue!20, text=black, rectangle, rounded corners
    }
}

\NewEnviron{tamtam}{%
\begin{tikzpicture}
\node [mybox] (box){%
\begin{minipage}{.89\textwidth}
\BODY
\end{minipage}
};
\node[fancytitle, left=10pt] at (box.north east) {\AR{نظـريـة}};
\end{tikzpicture}%
}


\begin{document}


\begin{tamtam}
لتكن $f$ دالة مستمرة على المجال $[a,b]$ و قابلة للإشتقاق على $]a,b[$, 
حيث $f(a)=f(b)$.
إذن, يوجد عدد حقيقي $c \in ]a,b[$ حيث 
$$
f^\prime(c)=0.
$$
\end{tamtam}

\end{document}
| improve this answer | |
  • 1
    Awsome, you are a life saver @Jake. Thank you again. – singular Jul 17 '13 at 17:34

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.