2

I built a documentclass which uses the eso-pic package to place content on each page relative to the top left corner. Now I used this documentclass in a document which is (partly) hebrew. For hebrew I am using the polyglossia package, according to this post together with XeLaTeX. The polyglossia uses bidi to switch the page layout to right-to-left.

Everything is working fine except the positioning in the top left corner. The following exaple shows my problem:

\documentclass{article}

% set font for hebrew
\usepackage{fontspec}
\setmainfont{DejaVuSans.ttf}

% if polyglossia is commented
\providecommand{\setLTR}{}
\providecommand{\setRTL}{}

% write "test" a few times
\newcounter{loopcounter}
\newcommand{\writetest}{
    \loop
    \ifnum\value{loopcounter}<36
        Test\theloopcounter 
        \stepcounter{loopcounter}
    \repeat
}

% add the test in the top left corner
\usepackage{calc}
\usepackage{picture}
\usepackage{eso-pic}
\AddToShipoutPictureFG{
    \AtPageUpperLeft{%
        % see the bottom of the question for the \put()
        \put(0,0){
            \raisebox{-\height-3pt}{
                % needed to do left to right align and for breaking
                \parbox{\paperwidth}{
                    \setLTR
                    \writetest
                }
            }
        }
    }
}

\usepackage{polyglossia} % <- If those packages are commented the placing
\setmainlanguage{hebrew} % <- of the top left content is correct.

\begin{document}
    תוכן
\end{document}

If I compile the given example I get the result shown at the bottom of the following picture. But there the content placed at the top left corner is not in the top left corner.

The second upper picture is the exact same example but the \usepackage{polyglossia} and the \setmainlanguage{hebrew} are commented. So the bidi package is not being loaded. The corner text is correct. But now the hebrew text is (of course) not right to left.

enter image description here

As you can see in my provided code I already tried to use \put() (together with the picture package) to fix the offset. But I cannot find out what it is. It should be something like -\textwidth-\marginright. But it isn't.

Note that the \AddToShipoutPictureFG is in the documentclass. It is not in the same file as the content. I want to use the documentclass in various files so the dimensions are changing. I have to know the offset in relation to the page dimensions. Not as absolute values. Using put(-11.872cm, 0) does not solve my problem.

How can I use polyglossia together with eso-pic placing content in the top left corner?

2
  • Would you consider a tikz solution? Commented Mar 8, 2019 at 13:26
  • @DavidPurton Hmm, tinkz is not really for me because of a longer loading time. But the solution may help others so you can still include it :)
    – miile7
    Commented Mar 12, 2019 at 6:43

1 Answer 1

1

Although not what you were hoping for, here's a solution that is easy to implement using the background package and tikz:

\documentclass[letterpaper]{article}

% set font for hebrew
\usepackage{fontspec}
\setmainfont{DejaVuSans.ttf}

% write "test" a few times
\newcounter{loopcounter}
\newcommand{\writetest}{
    \loop
    \ifnum\value{loopcounter}<36
        Test\theloopcounter 
        \stepcounter{loopcounter}
    \repeat
}

% add the test in the top left corner
\usepackage[all]{background}
\backgroundsetup{%
  placement = top,
  color = black,
  opacity=1,
  scale = 1,
  vshift=-6pt,
  contents = {%
    \tikz \node [text width=\paperwidth-12pt, align=justify] {\writetest};
  },
}

\usepackage{polyglossia}
\setmainlanguage{hebrew}

\begin{document}
    תוכן
\end{document}

output

1
  • Thank you for the answer. Maybe I'll give it a try even tough I wanted to avoid tikz. At least for others it may be helpful.
    – miile7
    Commented Mar 12, 2019 at 12:56

You must log in to answer this question.

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