Following this answer, I wrote a command that allows me to write \cont*{(D_\mu\phi)} to get the effect of (D_\mu\phi)^\dagger(D^\mu\phi).
\def\replace#1#2#3{%
\def\tmp##1#2{##1#3\tmp}%
\tmp#1\stopreplace#2\stopreplace}
\def\stopreplace#1\stopreplace{}
\makeatletter
\newcommand{\cont}{\@ifstar\@@cont\@cont}
\newcommand{\contsubst}[1]{\replace{#1}{_\mu}{^\mu}}
\def\@cont#1{{#1}\contsubst{#1}}
\def\@@cont#1{{#1}^\dagger\contsubst{#1}}
\makeatother
The problem is that this obviously doesn't work if \mu is inside curly braces, for things like F_{\mu\nu}.
I tried defining \contsubst like this
\edef\LB{\string{}
\newcommand{\contsubst}[1]{\replace{\replace{#1}{_\mu}{^\mu}}{_\LB\mu}{^\LB\mu}}
but that doesn't work.
Edit:
Here are some more examples of what the command should do:
\cont{A_\mu} -> A_\mu A^\mu
\cont{F_{\mu\nu}} -> F_{\mu\nu} F^{\mu\nu}
\cont*{\phi} -> \phi^\dagger \phi
\cont*{(D_\mu\phi_1)} -> (D_\mu\phi_1)^\dagger (D^\mu\phi_1) % subscript 1 stays a subscript
\cont*{\Phi_{\mu\nu}} -> \Phi_{\mu\nu}^\dagger \Phi^{\mu\nu}



F_{\mu}\nu F^{\mu}\nufor\cont{F_{\mu\nu}}and a bunch of NoValue for\cont*{\phi}. – SU3 Nov 05 '19 at 04:12_in the input, since you didn't provide anything else. You should be more clear in your question presentation and include all possibly inputs. – Werner Nov 05 '19 at 05:03