# How to best format function / method names in TeX?

Functions commonly have multi-character names - mainly acronyms - in cryptography, much more so than in math. The question is how we can best format these methods in LaTeX? If we don't do anything then they seem to consist of multiple symbols (indicating, perhaps, multiplication) in italics.

For example $KDF$ will look like three separate characters, K, D and F (in a different font of course).

The \operatorname command works well for this purpose, and I think it's the most appropriate choice. It disables italics, prevents hyphens from being converted into minus signs, and more.

Example: HMAC-SHA256(k, m) can be typeset using $\operatorname{HMAC-SHA256}(k,m)$.

Unfortunately, \operatorname is a lot to type. Usually, a document would use \DeclareMathOperator once at the beginning to define shorter command names for common operators. This actually works on Crypto SE:

$\DeclareMathOperator{\hmac}{HMAC}$
Now $\hmac(k,m)$ will be rendered just like $\operatorname{HMAC}(k,m)$.


The first line defines a new command \hmac, and the second line uses it.

This might be worthwhile if you're writing a long answer, but it seems like overkill in most cases. Maybe Crypto SE could eventually declare some popular operators automatically?

Even without \DeclareMathOperator, there are still some shorter options. I think the semantics of these commands are less appropriate, but that's not the end of the world.

• \text: Does not space things out as nicely as \operatorname does.
• \mathrm: Does not handle hyphens properly, so HMAC-SHA256 is rendered as "HMAC minus SHA256". Same spacing problem as \text.

Personally, I've been using \text on Crypto SE. That's out of laziness: I think \operatorname (or declaring a custom operator command) is a better choice.

• Been abusing \text too… thanks for the pointer towards \operatorname which indeed seems to be a better fit. – e-sushi Feb 16 '16 at 23:29
• I presume we cannot use \DeclareMathOperator on Crypto.SE with all the small snippets of LaTeX? – Maarten Bodewes Feb 21 '16 at 14:38
• @MaartenBodewes I added some details on that – Tim McLean Feb 22 '16 at 2:43