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

DBSFinishesWithLineBreak: 1 confused #402

Closed
tdegeus opened this issue Dec 27, 2022 · 12 comments
Closed

DBSFinishesWithLineBreak: 1 confused #402

tdegeus opened this issue Dec 27, 2022 · 12 comments
Labels
enhancement enhancement which might be to an existing feature or the development of a new feature feature-request user-centred feature request for an enhancement to an existing feature, or for a new feature implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix

Comments

@tdegeus
Copy link
Contributor

tdegeus commented Dec 27, 2022

original .tex code

This is some text. That needs formatting
\detail{
    \begin{equation}
        \begin{split}
            a = b \\
            c = d
        \end{split}
    \end{equation}
}
that ends here.

yaml settings

onlyOneBackUp: 1
defaultIndent: '    '
removeTrailingWhitespace: 1

lookForAlignDelims:
  align: 0

modifyLineBreaks:
  oneSentencePerLine:
    manipulateSentences: 1
    removeSentenceLineBreaks: 1
    textWrapSentences: 1
    multipleSpacesToSingle: 1
  items:
    ItemFinishesWithLineBreak: 1
  environments:
    BeginStartsOnOwnLine: 1
    BodyStartsOnOwnLine: 1
    EndStartsOnOwnLine: 1
    EndFinishesWithLineBreak: 1
    DBSFinishesWithLineBreak: 1
indentRules:
  item: '    '
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

This is some text.
That needs formatting \detail{
    \begin{equation}
        \begin{split}
            a = b \\ c = d
        \end{split}
    \end{equation}
} that ends here.

desired or expected output

This is some text.
That needs formatting
\detail{
    \begin{equation}
        \begin{split}
            a = b \\
            c = d
        \end{split}
    \end{equation}
}
that ends here.
@cmhughes
Copy link
Owner

Please use the issue template, then I'll look at it.

@tdegeus
Copy link
Contributor Author

tdegeus commented Dec 27, 2022

ok. edited.

@cmhughes
Copy link
Owner

Starting with

This is some text. That needs formatting
\detail{
    \begin{equation}
        \begin{split}
            a = b \\
            c = d
        \end{split}
    \end{equation}
}
that ends here.

and using

modifyLineBreaks:
  oneSentencePerLine:
    manipulateSentences: 1
  environments:
    BeginStartsOnOwnLine: 1
    BodyStartsOnOwnLine: 1
    EndStartsOnOwnLine: 1
    EndFinishesWithLineBreak: 1
    DBSFinishesWithLineBreak: 1
  commands:                        # <!--- NEW BIT
    detail:                        # <!--- NEW BIT
      CommandStartsOnOwnLine: 1    # <!--- NEW BIT
  mandatoryArguments:              # <!--- NEW BIT
    detail:                        # <!--- NEW BIT
      RCuBFinishesWithLineBreak: 1 # <!--- NEW BIT

gives

This is some text.
That needs formatting
\detail{
	\begin{equation}
		\begin{split}
			a = b \\ c = d
		\end{split}
	\end{equation}
}
that ends here.

@cmhughes cmhughes added question user-centred question about behaviour of latexindent.pl answered question has been answered one-sentence-per-line one sentence per line; documented at https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch labels Dec 27, 2022
@cmhughes
Copy link
Owner

Oh, and if you want the DBSFinishesWithLineBreak to activate, then you need to use

lookForAlignDelims:
  split: 1

Here's the complete YAML

lookForAlignDelims:
  split: 1

modifyLineBreaks:
  oneSentencePerLine:
    manipulateSentences: 1
  environments:
    BeginStartsOnOwnLine: 1
    BodyStartsOnOwnLine: 1
    EndStartsOnOwnLine: 1
    EndFinishesWithLineBreak: 1
    DBSFinishesWithLineBreak: 1
  commands:                        # <!--- NEW BIT
    detail:                        # <!--- NEW BIT
      CommandStartsOnOwnLine: 1    # <!--- NEW BIT
  mandatoryArguments:              # <!--- NEW BIT
    detail:                        # <!--- NEW BIT
      RCuBFinishesWithLineBreak: 1 # <!--- NEW BIT

then you receive

This is some text.
That needs formatting
\detail{
	\begin{equation}
		\begin{split}
			a = b \\
			c = d
		\end{split}
	\end{equation}
}
that ends here.

@tdegeus
Copy link
Contributor Author

tdegeus commented Dec 27, 2022

Thanks. However, it does not work for me:

onlyOneBackUp: 1
defaultIndent: '    '
removeTrailingWhitespace: 1

lookForAlignDelims:
  align: 0

modifyLineBreaks:
  oneSentencePerLine:
    manipulateSentences: 1
    removeSentenceLineBreaks: 1
    textWrapSentences: 1
    multipleSpacesToSingle: 1
  mandatoryArguments:
    footnote:
      MandArgBodyStartsOnOwnLine: 1
      RCuBFinishesWithLineBreak: 1
    detail:
      MandArgBodyStartsOnOwnLine: 1
      RCuBFinishesWithLineBreak: 1
  commands:
    label:
      CommandStartsOnOwnLine: 1
    detail:
      CommandStartsOnOwnLine: 1
  items:
    ItemFinishesWithLineBreak: 1
  environments:
    BeginStartsOnOwnLine: 1
    BodyStartsOnOwnLine: 1
    EndStartsOnOwnLine: 1
    EndFinishesWithLineBreak: 1
    DBSFinishesWithLineBreak: 1
indentRules:
  item: '    '
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

formats to

This is some text.
That needs formatting
\detail{
    \begin{equation}
        \begin{split}
            a = b \\ c = d
        \end{split}
    \end{equation}
}
that ends here.

@cmhughes
Copy link
Owner

You need this bit

lookForAlignDelims:
  split: 1

to give

This is some text.
That needs formatting
\detail{
    \begin{equation}
        \begin{split}
            a = b \\
            c = d
        \end{split}
    \end{equation}
}
that ends here.

@tdegeus
Copy link
Contributor Author

tdegeus commented Dec 28, 2022

I see, thanks. It is not exactly what I hoped to have, that is that

This is some text. That needs formatting
\detail{
    \begin{equation}
        \begin{split}
            a = b + c \\
            d = e \\
            f = g
        \end{split}
    \end{equation}
}
that ends here.

would not be formatted with

lookForAlignDelims:
  align: 0
  split: 0

modifyLineBreaks:
  environments:
    DBSFinishesWithLineBreak: 1

both split and equation are an environment, so I would expect the double backslash to be forced to have a line break. Instead, it is formatted to

This is some text.
That needs formatting
\begin{equation}
    \begin{split}
        a = b + c \\ d = e \\ f = g
    \end{split}
\end{equation}
that ends here.

which I would say to contradict the DBSFinishesWithLineBreak: 1.


What does work as expected (though not what I wanted), is that with

lookForAlignDelims:
  align: 1
  split: 1

modifyLineBreaks:
  environments:
    DBSFinishesWithLineBreak: 1

the text is formatted to:

This is some text.
That needs formatting
\detail{
    \begin{equation}
        \begin{split}
            a = b + c \\
            d = e     \\
            f = g
        \end{split}
    \end{equation}
}
that ends here.

@tdegeus
Copy link
Contributor Author

tdegeus commented Dec 28, 2022

Ok I got it:

lookForAlignDelims:
  align:
    delims: 1
    alignDoubleBackSlash: 0
  split:
    delims: 1
    alignDoubleBackSlash: 0

but I'm still a bit confused that DBSFinishesWithLineBreak did not do it.

@cmhughes
Copy link
Owner

Great, thanks.

I'm going to consider this a feature request: see if it's possible to enable DBS poly-switches can work without requiring lookForAlignDelims.

This came up in #393 from @ankitp94. I'd hope this won't take too long, but I'm currently working on text wrapping.

@cmhughes cmhughes added enhancement enhancement which might be to an existing feature or the development of a new feature feature-request user-centred feature request for an enhancement to an existing feature, or for a new feature and removed question user-centred question about behaviour of latexindent.pl answered question has been answered one-sentence-per-line one sentence per line; documented at https://latexindentpl.readthedocs.io/en/latest/sec-the-m-switch labels Dec 28, 2022
@cmhughes
Copy link
Owner

As of 3ef192c, this is implemented. Specifically, there is now no longer a need to specify a code block within lookForAlignDelims.

This will be part of the next release (early 2023), let's leave this open until then. Demonstrations below.

demonstration 1

starting with

This is some text. That needs formatting
\detail{
    \begin{equation}
        \begin{split}
            a = b \\
            c = d
        \end{split}
    \end{equation}
}
that ends here.

and using

defaultIndent: '    '

modifyLineBreaks:
  oneSentencePerLine:
    manipulateSentences: 1
    textWrapSentences: 1
  environments:
    BeginStartsOnOwnLine: 1
    BodyStartsOnOwnLine: 1
    EndStartsOnOwnLine: 1
    EndFinishesWithLineBreak: 1
    DBSFinishesWithLineBreak: 1

gives

This is some text.
That needs formatting \detail{
    \begin{equation}
        \begin{split}
            a = b \\
            c = d
        \end{split}
    \end{equation}
} that ends here.

demonstration 2

starting with

This is some text.
That needs formatting
\[
        a = b + c \\ d = e \\ f = g
\]
that ends here.

and using

defaultIndent: '    '

modifyLineBreaks:
  oneSentencePerLine:
    manipulateSentences: 1
    textWrapSentences: 1
  specialBeginEnd:
    DBSFinishesWithLineBreak: 2
    SpecialBeginStartsOnOwnLine: 1
    SpecialBodyStartsOnOwnLine: 1
    SpecialEndStartsOnOwnLine: 1
    SpecialEndFinishesWithLineBreak: 1

gives

This is some text.
That needs formatting
\[
    a = b + c \\%
    d = e \\%
    f = g
\]
that ends here.

demonstration 3

starting with

This is some text.
That needs formatting
\cmh{
        a = b + c \\ d = e \\ f = g
      }
that ends here.

and using

defaultIndent: '    '

modifyLineBreaks:
  oneSentencePerLine:
    manipulateSentences: 1
    textWrapSentences: 1
  mandatoryArguments:                     
      MandArgBodyStartsOnOwnLine: 1
      RCuBStartsOnOwnLine: 1
      RCuBFinishesWithLineBreak: 1
      DBSFinishesWithLineBreak: 2

gives

This is some text.
That needs formatting \cmh{
    a = b + c \\%
    d = e \\%
    f = g
}
that ends here.

@cmhughes cmhughes added the implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix label Dec 30, 2022
@tdegeus
Copy link
Contributor Author

tdegeus commented Dec 31, 2022

That's amazing, and makes a lot of sense. Thanks a lot!

@cmhughes
Copy link
Owner

cmhughes commented Jan 1, 2023

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 cmhughes closed this as completed Jan 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement enhancement which might be to an existing feature or the development of a new feature feature-request user-centred feature request for an enhancement to an existing feature, or for a new feature implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix
Projects
None yet
Development

No branches or pull requests

2 participants