Cryptography uses "custom" TeX operators quite frequently, at least in research papers, for typesetting/kerning purposes. Approximately 1.6% of answers (282 out of ~18k) on this StackExchange use operatorname or DeclareMathOperator. Of those, there are some common ones that show up more than twenty times:

  • $\operatorname{lcm} $ - 66 times
  • $\operatorname{MD5} $ - 62 times
  • $\operatorname{Enc} $ - 51 times
  • $\operatorname{HMAC} $ - 48 times
  • $\operatorname{SHA-256} $ - 42 times
  • $\operatorname{Pr} $ - 40 times
  • $\operatorname{GF} $ - 37 times
  • $\operatorname{hash} $ - 34 times
  • $\operatorname{AES} $ - 31 times
  • $\operatorname{SHA-1} $ - 30 times
  • $\operatorname{MAC} $ - 27 times
  • $\operatorname{Dec} $ - 25 times
  • $\operatorname{mod} $ - 24 times (\bmod should work just as well here, I think?)

Could we perhaps make these global across-the-site using \DeclareMathOperator like so:

\DeclareMathOperator{\lcm}{lcm}

which lets one type $\lcm(a,b)$ in posts?

As a quick test, re-declaring operators in Mathjax doesn't seem to be a problem, and the later one on the page seems to take precedence:

$\DeclareMathOperator{\lcm}{lcm}\DeclareMathOperator{\lcm}{gcd} \lcm(a,b)$

renders as: $\DeclareMathOperator{\lcm}{lcm}\DeclareMathOperator{\lcm}{gcd} \lcm(a,b)$, so I this should be backwards-compatible with existing posts, even if someone does something funny.

I realize these are a small percentage of answers, and answers can always use DeclareMathOperator on their own, but it'd make using the site a little nicer day-to-day to have these common ones globally defined.

  • 2
    The content of the site is not only shown on this site. It gets dumped to archive.org and imported elsewhere, shown in mobile apps (both by SE and 3rd parties), posts get migrated... All of this works when posts are self-contained. Dependency on a macro that is stored somewhere else is a problem. – user21894 Oct 6 '17 at 1:59
  • @Desire That's a really good point I hadn't considered. This proposal might be dead in the water as a result. – Reid Oct 6 '17 at 2:21
  • 1
    Note that $\Pr$ (code: \Pr) is already a thing. – SEJPM Oct 6 '17 at 9:43
  • 1
    We may actually be able to do it with the templates that are coming out. Then it would be inlined and should be fine even after migration (if the site it is migrated to supports mathjax). – mikeazo Oct 6 '17 at 12:16
  • Well, if the other site doesn't support MathJax then it is out of luck anyway, half of the questions would be unreadable. – Maarten Bodewes Dec 2 '17 at 11:14
  • @mikeazo: I don't think that would be a good idea. Putting a bunch of MathJax boilerplate in post templates is likely to confuse new users and make posts annoying to edit. It would also likely make a mess of the post excerpts shown e.g. in search results. And if people customize the definitions, they can leak into other posts (yes, even from excerpts!). IMO, as long as the bug I linked isn't properly fixed, \DeclareMathOperator etc. should be treated as hidden "power user features", reserved for people who actually know how to use them safely. – Ilmari Karonen Dec 6 '17 at 18:18
  • Anyway, in principle, SE devs could add a bunch of custom command definitions into the per-site MathJax config. I wouldn't hold my breath waiting for it to happen, but it is possible. – Ilmari Karonen Dec 6 '17 at 18:20

Over on Chemistry, we've enabled the mhchem MathJax extension. It's based on a commonly used $\LaTeX$ package for typesetting chemical equations. It's also used on Biology and Earth Sciences. From our perspective, supporting that extension was attractive because:

  1. it was relatively easy to maintain without us having to know anything about chemistry or the typesetting conventions thereof,
  2. rendered posts look dramatically more professional, and
  3. several sites can take advantage of the functionality.

I think the proposed extension has none of these advantages. For #1, we'd prefer a standard package that's already well supported. Cryptographic typesetting isn't exactly our strength. (In addition, using an existing standard reduces the lock-in concern brought up in the comments.) For the second criteria, I admit $\gcd(a,b)$ looks better than gdc(a,b) (or gdc(a,b)), but I'm not sure it's quite so clear a win as the chemistry examples. Finally, I think other sites might appreciate having a cryptography extension, but they might prefer a more general set of macros.


In the comments, there was some discussion of using question templates to implement a standard set of operators. I had a conversation this morning about the future of question templates and it looks like we might try giving askers a list of 3-5 templates to match their specific problem. Since each site would need a different set of templates, I anticipate these would be editable by the community (either directly or via moderators). So sites could give askers the option to include a standard set of operators if they want them.

I do see that there is one potential problem with definitions leaking to other posts. (In fact, I borrowed your definition of \lcd in my example above.) On the other hand, that could be a feature since the question would, in essence, define operators once for all answers. Obviously there's room for abuse and difficult-to-find bugs. But given community-editable templates, it might be a reasonable hack not just for this site, but for every site that uses MathJax.

We're still in the very initial stages of testing templates, so I can't say for sure if we'll be implementing them across the network. But the early results are mildly promising even with a very simple template. Let's see how it develops.

A drawback of custom commands is decreased portability of site's content. This site's content can be and is published in places other than https://crypto.stackexchange.com. For example, mobile apps display it, and so would have to be given those same custom commands (but their development is frozen currently). Then what about third-party apps? sites mirroring SE content? people downloading the data dump for offline use?

The users of custom math operators may be interested in a userscript solution (disclaimer: I'm the author). The two features of it that I use most often are:

  • Blackboard bold: \RR => \mathbb{R}
  • Operator names: \gcd% => \operatorname{gcd}

Both expand immediately in the editor window. Direct link for installation (assuming a userscript manager is installed).

You must log in to answer this question.

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