13
$\begingroup$

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?

$\endgroup$
11
  • 3
    $\begingroup$ 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). $\endgroup$
    – Nat
    Commented Mar 16, 2018 at 19:09
  • 4
    $\begingroup$ I think this post may be what you're looking for. $\endgroup$ Commented Mar 16, 2018 at 19:52
  • 2
    $\begingroup$ I vaguely believe that MathOverflow (used to?) have some. @Asaf do you happen to recall details? $\endgroup$
    – quid
    Commented Mar 17, 2018 at 12:13
  • $\begingroup$ @quid: Unfortunately, no. $\endgroup$
    – Asaf Karagila Mod
    Commented Mar 17, 2018 at 12:24
  • 2
    $\begingroup$ 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. $\endgroup$ Commented Mar 21, 2018 at 8:53
  • $\begingroup$ @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. $\endgroup$
    – Nat
    Commented Mar 21, 2018 at 9:14
  • $\begingroup$ Would you be averse to writing $\langle x\mid y\rangle$ instead of $\left< x \middle| y\right>$? $\endgroup$ Commented Mar 22, 2018 at 22:23
  • $\begingroup$ @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. $\endgroup$
    – Nat
    Commented Mar 22, 2018 at 22:32
  • $\begingroup$ @AsafKaragila Just so you know, I blame you for this. $\endgroup$
    – Nat
    Commented Apr 23, 2018 at 3:36
  • $\begingroup$ @Nat: And I blame someone from MathOverflow for that! $\endgroup$
    – Asaf Karagila Mod
    Commented Apr 23, 2018 at 6:03
  • 2

2 Answers 2

13
$\begingroup$

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.

$\endgroup$
5
  • 8
    $\begingroup$ +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. $\endgroup$
    – GEdgar
    Commented Mar 17, 2018 at 14:15
  • $\begingroup$ 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. $\endgroup$
    – Nat
    Commented Mar 17, 2018 at 17:54
  • 2
    $\begingroup$ 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. $\endgroup$ Commented Mar 20, 2018 at 11:05
  • 5
    $\begingroup$ @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. $\endgroup$
    – Asaf Karagila Mod
    Commented Mar 20, 2018 at 11:08
  • $\begingroup$ 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. $\endgroup$ Commented Mar 20, 2018 at 11:18
-1
$\begingroup$

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

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$
    – GEdgar
    Commented Mar 21, 2018 at 13:29
  • 3
    $\begingroup$ @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. $\endgroup$ Commented Mar 22, 2018 at 16:37

You must log in to answer this question.

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