سلام. با استفاده از TikZ یک محیط تعریف کرده ایم به صورت زیر:
\documentclass{article}
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{tikzmark,calc}
\begin{document}
\newcommand{\tw}{\textwidth}
\newcommand{\bs}{\baselineskip}
\begin{tikzpicture}[remember picture,overlay]
\coordinate (A) at ($(pic cs:AA)+(0,2\bs)$);
\coordinate (B) at ($(pic cs:BB)+(0,-1\bs)$);
\coordinate (C) at ($(A-|current page text area.west)$);
\coordinate (D) at ($(A-|current page text area.east)$);
\coordinate (E) at ($(B-|current page text area.east)$);
\coordinate (F) at ($(B-|current page text area.west)$);
\coordinate (G) at ($(C)+(0.4\tw,0.5\bs)$);
\coordinate (H) at ($(C)+(0.5\tw,0)$);
\coordinate (I) at ($(C)+(0.4\tw,-0.5\bs)$);
\coordinate (J) at ($(D)+(-0.4\tw,0.5\bs)$);
\coordinate (K) at ($(D)+(-0.4\tw,-0.5\bs)$);
\coordinate (L) at ($(E)+(-0.4\tw,0.5\bs)$);
\coordinate (M) at ($(E)+(-0.4\tw,-0.5\bs)$);
\coordinate (N) at ($(E)+(-0.5\tw,0)$);
\coordinate (O) at ($(F)+(0.4\tw,0.5\bs)$);
\coordinate (P) at ($(F)+(0.4\tw,-0.5\bs)$);
\filldraw[draw=yellow!70!white,fill=yellow!20!white] (C)--(D)--(E)--(F)--(C);
\filldraw[red!30!yellow] (D)--(J)-- (H) -- (K) -- (D);
\filldraw[red!30!yellow] (C)--(G) --(H)--(I)--(C);
\fill[red!30!yellow] (H) circle (0.5\bs);
\filldraw[red!30!yellow] (E)--(L)-- (N) -- (M) -- (E);
\filldraw[red!30!yellow] (F)--(O) --(N)--(P)--(F);
\fill[red!30!yellow] (N) circle (0.5\bs);
\end{tikzpicture}
\newenvironment{mynote}{\tikzmark{AA}}{\tikzmark{BB}}
\begin{mynote}
I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ.
\end{mynote}
\end{document}
که خروجی آن به صورت زیر است:
با توجه به این که از گزینه های remember picture و overlay استفاده کرده ایم می خواهیم این محیط قابل استفاده مجدد باشد و بتوانیم بارها از آن استفاده کنیم و اگر متن در اطراف آن باشد مشکلی پیش نیاید اما چنین نیست. مثلا با کد زیر مشکل پیش می آید.
\documentclass{article}
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{tikzmark,calc}
\begin{document}
\newcommand{\tw}{\textwidth}
\newcommand{\bs}{\baselineskip}
\begin{tikzpicture}[remember picture,overlay]
\coordinate (A) at ($(pic cs:AA)+(0,2\bs)$);
\coordinate (B) at ($(pic cs:BB)+(0,-1\bs)$);
\coordinate (C) at ($(A-|current page text area.west)$);
\coordinate (D) at ($(A-|current page text area.east)$);
\coordinate (E) at ($(B-|current page text area.east)$);
\coordinate (F) at ($(B-|current page text area.west)$);
\coordinate (G) at ($(C)+(0.4\tw,0.5\bs)$);
\coordinate (H) at ($(C)+(0.5\tw,0)$);
\coordinate (I) at ($(C)+(0.4\tw,-0.5\bs)$);
\coordinate (J) at ($(D)+(-0.4\tw,0.5\bs)$);
\coordinate (K) at ($(D)+(-0.4\tw,-0.5\bs)$);
\coordinate (L) at ($(E)+(-0.4\tw,0.5\bs)$);
\coordinate (M) at ($(E)+(-0.4\tw,-0.5\bs)$);
\coordinate (N) at ($(E)+(-0.5\tw,0)$);
\coordinate (O) at ($(F)+(0.4\tw,0.5\bs)$);
\coordinate (P) at ($(F)+(0.4\tw,-0.5\bs)$);
\filldraw[draw=yellow!70!white,fill=yellow!20!white] (C)--(D)--(E)--(F)--(C);
\filldraw[red!30!yellow] (D)--(J)-- (H) -- (K) -- (D);
\filldraw[red!30!yellow] (C)--(G) --(H)--(I)--(C);
\fill[red!30!yellow] (H) circle (0.5\bs);
\filldraw[red!30!yellow] (E)--(L)-- (N) -- (M) -- (E);
\filldraw[red!30!yellow] (F)--(O) --(N)--(P)--(F);
\fill[red!30!yellow] (N) circle (0.5\bs);
\end{tikzpicture}
\newenvironment{mynote}{\tikzmark{AA}}{\tikzmark{BB}}
\begin{mynote}
I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ. I want to define a reusable environment with TikZ.
\end{mynote}
\par
This is some text after the mynote environment but overlaps it. This is some text after the mynote environment but overlaps it. This is some text after the mynote environment but overlaps it. This is some text after the mynote environment but overlaps it.
\par
\begin{mynote}
I want to use the mynote environment again, but it doesn't work. I want to use the mynote environment again, but it doesn't work. I want to use the mynote environment again, but it doesn't work. I want to use the mynote environment again, but it doesn't work.
\end{mynote}
\end{document}
چگونه می توان این مشکل را حل کرد؟
توجه! ممکن است برای دیدن خروجی کامل نیاز به چند بار پردازش باشد.