3

I am trying to set up a custom margin note command for my lecture notes but I encountered a few problems.

First of all, this is how it should look:

margin notes

As you can see in the screenshot above, the margin notes are numbered (I tried to mimic footnotes).

First, I tried to use the marginpar command. Sadly, it cannot be used in math environments as well as tcbtheorem environments from the tcolorbox package which I happen to use quite frequently.

After trying with marginpar I ended up with the marginnote package, which does work in math as well as tcbtheorem environments, but there are different problems. The biggest downside is, that margin notes from the marginnote command overlap very easily and it's annoying to manually move them up and down until one finds the right spot.

What I am trying to achieve are numbered margin notes which can be referenced (used with the label/ref commands), used in math as well as tcbtheorem environments and don't overlap (they should behave like margin notes from the marginpar command, which automatically move up and down).

Is something like this achievable?

Minimal example (comment out mpar command to see errors):

\documentclass{article}

\usepackage[left=10mm,right=65mm,top=20mm,bottom=25mm,headheight=15pt]{geometry}
\usepackage{marginnote}
\usepackage[most]{tcolorbox}
\usepackage{blindtext}

\setlength{\marginparwidth}{50mm}
\setlength{\marginparsep}{5mm}

\newcounter{mnotecnt}
\renewcommand\themnotecnt{\textsuperscript{\arabic{mnotecnt}}}
\newcommand\mpar[1]{\refstepcounter{mnotecnt}\themnotecnt\marginpar{\footnotesize\themnotecnt\hspace{1pt}#1}}

\newcommand\mnote[1]{\refstepcounter{mnotecnt}\themnotecnt\marginnote{\footnotesize\themnotecnt\hspace{1pt}#1}}

\newtcbtheorem[]{mytheo}{Theorem}{}{thm}

\begin{document}

This is a sentence.\mpar{Margin note using the marginpar command.}
\blindtext

\begin{mytheo}{}{}
  This is a theorem.\mnote{Margin note using the marginnote package.}
\end{mytheo}

\section*{Problems:}

\begin{mytheo}{}{}
  This is a theorem.\mnote{marginnote} This is a sentence.\mnote{another one}
  (should not overlap!)
\end{mytheo}

\begin{align*}
  \alpha + \beta = \gamma%\mpar{Does not work.} % comment out for error
\end{align*}

\begin{mytheo}{}{}
  This is a theorem.%\mpar{Does not work.} % comment out for error
\end{mytheo}

\end{document}
5
  • See tex.stackexchange.com/questions/215322/… and tex.stackexchange.com/questions/305022/… Note that this is similar to the approach of the marginfix package. Jan 18, 2022 at 16:54
  • Regarding the horizontal offset, see tex.stackexchange.com/questions/269426/… Jan 18, 2022 at 17:14
  • Amazing work! Thank you very much! I just tested it out and I have two questions: (1) The margin notes automatically switch sides. Is there a way to turn it off? (2) Is there a way to conveniently place the source code into my preamble? Doing so raises some everypage warnings which result in errors. The warning/error messages are too long to paste into a comment. I can provide a minimal example, but where should I send it to? The limit of marginnotes per page seems to be 10, right?
    – gyha4
    Jan 18, 2022 at 19:07
  • The easy solution is to use oneside documents. Long source codes can be stored in a separate .tex file and read using \input. I really need to update the solution anyway. See also tex.stackexchange.com/questions/573329/… Jan 18, 2022 at 21:36
  • \input didn't work for me earlier, but now it does, weird. Sadly, I don't know how to implement the solution displayed in the last link you provided. I also tried setting the onepage option in both the report and article class but the margin notes still switch sides. Furthermore, using one of the packages xifthen or calc leads to the margin notes being moved down to the end of the page. Is there a fix to this? I would really appreciate an updated version if you have the time to make one!
    – gyha4
    Jan 18, 2022 at 22:22

1 Answer 1

3

The memoir class (a superset of book, report and article classes) provides a variety of what I called "page notes", which include footenotes, either at the page bottom or in the margin, or unnumbered notes in the margin which can extend for over multiple pages.

When using the article option memoir treats \chapter as \section, and \subsection as \section. and so on, so that a document initially written like a book can be typeset as an article. This was the initial idea for an easy conversion from book/report to article.

However there was no way to typeset an original article document using memoir except by editing the original document and changing all \section to \chapter, \subsection to \section, etc. The following MWE shows how you can use the memoir facilities on unedited article code.

% memarticleprob.tex  SE 630602

\documentclass[article]{memoir}
\let\subsection\section % undo article option change of divisions
\let\section\chapter    % ditto

\footnotesinmargin % set footnotes in the margin

\usepackage{lipsum}

\begin{document}
\tableofcontents

\section{First}
\lipsum[2]

Some sidefootnoted text.\footnote{Margined footnote.}

\lipsum[4]

Some sidefootnoted text.\footnote{Another margined footnote.}

\subsection{First sub}
\lipsum[2]
\footnotesatfoot % revert to bottom of page footnotes
Some footnoted text.\footnote{Footnote at bottom.}

\end{document}

Read the manual (texdoc memoir chapter "Page notes") for more on the page notes facilities.

enter image description here

4
  • Sadly, the footnote environment in the memoir class is a float, so it won't work with either math or tcbtheorem environments. But thank you for the suggestion.
    – gyha4
    Jan 18, 2022 at 19:22
  • @gyha4 Is there any class where \footnote works in math or tcbtheorem environments? If not, what is the equivalent? Jan 19, 2022 at 18:32
  • As specified in my question, I am looking for a margin note command that is numbered like a footnote and can be used in math and tcbtheorem environments. The marginnotes package with its marginnote command does work in those environments (since it is not a float) but these notes tend to overlap. The command should not be restricted to any class.
    – gyha4
    Jan 19, 2022 at 21:55
  • @gyha4 It seems to me that you are looking for a \footnote macro that behaves the same in math and minipage environments as it does in regular text, putting the footnote text at the bottom of the page and continuous numbering. That is not for me. Jan 21, 2022 at 18:41

You must log in to answer this question.

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