WGUNDERWOOD / tex-fmt

An extremely fast LaTeX formatter written in Rust
MIT License
265 stars 20 forks source link

[bug] indentation after lstlisting with long captions #50

Closed jonsch318 closed 3 weeks ago

jonsch318 commented 4 weeks ago

A very simple example would be this. This is the formatting tex-fmt gives:

\begin{document}

\begin{lstlisting}[caption={a very long and complicated caption that
does not fit into one line}]
    \end{lstlisting}

    \section{asdas}
    Indent wrong

    \end{document}

I would expect someting more like:

\begin{document}

\begin{lstlisting}[caption={a very long and complicated caption that
  does not fit into one line}]
\end{lstlisting}

\section{asdas}
Indent wrong

\end{document}

I don't now the exact reason, but when switching to some other blocktype e.g. figure the identation is correct.

jonsch318 commented 4 weeks ago

i think it's all Verbatim environments at least verbatim, Verbatim, lstlisting, and minted

WGUNDERWOOD commented 4 weeks ago

Thanks, I will look into this.

WGUNDERWOOD commented 4 weeks ago

I have added a fix in 5338473f6160b07d06b5e6d78cb10f9c6ff91feb on the indentation-verbatim branch. The new approach is to totally ignore lines containing \begin{lstlisting} and \end{lstlisting}, as well as the lines in between. The same applies for verbatim, Verbatim, etc. This should prevent the incorrect indentation bug you are experiencing, but doesn't provide the wrapping and indenting of long captions you suggeseted. I think this is going to be hard to implement at the moment as it will need considerable care to make sure we match the caption (and other environment options) while not affecting any content inside the verbatim environment.

WGUNDERWOOD commented 3 weeks ago

I'm going to close this issue now the main problem has been resolved. I understand this may not be the ideal solution at this stage; feel free to reopen the issue, especially if you have thoughts on an implementation.

jonsch318 commented 1 week ago

I'm going to close this issue now the main problem has been resolved. I understand this may not be the ideal solution at this stage; feel free to reopen the issue, especially if you have thoughts on an implementation.

I will hopefully look at implementing a fix for this. I am currently working on my thesis and after that there should be time :).