1

I'm working on a game manual and I'd like to put page references in the margins for key concepts, for example something like this (from Justin Alexander's Legends and Labyrinths):

an except from Justin Alexander's Legends and Labyrinths

I can use \marginpar to produce the margin notes. But I would like only one margin note per key concept per page. For example, the word class is used several times in the above example, but there is only one margin note. But when writing my LaTeX source, I don't know what the output pagination will be. So, for example, I might use the word class in two different paragraphs. If they end up on the same page, I only want one note. If they end up on different pages, I want one note on each page.

One solution would be to wait until I've completed the main body of text, then manually go back and add margin notes making sure I don't add duplicates on any given page. But that's a lot of work, and if I need to edit the document after adding the notes I may need to redo it all. So I'm wondering if there's an automated way to do this in LaTeX itself.

I've searched for any package that provides this sort of functionality, but have not found any. I figure there's a not simple solution, but I am willing to try programming my own solution. That said, I'm not very knowledgeable about LaTeX/TeX programming, so any details or references would be greatly appreciated. Thank you,

4
  • Can you estimate the number of different margin notes? Hundreds, thousands? Commented Dec 30, 2022 at 17:02
  • I'd estimate an average of 3 per page, and a couple hundred pages, so in the ballpark of 500 total.
    – Tom
    Commented Dec 30, 2022 at 17:17
  • There is a package with that feature, but only for repeated footnotes.
    – Fran
    Commented Dec 30, 2022 at 23:48
  • @Fran It was a challenge, but the solution is relatively easy, up to potential conflict with existing names. Commented Jan 2, 2023 at 7:09

1 Answer 1

0

The solution is not perfect, as it can overwrite the existing counters, so one should avoid names like chapter, section, enumi, and so on.

The first parameter is the name of counter (our label), the second is the text of the margin note.

\documentclass{article}%

%The two following commands are only for smaller pages -  PS
\textwidth6cm
\textheight4cm
\begin{document}
\makeatletter
\def\mparr#1#2{\@ifundefined{c@#1}
    {\newcounter{#1}[page]
    }
    {}
\stepcounter{#1} \ifnum\value{#1}<2\marginpar{#2}
\fi
}
\makeatother

Bla  bla bla \mparr{aaa}{aaa}

Bla  bla bla \mparr{aaa}{aaa}

Bla  bla bla \mparr{aab}{bbb}

Bla  bla bla \mparr{aab}{bbb}

\newpage

Bla  bla bla \mparr{aaa}{aaa}

Bla  bla bla \mparr{aaa}{aaa}

\end{document}

enter image description here

enter image description here

It needs e-tex, as we need many counters. But about 500 is less than over 30k. If your TeX installation is not too old, it is accessible without additional actions.

3
  • very nice solution.
    – gildux
    Commented Jan 3, 2023 at 10:20
  • 1
    @gildux Thank you. Because of no feedback from OP, I was afraid that something is wrong. Commented Jan 3, 2023 at 13:43
  • 2
    Unfortunately, not everybody play according to the rules that make SE galaxy so useful. However, it's not so late (less than a day and OP may be busy at something else) fingers crossed…
    – gildux
    Commented Jan 3, 2023 at 21:20

You must log in to answer this question.

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