I'm trying to use marginpar
and todonotes
to make comments in a latex file as to ease the collaboration. The margins are just quick todo notes and fixes and I don't want to hardcode the position of every margin note since they'll be temporary. So, I'm trying to create small scripts in the preamble and use them as I go.
My problem is with long margin texts that multiples of them in one paragraph/page will either overlap or get too far away from the actual text. Naturally, I I thought I should be able to change the margin to appear on the left or right side of page per case that I have. That is, I want to be able to define to commands, let's say \lmargin
and rmargin
so that all the margin notes with \lmargin
appear on one side and all the ones with \rmargin
to appear on the other side. I don't really care about which one is on the left and which one is on the right, as long as they are on opposite sides. Or ideally, it would be great if latex could keep track of the margin notes and alternate between left and right automatically.
Searching through forums, the only solutions change the side of the margins for all the document. The closest solution I could find is to use \reversemarginpar
. It works as long as the margin notes are in different paragraphs, but I don't want to break the paragraphs just for each note that I add to text.
Here is a MnonWE for the marginpar, the todonotes package is similar:
\documentclass[]{article}
\usepackage{pgf}
\usepackage[ %
%top=Bcm,
%bottom=Hcm,
%outer=Ccm,
%inner=Acm,
%heightrounded,
marginparwidth=2.5cm,
%marginparsep=Ecm
]{geometry}
\usepackage{lipsum}
\usepackage{soul} % for highlighting the text: \hl
\usepackage{setspace} % for setting the linespace for a portion of the text: \setstretch
\definecolor{dkblue}{rgb}{0.0, 0.0, 0.6}
\definecolor{ltblue}{rgb}{0.6, 0.6, 1.0}
\usepackage{color}
\newcommand{\lmargin}[2]{\sethlcolor{ltblue}\hl{#1}\marginpar{\setstretch{0.5} {\color{dkblue} \tiny note: #2}}}
\begin{document}
And even there \lmargin{are}{there's something here that I need to pay attention to, and I need to be very clear about it, so I am going to write everything that comes to my mind here in the margin so that it doesn't take anyone 400 years to come up with the same thing!} more things that can be said, but I am \reversemarginpar\lmargin{not sure}{Same thing here: there's something here that I need to pay attention to, and I need to be very clear about it, so I am going to write everything that comes to my mind here in the margin so that it doesn't take anyone 400 years to come up with the same thing!} exactly what. \lipsum[7]
Do you see the problem \reversemarginpar\lmargin{here}{And this is what I need}? If I don't go to a new paragraph, everything changes altogether! and overlaps even when I do!
\end{document}
Best Answer
While I was looking at my old paracol solution I started thinking I could do it better. In particular, I should be able to handle more than one note per paragraph.
The advantage of this solution is that it will never overlap and will break across pages. Because the notes are being written to the AUX file, I put most of the formatting into
\marginparformat
. Also, it takes two runs.The main problem in implementing this is that you can only switch columns between paragraphs, which can be solved using
\everypar
. Even then, you need to know at the beginning of the paragraph what will be coming up later. The solution is to write the needed information to the AUX file. When you switch back to the original column, it immediately kicks off another\everypar
which you have to ignore or get trapped in a loop.It should be noted that
\everypar
tends not to be preserved. I rewrote\@afterheading
, but there are bound to be others.