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

Output of latexindent isn't stable (specialBeginEnd) #477

Closed
arodomanov opened this issue Sep 19, 2023 · 6 comments
Closed

Output of latexindent isn't stable (specialBeginEnd) #477

arodomanov opened this issue Sep 19, 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 specialBeginEnd

Comments

@arodomanov
Copy link

Hi,

I'm trying to make latexindent automatically indent the text inside any (round) parentheses (in other words, to treat ( and ) as the beginning and end, respectively, of a certain environment).

To achieve this, I've tried to declare a specialBeginEnd block (see the latexindent.yaml file below).

At first, this seemed to work fine and produced the result I wanted. However, I then noticed that the result isn't stable. Specifically, the output changes if you run latexindent again (one or several times) without changing anything. In particular, I managed to obtain two different outputs after running latexindent several times on the same file with the same settings and by using the same command (see below).

From my limited understanding (after inspecting the log file), it looks as if the problem is that each run of latexindent joins the settings from specialBeginEnd in an arbitrary order which results in different internal regular expressions.

Please confirm if it's a bug, or if I'm misusing the specialBeginEnd feature.

Original .tex code (source.tex)

$
  a
  +
  (
    b + c
  )
  =
  d
$
and
$
  e + f = g
$

yaml settings (latexindent.yaml)

defaultIndent: "  "

specialBeginEnd:
  specialBeforeCommand: 1

  parentheses:
    begin: \(
    end: \)
    lookForThis: 1

The command used to run latexindent

latexindent -l latexindent.yaml -o=+-mod.tex source.tex

Actual output 1 [good] (source-mod.tex)

$
  a
  +
  (
    b + c
  )
  =
  d
$
and
$
  e + f = g
$

Actual output 2 [bad] (source-mod.tex)

$
  a
  +
  (
    b + c
  )
  =
  d
  $
    and
  $
  e + f = g
$

Desired or expected output

The desired output is output 1 [good] presented above.

Version of latexindent

3.23.1, 2023-09-13
@cmhughes cmhughes added the bug unexpected behaviour; should be a priority for fixing label Sep 19, 2023
@cmhughes
Copy link
Owner

Many thanks, that's a helpful example.

Certainly not expected behaviour, and definitely a bug. I'll look into it.

@cmhughes cmhughes changed the title Output of latexindent isn't stable Output of latexindent isn't stable (specialBeginEnd) Sep 19, 2023
@cmhughes
Copy link
Owner

Note to self, maybe try removing the g switch from the find and replace in

https://github.com/cmhughes/latexindent.pl/blob/main/LatexIndent/Special.pm

@cmhughes
Copy link
Owner

Note to self, maybe try removing the g switch from the find and replace in

https://github.com/cmhughes/latexindent.pl/blob/main/LatexIndent/Special.pm

This didn't work

cmhughes added a commit that referenced this issue Sep 23, 2023
@cmhughes cmhughes added the implemented implemented tag means that either an enhancement or feature request has been implemented, or bugfix label Sep 23, 2023
@cmhughes
Copy link
Owner

Implemented and released at https://github.com/cmhughes/latexindent.pl/releases/tag/V3.23.2

thanks again!

@arodomanov
Copy link
Author

Thanks a lot for such a quick fix!

@cmhughes
Copy link
Owner

cmhughes commented Sep 25, 2023 via email

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 specialBeginEnd
Projects
None yet
Development

No branches or pull requests

2 participants