\documentclass{article} \usepackage{mathtools} \makeatletter \newcommand{\@distr}[2]{\underbracket[0.3pt][1pt]{#1#2}} \newcommand{\distr}[1]{\mathpalette{\@distr}{#1}} \let\oldmathcal\mathcal \renewcommand{\mathcal}[1]{% \oldmathcal{#1} \@ifnextchar\distr\!\relax } \makeatother \begin{document} \[ a_f\ a_{\distr{f}} \qquad \mathcal{L}\psi\ \mathcal{L}\distr{\psi} \] \end{document}