Subject: Re: bug#71436: Fwd: preview in LuaTeX with RTL as main language does not work

From: Arash Esbati <[email-masked]>
Date: Wed, 12 Jun 2024 13:25:51 +0200

Udicoudco <[email-masked]> writes:

> Oh, there was another typo. I did not test that the documentation
> is typesetting properly, and there was a "\begn{macro}" instead
> of `\begin{macro}`. I also updated the checksum of preview.dtx.
> Tested now with the various engines and things seems to be working
> (but please test thoroughly :)

Thanks for the patch.  I have some minor comments (and I'm not good at
writing TeX-code):

> From 0fe4d61af2d9494539e79ffd354623df9efde3e1 Mon Sep 17 00:00:00 2001
> From: Udi Fogiel <[email-masked]>
> Date: Tue, 11 Jun 2024 11:33:35 +0300
> Subject: [PATCH] consider pagerightoffset in luatex with rtl languages
                   ^ Consider

> This patch will calculate \pagerightoffset when LuaTeX is used
> and the page direction is right to left. It is important as in
                                          ^ 2 spaces please

> this case LuaTeX will use this register, and not \hoffset to
> position the page.
> ---
>  latex/preview.dtx | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/latex/preview.dtx b/latex/preview.dtx
> index 23f5b2da..483e6f82 100644
> --- a/latex/preview.dtx
> +++ b/latex/preview.dtx
> @@ -20,7 +20,7 @@
>  %     Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
>  %     Boston, MA 02110-1301  USA
>  % \fi
> -% \CheckSum{1758}
> +% \CheckSum{1779}
>  % \GetFileInfo{preview.sty}
>  % \date{\filedate}
>  % \author{David Kastrup\thanks{\[email-masked]}}}
> @@ -752,6 +752,7 @@
>     \ifx\pr@offset@override\@undefined
>       \voffset=-\ht\pr@box
>       \hoffset=\z@
> +     \pr@set@pagerightoffset
>     \fi
>     \c@page=\pr@snippet
>     \pr@shipout
> @@ -769,6 +770,22 @@
>  %    \end{macrocode}
>  % \end{macro}
>  % \end{macro}
> +% \begin{macro}{\pr@set@pagerightoffset}
> +%   In |luatex| when page direction is right to left, |\pagerightoffset|
> +%   is used instead of |\hoffset|, so we need to calculate that as well.
> +%    \begin{macrocode}
> +\let\pr@set@pagerightoffset\@empty

Why not defining the macro properly instead of \let-ing?

\newcommand*\pr@set@pagerightoffset{}

> +\ifx\pagerightoffset\@undefined\else
> +  \def\pr@set@pagerightoffset{%
> +    \ifnum\pagedirection=1

I don't think this relevant here, but

\ifnum\pagedirection=1 %

is the safe version?

> +      \pagerightoffset=-1in
> +      \advance\pagerightoffset-\pr@bb@i
> +      \advance\pagerightoffset\pr@bb@iii
> +    \fi
> +  }
> +\fi
> +%    \end{macrocode}
> +% \end{macro}

Best, Arash