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

modifyLineBreaks with when: after has problems in the presence of comments and \item #450

Closed
niveK77pur opened this issue Jun 12, 2023 · 6 comments
Labels
bug unexpected behaviour; should be a priority for fixing implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix text-wrap text wrapping; documented at https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html

Comments

@niveK77pur
Copy link

niveK77pur commented Jun 12, 2023

original .tex code

\documentclass{article}
\usepackage{minted}
\begin{document}

the main idea behind trig integrals: pythagorean theorem identities. what is a triangle anyway?

the main idea behind trig integrals:
%
pythagorean theorem identities.
what is a triangle anyway?

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
pythagorean theorem identities.
what is a triangle anyway?

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
%
pythagorean theorem identities.
what is a triangle anyway?

\begin{itemize}

  \item the main idea behind trig integrals: pythagorean theorem identities. what is a triangle anyway?

  \item the main idea behind trig integrals:
    %
    pythagorean theorem identities.
    what is a triangle anyway?

  \item the main idea behind trig integrals:
    %
    \mintinline{bash}{echo "hello"}
    pythagorean theorem identities.
    what is a triangle anyway?

  \item the main idea behind trig integrals:
    %
    \mintinline{bash}{echo "hello"}
    %
    pythagorean theorem identities.
    what is a triangle anyway?


\end{itemize}

\end{document}

yaml settings

modifyLineBreaks:
  textWrapOptions:
    columns: 70
    when: "after"

actual/given output

\documentclass{article}
\usepackage{minted}
\begin{document}

the main idea behind trig integrals: pythagorean theorem identities.
what is a triangle anyway?

the main idea behind trig integrals:
%
pythagorean theorem identities. what
                                is a triangle anyway?

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
pythagorean theorem identities.
what is a triangle anyway?

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
%
pythagorean theorem identities. what
                                is a triangle anyway?

\begin{itemize}

	\item the main idea behind trig integrals: pythagorean theorem
      identities. what is a triangle anyway?

	\item the main idea behind trig integrals: pythagorean theorem
      identities. what is a triangle anyway?%

	\item the main idea behind trig integrals: \mintinline{bash}{echo
      "hello"} pythagorean theorem identities. what is a triangle
      anyway?%

	\item the main idea behind trig integrals: \mintinline{bash}{echo
      "hello"} pythagorean theorem identities. what is a triangle
      anyway?%%

\end{itemize}

\end{document}

desired or expected output

\documentclass{article}
\usepackage{minted}
\begin{document}

the main idea behind trig integrals: pythagorean theorem identities.
what is a triangle anyway?

the main idea behind trig integrals:
%
pythagorean theorem identities. what is a triangle anyway?

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
pythagorean theorem identities.
what is a triangle anyway?

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
%
pythagorean theorem identities. what is a triangle anyway?

\begin{itemize}

	\item the main idea behind trig integrals: pythagorean theorem
      identities. what is a triangle anyway?

	\item the main idea behind trig integrals:
	      %
	      pythagorean theorem identities. what is a triangle anyway?%

	\item the main idea behind trig integrals:
	      %
	      \mintinline{bash}{echo "hello"}
	      pythagorean theorem identities.
	      what is a triangle anyway?

	\item the main idea behind trig integrals:
	      %
	      \mintinline{bash}{echo "hello"}
	      %
	      pythagorean theorem identities. what is a triangle anyway?

\end{itemize}

\end{document}

anything else

This issue seems related to #412, as it shows many of the same symptoms. Everything works perfectly fine once I remove the when: after setting!

A few notes on my example:

  • It is a bit lengthy (apologies for that), but I tried to be very explicit with all the cases I encountered. Maybe there are other edge cases I am yet to discover where things fall apart.
  • Each paragraph also reappears as an item in the itemize environment. For the itemize cases in particular, the wrapping seems entirely disrespected and the comments become wrapped like shown in section 6.1.6 Text wrap: trailing comments and spaces of the user manual, which is not the expected behavior here given that the comments are on their own lines. (great job on the manual btw!!)
  • The reason for me to split a paragraph like this is mainly related to the verbatim macros (like \mintinline).
    • It can happen that the line wrapping happens inside the verbatim's text, which will cause a compilation error in the case of minted (NB: line break in the tex file, not the output PDF). See the last two \item from the actual/given output
    • Separating it into its own line like this solves the issue (together with the verbatimCommands option). It avoids the formatter to accidentally insert a line break and cause a compile error or other artifacts.
    • It can generally also help to visually distinguish different ideas in a larger paragraph for the sake of writing (in the tex file).
  • Small question while I am at it: the 3rd paragraph does not get wrapped/formatted after the commented line. I suppose it is related to the verbatim \mintinline macro. Is this the expected behavior? I'm not sure if I would have expected the text to be wrapped such that it continues after the \mintinline here; but this is fine as well. I just wanted a small clarification!
@cmhughes
Copy link
Owner

Thanks for this, I hope to get to this soon.

@cmhughes cmhughes added bug unexpected behaviour; should be a priority for fixing text-wrap text wrapping; documented at https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html labels Jun 16, 2023
@cmhughes
Copy link
Owner

Apologies for the delay, I'm working on this.

I've so far resolved parts of the problem, but not all.

Thanks again for reporting this, and for providing such a helpful example! I'll report back once I've got it fixed...

cmhughes added a commit that referenced this issue Jul 2, 2023
@cmhughes
Copy link
Owner

cmhughes commented Jul 2, 2023

As of fdc2ea0 this is resolved.

original

\documentclass{article}
\usepackage{minted}
\begin{document}

the main idea behind trig integrals: pythagorean theorem identities. what is a triangle anyway?

the main idea behind trig integrals:
%
pythagorean theorem identities.
what is a triangle anyway?

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
pythagorean theorem identities.
what is a triangle anyway?

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
%
pythagorean theorem identities.
what is a triangle anyway?

\begin{itemize}

  \item the main idea behind trig integrals: pythagorean theorem identities. what is a triangle anyway?

  \item the main idea behind trig integrals:
    %
    pythagorean theorem identities.
    what is a triangle anyway?

  \item the main idea behind trig integrals:
    %
    \mintinline{bash}{echo "hello"}
    pythagorean theorem identities.
    what is a triangle anyway?

  \item the main idea behind trig integrals:
    %
    \mintinline{bash}{echo "hello"}
    %
    pythagorean theorem identities.
    what is a triangle anyway?


\end{itemize}

\end{document}

settings

noIndentBlock:
    mintinline:
      begin: (?<!\\)\\mintinline\{
      body: [^}]*?\}\{[^}]*?
      end: \}

modifyLineBreaks:
  textWrapOptions:
    columns: 70
    when: "after"

output

\documentclass{article}
\usepackage{minted}
\begin{document}

the main idea behind trig integrals: pythagorean theorem identities.
what is a triangle anyway?

the main idea behind trig integrals:
%
pythagorean theorem identities. what is a triangle anyway?

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
pythagorean theorem identities. what is a triangle anyway?

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
%
pythagorean theorem identities. what is a triangle anyway?

\begin{itemize}

	\item the main idea behind trig integrals: pythagorean theorem
	      identities. what is a triangle anyway?

	\item the main idea behind trig integrals:
	      %
	      pythagorean theorem identities. what is a triangle anyway?

	\item the main idea behind trig integrals:
	      %
	      \mintinline{bash}{echo "hello"}
	      pythagorean theorem identities. what is a triangle anyway?

	\item the main idea behind trig integrals:
	      %
	      \mintinline{bash}{echo "hello"}
	      %
	      pythagorean theorem identities. what is a triangle anyway?

\end{itemize}

\end{document}

Thanks again, I'll get this released imminently :)

@cmhughes cmhughes added the implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix label Jul 2, 2023
@niveK77pur
Copy link
Author

Thank you so much for the effort to fix this! Have a great day :D

@niveK77pur
Copy link
Author

I have just discovered another minor issue/bug that also goes away when I remove the when: after. It seems related to the noIndentBlock that you suggested, but I don't seem to spot any issue with the suggested regex itself. I'll just put it here without re-opening the issue myself, in case the problem is related to something else!

Original

\documentclass{article}
\usepackage{minted}
\begin{document}

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
pythagorean theorem identities.
what is a triangle anyway?
It has three sides!

\begin{itemize}

  \item the main idea behind trig integrals:
    %
    \mintinline{bash}{echo "hello"}
    pythagorean theorem identities.
    what is a triangle anyway?
    It has three sides!

\end{itemize}

\end{document}

Actual Output

You can see that the has three sides! outside the itemize is indented.

\documentclass{article}
\usepackage{minted}
\begin{document}

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
pythagorean theorem identities. what is a triangle anyway? It
     has three sides!

\begin{itemize}

        \item the main idea behind trig integrals:
              %
              \mintinline{bash}{echo "hello"}
              pythagorean theorem identities. what is a triangle anyway?
              It has three sides!

\end{itemize}

\end{document}

Expected output

(only relevant exert)

When removing the when: after, it becomes wrapped properly

the main idea behind trig integrals:
%
\mintinline{bash}{echo "hello"}
pythagorean theorem identities. what is a triangle anyway? It has
three sides!

Settings

Note: I quote the body: because my LSP throws errors on that line. The behaviour is exactly the same both with and without the quotes there!

noIndentBlock:
    mintinline:
      begin: (?<!\\)\\mintinline\{
      body: '[^}]*?\}\{[^}]*?'
      end: \}

modifyLineBreaks:
  textWrapOptions:
    columns: 70
    when: "after"

cmhughes added a commit that referenced this issue Jul 3, 2023
@cmhughes
Copy link
Owner

cmhughes commented Jul 3, 2023

My apologies, I should have caught this previously.

As of 4b3458c you get your desired output.

I'll do some more testing, and get another release out soon. Thanks, and apologies again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected behaviour; should be a priority for fixing implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix text-wrap text wrapping; documented at https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch.html
Projects
None yet
Development

No branches or pull requests

2 participants