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

bugfix for Incorrect encoding #548

Closed fengzyf closed 2 months ago

fengzyf commented 2 months ago

what is this pull request about?

fix for Incorrect encoding (possiblely due to #505)

does this relate to an existing issue?

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

does this change any existing behaviour?

yes

what does this add?

Use Windows:: GetACP() to obtain the code page of the Windows system, and then obtain the system default encoding. Users do not need to specify the encoding.

qiancy98 commented 2 months ago

感谢,看起来很优雅(至少比我原来写的优雅hhh)

cmhughes commented 2 months ago

I'm sorry, I don't speak this language

On Sun, 9 Jun 2024, 11:41 qiancy98, @.***> wrote:

感谢,看起来很优雅(至少比我原来写的优雅hhh)

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

qiancy98 commented 2 months ago

I'm sorry, I don't speak this language On Sun, 9 Jun 2024, 11:41 qiancy98, @.> wrote: 感谢,看起来很优雅(至少比我原来写的优雅hhh) — Reply to this email directly, view it on GitHub <#548 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYA7BP5P2MJ73SQFNGDZGQWO7AVCNFSM6AAAAABJAW3JFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJWGQZTOMJYGM . You are receiving this because you are subscribed to this thread.Message ID: @.>

That reads

Thanks for your coding. This looks elegent. (at least more elegent than what I typed.)

This is just a thanks.

cmhughes commented 2 months ago

Thank you so much, and I'm sorry for not knowing your native language.

On Sun, 9 Jun 2024, 14:22 qiancy98, @.***> wrote:

I'm sorry, I don't speak this language … <#m-1726361654267661857> On Sun, 9 Jun 2024, 11:41 qiancy98, @.> wrote: 感谢,看起来很优雅(至少比我原来写的优雅hhh) — Reply to this email directly, view it on GitHub <#548 (comment) https://github.com/cmhughes/latexindent.pl/pull/548#issuecomment-2156437183>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7CYA7BP5P2MJ73SQFNGDZGQWO7AVCNFSM6AAAAABJAW3JFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJWGQZTOMJYGM https://github.com/notifications/unsubscribe-auth/AAQ7CYA7BP5P2MJ73SQFNGDZGQWO7AVCNFSM6AAAAABJAW3JFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJWGQZTOMJYGM . You are receiving this because you are subscribed to this thread.Message ID: @.>

That reads

Thanks for your coding. This looks elegent. (at least more elegent than what I typed.) This is just a thanks.

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

cmhughes commented 2 months ago

Thanks for you help with this.

Does this mean that https://latexindentpl.readthedocs.io/en/latest/sec-appendices.html#encoding-indentconfig-yaml should be removed? and all references to encoding should be removed?

fengzyf commented 2 months ago

Does this mean that https://latexindentpl.readthedocs.io/en/latest/sec-appendices.html#encoding-indentconfig-yaml should be removed? and all references to encoding should be removed?

Certainly, they need to be removed.

Perhaps new explanations about encoding can be added to inform users:

  1. For the Windows executable file latexindent.exe, its options support UTF-8 characters.
  2. For the Windows Perl script latexindent.pl, its options support characters encoded according to the system code page. You can check the system code page by using chcp in the command prompt, and refer to the supported characters at Microsoft's code page identifier table.
  3. For Ubuntu Linux and macOS users, whether using the Perl script or the executable file, the options support UTF-8 characters.
  4. When reading and writing files, the files are read and written in UTF-8 format by default. That is to say, the encoding format for tex and yaml files needs to be in UTF-8 format.
cmhughes commented 2 months ago

Many thanks. Would like to update the documentation to reflect the this?

On Tue, 11 Jun 2024, 10:00 fengzyf, @.***> wrote:

Does this mean that https://latexindentpl.readthedocs.io/en/latest/sec-appendices.html#encoding-indentconfig-yaml should be removed? and all references to encoding should be removed?

Certainly, they need to be removed.

Perhaps new explanations about encoding can be added to inform users:

  1. For the Windows executable file latexindent.exe, its options support UTF-8 characters.
  2. For the Windows Perl script latexindent.pl, its options support characters encoded according to the system code page. You can check the system code page by using chcp in the command prompt, and refer to the supported characters at Microsoft's code page identifier table https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers .
  3. For Ubuntu Linux and macOS users, whether using the Perl script or the executable file, the options support UTF-8 characters.
  4. When reading and writing files, the files are read and written in UTF-8 format by default. That is to say, the encoding format for tex and yaml files needs to be in UTF-8 format.

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

cmhughes commented 2 months ago

The file is documentation/sec-appendices.tex

fengzyf commented 2 months ago

I have updated the document, but I am not very proficient in English. Therefore, I hope you can help me check it and make any necessary modifications.

cmhughes commented 2 months ago

Something isn't right with this... can you look at the output at https://github.com/cmhughes/latexindent.pl/actions/runs/9468805527/job/26086016558?pr=548 ?

cmhughes commented 2 months ago

Thanks.

This still isn't working https://github.com/cmhughes/latexindent.pl/actions/runs/9488246197/job/26149866332?pr=548

(I appreciate I need to make it more obvious that the checks fail)

fengzyf commented 2 months ago

https://github.com/cmhughes/latexindent.pl/actions/runs/9502252857/job/26189794904

This new commit still triggers an error: Error: Attempt to call undefined import method with arguments ("$ifElseFiBasicRegExp") via package "LatexIndent::IfElseFi" (Perhaps you forgot to load the package?) at /usr/local/bin/LatexIndent/Special.pm line 25.

According to my Google search results, it may have appeared after Perl was updated to 5.39.9. see https://perldoc.perl.org/5.39.9/perl5391delta.

New Errors Attempt to call undefined %s method with arguments via package "%s" (perhaps you forgot to load the package?) (F) You called the import() or unimport() method of a class that has no import method defined in its inheritance graph, and passed an argument to the method. This is very often the sign of a misspelled package name in a use or require statement that has silently succeeded due to a case-insensitive file system. Another common reason this may happen is when mistakenly attempting to import or unimport a symbol from a class definition or package which does not use Exporter or otherwise define its own import or unimport method.

I don't know how to fix it. However, if you change the Perl version from 'latest' to 5.38 in the 'test-cases-on-pull.yaml', this error message will not appear.

cmhughes commented 2 months ago

Many thanks, that's helpful.

I've fixed this as of https://github.com/cmhughes/latexindent.pl/commit/339d3962e29a6941cbf3059998328db4dad52ed3

Can you re-base your branch and push another commit?

cmhughes commented 2 months ago

Thanks so much for your work on this! I really appreciate it.