0

With this example I have created a clickable area on top of an image in right to left context, the result is fine outside minipage (clickable box appears on the right). But when repeating the same code on image inside a minipage clickable box appears on the left. Is there an explanation for this or am I missing something here ?

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[bidi=basic]{babel}
\babelprovide[import, main]{arabic}

\newbox\mybox

\parindent=0pt

\begin{document}

\setbox\mybox=\vbox{\hyperlink{top}{%
       \vbox to 2cm{%
        \hbox to 2cm{\hfil}%
        \vfil%
      }%
    }}%
    
\ht\mybox=0pt
\dp\mybox=0pt
\wd\mybox=0pt    

\copy\mybox%    
\includegraphics[width=.5\linewidth]{example-image}

\bigskip

\begin{minipage}{\linewidth}
\box\mybox%    
\includegraphics[width=.5\linewidth]{example-image}
\end{minipage}

\newpage

\hypertarget{top}{Text text Text}

\end{document}

enter image description here

Update

If we remove the line \includegraphics[width=.5\linewidth]{example-image} link box appears on the right, so the problem appears when adding anything in the same line after the link box.

1 Answer 1

2

This has nothing to do with hyperref. A minipage without additional optional argument uses \vcenter to center the box and so you are in mathmode. As you are using low-level TeX boxes this stays and affects your box.

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage[bidi=basic]{babel}
\babelprovide[import, main]{arabic}

\newbox\mybox

\parindent=0pt

\begin{document}
\newsavebox\myboxB
\sbox\myboxB{\mbox{.!.!.}}

% LaTeX boxes work:
\begin{minipage}{\linewidth}
\usebox\myboxB\par
xxx
\end{minipage}

\bigskip

\setbox\mybox=\vbox{\hbox{.!.!}}%

%Low-level fail
\begin{minipage}{\linewidth}
\copy\mybox%    
xxx
\end{minipage}
    
\bigskip

% [t] alignment works:
\begin{minipage}[t]{\linewidth}
\copy\mybox%    
xxx
\end{minipage}

\bigskip

% leaving vmode works:
\begin{minipage}{\linewidth}
\leavevmode\copy\mybox \par%    
xxx
\end{minipage}


\bigskip 
  
%changing mathdir works:
\mathdir TRT
\begin{minipage}[t]{\linewidth}
\copy\mybox%    
xxx
\end{minipage}

\end{document}

enter image description here

The problem "disappears" if you remove the graphic as the minipage then doesn't have the width you expect it to have (again because of your use of low-level TeX boxes which do not start a paragraph). That is independant of bidi:

\documentclass{article}
\newbox\mybox

\parindent=0pt

\begin{document}

\setbox\mybox=\vbox{\hbox{.!.!}}%

\fbox{%
\begin{minipage}{\linewidth}
\copy\mybox
\end{minipage}}
    
\fbox{%
\begin{minipage}{\linewidth}
\copy\mybox x
\end{minipage}}    
    
\fbox{%
\begin{minipage}{\linewidth}
\leavevmode\copy\mybox 
\end{minipage}}       
\end{document}

enter image description here

1
  • Thanks for the detailed answer that clarified a lot for me.
    – Salim Bou
    Jan 4, 2023 at 15:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .