# tcolorbox and bidi behaviour

When using bidi with tcolorbox package the box is not inline with the text. Running the MWE with bidi commented or not makes it all clear. Can somebody explain this behaviour and possibly come up with a solution/workaround.

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{bidi}

\begin{document}
Lorem ipsum before \tcbox[size=tight, on line]{some tcb text} lorem ipsum after
\end{document}


The cause of the problem is that the bidi package redefines tikzpicture and pgfpicture in a way which puts them into a paragraph. The following also does not work properly with your MWE, if bidi is enabled:

Lorem ipsum before \tikz\node[draw] {text}; lorem ipsum after


One could reset pgfpicture locally to its original behaviour. But, of course, this would disable the bidi adaptions also (locally). But, maybe, this does not matter for you application. Try the following:

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{bidi}

\makeatletter

\tcbset{%
bidi reset/.code={%
\let\pgfpicture\origin@pgfpicture%
\let\endpgfpicture\origin@endpgfpicture%
}
}

\makeatother

\begin{document}
Lorem ipsum before \tcbox[bidi reset, size=tight, on line]{some tcb text} lorem ipsum after
\end{document}


This works for the MWE. But, it may not give the expected results for your intended application since you will have included bidi for a reason...

• this solves the issue. I use tcolorbox to create a wavy underline (see my other post tex.stackexchange.com/questions/225650/…) in a generally roman script containing doc with sporadic non roman script (arabic, persan) text. Feb 2 '15 at 11:28
• @user2263306 I'm glad I could help. Feb 2 '15 at 13:19

This is fixed in version 18.3 of the bidi package. You can even have it RTL:

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{bidi}
\setRTL
\begin{document}
Lorem ipsum before \tcbox[size=tight, on line]{some tcb text} lorem ipsum after
\end{document}


which produces the following output: