How to create a custom decorator symbol in math mode (like \tilde)

Why not declaring the symbol as an accent?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
%\usepackage{accents}
\usepackage{bm}

% import certain symbols from MnSymbol,
% https://tex.stackexchange.com/questions/450691/create-diamond-with-a-dash-in-it/450703#450703
\newcommand\ImportFromMnSymbol[1]{%
  \DeclareFontFamily{U}{MnSymbol#1}{}
  \DeclareFontShape{U}{MnSymbol#1}{m}{n}
    { <-6>    MnSymbol#15
      <6-7>   MnSymbol#16
      <7-8>   MnSymbol#17
      <8-9>   MnSymbol#18
      <9-10>  MnSymbol#19
      <10-12> MnSymbol#110
      <12->   MnSymbol#112
    }{}
  \DeclareFontShape{U}{MnSymbol#1}{b}{n}
    { <-6>    MnSymbol#1-Bold5
      <6-7>   MnSymbol#1-Bold6
      <7-8>   MnSymbol#1-Bold7
      <8-9>   MnSymbol#1-Bold8
      <9-10>  MnSymbol#1-Bold9
      <10-12> MnSymbol#1-Bold10
      <12->   MnSymbol#1-Bold12
    }{}
  \DeclareSymbolFont{MnSy#1}{U}{MnSymbol#1}{m}{n}
  \SetSymbolFont{MnSy#1}{bold}{U}{MnSymbol#1}{b}{n}
}
\newcommand\DeclareMnSymbol[4]{\DeclareMathSymbol{#1}{#2}{MnSy#3}{#4}}
\newcommand\DeclareMnAccent[4]{\DeclareMathAccent{#1}{#2}{MnSy#3}{#4}}

\ImportFromMnSymbol{C}
\DeclareMnAccent{\acctriangleup}{\mathord}{C}{73}

\begin{document}

$\acctriangleup{f}+\tilde{f}$

{\boldmath$\acctriangleup{f}+\tilde{f}$}

\end{document}

I reformatted the code for readability (I'm not sure about the intervals, though, but it's not a big deal) and added the setup for the bold math version.

enter image description here

Here's how you can scale down the requested font. I added some arguments in order to allow for loading the same font at different scale factors.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
%\usepackage{accents}
\usepackage{bm}

% import certain symbols from MnSymbol,
% https://tex.stackexchange.com/questions/450691/create-diamond-with-a-dash-in-it/450703#450703
\begingroup\makeatletter\nfss@catcodes
\gdef\ImportFromMnSymbolaux#1#2#3{%
  \DeclareFontFamily{U}{MnSymbol#2#3}{}
  \DeclareFontShape{U}{MnSymbol#2#3}{m}{n}
    { <-6>    s*[#1] MnSymbol#25
      <6-7>   s*[#1] MnSymbol#26
      <7-8>   s*[#1] MnSymbol#27
      <8-9>   s*[#1] MnSymbol#28
      <9-10>  s*[#1] MnSymbol#29
      <10-12> s*[#1] MnSymbol#210
      <12->   s*[#1] MnSymbol#212
    }{}
  \DeclareFontShape{U}{MnSymbol#2#3}{b}{n}
    { <-6>    s*[#1] MnSymbol#2-Bold5
      <6-7>   s*[#1] MnSymbol#2-Bold6
      <7-8>   s*[#1] MnSymbol#2-Bold7
      <8-9>   s*[#1] MnSymbol#2-Bold8
      <9-10>  s*[#1] MnSymbol#2-Bold9
      <10-12> s*[#1] MnSymbol#2-Bold10
      <12->   s*[#1] MnSymbol#2-Bold12
    }{}
  \DeclareSymbolFont{MnSy#2#3}{U}{MnSymbol#2#3}{m}{n}
  \SetSymbolFont{MnSy#2#3}{bold}{U}{MnSymbol#2#3}{b}{n}
}
\endgroup
\newcommand{\ImportFromMnSymbol}[3][1]{\ImportFromMnSymbolaux{#1}{#2}{#3}}

\newcommand\DeclareMnSymbol[4]{\DeclareMathSymbol{#1}{#2}{MnSy#3}{#4}}
\newcommand\DeclareMnAccent[4]{\DeclareMathAccent{#1}{#2}{MnSy#3}{#4}}

\ImportFromMnSymbol[0.7]{C}{70}
\DeclareMnAccent{\acctriangleup}{\mathord}{C70}{73}

\begin{document}

$\acctriangleup{f}+\tilde{f}$

{\boldmath$\acctriangleup{f}+\tilde{f}$}

\end{document}

enter image description here


So, the accents package can be used and it provides a nice method for placing that \smalltringleup-Symbol from my question obove the letter. The two things one needs to bear in mind are:

  1. \bm{...} must be the outermost command enclosing \tilde, etc.
  2. There must be an extra set of braces inside \bm if an accent is used: \bm{{\tilde{...}}} (Otherwise the compiling process will fail)

With \usepackage{accents}:

    $
          \tilde{f}
    \quad \tilde{\bm{f}}
    \quad \bm{{\tilde{f}}}
    \quad \accentset{\smalltriangleup}{f}
    \quad \accentset{\smalltriangleup}{\bm{f}}
    \quad \bm{{\accentset{\smalltriangleup}{f}}}
    $

with accents package

As campa pointed out in a comment below my question, one of the two remaining issues can be fixed with the single option, i.e., \usepackage[single]{accents}:

with single option