4
$\begingroup$

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).

$\endgroup$
0

1 Answer 1

11
$\begingroup$

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)$.

screenshot of example

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .