2

It seems LaTeX can't tell whether it's on an even or odd page when it's at the beginning of a new page. I'm trying to put text in the margin using a custom sort of method in a book that I'm writing. marginpar and marginnote won't work for various reasons. I found this method here. I don't fully understand the syntax but I can mostly tell what it's doing.

I've printed things to the margins in 3 places using marginpar marginnote and the custom method, mynote: once at the beginning of the document, once at the beginning of a new page of the document, and once at the beginning of a new page of the document that is created by \newpage. The 1st and 3rd instances put each of the text in the correct place, but the second instance puts the mynote in the wrong margin, as though it thinks it's still on the previous page.

I've tried \strictpagecheck, that doesn't do anything. I can't really think of anything else to try.

Can anyone give some insight? To clarify, I want to have the "My Note" on the second page be on the left, as it should be, and as the marginpar and marginnote are.

EDIT: As per @Werner 's recommendation, I have changed it to

\documentclass{book}
\usepackage{marginnote}
\usepackage{tabto}
\usepackage{changepage}

\newcommand\mynote[1]{%
    \checkoddpage\ifoddpage
    \tabto*{\dimexpr\textwidth+\marginparsep}%
    \else
    \tabto*{\dimexpr-\marginparsep-\marginparwidth\relax}%
    \fi
    \smash{\begin{minipage}[t]{\marginparwidth}{#1}\end{minipage}}%
    \tabto*{\TabPrevPos}%
}

\begin{document}    
\marginnote{Margin Note}
\mynote{My Note}
\marginpar{Margin Par}

\vspace{60em}
\marginnote{Margin Note}
\mynote{My Note}
\marginpar{Margin Par}

\newpage

\marginnote{Margin Note}
\mynote{My Note}
\marginpar{Margin Par}
\end{document}

But it still doesn't seem to get the My Note to the left on the second page for me, no matter how many times I compile. The output is here

If it helps to know the context, I'm using this MyNote thing for my "Asides" in my book on page 232.

  • Welcome! Please note that you should attribute the code you are using. Please provide a link to the source. – cfr Nov 10 '16 at 02:58
  • I think the problem is that you are acting too soon. What \marginpar does, I think, is to save the marginal note into a box and then use that later in a context when it can be more confident of getting the checks right. But note that marginal notes will still sometimes end up on the wrong side if things get sufficiently complicated. – cfr Nov 10 '16 at 03:22
  • That makes sense. My reason for not using marginpar and marginnote, I think, was that I couldn't use an mdframed environment inside of it. So I tried to use this custom kind of approach. – MaanDoabeDa Nov 10 '16 at 03:25
  • You could use some other kind of framed box, since you obviously don't need it to be breakable here. – cfr Nov 10 '16 at 03:29

0 Answers0