Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layout=graphics fail with breakable box (tcolorbox package) #95

Closed
seloumi opened this issue Sep 23, 2020 · 12 comments
Closed

layout=graphics fail with breakable box (tcolorbox package) #95

seloumi opened this issue Sep 23, 2020 · 12 comments
Labels
enhancement New feature or request

Comments

@seloumi
Copy link
Contributor

seloumi commented Sep 23, 2020

This example with option layout=graphics produce breakable box out of page ( the non breakable one is ok)

\documentclass{report}
\usepackage[paper width=5cm,paper height=5cm]{geometry}
\usepackage[most]{tcolorbox}
\usepackage[bidi=basic,layout=graphics]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}{Amiri}

\pagestyle{empty}

\begin{document}
Text text text text\par
Text text text text\par
Text text text text

\begin{tcolorbox}[breakable]
Text text text text\par
Text text text text\par
Text text text text
\end{tcolorbox}

\begin{tcolorbox} 
Text text text text\par
Text text text text\par
Text text text text
\end{tcolorbox}

\end{document}

image

@seloumi
Copy link
Contributor Author

seloumi commented Sep 24, 2020

With layout=graphics if we insert pgfpicture environment at the beginning of paragraph (vmode) it appear on the margin

\documentclass{report}
\usepackage[showframe]{geometry}
\usepackage[most]{tcolorbox}
\usepackage[bidi=basic,layout=graphics]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}{Amiri}

\pagestyle{empty}

\parindent=0pt

\begin{document}

\begin{pgfpicture}
\color{red}
\pgfpathrectangle{\pgfpointorigin}{\pgfpoint{3cm}{2cm}}
\pgfusepath{stroke}
\end{pgfpicture}

\leavevmode
\begin{pgfpicture}
\color{red}
\pgfpathrectangle{\pgfpointorigin}{\pgfpoint{3cm}{2cm}}
\pgfusepath{stroke}
\end{pgfpicture}

\end{document}

image

@seloumi
Copy link
Contributor Author

seloumi commented Sep 25, 2020

Adding \leavevmode to \bbl@pictsetdir solve the issue

\makeatletter
 \def\bbl@pictsetdir{%
     \ifcase\bbl@thetextdir
       \let\bbl@pictresetdir\relax
     \else
       \leavevmode\unskip\textdir TLT\relax
       \def\bbl@pictresetdir{\textdir TRT\relax}%
     \fi}%
\makeatother 

@jbezos
Copy link
Contributor

jbezos commented Sep 26, 2020

Thank you. Graphics in RTL are, as you know, problematic. I'd like to make some tests before making the final decision.

@seloumi
Copy link
Contributor Author

seloumi commented Oct 4, 2020

@jbezos maybe patch of pgfpicture environment for RTL context should be done at the end in \endpgfpicture without changing text direction.

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{tikz,amssymb}
\usepackage[bidi=basic,nil]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}{Amiri}
            
\fboxsep=0pt            
\parindent=0pt

\makeatletter
  
\def\endrlpgfpicture{%
              \ifpgfrememberpicturepositiononpage%
                \hbox to0pt{\pgfsys@markposition{\pgfpictureid}}%
              \fi%
              % ok, now let's position the box
              \ifdim\pgf@picmaxx=-16000pt\relax%
                % empty picture. make size 0.
                \global\pgf@picmaxx=0pt\relax%
                \global\pgf@picminx=0pt\relax%
                \global\pgf@picmaxy=0pt\relax%
                \global\pgf@picminy=0pt\relax%
              \fi%
              % Shift baseline outside:
              \pgf@relevantforpicturesizefalse%
              \pgf@process{\pgf@baseline}%
              \xdef\pgf@shift@baseline{\the\pgf@y}%
              %
              \pgf@process{\pgf@trimleft}%
              \global\advance\pgf@x by\pgf@picmaxx% <--
              % prepare \hskip\pgf@trimleft@final.
              % note that \pgf@trimleft@final is also queried
              % by the pgf image externalization.
              \xdef\pgf@trimleft@final{\the\pgf@x}% <--
              %
              \pgf@process{\pgf@trimright}%
              \global\advance\pgf@x by\pgf@picminx% <--
              % prepare \hskip\pgf@trimright@final.
              % note that \pgf@trimright@final is also queried
              % by the pgf image externalization.
              \xdef\pgf@trimright@final{-\the\pgf@x}% <--
        %
        \pgf@remember@layerlist@globally
            \endgroup%
            \hss%
          \egroup%
      \pgf@restore@layerlist@from@global
          \pgf@insertlayers%
        \endgroup%
        \pgfsys@discardpath%
        \endgroup%
      \pgfsys@endscope%
    \pgfsys@endpicture%
    \endgroup%
    \hss
  \egroup%
  \pgfsys@typesetpicturebox\pgfpic%
  \endgroup%
}

\let\endlrpgfpicture\endpgfpicture  

\def\endpgfpicture{%
\ifcase\bbl@thetextdir
\endlrpgfpicture%
\else
\endrlpgfpicture%
\fi
}
\makeatother
            
\begin{document}

$\blacktriangleleft$%
\fbox{%
\begin{pgfpicture}
\color{red}
\pgfpathmoveto{\pgfpointorigin}
\pgfpathlineto{\pgfpoint{1cm}{1cm}}
\pgfpathlineto{\pgfpoint{4cm}{3cm}}
\pgfusepath{stroke}
\end{pgfpicture}}%
$\blacktriangleright$

\selectlanguage{nil}

$\blacktriangleright$%
\fbox{%
\begin{pgfpicture}
\color{red}
\pgfpathmoveto{\pgfpointorigin}
\pgfpathlineto{\pgfpoint{1cm}{1cm}}
\pgfpathlineto{\pgfpoint{4cm}{3cm}}
\pgfusepath{stroke}
\end{pgfpicture}}%
$\blacktriangleleft$

\end{document}

Changes was in

  • \global\advance\pgf@x by\pgf@picmaxx (orig \global\advance\pgf@x by-\pgf@picminx )

  • \xdef\pgf@trimleft@final{\the\pgf@x} (orig \xdef\pgf@trimleft@final{-\the\pgf@x})

  • \global\advance\pgf@x by\pgf@picminx (orig \global\advance\pgf@x by-\pgf@picmaxx)

  • \xdef\pgf@trimright@final{-\the\pgf@x} (orig \xdef\pgf@trimright@final{\the\pgf@x})

@jbezos
Copy link
Contributor

jbezos commented Oct 6, 2020

Sadly, it breaks some of the figures in my test files. So, I have to investigate further.

@seloumi
Copy link
Contributor Author

seloumi commented Oct 6, 2020

With last update of latex layout graphics produce an error exactly with this part

\def\put(#1,#2)#3{%  Not easy to patch. Better redefine.
    \@killglue
    \raise#2\unitlength
    \hb@xt@\z@{\kern#1\unitlength{\bbl@pictresetdir#3}\hss}}%
\documentclass{report}
\usepackage{tikz}
\usepackage[bidi=basic]{babel}
\babelprovide[import,main]{arabic}
\babelfont{rm}{Amiri}

\makeatletter
   \let\bbl@pictresetdir\relax
   \def\put(#1,#2)#3{%  Not easy to patch. Better redefine.
     \@killglue
     \raise#2\unitlength
     \hb@xt@\z@{\kern#1\unitlength{\bbl@pictresetdir#3}\hss}}%
\makeatother

\begin{document}
text
\end{document}

test3.log

@jbezos
Copy link
Contributor

jbezos commented Oct 9, 2020

This is another issue. I'll open a new one.

@jbezos jbezos added the enhancement New feature or request label Oct 27, 2020
@jbezos
Copy link
Contributor

jbezos commented Feb 18, 2021

As to the issue with tcolorbox I think the new hooking mechanism in LaTeX can help a lot. It seems to work if I add:

\AddToHook{env/tcolorbox/begin}{\textdir TLT }

Which doesn't mean it is the solution.

@jbezos
Copy link
Contributor

jbezos commented Feb 22, 2021

@seloumi After some tests, I'd say this little addition is enough. I'm closing this issue, but don't hesitate to re-open it if necessary.

@jbezos jbezos closed this as completed Feb 22, 2021
@seloumi
Copy link
Contributor Author

seloumi commented Feb 22, 2021

Thanks @jbezos for the solution, I have posted the issue on pgf repository to create an adapted pgfpicture env for RTL context which can solve large number of related issues.
My request did not receive a response pgf-tikz/pgf#939 (comment)

@jbezos
Copy link
Contributor

jbezos commented Feb 23, 2021

@seloumi I'll have a look at it.

@jbezos
Copy link
Contributor

jbezos commented Mar 3, 2021

I've added a little and tentative piece of code to set the picture box and place the origin (0,0) at the correct place (lower left corner). In my tests, the text is correctly rendered, too. Any shift inside this box should be done by the corresponding graphics package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants