环境、阿拉伯语和 tikz 存在问题

环境、阿拉伯语和 tikz 存在问题

这里还有一个关于我上一个主题的问题。我想创建一个环境,在我的定理及其标题周围放一个漂亮的框。以下是带有所需输出的代码:

\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}

现在,如果我创建环境tamtam来获得一个好看的阿拉伯语文本周围的框,它却做不到

\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}

注意:您必须在\begin{tamtam}阿拉伯语文本之间留出 2 个空行才能获得可读的阿拉伯语输出!!??

答案1

这个问题与阿拉伯文本无关,而是源于对\newenvironment工作原理的误解:在\newenvironment定义中,#1不包含环境主体。

要定义一个按预期工作的环境,您可以使用以下方法定义一个新环境,其内容位于 TikZ 节点中

\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}

相关内容