Use case or problem
I use a few LaTeX environment templates which often involve wrapping \begin{} and \end{} around what I am currently writing. Inserting a template always places the cursor at the end of the inserted text, and you can’t template around a current selection. I would like this functionality. I am sure there are a bunch of other use cases for this as well
Proposed solution
The {{@}} template tag will get special status such that:
- {{@}} is replaced by the current selection
- The cursor is placed immediately after the {{@}} tag after templating.
With no selection, this would simply have the effect of the cursor being placed at {{@}} within the inserted template.
With a selection, it is possible to implement templates that ‘wrap’ some preexisting content.
For example, to mimic the behaviour of the existing CTRL+B boldening feature, use the following template:
**{{@}}**
Or add a shortcut for putting the selection into inline math:
${{@}}$
To put the current selection into an align environment (or if no selection this effectively wraps the environment around the cursor):
\begin{align}
{{@}}
\end{align}
Combined with a template hotkey feature, this could even be used to implement some core functionality like turning things bold, italics, inserting links etc. This would have the benefit of allowing users to override that behaviour as well, such that people preferring __ style boldening to ** could implement that themselves.
Alternative implementation
Have {{@}} insert selection and {{!}} place the cursor. If multi-cursor support is then provided in the future, multiple cursors could be placed using a template.
For example, inserting a footnote in a clever way that uses the selection as the ‘key’:
[^{{@}}]
[^{{@}}]: {{!}}