I want to write a marginnote command that detects whether it is called within a mdframed environment, in particular I want to be able to distinguish the following
normal text
normal math
text in
mdframedmath in
mdframed
I'm not a TeX expert and I've tried looking at \ifinner, \ifhmode, \ifvmode, \ifmmode, but I cannot distinguish the mdframed instances. See the code below to demonstrate my task. Is it possible to do what I want?
\documentclass[12pt, a4paper]{report}
\usepackage{amsmath, amssymb}
\usepackage[framemethod=tikz, roundcorner=8pt, shadow,%
shadowsize=8pt, innerbottommargin=10pt, splittopskip=20pt, splitbottomskip=20pt]{mdframed}
\newcommand{\nmarginnote}[1]{
\ifhmode
Detected hmode
\fi
\ifvmode
Detected vmode
\fi
\ifmmode
Detected mmode
\fi
\ifinner
Detected inner
\fi
}
\begin{document}
\section*{Normal text}
Test \nmarginnote{Test}
\section*{Normal math}
\begin{align*}
A + B = C \nmarginnote{Test}
\end{align*}
\section*{Normal text in mdframed}
\begin{mdframed}[backgroundcolor=blue!10, nobreak=true, frametitle={Frame}]
this is an example \nmarginnote{Test}
\end{mdframed}
\section*{Math in mdframed}
\begin{mdframed}[backgroundcolor=blue!10, nobreak=true, frametitle={Frame}]
\begin{align*}
A + B = C \nmarginnote{Test}
\end{align*}
\end{mdframed}
\end{document}