Closed seloumi closed 1 year ago
@u-fischer Changes are limited only for lualatex engine, where it needs to be added?
That doesn't matter. If babel changes internal graphics commands, it means that every change we do there, must be copied into babel too. That is error prone and makes changes more complicated. Beside this: if the direction is wrong, then it is also wrong without babel. Should e.g. polyglossia add these patches too?
@u-fischer Changes do not include all commands in the package, eg with the rotating package only we need to change two commands to correct position of sidewaysfigure
environment in RTL context.
For polyglossia
patches of commands are done with bidi
package.
@u-fischer Changes do not include all commands in the package, eg with the rotating package only we need to change two commands to correct position of
sidewaysfigure
environment in RTL context.For
polyglossia
patches of commands are done withbidi
package.
I agree with @u-fischer that this would be better adding to graphics, adding some documented hook that is always there, but does nothing in LTR text.
Thanks, @seloumi. Please, could you provide a brief description of the issue addressed by this pull request and a test document?
@jbezos First with sidewaysfigure
defined in rotating pkg, embedded image doesn't show up on the page (goes out on the page border) in RTL context
\documentclass{article}
\usepackage{rotating}
\usepackage[bidi=basic,layout=graphics]{babel}
\babelprovide[import, main]{arabic}
\babelfont{rm}{Amiri}
\begin{document}
\begin{sidewaysfigure}
\centering
\includegraphics[scale=0.6]{example-image-a}
\label{fig:mine}
\caption{عنوان الشكل}
\end{sidewaysfigure}
\end{document}
Patching of \@xrotfloat
and \@rotxdblfloat
(for double column floats) solve the issue
\def\@xrotfloat#1[#2]{%
\@float{#1}[#2]%
\bbl@pictsetdir\z@
\begin{lrbox}\rot@float@box
\begin{minipage}\textheight
\bbl@pictresetdir
}
\def\@rotxdblfloat#1[#2]{%
\@float{#1}[#2]%
\hsize\textwidth\linewidth\textwidth
\bbl@pictsetdir\z@
\begin{lrbox}\rot@float@box
\begin{minipage}\textheight
\bbl@pictresetdir
}
@jbezos For graphics
package we need to adjust \rotatebox
and \includegraphics
so we don't have to change direction explicitly every time we use commands.
\documentclass{article}
\usepackage{graphicx}
\usepackage[bidi=basic,layout=graphics]{babel}
\babelprovide[import, main]{arabic}
\babelfont{rm}{Amiri}
\fboxsep=0pt
\def\sample{\fbox{سلام}}
\makeatletter
\long\def\Grot@box@std#1#2{%
\bbl@pictsetdir\@ne%
\Grot@setangle{#1}%
\setbox\z@\hbox{\bbl@pictresetdir{#2}}%
\Grot@x\z@
\Grot@y\z@
\Grot@box
\bbl@pictresetdir
}
\def\Gin@ii[#1]#2{%
\def\@tempa{[}\def\@tempb{#2}%
\ifx\@tempa\@tempb
\def\@tempa{\Gin@iii[#1][}%
\expandafter\@tempa
\else
\begingroup
\bbl@pictsetdir\@ne%
\@tempswafalse
\toks@{\Ginclude@graphics{#2}}%
\setkeys{Gin}{#1}%
\Gin@esetsize
\the\toks@
\endgroup
\fi}
\def\Gin@iii[#1,#2][#3,#4]#5{%
\begingroup
\bbl@pictsetdir\@ne%
\Gin@bboxtrue
\Gin@defaultbp\Gin@llx{#1}%
\Gin@defaultbp\Gin@lly{#2}%
\Gin@defaultbp\Gin@urx{#3}%
\Gin@defaultbp\Gin@ury{#4}%
\Ginclude@graphics{#5}%
\endgroup}
\makeatother
\begin{document}
\huge
قبل
\rotatebox{90}{\sample}
بعد
\qquad
قبل
\babelsublr{\rotatebox{90}{\sample}}
بعد
\vspace{3\baselineskip}
قبل
\includegraphics[scale=.1,angle=90]{example-image}
بعد
\qquad
قبل
\babelsublr{\includegraphics[scale=.1,angle=90]{example-image}}
بعد
\end{document}
@seloumi In this case I’d like to investigate a bit further.
@jbezos For \@xrotfloat
and \@rotxdblfloat
patches can be made using
\AddToHook{cmd/@xrotfloat/before}{\bbl@pictsetdir\z@}
\AddToHook{cmd/@xrotfloat/after}{\bbl@pictresetdir}
\AddToHook{cmd/@rotxdblfloat/before}{\bbl@pictsetdir\z@}
\AddToHook{cmd/@rotxdblfloat/after}{\bbl@pictresetdir}
👍 Perfect, it's one of the things I wanted to investigate.
I don't think that babel should patch like this graphics commands. If interfaces are needed for RTL they should be added in the graphics + rotating package directly.