Question. Is there something which would make possible to quickly include predefined text in a new post I start writing. (For example, some bookmarklet for this - with a bookmarklet, one click could be enough to get text into a post.)
Typically I would imagine that this might be useful for users who often define macros, so that they don't have to copy-paste them manually. So, for example, a user might have predefined text such as $\newcommand{\N}{\mathbb N}\newcommand{\Q}{\mathbb Q}\newcommand{\Z}{\mathbb Z}\newcommand{\R}{\mathbb R}\newcommand{\C}{\mathbb C}$
(or some other macros they frequently use) and a bookmarklet which would include this text at the beginning of an answer/a question they are currently writing by a single click.
Some past discussions suggest that this might be useful for some users, for example posts such as: Specific Latex commands for user's account, Personalised $\LaTeX$ commands for users, $\LaTeX$ shortcuts, Can custom TeX/MathJax commands be defined by default for a site?, etc.
Recently a similar feature request was posted on Meta Stack Exchange: Enable blackboard bold TeX macros \N, \Z, \Q, \R, \C for N, Z, Q, R, C () in MathJax configuration.
I would understand if this is closed as off-topic - since to some extent this question can be read as "do this bookmarklet for me, please". On the other hand, I think that such bookmarklet might be useful for some users - unfortunately, I do not have enough programming experience to create it by myself. (And I will admit that my motivation for posting this was partly to make the users of this site aware of the discussion on Meta Stack Exchange. Since the change would influence this site, if users from here have some feedback on this, it would be useful if they have a look at that feature request.)
EDIT: I have done at least some attempt to create something like that and placed the bookmarklet on my website. (This is the bookmarklet called "Insert macros".) The source is: javascript:(function(){h=$('#wmd-input').val();$('#post-editor #wmd-input').val('$\\newcommand{\\N}{\\mathbb N}\\newcommand{\\Q}{\\mathbb Q}\\newcommand{\\Z}{\\mathbb Z}\\newcommand{\\R}{\\mathbb R}\\newcommand{\\C}{\\mathbb C}$\n'+h);})()
. I am pretty sure that people who have more experience with JavaScript would be able to do various improvements. (Thanks to Makyen for pointing out that my original version would overwrite the whole text of the post, the current version should put the macros at the beginning of the post.)
If somebody wanted to use this bookmarklet with different set of macros, they would have to edit the code. (In such case do not forget that you have to escape backslash, i.e., you have to use \\
. If you prefer to have each macro on a separate line, you can use \n
for newline.) Maybe a nicer way would be if the bookmarklet took macros from some url - however, I am not sure whether this is possible or how to do this.
EDIT 2: I have tried to search on Stack Apps whether I find something similar, but I wasn't able to find anything. (I found some userscripts which should add some shortcuts useful for editing posts with MathJax: MathJax Buttons and Markdown Shortcuts for StackExchange - insert latex commands quickly by keybindings. While they might be useful for users of this site, this definitely goes in another direction from what I suggested.)