Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to add margin notes in the Tufte style to my Plain TeX document. (I'm using eplain, if that matters.) I know that if I were using LaTeX I could just use tufte-latex, but as a thorough contrarian I enjoy coding these things myself.

I'm almost there but my current macro will place text relative to the current location when I invoke it, instead of the margin. In my MWE, the note is placed smack dab in the middle of things. But if you move the invocation of \sidenote around, the side note may appear closer to the left margin. How can I reposition my sidenote text relative to the left (or right) margin, instead of the current location? (I used the left margin in my MWE.)

The thing I really do like about my macro is that the baselines of the first line of the side note and the main body text to which it refers align. I want to keep that. And any other suggestions about my macro are welcome.

MWE:

\input eplain
\leftmargin=2in

\font\sidenotefont=      pxi at8.5pt

\long\def\sidenote#1{\llap{\smash{\vtop{%
\parindent=0pt\hsize=1.5in\rightskip=.87in\parfillskip=0pt\leftskip=-1in plus1fil%
\baselineskip=10pt\sidenotefont #1}}}}


When we are working at a difficult task and strive after a good thing, we are
fighting a righteous battle, the direct reward of which is that we are kept from
\sidenote{This note has been brought to you by the letter pi and
the number e. Please make a note of it. The reason for its existence is the
great lengths I went to do things.}much evil. As we advance in life it becomes more and more difficult, but in
fighting the difficulties the inmost strength of the heart is developed. Indeed
life is a have to defend and protect ourselves, and with a cheerful and brace
spirit we must battle; we plan and calculate in order to make progress.

\bye
share|improve this question
    
Would an \insert-based solution work for you? i.e., output routine. –  morbusg Dec 8 '12 at 10:04
    
@morbusg, I was looking at \insert yesterday. I was concerned that I wouldn't be able to easily get the alignment right; sidenotes must be beside the text the're commenting on. Do you know if this can be done? –  EfForEffort Dec 8 '12 at 12:58
    
Ah, yes, it gets very difficult then; I know because I have tried (and failed). I think \pagetotal could somehow be used for those calculations, but the problems (again: at least for me) arise when there are more than one sidenote on a page. –  morbusg Dec 8 '12 at 20:36

4 Answers 4

up vote 10 down vote accepted

If lines don't have unusual depth, this could be a starting point:

\input eplain
\leftmargin=2in

\font\mainfont=pxr at 10pt
\font\sidenotefont=pxi at 8.5pt

\long\def\sidenote#1{%
  \vadjust{\llap{\smash{\vtop{%
    \parindent=0pt
    \hsize=1.7in
    \parfillskip=0pt
    \leftskip=0pt plus1fil
    \baselineskip=10pt\sidenotefont\vglue-\ht\strutbox #1}}\kern1em}}}

\mainfont

When we are working at a difficult task and strive after a good thing, we   
are fighting a righteous battle, the direct reward of which is that we are 
kept from \sidenote{This note has been brought to you by the letter pi and 
the number e. Please make a note of it. The reason for its existence is the 
great lengths I went to do things.}much evil. As we advance in life it becomes 
more and more difficult, but in fighting the difficulties the inmost strength 
of the heart is developed. Indeed life is a have to defend and protect ourselves, 
and with a cheerful and brace spirit we must battle; we plan and calculate in 
order to make progress.

\bye

The key is \vadjust that adds the material to the enclosing vertical list.

enter image description here

share|improve this answer
    
This is great, thanks! Now to learn what strutbox is and how I can adjust it for different font sizes.... –  EfForEffort Dec 8 '12 at 14:37
    
@D.Bueno: You might want to look at exercise 14.28 of the TeXbook (and it's answer in the Appendix A). The solution is very similar to egreg's proposal and Knuth's explanations are always nice, so it's a good read. –  Mafra Dec 8 '12 at 23:08
    
@D.Bueno: For that, you could use LaTeX's definition of the strutbox; it uses .7\baselineskip for height, and .3\baselineskip for depth, instead of “hard-coded” values as in plain. Also you might want to set \parskip=0pt to avoid possible “drifting” of baselines between the main column content and the sidenote column (plain's default is 0pt plus 1pt). –  morbusg Dec 11 '12 at 6:26
    
@morbusg: Thanks! These are good suggestions. –  EfForEffort Dec 11 '12 at 19:59

After reading the appropriate exercise in the TeXBook (14.28), here is my \strut-based solution. Thanks to @Mafra for suggesting the exercise.

\def\strutdepth{\dp\strutbox}
\def\simplesidenote#1{%
  \strut\vadjust{\kern-\strutdepth\lsidenote{#1}}}
\def\lsidenote#1{\vtop to \strutdepth{%
                  \baselineskip\strutdepth%
                  \vss\llap{\vtop to 0pt{%
                      \leftskip=0pt plus1fill \rightskip=8pt%
                      \parfillskip=0pt \parindent=0pt%
                      \hsize=1.7in%
                      \eightpoint\it #1}}\null}}

Note that \eightpoint is just a macro to adjust the font size.

share|improve this answer
    
Heh, I think I suggested exercise 14.28 :-) –  Mafra Dec 12 '12 at 23:22
    
lol. Indeed, you did. Sorry about that! I've corrected it in the answer. –  EfForEffort Dec 12 '12 at 23:30

There is a great macro written by Petr Olsak from the Czech Republic, which perhaps beats even eplain. Olsak is notorious for prefering plainTeX over LaTeX, and he wrote this macro in order to offer the power of LaTeX to plainTeX users. The name of the file (opmac.tex) actually stand for Olsak's Plaintex MACros.

http://petr.olsak.net/opmac-e.html

Documentation is available in English, too. After installing and \input opmac you can just type \mnote{your text in margin} and it will place it accordingly, in the left margin on odd pages, in the right margins on even ones, unless you have reason to have them on the same side of all pages. Everything can be setup, as you'll learn in the documentation.

share|improve this answer
    
Hello, this does not directly answer the question of positioning the margin notes w.r.t. the page boundary. "Read the documentation", as you suggest, certainly does not stand as an answer to the TeX.SX standards. –  yo' Jan 7 at 10:17
    
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  mafp Jan 7 at 10:40
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  Masroor Jan 7 at 10:43

I want point out that there are problems in the previous answers and give more simple solution.

The egerg's answer includes the ad-hoc correction \vglue-\ht\strutbox. The vertical positioning of the margin note text depends on the depth of the line in the paragraph and on the height of the first line in the note text in his solution. You can try to remove all letters and characters with non-zero descenders from the second line of the paragraph in the example (i.e. g, p, comma, etc.) and you can see that the marginal note position will be bad. This bug is malicious because the code \vglue-\ht\strutbox seems that there is some reason for this. But it is not true. The \vskip-8.5pt does the same work and don't remove the accidental position of the marginal note.

The EfForEffort's answer is bad, because the \baselineskip is set to small value in the \vtop resulting the lines without equidistant baseline: the lines are leaning each against other with small vertical space 1pt which is default from the \lineskip register.

The Knuth's answer to exercise 14.28 from TeXbook (print star to the left margin using \marginstar macro):

\def\strutdepth{\dp\strutbox}
\def\marginalstar{\strut\vadjust{\kern-\strutdepth\specialstar}}
\def\specialstar{\vtop to \strutdepth{
   \baselineskip\strutdepth
   \vss\llap{* }\null}}

is overcomplicated because there is \vtop to\strutdepth followed by setting \baselineskip=\strutdepth followed by \null terminator in the \vtop. Much more simple is this solution of the 14.28 excercise:

\def\marginalstar{\strut\vadjust{\kern-\dp\strutbox\smash{\llap{* }}\kern\dp\strutbox}}

If you need more lines in the margin note:

\let\mnotefont=\tenit
\def\mnote#1{\strut\vadjust{\kern-\dp\strutbox\mnoteA{#1}\kern\dp\strutbox}}
\def\mnoteA#1{\smash{\llap{\hbox{\vtop{\mnoteB#1}\kern1em}}}}
\def\mnoteB{\hsize=1.7in \parindent=0pt \leftskip=0pt plus1fill \mnotefont}
\hoffset=1.5in \advance\hsize by-\hoffset

When we are working at a difficult task and strive after a good thing, we
are fighting a righteous battle, the direct reward of which is that we are
kept from%
\mnote{This note has been brought to you by the letter pi and the number e.
       Please make a note of it. The reason for its existence is the great
       lengths I went to do things.}
much evil. As we advance in life it becomes more and
more difficult, but in fighting the difficulties the inmost strength of the
heart is developed. Indeed life is a have to defend and protect ourselves,
and with a cheerful and brace spirit we must battle; we plan and calculate
in order to make progress.

\bye

If you are using OPmac:

\input opmac
\fixmnotes\left \mnotesize=1.7in \def\mnotehook{\typosize[8/10]\it}
\margins/1 letter (2.5,1,1,1)in

When we are working at a difficult task and strive after a good thing, we
are fighting a righteous battle, the direct reward of which is that we are
kept from%
\mnote{This note has been brought to you by the letter pi and the number e.
       Please make a note of it. The reason for its existence is the great
       lengths I went to do things.}
much evil. As we advance in life it becomes more and
more difficult, but in fighting the difficulties the inmost strength of the
heart is developed. Indeed life is a have to defend and protect ourselves,
and with a cheerful and brace spirit we must battle; we plan and calculate
in order to make progress.

\bye
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.