I want to define a math command which behaves differently in display mode and inline mode. For example, I want to define a `\myfrac#1#2`，which equals $\frac{#1}{#2}$, but equals $#1/#2$ in inline mode. An MWE is like the following:

```tex
\documentclass{article}
\makeatletter
\newcommand\myfrac#1#2{
  \ifdisplay \frac{#1}{#2}
  \else #1/#2
  \fi
}
\makeatother
\begin{document}
\[ \myfrac12 = \frac12 \]

$\myfrac12=1/2$.
\end{document} 

```

But I don't know how to jugde the math mode. Thank you for your adive!