1

For the plain tex margin note solution suggest by 'wipet' here, it seems like all the lines preceding, and including the line at which margin note is positioned are pulled down by some length (probably depth of strut).

This screenshot shows how my compiled document looks like (see how first 3 lines are shifted down towards the following lines):

enter image description here

What follows is my complete example where I place this note in different settings on 3 new pages. Command to run this is >>lualatex marginnote.tex. You can uncomment the line that declares package lua-visual-debug to add debug markers too.

% marginnote.tex

\documentclass[notitlepage,letterpaper]{article}

% NOTE: Uncomment the following line, and run with lualatex if you want to visualize debug markers
%\usepackage{lua-visual-debug}
\usepackage{geometry}
\usepackage{fontspec}
\usepackage{blindtext}
\geometry{left=2in,right=2in,top=1in,bottom=1in}
\setmainfont{Verdana}

% wipet's original plain tex margin note solution::
% NOTE: Commented this as using \mnotefont gives me error (I tried with lualatex)
%\let\mnotefont=\tenit
% NOTE: Also increased the horizontal kern to 3em, for some reason 1em makes margin note
% collide with the main contents
\def\mnote#1{\strut\vadjust{\kern-\dp\strutbox\mnoteA{#1}\kern\dp\strutbox}}
\def\mnoteA#1{\smash{\llap{\hbox{\vtop{\mnoteB#1}\kern3em}}}}
\def\mnoteB{\hsize=1.7in \parindent=0pt \leftskip=0pt plus1fill}% \mnotefont}
% NOTE: Commented as doesn't seem relevant as I am using package geometry
%\hoffset=1.5in \advance\hsize by-\hoffset

\begin{document}

\thispagestyle{empty}

\newcommand{\mytesttext}{This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world.\mnote{This is a great world. This is a great world. This is a great world. This is a great world.} This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world. This is a great world.}

\mytesttext

\newpage
\thispagestyle{empty}



\begin{minipage}[t][1cm][t]{\linewidth}
    \mytesttext
\end{minipage}



\newpage
\thispagestyle{empty}

\newbox\myoddvbox
\setbox\myoddvbox=\vbox{{\hsize=\textwidth \mytesttext \endgraf}}%


\begin{minipage}[t][1cm][t]{\linewidth}
    \box\myoddvbox
\end{minipage}


\end{document}

1 Answer 1

3

The problem is that you used LaTeX and the macro is designed for plain TeX. It works without problems in plain TeX.

This is one of several situations where LaTeX defines original plain TeX macro differently. The macro \smash keeps vertical mode in plain TeX but it opens horizontal mode in LaTeX. Why? I don't know. See the line 5912 in latex.ltx:

\def\finsm@sh{\ht\z@\z@ \dp\z@\z@ \leavevmode@ifvmode\box\z@}

and the line 1040 in plain.tex:

\def\finsm@sh{\ht\z@\z@ \dp\z@\z@ \box\z@}

You can see the difference.

It is clear that my macro:

\def\mnote#1{\strut\vadjust{\kern-\dp\strutbox\mnoteA{#1}\kern\dp\strutbox}}
\def\mnoteA#1{\smash{\llap{\hbox{\vtop{\mnoteB#1}\kern3em}}}}

creates \kern\dp\strutbox in vertical mode in plain TeX (and this is correct) but it creates \kern\dp\strutbox in horizontal mode in LaTeX (and this is incorrect).

If we cannot rely on the fact that our macros will be used in plain TeX only (which is recommended) then we cannot use macros like \smash and we must to use only primitives instead such macros:

\def\mnote#1{\strut\vadjust{\kern-\dp\strutbox\mnoteA{#1}\kern\dp\strutbox}}
\def\mnoteA#1{\setbox0=\hbox to0pt{\hss\hbox{\vtop{\mnoteB#1}\kern3em}}%
              \ht0=0pt \dp0=0pt \box0 }
5
  • Thanks, I agree in general that's recommended. I wonder if there is document where latex team has listed all the tex commands they redefined for latex. Btw, this solution of yours fixes spacing problem in main text, though now the baseline of first line of text in \mnote does not align with the baseline of main text where it is placed, instead the top of the tallest character aligns with the baseline of main text... please take a look.
    – codepoet
    Apr 11, 2020 at 5:47
  • 1
    This was my mistake. I corrected my answer. Now, my macro roughly traces the \smash macro.
    – wipet
    Apr 11, 2020 at 6:27
  • Thanks, this completely resolved the issue. As a side note to this dual tex -- *latex compatibility. In my experience it is a good idea to use a named box instead of box numbers when writing plain tex code that one intends to mix with *latex code. I think that's because internally some environments of latex recycle box numbers. So a numbered box like box0 might then point to some other box, and it can get hard to debug. Moreover different *latex engines allow different number of boxes, for instance lualatex allows 65535 box registers. On my side I have updated my code to use a named box...
    – codepoet
    Apr 11, 2020 at 6:40
  • Named box is not needed here. If the box is saved and immediatelly used (without any macro between first and second step) then we need not named box. LaTeX macros follow the same principle: if the box is saved and immediately used then named box isn't needed. The \smash macro is an example of this principle.
    – wipet
    Apr 11, 2020 at 6:48
  • I agree its not needed here in this exact example :) Also, my error when I mentioned dual tex-latex compatibility, seems like named boxes are *latex addition, as \newbox is defined in latex.ltx. More of that I meant was mixing tex-latex style, meaning writing making plain tex code compatible & workable in *latex document.
    – codepoet
    Apr 11, 2020 at 6:54

You must log in to answer this question.

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