TransWikia.com

Create an adapted pgfpicture with fixed width for RTL context

TeX - LaTeX Asked on January 28, 2021

This is a complement of my question Issue breakable box (tcolorbox package) with babel (layout=graphics)
the problem come from pgfpicture environment. here an example showing the issue

documentclass{article}
usepackage{pgf}
usepackage[showframe]{geometry}

parindent0pt

begin{document}

pagedir TRT pardir TRT textdir TRT bodydir TRT  

A {textdir TLTbegin{pgfpicture}{0pt}{0bp}{50pt}{3cm}
color{red}
pgfpathrectangle{pgfpointorigin}{pgfpoint{10cm}{2cm}}
pgfpathmoveto{pgfpointorigin}
pgfpathlineto{pgfpoint{10cm}{2cm}}
pgfusepath{stroke}
pgfpathmoveto{pgfpointorigin}
pgfpathqcircle{3pt}
pgfsetfillcolor{blue}
pgfusepath{fill}
end{pgfpicture}} B

end{document}

So with begin{pgfpicture}{0pt}{0pt}{50pt}{3cm} contents of environment appears on the margin but in RTL pgfpic box should appears left of A point not right of B.

My question is there a solution which consist of redefining pgfpicture to allow a correct result in RTL context (pgfpicture contents in the page not outside).

enter image description here

Result in RTL context should look like this

enter image description here

One Answer

Here my attempt: two pgfpicture environments the second is void just to create bounding box, look if there is a possibility to use just one pgfpicture environment.

documentclass{article}
usepackage{pgf}
usepackage[showframe]{geometry}

parindent0pt

makeatletter

newboxpgfrtlpic

newdimenpgf@rtlpicminx
newdimenpgf@rtlpicmaxx
newdimenpgf@rtlpicminy
newdimenpgf@rtlpicmaxy


defrtlpgfpicture#1#2#3#4{%
pgf@rtlpicminx=#1relax%
pgf@rtlpicminy=#2relax%
pgf@rtlpicmaxx=#3relax%
pgf@rtlpicmaxy=#4relax%
setboxpgfrtlpichbox dir TLT to 0ptbgrouphsspgfpicture%
}

defendrtlpgfpicture{%
endpgfpictureegroup%
hbox to 0pt{hskip-pgf@rtlpicminxboxpgfrtlpichss}%
pgfpicture{pgf@rtlpicminx}{pgf@rtlpicminy}{pgf@rtlpicmaxx}{pgf@rtlpicmaxy}%
endpgfpicture%
}

makeatother

begin{document}

pagedir TRT pardir TRT textdir TRT bodydir TRT  

A {%
begin{rtlpgfpicture}{0pt}{0pt}{50pt}{3cm}
color{red}
pgfpathrectangle{pgfpointorigin}{pgfpoint{10cm}{2cm}}
pgfpathmoveto{pgfpointorigin}
pgfpathlineto{pgfpoint{10cm}{2cm}}
pgfusepath{stroke}
pgfpathmoveto{pgfpointorigin}
pgfpathqcircle{3pt}
pgfsetfillcolor{blue}
pgfusepath{fill}
end{rtlpgfpicture}%
} B

end{document}

enter image description here

Answered by Salim Bou on January 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP