6
$\begingroup$

Sort of crossposted to https://math.meta.stackexchange.com/questions/3845/mathjax-custom-commands

MathJax allows the use of \newcommand in TeX. For example, this command:

\newcommand{\lorentz}[1]{\frac{#1}{\sqrt{1-\frac{v^2}{c^2}}}}

would be pretty useful in lots of situations. If this was placed somewhere in the body (AFAIK before it is called), then \lorentz{m_0} would give the expression for relativistic mass. \lorentz{1} would give the normal lorentz factor. lorentz{m_0c^2} gives us the expression for energy.

Like this, I can think up quite a lot of TeXcodes that are tedious to type, but crop up often. \frac{1}{2} and \frac{1}{\sqrt{2}} are some (smaller and less tedious) examples. A few more commands that quickly give expressions for the nabla operator, div, grad, curl would be nice as well.

Basically, is there any way that we can have a user-dictated commandset?

IMO, it's easy to code it, just keep "$$ *insert commands here* $$" at the top of the <body> tag. Less easy to code would be the way to make it user-dictated, but I'm thinking something akin to the way Community Promotion Ads - 2012 works would be easy to implement, as the code is already there. Just modify it so that it takes all the mathjax in the body of an answer with enough upvotes and appends it to some div in the beginning of the body tag (set display:none just to be safe).

Thoughts? Suggestions? Rants? Cookies?

$\endgroup$
  • $\begingroup$ PS: I think the guys at math.SE would like this as well. Is it OK to crosspost this? $\endgroup$ – Manishearth Mar 1 '12 at 8:21
  • $\begingroup$ Any reason for math not working on the meta? It works on mathmeta.. $\endgroup$ – Manishearth Mar 1 '12 at 8:22
  • $\begingroup$ It works only in places where people were complaining that it is not working. $\endgroup$ – user68 Mar 1 '12 at 11:02
  • $\begingroup$ I don't think we really need it here though, do we? $\endgroup$ – Manishearth Mar 1 '12 at 11:06
  • $\begingroup$ It wouldn't hurt, but we don't have that much need for it. $\endgroup$ – David Z Mar 1 '12 at 20:49
  • 2
    $\begingroup$ I'm beginning to find quite tiresome writing all those \rangles. Can we at least get \ket{x}? $\endgroup$ – Emilio Pisanty May 6 '12 at 12:16
  • $\begingroup$ @episanty I can give you a bookmarklet that provides a keyboard shortcut for \ket{..}.. And any other thingy you can think of. Its better if you tell me which key combination for which function(alt or ctrl+key). Just make sure the markdown editor doesn't use 'em already. $\endgroup$ – Manishearth May 6 '12 at 14:48
  • 1
    $\begingroup$ You mean something that will implement Alt+k(say)-> \ket{}? That won't render, though. The beauty of TeX commands is that they read (more or less) like equations sound in one's head. My ideal solution would be a central core of customized commands (i.e. including \ket{}), which one could then personalize on the profile page. (Though I'm aware this is getting close to the pony tag.) $\endgroup$ – Emilio Pisanty May 6 '12 at 15:35
  • $\begingroup$ @episanty: It will be similar to how this new script works. Actually, it'll be the same--since I'll be copying the keyboard-shortcut lambdas into a bookmarklet. It will do alt-k-->|(cursor)\rangle. Remember the cursor will auto-position itself. So, the flow is like this: dollar symbol;psi;=;alt-k;1;right arrow to leave ket;+;alt-k;0;right arrow;dollar for $\psi=|1\rangle+|0\rangle$. OK, I guess it can get complicated :/ (But it fits beautifully into the flow when typing chemical equations on chem.SE, so it may work) $\endgroup$ – Manishearth May 6 '12 at 15:42
  • $\begingroup$ @Manishearth: That overlooks the point - I hold that being able to write \ket{} and have it come out right is a valuable end in itself. Given that putting $\newcommand{\ket}[1]{|#1\rangle}$ on top of a post currently works, it shouldn't be unthinkable to define a core+personalized header that gets included on all posts, or all posts that use it. $\endgroup$ – Emilio Pisanty May 6 '12 at 15:59
  • 1
    $\begingroup$ @episanty: I know, I was talking about a temporary solution to help you. Actually, I may think of adding such customizable custom commands script. But it'll take a while. $\endgroup$ – Manishearth May 6 '12 at 16:01
  • $\begingroup$ @Manishearth Wow, it's been a while since this. Any chance of bras and kets in that nice script of yours? $\endgroup$ – Emilio Pisanty Sep 10 '13 at 12:58
  • $\begingroup$ @EmilioPisanty /me has no time :/ $\endgroup$ – Manishearth Sep 10 '13 at 14:44
  • $\begingroup$ Sorry to revive this (but as it is not fixed yet). I'd love to see a library of commonly used macros happen. Any pointers how I can help to make this happen? $\endgroup$ – Sebastian Riese May 15 '15 at 23:58
  • $\begingroup$ This question is not visible enough — it should be immediately discoverable by anybody who is looking for braket/Feynman/etc. notation. I had to click 3-4 links to check that this is known by the community. Should we create some questions and link them with each other? $\endgroup$ – Andrii Magalich Jun 15 '16 at 23:18
5
$\begingroup$

If you have a set of commands you use frequently, perhaps just save $ insert commands here $ in a text file and copy it into the top of your post whenever you need it (I'm not sure if that works, but it's worth a try).

If the SE people are amenable to site-specific customizations, though, I do have a LaTeX package of physics symbols that contains a few things we might consider for inclusion. These would be a limited number of highly standardized notations, like \ket{x} for |x\rangle, for instance, or \ud{y}{x} for the derivative \frac{\mathrm{d}y}{\mathrm{d}x}. It would also be fantastic to have the \SI command from siunitx, though admittedly that is a large and complex package that is probably not practical to implement in MathJaX (at least not in a way that faithfully reproduces the original typesetting, though that wouldn't necessarily be a requirement).

$\endgroup$
  • $\begingroup$ AFAICT MathJax only works with amsmath. A new package, in the general case, would require a whole bunch of new AJAX+fonts. Even if the package just condenses amsmath commands, it won't work. But yes, we can choose the good ones from there and use 'em. $\endgroup$ – Manishearth Mar 2 '12 at 1:14
  • $\begingroup$ WRT text document: that would work, but that might make the post huge in the case of a large commandset. $\endgroup$ – Manishearth Mar 2 '12 at 1:16
2
$\begingroup$

You face a significant problem here in that notation varies across sub-disciplines. In particular I can assure you that the Lorentz factor is $\frac{1}{sqrt{1 - v^2}}$ because everyone knows that $c$---like $G$ and $\hbar$--is a dimensionless unit constant.

$\endgroup$
  • $\begingroup$ You'd only ever have to write the expression for the lorentz factor while explaining a bit of SR to a novice. And a novice won't know the notation $c=1$. In other places, $\gamma$ is fine. $\endgroup$ – Manishearth Mar 1 '12 at 17:23
  • $\begingroup$ But the point is valid for other subdisciplines, though I can't think of any conflicts atm. $\endgroup$ – Manishearth Mar 1 '12 at 17:25
  • $\begingroup$ WRT the novice thing: atleast, that's the only place I've seen it used. $\endgroup$ – Manishearth Mar 1 '12 at 17:34

You must log in to answer this question.

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