how can I insert "tex code" into a shortcut?
I'm trying to create a short cut for some tikz code and can't find how to do so
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityYou can use a command-sequence but a semi-colon is a special character for a command-sequence and there is no documented escape. This makes it difficult to, for example, insert a semi-colon, which is often useful for TikZ.
The following, for example, does not work as intended:
command-sequence preview-insert; ert-insert; self-insert \begin{tikzpicture} \draw (-1,-1) rectangle (1,1); \end{tikzpicture}
because the semicolon at the end of the draw
command is not inserted. Instead, we can use LyX's unicode-insert
as a workaround. I also add paragraph-breaks:
command-sequence preview-insert; ert-insert; self-insert \begin{tikzpicture}; paragraph-break; self-insert \draw (-1,-1) rectangle (1,1); unicode-insert 0x003B; paragraph-break; self-insert \end{tikzpicture}
you can create a "tex code" box with the command:
ert-insert;
to insert the code itself you will use the command:
self-insert <code here>
for example:
if you try to create a shortcut for the beginning of the tikz code with the preview you can use the following code in your shortcut:
command-sequence preview-insert; ert-insert; self-insert \begin{tikzpicture} \end{tikzpicture}
unicode-insert
as a workaround. I added an answer with details. Feel free to incorporate the relevant part into your answer and I can delete my answer.
May 23, 2021 at 18:47