cmhughes / latexindent.pl

Perl script to add indentation (leading horizontal space) to LaTeX files. It can modify line breaks before, during and after code blocks; it can perform text wrapping and paragraph line break removal. It can also perform string-based and regex-based substitutions/replacements. The script is customisable through its YAML interface.
GNU General Public License v3.0
864 stars 84 forks source link

Formatting of listings #515

Closed mnsgs closed 6 months ago

mnsgs commented 6 months ago

Please provide the following when posting an issue:

original .tex code

\documentclass{article}

\usepackage{listings}

\begin{document}

Listing test
  \begin{lstlisting}
Important listing
            \end{lstlisting}

Itemize test
  \begin{itemize}
\item test item
            \end{itemize}

\end{document}

yaml settings

None

actual/given output

\documentclass{article}

\usepackage{listings}

\begin{document}

Listing test
\begin{lstlisting}
Important listing
            \end{lstlisting}

Itemize test
\begin{itemize}
        \item test item
\end{itemize}

\end{document}

desired or expected output

\documentclass{article}

\usepackage{listings}

\begin{document}

Listing test
\begin{lstlisting}
Important listing
\end{lstlisting}

Itemize test
\begin{itemize}
        \item test item
\end{itemize}

\end{document}

anything else

Formatting applied using the logic

latexindent test.tex

I would expect \end{lstlisting} to be indented to the same level as of the \begin{lstlisting} as is the case for the itemize environment which is added for illustration purpose

-- Context

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy
$ latexindent -v
3.23.6, 2024-01-17
cmhughes commented 6 months ago

This is a verbatim environment, if you don't want it to be verbatim then you can use

verbatimEnvironments:
  lstlisting: 0
mnsgs commented 6 months ago

Thanks @cmhughes , latexindent --yaml="verbatimEnvironments:lstlisting: 0" test.tex does not really solve the issue though - it yields the following

\documentclass{article}

\usepackage{listings}

\begin{document}

Listing test
\begin{lstlisting}
        Important listing
\end{lstlisting}

Itemize test
\begin{itemize}
        \item test item
\end{itemize}

\end{document}

hence idents also the content inside the environment.

I would consider it a bug that the \begin and \end are not aligned with the default settings?

cmhughes commented 6 months ago

Thanks for the follow up.

Verbatim blocks are deliberately left alone, this is not a bug.

Perhaps you might like noAdditionalIndent?

mnsgs commented 6 months ago

Thanks for clarifying