Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yet another \item indentation error #2382

Closed
hamdav opened this issue May 2, 2022 · 4 comments
Closed

Yet another \item indentation error #2382

hamdav opened this issue May 2, 2022 · 4 comments
Labels

Comments

@hamdav
Copy link

hamdav commented May 2, 2022

Description

I've tried checking out the other \item indentation error issues but they are either claimed to be resolved or not quite the same as this one, so I'm making a new one.
The problem is this: I have a couple of lines hastily written down like so:

the first item
the second item
and so on

And then when I later go to clean up what I've written, I end up with

\begin{itemize}
    \item the first item
        \item the second item
             \item the third item
\end{itemize}

What I am doing is first putting the environment around the lines that will become the list, and then insert \item to the front of the line. If I from the beginning write the items in order then the indentation becomes correct. =ie does fix it but it's annoying to have to do that all the time.

Steps to reproduce

Minimal init.vim:

all plug#begin('~/.config/nvim/plugged')
Plug 'lervag/vimtex'
call plug#end()
  1. Open a tex document
  2. write two lines
  3. surround in \begin{itemize} / \end{itemize}
  4. Insert \item at the beginning of the two lines
    The first one is correctly indented, the second is indented too much

Expected behavior

All \items being indented one tab / four spaces

Actual behavior

Indent level increasing with each \item

Do you use a latexmkrc file?

no

VimtexInfo

System info:
  OS: macOS 11.2.3 (20D91)
  Vim version: NVIM v0.6.1
  Has clientserver: true
  Servername: /var/folders/mn/7wv53fcj6m95stzmb3nq73bw0000gn/T/nvimSyp5Hp/0

VimTeX project: main
  base: main.tex
  root: /Users/davidhambraeus/Hive/Courses/QIP_II/Excercises/ps8_paper_reading
  tex: /Users/davidhambraeus/Hive/Courses/QIP_II/Excercises/ps8_paper_reading/main.tex
  main parser: current file verified
  document class: article
  packages: aligned-overset amsbsy amsfonts amsgen amsmath amsopn amssymb amstext amsthm a
  source files:
    main.tex
    packages.tex
    mathCommands.tex
    textSettings.tex
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: General
  qf method: LaTeX logfile
@hamdav hamdav added the bug label May 2, 2022
@lervag
Copy link
Owner

lervag commented May 2, 2022

I believe the problem is that the specified workflow sort of breaks the expectations used for auto indentation here. That is, given:

\begin{itemize}
  \item first
second
\end{itemize}

When you start adding the \item in front, e.g. with I\ite, you get this (| marks the cursor):

\begin{itemize}
  \item first
\ite|second
\end{itemize}

Now continue in insert mode by adding "m", you get:

\begin{itemize}
  \item first
    \itemsecond
\end{itemize}

This is because the indentation is triggered by the \item, which does not look forward in the line. But the indentation rule does not recognize \itemsecond as an actual bullet and the lien is therefore indented as if it is not a new separate \item line.

As a "proof" of this, you can try the same story as above, except add the initial space. That is, do 0i <left>\item, and the indentation is now as expected:

\begin{itemize}
  \item first
\ite| second
  % continue with "m" →
  \item second
\end{itemize}

I've tried to thing of a "solution" to this, but I'm afraid I don't immediately see any. Or, one possibility is to relax the regex used for the indentation:

let s:envs_item = '^\s*\\item\>'

If we remove \> at the above line, then things work. But this could break indentation if you for some reason wrote something like:

\begin{env}
  Some text where you for some reason break the line here
  \itemcmd and continue here with some random command starting with
    "\item..". The indentation is now broken.
\end{env}

I might consider going for this, as the broken scenario seems very unlikely. But still, we will have to choose between things that are not perfect.

I would be happy to hear more opinions on this matter. Or better; suggestions for other ways to handle this.

@hamdav
Copy link
Author

hamdav commented May 2, 2022

Would it be possible to trigger the indentation on \item (with the space) instead of just \item?

@lervag
Copy link
Owner

lervag commented May 7, 2022

Yes, that is possible, but it would ruin auto indent on \item[. However, that may be OK, as I could just add that as an additional indent key...

@lervag
Copy link
Owner

lervag commented May 7, 2022

I believe this is actually a superior behaviour. It also means we can remove some code we use to fix an indent issue on completion (#2179, #2156). I'm pushing the updates now.

@lervag lervag closed this as completed May 7, 2022
lervag added a commit that referenced this issue May 7, 2022
Only trigger autoindent after space or [ to avoid unexpected auto
indents.

refer: #2382
lervag added a commit that referenced this issue May 7, 2022
Using a more specific indentkeys setting (see #2382) means the fix for
the issues #2179 and #2156 are no longer necessary.

refer: #2382, #2179, #2156
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants