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
867 stars 84 forks source link

defaultSettings and schema #485

Closed arkandias closed 11 months ago

arkandias commented 11 months ago

The file defaultSettings.yaml was an invalid YAML because of unexpected alias/scalars. This is easily fixed by adding single quotes (double in one case). Also, the indentation was inconsistent (sometimes 4, 2 or 3 spaces), so I just used Prettier to format it (actually I had to realign the comments afterwards). Finally I completed latexindent-yaml-schema.json file with several missing fields.

cmhughes commented 11 months ago

Thanks for this.

The indentation changes look fine.

I'm not sure why the quotes are needed....?

arkandias commented 11 months ago

Hi, I am no expert in YAML. The formatter (Prettier in my case -- but I also tried with Red Hat's YAML plugin in VS Code) throw the following errors when trying to save the file defaultSettings.yaml (I also tried a YAML validator online, which returned exactly the same errors).

The following field yields an "Unexpected alias at node end"

specialBeginEnd:
  inlineMath:
    body: [^$]*?

while the four ones below yield an "Unexpected scalar at node end"

fineTuning:
    environments:
      name: [a-zA-Z@\*0-9_\\]+
    commands:
      name: [+a-zA-Z@\*0-9_\:]+?
    keyEqualsValuesBracesBrackets:
      name: [a-zA-Z@\*0-9_\/.:\#-]+[a-zA-Z@\*0-9_\/.\h\{\}:\#-]*?
    namedGroupingBracesBrackets:
      name: [0-9\.a-zA-Z@\*><]+?

The first one can be escaped with double quotes, but the others need single quotes (because of the escaped characters \*, \\, etc.).

By the way, fields like

replacements:
  -
    amalgamate: 1
  -
    this: latexindent.pl
    that: pl.latexindent
    lookForThis: 0
    when: before

can be rewritten

replacements:
  - amalgamate: 1
  - this: latexindent.pl
    that: pl.latexindent
    lookForThis: 0
    when: before

(actually this is handled by any formatter I tried).

cmhughes commented 11 months ago

OK, many thanks.

In which case, can you remove the extra quotes from defaultSettings and keep it only to formatting changes?

On Fri, 6 Oct 2023, 08:32 Julien Hauseux, @.***> wrote:

Hi, I am no expert in YAML. The formatter (Prettier in my case -- but I also tried with Red Hat's YAML plugin in VS Code) throw the following errors when trying to save the file defaultSettings.yaml (I also tried a YAML validator online, which returned exactly the same errors).

The following field yields an "Unexpected alias at node end"

specialBeginEnd: inlineMath: body: [^$]*?

while the four ones below yield an "Unexpected scalar at node end"

fineTuning: environments: name: [a-zA-Z@*0-9\]+ commands: name: [+a-zA-Z@*0-9\:]+? keyEqualsValuesBracesBrackets: name: [a-zA-Z@*0-9\/.:#-]+[a-zA-Z@*0-9\/.\h{}:#-]? namedGroupingBracesBrackets: name: [0-9.a-zA-Z@\><]+?

The first one can be escaped with double quotes, but the others need single quotes (because of the escaped characters *, \, etc.).

By the way, fields like

replacements:

amalgamate: 1

- this: latexindent.pl that: pl.latexindent lookForThis: 0 when: before

can be rewritten

replacements:

  • amalgamate: 1
  • this: latexindent.pl that: pl.latexindent lookForThis: 0 when: before

(actually this is handled by any formatter I tried).

— Reply to this email directly, view it on GitHub https://github.com/cmhughes/latexindent.pl/pull/485#issuecomment-1750118265, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYH6YOTDNA54CZ3UFIDX56XXFAVCNFSM6AAAAAA5UQOMQ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJQGEYTQMRWGU . You are receiving this because you commented.Message ID: @.***>

arkandias commented 11 months ago

Done!

cmhughes commented 11 months ago

Great, thanks so much!