Related to Can I detect whether LaTeX is in vertical mode?
\documentclass{article}
\newcommand{\wm}{%
\ifinner INNER \else OUTER\fi
MODE
}
\newcommand{\mm}{%
(trying margin par)\ifinner(no margin par)\else\marginpar{yes marginpar}\fi
}
\begin{document}
\begin{table} \caption{Table}
\wm
...
\mm
\end{table}
\bigskip
Text: \wm
MPAR: \mm
\end{document}
This informs me that my float is lost. the output is
so how do I write a macro that sets a marginpar only when it is allowed to do so, and does not have the little side effects here (i.e., should have said "(no margin par)" and not give a lost float error)?
PS: When it works, \marginpar trick: not considered as float is pretty neat.

\gdef\@parmoderr{\@latex@error{Not in outer par mode}\@ehb}seems a bit drastic, too... – ivo Welch Nov 15 '21 at 17:18\hspace*{\fill}\rlap{\smash{\hspace{\marginparsep}\parbox[t]{\marginparwidth}{some text}}}– David Carlisle Nov 15 '21 at 19:16