latexindent.pl icon indicating copy to clipboard operation
latexindent.pl copied to clipboard

linewidth not respected exactly with indentation

Open tdegeus opened this issue 2 years ago • 6 comments

Please provide the following when posting an issue:

original .tex code

\begin{abstract}
    This is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation.
\end{abstract}

yaml settings

onlyOneBackUp: 1
defaultIndent: '    '
removeTrailingWhitespace: 1

lookForAlignDelims:
  align: 0

modifyLineBreaks:
  oneSentencePerLine:
    manipulateSentences: 1
    removeSentenceLineBreaks: 0
    textWrapSentences: 1
    sentencesFollow:
      other: |-
        (?x)
        \\caption\{\h*\R*
        \\footnote\{\h*\R*
  textWrapOptions:
    columns: 100

fineTuning:
  namedGroupingBracesBrackets:
    name: '[0-9\.a-zA-Z@\*><_]+?'

# remove recurrent spaces
replacements:
- substitution: s/([a-zA-Z0-9.}{])\h{2,}([a-zA-Z0-9.}{])/$1 $2/sg
  when: before
- substitution: s/([a-zA-Z0-9.()}{])\h{2,}([a-zA-Z0-9.()}{]|(?:\\(?!\\)))/$1 $2/sg
  when: after

actual/given output

\begin{abstract}
    This is a very long sentence that should be wrapped at some point, which is the case but is is is
    is line width is not respected because of the indentation.
\end{abstract}

desired or expected output

\begin{abstract}
    This is a very long sentence that should be wrapped at some point, which is the case but is is 
    is is line width is not respected because of the indentation.
\end{abstract}

tdegeus avatar Apr 24 '22 07:04 tdegeus

Thanks for this.

So if there was no indentation then the line width would be correct....?

cmhughes avatar Apr 24 '22 09:04 cmhughes

Indeed

tdegeus avatar Apr 24 '22 09:04 tdegeus

OK, in which case this is a known issue : https://latexindentpl.readthedocs.io/en/latest/sec-conclusions-know-limitations.html

I'll see if I can look into changing the order of things. I have no idea how difficult it will be.

Text wrapping is the gift that keeps on giving.

cmhughes avatar Apr 24 '22 10:04 cmhughes

In that case sorry for reporting a know issue ;) Don't worry nothing urgent/important. Just reporting in order to help the project

tdegeus avatar Apr 24 '22 12:04 tdegeus

For my reference

https://github.com/cmhughes/latexindent.pl/issues/306

cmhughes avatar Apr 26 '22 05:04 cmhughes

This issue is on my mind a lot, I have a plan for how to tackle it, just need the head space to sit down and do it.

I'm hoping to get to it before the end of 2022, at the latest.

cmhughes avatar Sep 23 '22 09:09 cmhughes

For my reference

https://github.com/cmhughes/latexindent.pl/issues/356

cmhughes avatar Oct 16 '22 08:10 cmhughes

Some good news! :)

As of https://github.com/cmhughes/latexindent.pl/commit/a54b7be45606d07518dd86308212852111710991 I've upgraded the text wrap routine.

demonstration 1

Starting with

\begin{abstract}
    This is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation.  Another is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation.
    \begin{another}
    Another is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation.
    \begin{itemize}
      \item Another is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation. One is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation. Two is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation.
      \item Another is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation. One is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation. Two is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation.
      \item Another is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation.
    \begin{itemize}
      \item One is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation.
      \item Two is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation.
    \end{itemize}
      \item Three is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation.
    \end{itemize}
    \end{another}
    This is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation. One is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation. Two is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation. Three is a very long sentence that should be wrapped at some point, which is the case but is is is is line width is not respected because of the indentation.
\end{abstract}

and the settings

defaultIndent: '    '

modifyLineBreaks:
    oneSentencePerLine:
      manipulateSentences: 1
      textWrapSentences: 1
      sentencesFollow:
          other: \\item
    textWrapOptions:
        columns: 100
        when: after                          # <!----------  NEW BIT

gives the output

\begin{abstract}
    This is a very long sentence that should be wrapped at some point, which is the case but is is
    is is line width is not respected because of the indentation.
    Another is a very long sentence that should be wrapped at some point, which is the case but is
    is is is line width is not respected because of the indentation.
    \begin{another}
        Another is a very long sentence that should be wrapped at some point, which is the case but
        is is is is line width is not respected because of the indentation.
        \begin{itemize}
            \item
                  Another is a very long sentence that should be wrapped at some point, which is
                  the case but is is is is line width is not respected because of the indentation.
                  One is a very long sentence that should be wrapped at some point, which is the
                  case but is is is is line width is not respected because of the indentation.
                  Two is a very long sentence that should be wrapped at some point, which is the
                  case but is is is is line width is not respected because of the indentation.
            \item
                  Another is a very long sentence that should be wrapped at some point, which is
                  the case but is is is is line width is not respected because of the indentation.
                  One is a very long sentence that should be wrapped at some point, which is the
                  case but is is is is line width is not respected because of the indentation.
                  Two is a very long sentence that should be wrapped at some point, which is the
                  case but is is is is line width is not respected because of the indentation.
            \item
                  Another is a very long sentence that should be wrapped at some point, which is
                  the case but is is is is line width is not respected because of the indentation.
                  \begin{itemize}
                      \item
                            One is a very long sentence that should be wrapped at some point, which
                            is the case but is is is is line width is not respected because of the
                            indentation.
                      \item
                            Two is a very long sentence that should be wrapped at some point, which
                            is the case but is is is is line width is not respected because of the
                            indentation.
                  \end{itemize}
            \item
                  Three is a very long sentence that should be wrapped at some point, which is the
                  case but is is is is line width is not respected because of the indentation.
        \end{itemize}
    \end{another}
    This is a very long sentence that should be wrapped at some point, which is the case but is is
    is is line width is not respected because of the indentation.
    One is a very long sentence that should be wrapped at some point, which is the case but is is
    is is line width is not respected because of the indentation.
    Two is a very long sentence that should be wrapped at some point, which is the case but is is
    is is line width is not respected because of the indentation.
    Three is a very long sentence that should be wrapped at some point, which is the case but is is
    is is line width is not respected because of the indentation.
\end{abstract}
----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|
   5   10   15   20   25   30   35   40   45   50   55   60   65   70   75   80   85   90   95   100   105   110

Note that columns have been respected :)

demonstration 2

Starting with

\begin{enumerate}
\item This is a very long sentence, which is mostly likely going to be longer than eighty characters---and it is.
\item This is a very long sentence, which is mostly likely going to be longer than eighty
characters---in fact, it is. But it's wrapped on one hundred characters, yes 100.
\end{enumerate}

and the settings

defaultIndent: "  "
modifyLineBreaks:
  textWrapOptions:
    columns: 80
    when: after    #<!------- NEW BIT

gives the output

\begin{enumerate}
  \item This is a very long sentence, which is mostly likely going to be longer
        than eighty characters---and it is.
  \item This is a very long sentence, which is mostly likely going to be longer
        than eighty characters---in fact, it is. But it's wrapped on one
        hundred characters, yes 100.
\end{enumerate}
----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|
   5   10   15   20   25   30   35   40   45   50   55   60   65   70   75   80   85   90

demonstration 3

From https://github.com/cmhughes/latexindent.pl/issues/306, starting with

\begin{document}
\begin{enumerate}[label=(\alph*)]
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit, cras imperdiet viv ris et molestie. Nulla molestie diam quam, ac molestie velit rhoncus placerat.
\begin{enumerate}[label=(\roman*)]
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit, cras imperdiet viv ris et molestie. Nulla molestie diam quam, ac molestie velit rhoncus placerat.
\end{enumerate}
\end{enumerate}
\end{document}

Using the settings

defaultIndent: '    '

modifyLineBreaks:
    textWrapOptions:
        columns: 100
        when: after                          # <!---- NEW BIT

gives the output

\begin{document}
\begin{enumerate}[label=(\alph*)]
    \item Lorem ipsum dolor sit amet, consectetur adipiscing elit, cras
          imperdiet viv ris et molestie. Nulla molestie diam quam, ac molestie
          velit rhoncus placerat.
          \begin{enumerate}[label=(\roman*)]
              \item Lorem ipsum dolor sit amet, consectetur adipiscing elit,
                    cras imperdiet viv ris et molestie. Nulla molestie diam
                    quam, ac molestie velit rhoncus placerat.
          \end{enumerate}
\end{enumerate}
\end{document}
----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|
   5   10   15   20   25   30   35   40   45   50   55   60   65   70   75   80   85   90   95   100   105   110

You'll notice that the text wrapping can now respect columns and indentation!

This will be part of the next release, coming soon in early 2023, hopefully :) Feel free to pull from develop if you're interested in testing :)

cmhughes avatar Dec 21 '22 20:12 cmhughes

This is part of V3.20 at https://github.com/cmhughes/latexindent.pl/releases/tag/V3.20. I've uploaded it to ctan. Many thanks!

cmhughes avatar Jan 01 '23 10:01 cmhughes