# New command for indexable word in math mode

What I would like to do is define a new command \kodim which I can index in math mode. With the following solution

\newcommand{\kodim}{kodim \,}


the result is unsatisfactory, because from

\kodim_V U


I get the space between the word kodim and the index V, instead of between kodim_V and the argument U.

How do I have to define the command instead to get the same result as from \dim_V U?

I also notice that my new word is not displayed in the same way in math mode as the built-in macro \dim. It is displayed in italic instead. How can I get the same result as with the built-in macro?

Thanks for help.

• \DeclareMathOperator\kodim{kodim} (amsmath package) will make \kodim act like \log and just add the space when needed Oct 25, 2020 at 10:23

Do load the amsmath package and issue the instruction

\DeclareMathOperator{\kodim}{kodim}


in the preamble.

\documentclass{article}
\usepackage{amsmath} % for "\DeclareMathOperator" macro
\DeclareMathOperator{\kodim}{kodim}
\begin{document}
$\kodim_V U \quad \dim_V U$
\end{document}

• Thanks a lot for the answer! Oct 25, 2020 at 10:52