4

Using \pagedir TRT with \pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm,landscape] from pgfpages package produce logical pages to be shifted out of page.

Same issue with layouts 4 on 1, 8 on 1, 16 on 1.

% lualatex 
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{pgfpages}

\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm,landscape]

\begin{document}

\pagedir TRT \bodydir TRT \pardir TRT

\Huge 

Page 1
 
\newpage

Page 2

\end{document}

enter image description here

Update 22/08/2020

I find a method to shift logical pages using \pagerightoffset, the problem is for every layout I need to add manually the amount of shift.

Example with 2 on 1 layout landscape page

% lualatex 
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{pgfpages}


\pgfpagesuselayout{2 on 1}[a4paper,landscape]

\begin{document}

\pagerightoffset = .55\pgfphysicalwidth % <--
\pagedir TRT \bodydir TRT \pardir TRT 

\Huge 

Page 1
 
\newpage

Page 2

\end{document}

enter image description here

3
  • I've opened an issue for this on pgfmorepages at github.com/loopspace/pgfmorepages/issues/4 Oct 29, 2020 at 14:29
  • With the 2 on 1 layout that you have, what should the order of logical pages be on the physical page? In the image, you have Page 1 on the left with Page 2 on the right. With RTL, shouldn't it be the other way around? Oct 29, 2020 at 14:30
  • @AndrewStacey yes with TRT page first page should be on the right and the second on the left.
    – Salim Bou
    Oct 29, 2020 at 14:54

2 Answers 2

3

I think you'd have to make a new layout that lays out the pages RTL.

I change one line in the 2 on 1 layout from:

center=\pgfpoint{.75\pgfphysicalwidth}{.5\pgfphysicalheight}%

to:

center=\pgfpoint{-.25\pgfphysicalwidth}{.5\pgfphysicalheight}%

I'ts possible to do this with xpatch:

\usepackage{xpatch}
\expandafter\xpatchcmd\csname pgfpages@layout@2 on 1\endcsname
  {center=\pgfpoint{.75\pgfphysicalwidth}{.5\pgfphysicalheight}}
  {center=\pgfpoint{-.25\pgfphysicalwidth}{.5\pgfphysicalheight}}
  {}
  {}

For the layouts with more pages per page, you'd need multiple calls to xpatchcmd.

Full example:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{pgfpages}

\pgfpagesdeclarelayout{rtl 2 on 1}
{
  \edef\pgfpageoptionheight{\the\paperwidth} % landscaped by default
  \edef\pgfpageoptionwidth{\the\paperheight}
  \def\pgfpageoptionborder{0pt}
  \def\pgfpageoptionfirstshipout{1}
}
{
  \pgfpagesphysicalpageoptions
  {%
    logical pages=2,%
    physical height=\pgfpageoptionheight,%
    physical width=\pgfpageoptionwidth,%
    current logical shipout=\pgfpageoptionfirstshipout%
  }
  \ifdim\paperheight>\paperwidth\relax
    % put side-by-side
    \pgfpageslogicalpageoptions{1}
    {%
      border shrink=\pgfpageoptionborder,%
      resized width=.5\pgfphysicalwidth,%
      resized height=\pgfphysicalheight,%
      center=\pgfpoint{.25\pgfphysicalwidth}{.5\pgfphysicalheight}%
    }%
    \pgfpageslogicalpageoptions{2}
    {%
      border shrink=\pgfpageoptionborder,%
      resized width=.5\pgfphysicalwidth,%
      resized height=\pgfphysicalheight,%
      center=\pgfpoint{-.25\pgfphysicalwidth}{.5\pgfphysicalheight}% <- Shift second page to left hand side
    }%
  \else
    % stack on top of one another
    \pgfpageslogicalpageoptions{1}
    {%
      border shrink=\pgfpageoptionborder,%
      resized width=\pgfphysicalwidth,%
      resized height=.5\pgfphysicalheight,%
      center=\pgfpoint{.5\pgfphysicalwidth}{.75\pgfphysicalheight}%
    }%
    \pgfpageslogicalpageoptions{2}
    {%
      border shrink=\pgfpageoptionborder,%
      resized width=\pgfphysicalwidth,%
      resized height=.5\pgfphysicalheight,%
      center=\pgfpoint{.5\pgfphysicalwidth}{.25\pgfphysicalheight}%
    }%
  \fi    
}

\pgfpagesuselayout{rtl 2 on 1}[a4paper,border shrink=5mm,landscape]

\usepackage[bidi=basic-r,nil]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}{Amiri}
      
\begin{document}

\Huge 
نص من اليمين الى اليسار

 الصفحة الأولى 1

\newpage

\Huge 
نص من اليمين الى اليسار

الصفحة الثانية 2

\end{document}

output

5
  • Thanks, this means that I need also to create an rtl layout for 4 on 1, 8 on 1, 16 on 1 layouts?
    – Salim Bou
    Aug 19, 2020 at 14:21
  • @SalimBou, since the layouts are hard coded to be LTR, I can't see any obvious alternative. Perhaps it would be possible to use xpatch if you dig through the what \pgfpagesdeclarelayout actually defines. Aug 19, 2020 at 14:28
  • 1
    \pgfpageslogicalpageoptions{2}{center=\pgfpoint{-.25\pgfphysicalwidth}{.5\pgfphysicalheight}} can be used to solve the issue with 2 on 1 layout.
    – Salim Bou
    Aug 19, 2020 at 20:28
  • It looks like in LTR document the origin of coordinate is at left lower corner but in RTL the origin change with layout 2 on 1, 4 on 1, .....
    – Salim Bou
    Aug 19, 2020 at 20:55
  • We need also this patch of \pgfpages@buildshipoutbox command as reference point in TRT page is at lower right point unlike TLT page \xpatchcmd{\pgfpages@buildshipoutbox}{\pgfpoint{-.5\pgfutil@tempdima}}{\pgfpoint{.5\pgfutil@tempdima}}{}{}
    – Salim Bou
    Aug 24, 2020 at 14:15
0

I find a solution which is inverting x coordinate inside every \pgfpoint command like this

\let\Pgfpoint\pgfpoint
\def\pgfpoint#1#2{\Pgfpoint{-1*#1}{#2}}

This patch needs to be added to commands in pgfpages containing the command \pgfpoint to limit the action of patch inside other commands from other packages

% lualatex 
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{pgfpages}


\let\Pgfpoint\pgfpoint
\def\pgfpoint#1#2{\Pgfpoint{-1*#1}{#2}}
\pgfpagesuselayout{4 on 1}[a4paper,landscape]

\begin{document}

\pagedir TRT \bodydir TRT \pardir TRT 

\Huge 

Page 1
 
\newpage

Page 2

\newpage

Page 3

\newpage

Page 4

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.