I am considering a beamer presentation with notes at the right. To establish a better connection between the notes and the content they are referring to, I modified the \notes command in such a way (using zref's savepos) that the note text is printed at the same vertical position as the text where it appears. Therefore, it is not always feasible to put the \notes command directly in the frame, but sometimes it needs to appear within a different environment.
That's for the motivation, and it works great in most cases. However, consider this MWE:
\documentclass{beamer}
\usepackage{amsmath,pgfpages}
\setbeameroption{show notes on second screen=right}
\newcounter{notecounter}
\begin{document}
\begin{frame}
\begin{align}
a & = 1 \note{This is the first note: \arabic{notecounter}\stepcounter{notecounter}\} \
b & = 2 \note{This is the second note \arabic{notecounter}\stepcounter{notecounter}\}
\end{align}
\end{frame}
\end{document}
This is without any redefinitions, just using the plain beamer command which I of course internally use. The notes page will output the following content:
This is the first note: 0
This is the second note 1
This is the first note: 2
This is the second note 3
For some reason, the notes are repeated (even worse, expanded multiple times) whenever they occur in a multiline math environment (tested with align and gather, both starred and unstarred). But this does not seem to be a fundamental problem that you may not use \note at all in math mode, since it works for \[ \] and equation.
Is there a way to circumvent this problem, which completely messes up my spacing when I change to the aligned \note definition?
Edit: On request by samcarter, I give a MWE that contains parts of my code to provide the aligned notes. This is very boiled down, the original code also contains fixing of misplaced hyperlinks, incorporating scaleboxes, ..., but this is not relevant to show the problem. Probably, tikzmark would make the positioning algorithm more elegant. Since I typically use tikz, this would not come as a drawback for me; however, the implementation I imagine would fix the problem only superficially: Probably the alignment would be correct (and tikz will give a warning about using the same name twice), but the two identical notes would be printed on top of each other.
\documentclass{beamer}
\usepackage{amsmath,pgfpages,zref-user,zref-savepos}
\setbeameroption{show notes on second screen=right}
\setbeamertemplate{note page}[plain]
\newcounter{notecounter}
\makeatletter
\let\oldnote\note
\newcounter{pposes}
\newcounter{poses}
\AtBeginNote{%
\setcounter{poses}{0}%
}
\AtEndNote{%
\setcounter{poses}{0}%
\stepcounter{pposes}%
}
\renewcommand<>{\note}[1]{%
\only#2{%
\stepcounter{poses}%
\vbox to 0pt{%
\edef\l{p\the\value{pposes}-\the\value{poses}}%
\zsaveposy{\l}%
\zrefused{\l}%
\oldnote{%
\stepcounter{poses}%
\edef\l{p\the\value{pposes}-\the\value{poses}}%
\zref@ifrefundefined{\l}{}{%
\parbox[l][0pt][t]{0pt}{%
\hfuzz=\maxdimen%
\parbox{\textwidth}{%
\vspace{\dimexpr\paperheight - \zposy{\l}sp - 6mm}%
#1%
}%
}%
}%
}%
}%
}%
}
\begin{document}
\begin{frame}
\begin{align}
a & = 1 \note{This is the first note: \arabic{notecounter}\stepcounter{notecounter}} \
b & = 2 \note{This is the second note \arabic{notecounter}\stepcounter{notecounter}}
\end{align}
Problem \note{This is the third note: \arabic{notecounter}\stepcounter{notecounter}}
\end{frame}
\end{document}
Note that in this way, the problem has shifted: Now it is not that the notes are visible twice (since the macro does not find an associated position of the second appearances), but the \note command is used after the align-environment, first the unprinted doubled notes are given. Therefore, this MWE generates the first two notes correctly aligned, followed by the first note again, which is not aligned to the position of `Problem'. The duplicated second note and the actual third note are not shown at all.


atbegshifor positioning the content? It must be your adjustments that fix the problem. Do you somehow insert code to check for the uniqueness of the notes (I thought of doing this before, but a fix for the original cause of the note expanding twice would feel much more comfortable)? – Benjamin Desef Jul 17 '18 at 15:13beamerandamsmathbut only anamsmathrelated problem. The log file says that, if you have analignenvironment, latex enters math mode twice. I don't know why but assume this is the cause for this behavior. My solution just kinda worked: It printed the same text twice, over itself (instead of later, as in your code), while the counter you put in there changes. You can use an intern counter as workaround, but you will always see the text inalignnotes is thicker because of the double-printing. Hmmm – nox Jul 18 '18 at 04:20