# Can custom TeX/MathJax commands be defined by default for a site?

Recently SE.QuantumComputing started private beta (bit of a misnomer, as users can join freely), and we started a $\mathrm{\TeX}$-tutorial Meta discussion like the one found here at SE.Math.

Since quantum computing makes frequent use of bra-ket notation and it's a bit tedious to type out the $\mathrm{\TeX}$ for it constantly, it'd be nice if we could auto-include custom $\mathrm{\TeX}$ definitions for it, along with other common quantum-computing concepts, in our MathJax implementation.

For example, it'd be cool if we could auto-include

\newcommand{\bra}[1]{ \left< #1 \right| }
\newcommand{\ket}[1]{ \left| #1 \right> }
\newcommand{\bk }[2]{ \left< #1 \middle| #2 \right> }
\newcommand{\bke}[3]{ \left< #1 \middle| #2 \middle| #3 \right> }


, so then users could type

• $\bra{x}$ to get $\left< x \right|$;

• $\ket{y}$ to get $\left| y \right>$;

• $\bk{x}{y}$ to get $\left< x \middle| y \right>$;

etc..

Questions:

1. Does SE.Math or any other SE have such custom-defined ${\rlap{\raise{0.5ex}{\rule{2em}{1px}}}} \mathrm{\TeX}$ commands?

• As pointed out by @Quasicoherent in the comments, this has been proposed before and rejected. However, still curious about whether or not it's technically possible in the case that there's broad community agreement on common $\mathrm{\TeX}$ commands for specialized SE's.
2. If not, is it something that could be reasonably done if the community agrees on a set of highly useful commands?

• Just to note it, I'm asking here at SE.Math instead of at SE.QuantumComputing since it seems like a question this site's likely to have already addressed (though I wasn't able to find it on searching the Meta). – Nat Mar 16 '18 at 19:09
• I think this post may be what you're looking for. – Richard D. James Mar 16 '18 at 19:52
• I vaguely believe that MathOverflow (used to?) have some. @Asaf do you happen to recall details? – quid Mar 17 '18 at 12:13
• @quid: Unfortunately, no. – Asaf Karagila Mar 17 '18 at 12:24
• This is unrelated to the main issue, but looking at your example, wouldn't \langle and \rangle be a more natural choice than < and >. There is a related TeX.SE question: Braket notation in LaTeX. (Although it is not exactly about this, it seems to be mainly about braket package.) Since this is unrelated to the main question, I'd suggest that we could discuss this further (if needed) in the MathJax chatroom. – Martin Sleziak Mar 21 '18 at 8:53
• @MartinSleziak The issue with \langle and \rangle is that they're just characters, so they don't resize to their content. A working alternative is to use \left\langle and \right\rangle to get the same effect as \left< and \right>, but then it's just more characters for the same thing. – Nat Mar 21 '18 at 9:14
• Would you be averse to writing $\langle x\mid y\rangle$ instead of $\left< x \middle| y\right>$? – Michael Hardy Mar 22 '18 at 22:23
• @MichaelHardy I do kinda like the extra spacing from \mid, though unfortunately it doesn't scale (at least not with \middle\mid), so at the moment I wouldn't bother with it. I guess if we cared for the space, it could be \newcommand{\bk}[2]{\left< #1 \hspace{5px} \middle| \hspace{5px} #2 \right>} instead. Or, maybe a bit less than 5px, since it looks a bit much. – Nat Mar 22 '18 at 22:32
• @AsafKaragila Just so you know, I blame you for this. – Nat Apr 23 '18 at 3:36
• @Nat: And I blame someone from MathOverflow for that! – Asaf Karagila Apr 23 '18 at 6:03
• – Martin Sleziak Oct 7 at 3:03

## 2 Answers

Yes, this is possible. You can run a list of commands in the header of the documents that define a list of macros. I have that on my website, so I can always write \ZFC and produce $\mathsf{ZFC}$ in math-mode.

Of course, in the context of your question this is only very theoretical. I don't see a community agreement happening anytime soon.

• +1 I don't see a community agreement happening anytime soon. I find it inconvenient when I get a Latex snippet where someone has used his own private macros. – GEdgar Mar 17 '18 at 14:15
• Awesome! Yeah, I'm trying to avoid assuming too much about the potential for community agreement. Rather, I figured it'd make more sense to first check if it were technically possible, then start a Meta discussion about whether or not the community'd be interested in implementing any. – Nat Mar 17 '18 at 17:54
• Do we need a community agreement? We could just implement the most popular choice and let those who dislike it make do without predefined macros. – Joonas Ilmavirta Mar 20 '18 at 11:05
• @Joonas: Well, you'd have to agree to that. I find it very annoying when someone shoves their personal macros into my TeX. I find it irritating to even work with coauthors, unless exactly one person is in charge of the final TeX file. I would be quite upset if macros which are different than my own would be implemented globally. Not to mention, that you would de facto create a standard, and confuse newbies who try to copy their code to a LaTeX documents, unaware of the extra macros involved. So all in all, it's a bad idea, and I don't think there is enough consensus for even implementing it. – Asaf Karagila Mar 20 '18 at 11:08
• I agree that it's probably best not to implement any such things globally. It would also require making the macro list easily accessible whenever writing a post, and I'm not convinced we'd get that UI change. I wanted to explore the options, but I prefer the status quo. – Joonas Ilmavirta Mar 20 '18 at 11:18

I guess every answer is in an independent 'sandbox' such that it doesn't interfere with the $\LaTeX$ code of other users.

• There have actually been instances when macros defined in one answer affected answers below it on the page. And when the system rearranged the answers, some of them broke since they were no longer below their macro definitions. – GEdgar Mar 21 '18 at 13:29
• @GEdgar You can also reorder the answers by votes, date, or activity. Defining macros in the answers is not compatible with such juggling. I agree that all posts should be sandboxes, but unfortunately they aren't. – Joonas Ilmavirta Mar 22 '18 at 16:37