cdlatex icon indicating copy to clipboard operation
cdlatex copied to clipboard

Environment template: Unwanted newline at the beginning if there is only whitespace on the current line

Open Sinthoras7 opened this issue 2 years ago • 4 comments

Currently, the environment templates, e.g. equ then tab, insert the environment on the current line, if the cursor is at the beginning of the line; and first create a new line and then insert the environment if the cursor is at a line, where things have been typed before, i.e. the cursor is not at the beginning of the line.

This behavior is mostly great, because the begin{equation} should have its own line and not be at the end of some line. A problem arises, when there is only whitespace on the current line before the cursor. In this case, the begin{equation} should be inserted in the same line, since the line is empty modulo whitespace. But instead - I assume because the cursor is not at the beginning of the line, since there is whitespace before it - a new line gets inserted, creating a completely empty line between the text before and the begin{equation}.

This empty line is a problem, because Latex then interprets this as a new paragraph and inserts extra space between the text and the environment, e.g. the equation. (Also for aesthetic- and clarity-reasons in the .tex file, but those are secondary.) This problem gets enhanced, because Auctex creates these whitespaces automatically, when creating a new line in the .tex file inside an environment.

Sinthoras7 avatar Apr 25 '23 19:04 Sinthoras7

Hi, I am finally looking at that and can reproduce it. Easy to fix, in principle. However, cdlatex always inserts environments unindented. So if I simply no longer insert a newline, then the result might look like this:

    \begin{equation}

\label{...} \end{equation}

i.e. with the first line indented, but the others not. Should I remove the white space at before the cursor?

cdominik avatar Jul 08 '23 15:07 cdominik

This is not perfect, (ideally cdlatex would detect the indent and act accordingly) but I personally think it is an okay fix and better than the behaviour right now, so you should remove it.

Sinthoras7 avatar Jul 09 '23 09:07 Sinthoras7

Hi,

I have pushed a fix that does also keep the indentation. May I ask you to test it, Sinthoras, and report back? I have not yet changed the version number, so this will not yet move up into the package system.

cdominik avatar Jul 09 '23 15:07 cdominik

Hey, I tested it, and it seems to not have worked. It seems to have the same behaviour as before the fix. I am not entirely, but like 85% sure, that I have the version currently in the repository including the newest commit installed.

Sinthoras7 avatar Jul 12 '23 20:07 Sinthoras7