0

A description of the problem by way of a minimal working example

I saved the following LaTeX code in the file ~/Test.tex.

\documentclass{article}
\usepackage[hmarginratio=1:4]{geometry}
\usepackage[bidi=basic,hebrew,provide=*]{babel}
\usepackage{marginnote}
\makeatletter
\newif\if@RTL  \@RTLtrue
\makeatother
\begin{document}
\[
x + y = z\marginnote{Hello, world!}
\]
\end{document}

The code creates a document of class article, and adjusts the relative width of the article's left and right margins. It then establishes Hebrew as the document's main, and only language via the babel package. Then, after loading the marginnote package, it implements a hack suggested by Javier Bezos to resolve an issue arising when the marginnote package interacts with Hebrew documents managed by babel. Then, in the document's body, an equation, in which a margin note is embedded, is written in display mode.

Then I executed the following commands in the Terminal.

> cd ~
> lualatex Test
> lualatex Test

The compilation completed successfully, with no warning in ~/Test.log; in particular, no warning suggesting to rerun lualatex. As a consequence of the compilation, the file ~/Test.pdf was created. When opened in a PDF viewer the file displayed as follows. (I screenshot only the relevant part of the display.)

No margin note

As can be seen, there's no margin note on the page.

Questions

  1. Why wasn't the margin note printed out?
  2. What can I do to make the margin note appear without giving up on the elements that make up the preamble: the geometry package with adjusted margins, the babel package with Hebrew as the main language, and Javier Bezos' hack. (Actually, the hack can be done away with, as long as it is replaced by another solution to this problem, but I'd prefer it if Bezos' elegant hack could be retained.)
Evan Aad
  • 11,066
  • 1
    I wouldn't use the \@RTLtrue hack. That is clearly meant for compatibility with the bidi package and so for xelatex but the bidi models of xelatex and lualatex are different. – Ulrike Fischer Dec 30 '22 at 21:49
  • @UlrikeFischer The same problem occurs if Bezos' hack is replaced by your patch (at least in Overleaf, my normal computer is not currently at my disposal). – Evan Aad Dec 30 '22 at 21:55
  • 1
    well math is left to right isn't it? So you probably need the unpatch version. – Ulrike Fischer Dec 30 '22 at 22:06
  • @UlrikeFischer How can I have the patched and the unpatched versions in the same document? If I insert \let\mymarginnote\marginnote after \usepackage{marginnote} but before your patch, and use \mymarginnote inside the equation instead of \marginnote, I get the same erroneous result. – Evan Aad Dec 30 '22 at 22:17
  • 1
    You can try if it works if you use Javier's method and switch to \@RTLfalse before the equation. But imho you will have to properly test and adapt marginnote. That mean make a copy, e.g. bidi-marginnote, and then study the code and test changes. – Ulrike Fischer Dec 30 '22 at 23:32
  • @UlrikeFischer Thanks. Your last suggestion worked insofar as the margin note became visible. However, it is placed in the right margin, whereas it should be placed in the left margin, since the document's main language is Hebrew, and all margin notes should by default be placed in the same margin. – Evan Aad Dec 31 '22 at 05:33

1 Answers1

1

Qustion 1

The margin note actually is printed out, but, because the margin note is typeset inside math mode, the direction of kerning (which the package marginnote heavily rely upon) is opposite to that outside of math mode, which makes the margin note flush outside the right margin of the page (due to wrong calculation of the package, that expected kerning to be done to the right).

You can observe that by moving your margin note more to the left

\documentclass{article}
\usepackage[hmarginratio=1:4]{geometry}
\usepackage[bidi=basic,hebrew,provide=*]{babel}
\usepackage{marginnote}
\makeatletter
\newif\if@RTL  \@RTLtrue
\makeatother
\begin{document}
    \[
    x + y = z\marginnote{Hello, world!}\cos (2\theta) = \cos^2 \theta - \sin^2 \theta
    \]
\end{document}

enter image description here

Question 2

You can exit math mode by entering restricted horizontal mode (via \hbox) and restore the direction of \pardir and \textdir (that has changed inside math mode)

\documentclass{article}
\usepackage[hmarginratio=1:4,showframe]{geometry}
\usepackage[bidi=basic,hebrew,provide=*]{babel}
\usepackage{marginnote}
\makeatletter
\newif\if@RTL  \@RTLtrue
\makeatother
\begin{document}
    \[
    x + y = z\hbox{\pardir TRT \textdir TRT\marginnote{Hello, world!}}
    \]
\end{document}

enter image description here

but it might be better to use \hboxR from luabidi, which does essentially the same, but is more robust

\documentclass{article}
\usepackage[hmarginratio=1:4,showframe]{geometry}
\usepackage[bidi=basic,hebrew,provide=*]{babel}
\usepackage{marginnote}
\usepackage{luabidi}
\makeatletter
\@RTLtrue % luabidi already defines this conditional
\makeatother
\begin{document}
    \[
    x + y = z\hboxR{\marginnote{Hello, world!}}
    \]
\end{document}
Udi Fogiel
  • 3,824
  • Is there a way to use the LuaTex \hboxR solution with \marginnote's voffset optional argument, which moves the margin note vertically relative to the position it would be placed at if the optional argument weren't given? – Evan Aad Mar 19 '23 at 16:11
  • 1
    @EvanAad Do you mean something like x + y = z\hboxR{\marginnote{Hello, world!}[200pt]}? seems to be working. – Udi Fogiel Mar 19 '23 at 16:33