# Is it good practice to use a custom command for logical (consistent) markup of functions?

I am only recently learning about the importance of being consistent with markup when typesetting a document in LaTeX (Separate content from formatting - i.e., "just type"). For instance,

• \emph is a semantic markup, and not exactly an alternative to \textit: \emph or \textit
• Using \vec for vectors is good practice, not because vectors should be typeset with arrows above them, but because we have the freedom to redefine \vec later on for it to appear as we wish: How to change all \vec{} to \bf{}
• There are various kinds of \dots commands for use in different semantic contexts: Difference of the \dots*

Along the same lines, I am now wondering whether it is good to define a custom command, say \func, to be used for markup of functions. For example, would it be better to consistently write something like $$\func{f}(x), \func{g}(x_1, \dotsc, x_n)$$ instead of just $$f(x), g(x_1, \dotsc, x_n)$$?

I searched on this site before posting but could not find any discussion specifically about this aspect. This interesting question is related, but it asks how this can be done rather than if this should be done: How can I influence the spacing of mathematical functions by an own macro?

• Short answer: yes, but only if that make your life easier. For instance, I would use \specie{hOMO hOrribilis} if I want this string with emphasis, indexed, abbreviated and correctly capitalized as any scientific name (i.e., " H. horribilis ") but I would not use \flower{marguerite} if I want just type "marguerite". – Fran Mar 8 '20 at 7:51
• IMO, customization command is a way to reserve the room for future format changes. If you are pretty sure that there is no need for future changes, you don't need to bother yourself with overlength or complicated customized commands. – wklchris Mar 8 '20 at 7:53

I have spent years brainstorming about how to make the TeX math syntax more semantic, particularly when it comes to variables and functional expressions. Eventually, my efforts became the package SemanTeX. It has an object-oriented approach to mathematics where each variable belongs to a class, and classes are set up using keyval syntax. You can have a look at the syntax below:

\documentclass{article}

\usepackage{amsmath,semantex}

\NewVariableClass\MyVar % creates a new class of variables, called "\MyVar"

% Now we create a couple of variables of the class \MyVar:
\NewObject\MyVar\vf{f}
\NewObject\MyVar\vg{g}
\NewObject\MyVar\vh{h}
\NewObject\MyVar\vn{n}
\NewObject\MyVar\vp{p}
\NewObject\MyVar\vU{U}
\NewObject\MyVar\vx{x}
\NewObject\MyVar\sheafF{\mathcal{F}}

% Now we set up the class \MyVar:
\SetupClass\MyVar{
output=\MyVar,  % This means that the output of an object
% of class \MyVar is also of class \MyVar
% We add a few keys for use with the class \MyVar:
definekeys={ % we define a few keys
{inv}{upper={-1}},
{conj}{command=\overline}, % Applies \overline to the symbol
{inverseimage}{upper={-1},nopar},
},
definekeys[1]={ % we define keys taking 1 value
{der}{upper={(#1)}},
{stalk}{seplower={#1}},
% "seplower" means "separator + lower", i.e. lower index
% separated from any previous lower index by a separator,
% which by default is a comma
{res}{ rightreturn, symbolputright={|}, lower={#1} },
},
}

\begin{document}

$\vf[conj,der=\vn]$

$\vg[inv,res=\vU]{\vx}$

$\vh[inverseimage]{\sheafF}[spar,stalk=\vp] = \sheafF[stalk=\vh{\vp}]$

\end{document}