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 !!??

jub0bs
  • 58,916
singular
  • 105

1 Answers1

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}
Jake
  • 232,450