typora / typora-issues

Bugs, suggestions or free discussions about the minimal markdown editor — Typora
https://typora.io
1.53k stars 56 forks source link

feature request: automatically adding `\end{...}` in a LaTeX block #4312

Closed Pomax closed 3 years ago

Pomax commented 3 years ago

Typora currently knows that if you type some HTML tag, then text, and then you start typing </ it autocompletes the open tag for you. In that same vein, it would be great if it knew what to do while in a LaTeX block, where the equivalent of matched tags is matched \begin{...} and \end{...} strings.

It would be great if Typora tracked which environment it is in (identical logic as for HTML tags), and would automatically fill in "the rest" when you type \end{:

  1. user types \begin{aligned}
  2. user writes some text
  3. user starts writing \end
  4. when typora sees the user completing that to \end{, it adds <current env name> + }

Alternatively, it might be even more useful to follow the same logic that happens when they user types $$: this starts a block with the ending $$ already added, so we could use the same pattern:

  1. user types $$, Typora starts a new LaTeX block
  2. user types \begin{aligned}
  3. Typora automatically adds an empty line, and then \end{aligned} on the line after that empty line, placing the cursor on the empty line for the user.

The second implementation would be distinctly superior, but the first is still by far better than having no autocompletion for matched "tags".

abnerlee commented 3 years ago

2988

Pomax commented 3 years ago

That's a way more generic issue than this one, though: I'm just requesting begin/end environment autocompletion, because that's something that someone working on the code should be able to do in an hour or two.

Unlike "full autocomplete for LaTeX" as requested in 2988, which is a huge epic and no one would be able to get done even with a full week available to them.

abnerlee commented 3 years ago

Currently there's no autocomplete at all.

So I think it can be covered by #2988

Pomax commented 3 years ago

It can be, but 2988 would be the epic: "add automcomplete for LaTeX", which then breaks apart into quite a few subtasks that all need to be dealt with separately: environment autocomplete (which uses the same logic as HTML tags), base syntax autocomplete (parens, curly brackets, etc), automatically matching \left to \right, autoinjection of {} when someone types ^ or _, etc. So the tracking of the total task of autocompletion is definitely covered by 2988, but it would make a lot of sense to mark it as epic, and making this issue one of the tasks that needs to be completed for that epic to be considered done.