1

Hello guys I am using lualatex to write in Arabic using latex but when I use a personalized tcolorbox it gives me the result in the picture below the next code:

\documentclass{book}
\usepackage[paper width=5cm,paper height=5cm]{geometry}
\usepackage[most]{tcolorbox}
\usepackage[bidi=basic,layout=graphics]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}{Amiri}

\pagestyle{empty} \newtcbtheorem{defi}{تعريف}% { % frame stuff enhanced,frame empty,interior empty, colframe=white,%green!25!blue, colback=white, borderline west={3pt}{0pt}{green!25!blue},breakable, left=0.2cm, right skip={-0.029\linewidth}, % title stuff attach boxed title to top left={yshift=-2mm,xshift=-5mm}, coltitle=black, fonttitle=\bfseries, colbacktitle=white, boxed title style={boxrule=1pt,rounded corners,colframe=green!25!blue}}{defi}

\begin{document} Text text text text\par Text text text text\par Text text text text

\begin{tcolorbox}[breakable] وشا ضرك \end{tcolorbox}

\begin{defi} السلام عليكم لاباس \end{defi} \end{document}

enter image description here

Salim Bou
  • 17,021
  • 2
  • 31
  • 76

2 Answers2

2

Solution from here: problem with tcolorbox package and the arabi one : Add fontupper=\selectlanguage{arabic} to the tcolorbox options.

layout

Also, you have to tell babel which parts are which. (see comment in tcbraster with two side-by-side lists in English and Arabic).

I made some minor adjustments to the layout,

MWE

\documentclass{book}
%\usepackage[paper width=5cm,paper height=5cm]{geometry}
\usepackage[most]{tcolorbox}
\usepackage[bidi=basic]{babel}
%\babelprovide[import,main]{arabic}
\babelprovide[import, onchar = ids fonts]{arabic}
\babelfont[arabic]{rm}[Renderer=HarfBuzz]{Amiri}

\pagestyle{empty}

\newtcbtheorem{defi}{تعريف}% { % frame stuff enhanced, % frame empty,interior empty, colframe=green!25!blue, colback=blue!10, borderline east={3pt}{0pt}{green!25!blue},breakable, left=0.2cm, right skip={-0.029\linewidth}, fontupper=\selectlanguage{arabic}, % fontlower=\selectlanguage{arabic}, % title stuff attach boxed title to top right={yshift=-2mm,xshift=-5mm}, coltitle=black, fonttitle=\bfseries\large, colbacktitle=green!5, boxed title style={boxrule=1pt,rounded corners,colframe=green!25!blue}}{defi}

\begin{document} Text text text text\par Text text text text\par Text text text text

\begin{tcolorbox}\begin{otherlanguage}{arabic} وشا ضرك \end{otherlanguage} \end{tcolorbox}

\begin{defi}{}{}{\selectlanguage{arabic}}

السلام عليكم لاباس

\end{defi}

\end{document}

Cicada
  • 10,129
2

The problem is that defi env is in RTL context anchors of titlebox are shifted you need to place defi in LTR context with

\AddToHook{env/defi/begin}{\textdir TLT \bodydir TLT}

Then frame title and frame text must be preceded with \textdir TRT \bodydir TRT \pardir TRT using before title and before upper (before lower) keys

\documentclass{book}
\usepackage[paper width=5cm,paper height=5cm,centering]{geometry}
\usepackage[most]{tcolorbox}
\usepackage[bidi=basic,layout=graphics]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}{Amiri}

\AddToHook{env/defi/begin}{\textdir TLT \bodydir TLT}%

\pagestyle{empty} \newtcbtheorem{defi}{تعريف}% { % frame stuff before title=\textdir TRT \bodydir TRT \pardir TRT, before upper=\textdir TRT \bodydir TRT \pardir TRT, before lower=\textdir TRT \bodydir TRT \pardir TRT, enhanced,frame empty,interior empty, colframe=white, colback=white, borderline east={3pt}{0pt}{green!25!blue}, left=0.2cm, right skip={-0.029\linewidth}, % title stuff attach boxed title to top right={yshift=-2mm,xshift=5mm},breakable, coltitle=black, fonttitle=\bfseries, colbacktitle=white, boxed title style={boxrule=1pt,rounded corners,colframe=green!25!blue}}{defi}

\begin{document}

\begin{defi}{}{} السلام عليكم لاباس \end{defi}

\begin{defi}{}{} السلام عليكم لاباس

السلام عليكم لاباس

السلام عليكم لاباس

السلام عليكم لاباس

السلام عليكم لاباس

السلام عليكم لاباس

السلام عليكم لاباس

السلام عليكم لاباس

السلام عليكم لاباس

السلام عليكم لاباس

السلام عليكم لاباس

السلام عليكم لاباس

السلام عليكم لاباس

السلام عليكم لاباس \end{defi}

السلام عليكم

\end{document}

enter image description here

Patching \tikzpicture@tcb@hooked from skin library also like this give a correct result

\documentclass{book}
\usepackage[paper width=5cm,paper height=5cm,centering]{geometry}
\usepackage[most]{tcolorbox}
\usepackage[bidi=basic,layout=graphics]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}{Amiri}

\makeatletter \bbl@sreplace\tikzpicture@tcb@hooked{\noexpand\tikzpicture}% {\textdir TLT\noexpand\tikzpicture}% \makeatother

\pagestyle{empty} \newtcbtheorem{defi}{تعريف}% { % frame stuff enhanced,frame empty,interior empty, colframe=white, colback=white, borderline east={3pt}{0pt}{green!25!blue}, left=0.2cm, right skip={-0.029\linewidth}, % title stuff attach boxed title to top right={yshift=-2mm,xshift=5mm},breakable, coltitle=black, fonttitle=\bfseries, colbacktitle=white, boxed title style={boxrule=1pt,rounded corners,colframe=green!25!blue}}{defi}

\begin{document}

\begin{defi}{}{} السلام عليكم لاباس \end{defi}

السلام عليكم

\end{document}

Salim Bou
  • 17,021
  • 2
  • 31
  • 76