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.)

  • 3
    $\begingroup$ That should be very doable. $\endgroup$
    – Asaf Karagila Mod
    Commented Feb 13, 2020 at 10:13

2 Answers 2


I'm not certain exactly what you are looking for. There are a few ways which I can see interpreting what you're asking for. How to implement it, or what to use, is going to depend on what you want and what's comfortable for you.


Your code currently replaces the content of the text area with the text you've put in the bookmarklet. Personally, if I were creating a bookmarklet for this, I'd probably look at the code in the answers to How to insert text into the textarea at the current cursor position?, which would instead insert the text at the current cursor position, rather than replacing the content.

You could implement additional features, such as taking the content from a URL. However, that rapidly goes beyond something which would normally be implemented as a bookmarklet and into what would probably be more appropriate as a userscript.


It's certainly possible to create a userscript which does things along the lines of what you've described. You'd need to decide exactly what you want and how you want it to look on the page.

  • Do you want to always automatically include some specified text when you select the input box for an answer or question, or only when you begin a new question or answer (perhaps only on some SE sites)?
  • Do you want to have a user-adjustable set of auto-text, similar to what's done for comments and custom close reasons by AutoReviewComments - Pro-forma comments for SE? That userscript also has the ability to download comment sets from a URL, so you could get a feel for how it does that.
  • Do you want to add a button or buttons to the edit controls for the questions/answer creation/edit boxes?
    If so, you might want to look at Magic™ Editor  (GitHub) (install) to see what's necessary to detect the edit box and insert a button in those controls.
    There are other userscripts that insert an icon in there, which might be easier to take code from. Magic Editor is just one that I use, so it came immediately to mind. It looks like the MathJax Buttons userscript you found on Stack Apps also inserts buttons in the edit interface. I haven't used it, so I'm not sure if it's up to date with SE's code changes and/or that it does a good job of detecting inline/in-page editing, etc. It looks like it was last modified in 2014, so it might be a bit dated at this point.

A clipboard manager with stickies

This is probably the solution which I'd choose, if I was implementing for myself what I think you're describing. However, I already have a clipboard manager installed, so the choice to use it has a low barrier to entry. I should probably also note that a clipboard manager is a program I almost always install on any machine I'm going to be using for a while, as the expanded features are something I use many times every day. So, my choice of this solution my be a bit biased by how I use windowing systems.

A clipboard manager is a program you install on your computer which significantly increases the functionality of your windowing system's clipboard. There are a significant number of different programs to choose from which will add a variety of features. For what you've described, the feature you'd probably be most interested in goes by a few different names, but I usually see it called something similar to "stickies".

"Stickies" allow you to pre-define text which will always be quickly available through an enhanced interface for your computer's clipboard, in addition to, or as an alternate to, the normal clipboard operation. How each program implements it is slightly different. Personally, I find having this capability quite valuable to hold text I commonly use in various different programs. I do have some stickies defined with text I commonly use when editing on Stack Overflow (e.g. to define code syntax highlighting, use code snippets, etc.). For what you've described, defining a "sticky" with the text you want would likely be my go-to solution.

You'll need to do a search for clipboard managers, but limited to the operating system you use. I'd suggest going through some sites which offer comparisons in order to find one that fits your needs. Then try it out and switch to another one if the one you first picked doesn't really do what you want.

For Windows, I use ClipX (Wikipedia) (main ClipX site). However, I can't recommend it at this point, because development stopped on it in 2008. It does still work with Windows 10 and earlier. With its available plug-ins, it has the features I'm looking for, but may not continue to work in the future. I use it because I've used it for years and am familiar with it. For someone who isn't already invested in it, I'd recommend doing some research to find a clipboard manager which fits your needs and is still maintained.


As an alternative to the Clipboard Managers mentioned by Makyen:

Many people these days have a password manager. If it can autotype based on the active window and copy into the clipboard, it can take the place of a clipboard manager for this by saving your commands to the clipboard, and then sending ctrl+v.

E.g. for Keepass, one would add a string field 'CopyPasteDump' where one would put everything one wants to be copied into the text field, then add the following autotype-sequence for stackexchange websites:

{C:Copy-Paste standard commands}{CLIPBOARD-SET:/{S:CopyPasteDump}/}^v{Delay 100}

As long as KeePass is open, one can then on a stackexchange site simply prompt an autotype (ctrl+alt+a) and choose the option annotated with 'Copy-Paste standard commands'.


You must log in to answer this question.

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