0

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

2 Answers 2

1

You 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}
1

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}
5
  • 1
    If you indent the line by four spaces, the line is turned into "code". See the edits.
    – scottkosty
    Apr 3, 2021 at 14:10
  • ok. but how do I use semicolons (;) in shortcuts? May 22, 2021 at 13:30
  • I'm not sure what you mean, but the semicolons in your command-sequences seem to show up correctly.
    – scottkosty
    May 22, 2021 at 14:26
  • I mean creating a shortcut for some tikz code with a semicolon at the end. for example: \draw (-1,-1) rectangle (1,1); May 23, 2021 at 4:56
  • 1
    ah, I see. You can use 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.
    – scottkosty
    May 23, 2021 at 18:47

You must log in to answer this question.

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