# Personalised $\LaTeX$ commands for users


To be more clear here's an example:

• I define somewhere in my account \newcommand{\trace}{\operatorname{Tr}}

• I write an answer like:

Note that \$\trace(A)\neq 0\$ and thus \$A\neq 0\$. blabla...

• I press the "magic button" and my answer gets automatically transformed into

Note that \$\operatorname{Tr}(A)\neq 0\$ and thus \$A\neq 0\$. blabla...

This would avoid the three problems listed by Grigory M in the linked thread (if I understood them well). In worst case, if you define a lot of commands then it gets slow for you when you press the "magic button" but this doesn't affect the other members of the community.

I don't know how easy/hard this would be to implement but I'm interested to have your opinion on this feature and what kinds of problems it might raise.

• One possible drawback is that your notation may sometimes slightly mismatch the question (the question could have "tr" instead of "Tr", for example). I usually try to answer using the notation identical to the question. But for common operators like Re and Im this would be useful... but more likely to be implemented by some user as a userscript, than by SE. – user147263 Jan 7 '15 at 18:30
• interesting (and indeed it avoids that 3 problems I think). btw, this can be implemented by a browser extension — perhaps something like this exists already?.. – Grigory M Jan 7 '15 at 18:34
• @Fundamental this is a good point, however changing the Tr in tr after pressing the button is probably quicker than writing \operatorname{tr} each time (but this raise the chance of have different notations in the same answer...). – Surb Jan 7 '15 at 18:35
• @GrigoryM If you cross something like that on your way, I'd be interested to test it :) – Surb Jan 7 '15 at 18:35
• Google tells that Popchrom extension seems to be capable of something like this – Grigory M Jan 7 '15 at 18:39
• You could consider writing your own AutoHotKey script. They can really help in writing TeX much faster, and more accurate as well. – Lord_Farin Jan 7 '15 at 18:45
• Wouldn't that feature break (or half-break) preview? You'd only get a proper review after pressing the button, if I understand correctly. Not a deal-breaker, but something to consider, I think. – Daniel Fischer Jan 7 '15 at 18:52
• @DanielFischer this is another very goodpoint however we could immagin to be possible to press the button in the middle of writing the answer when the user wants to see the preview. – Surb Jan 7 '15 at 19:49
• Seems like this is just an aliasing thing, surely there must be some existing Javascript (or text editor) plugin that would get the job done. – Alexander Gruber Jan 8 '15 at 2:18

Specifically for operator names, the bookmarklet operator names does the job. Its syntax is \name%; I picked % as delimiter to minimize side effects, but if someone has a better idea, let me know. For example, typing \tr% results in \operatorname{tr}.
The code is quite simple: I include it below. Other substitutions can be implemented similarly, but I don't know what they should be. (One thing I'm considering for myself is \bb => \mathbb and similarly for other font commands.)
var editor = document.getElementById('wmd-input');
editor.value = editor.value.replace(/\\(\w+)%/g, '\\operatorname{$1}'); window.setTimeout(convertInput,1000); }  • This is very nice! However, it seems to not work when editing a question or an answer (only during the first shot) and it transforms also the expressions when they are not between \$...\\$ (although I don't really see why it is a problem because I don't remember writing \abc% in texts). – Surb Jan 8 '15 at 8:59
• Thanks for the bug report. I updated the bookmarklet: the new version should work for edits too. (Changed the first line to var editor = document.querySelector('.wmd-input.processed');). False positives outside of math mode seem unlikely; in any case there is no easy and reliable way to detect what's in math mode. – user147263 Jan 8 '15 at 20:07