Package marginnote doesn’t type the margin note text in the margin paragraph section

hebrewmarginnote

Consider the following MWE:

\documentclass[oneside,leqno,fleqn]{book}
\usepackage{marginnote}

\usepackage{geometry}
\geometry{%
left=70mm,
textwidth=130mm,
marginparsep=8.2mm,
marginparwidth=50mm,
showframe
}

\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\defaultfontfeatures{Scale = MatchUppercase , Ligatures =TeX}
\newfontfamily\englishfont{Latin Modern Roman}[Script=Latin,Language=English]
\newfontfamily\hebrewfont{David CLM}[Script=Hebrew]

\begin{document}
לורם איפסום דולור סיט אמט.
\marginnote{זו הערה שצריכה להופיע בשולי הדף}
\end{document}

enter image description here

Why is the marginnote text not typed in the margin paragraph area? How to fix it?

Best Answer

I think that the source of that deviation is from the fact that bidi changes the value of \oddsidemargin. Note that by default marginnote should be touching the right border of the marginpar part. Here is a quick patch that should solve your particular case

%!TEX TS-program = xelatex

\documentclass[oneside,leqno,fleqn]{book}
\usepackage{marginnote}
\usepackage{regexpatch}
\makeatletter
\xpatchcmd{\@mn@@@marginnote}{\else\kern\oddsidemargin}{%
    \else
    \@mn@if@RTL{%
        \kern\dimexpr\mn@pagewidth-\marginnotetextwidth-\oddsidemargin-2in\relax
    }{%
        \kern\oddsidemargin
    }%
}{}{}
\makeatother
\usepackage{geometry}
\geometry{%
    left=70mm,
    textwidth=130mm,
    marginparsep=8.2mm,
    marginparwidth=50mm,
    showframe
}

\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\defaultfontfeatures{Scale = MatchUppercase , Ligatures =TeX}
\newfontfamily\englishfont{Latin Modern Roman}[Script=Latin,Language=English]
\newfontfamily\hebrewfont{David CLM}[Script=Hebrew]

\begin{document}
    לורם איפסום דולור סיט אמט.
    \marginnote{זו הערה שצריכה להופיע בשולי הדף}
\end{document}

enter image description here

With lualatex you wont get this deviation

%!TEX TS-program = lualatex

\documentclass[oneside,leqno,fleqn]{book}
\usepackage{marginnote}

\usepackage{geometry}
\geometry{%
    right=70mm, %<-- note the change
    textwidth=130mm,
    marginparsep=8.2mm,
    marginparwidth=50mm,
    showframe
}

\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\defaultfontfeatures{Scale = MatchUppercase , Ligatures =TeX}
\newfontfamily\englishfont{Latin Modern Roman}[Script=Latin,Language=English]
\newfontfamily\hebrewfont{David CLM}[Script=Hebrew]

\begin{document}
    לורם איפסום דולור סיט אמט.
    \marginnote{זו הערה שצריכה להופיע בשולי הדף}
\end{document}