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.