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

latexindent.exe win32 #326

Closed
ostaith opened this issue Jan 16, 2022 · 8 comments
Closed

latexindent.exe win32 #326

ostaith opened this issue Jan 16, 2022 · 8 comments
Labels
feature-request user-centred feature request for an enhancement to an existing feature, or for a new feature Help-wanted I'd like assistance with this issue, please!

Comments

@ostaith
Copy link

ostaith commented Jan 16, 2022

Hi cmhughes,
Thanks for your nice indent tool. Can I expect some new features?

  1. can you build 32bit latexindent.exe still?

  2. for latex3 code, can set such as 'add extra space' to each token to separate them.

code1:

\cs_new_protected_nopar:Npn\maoxuan_hyper_link:nn
  {\hyper@link{link }}

indent to:

\cs_new_protected_nopar:Npn \maoxuan_hyper_link:nn
  { \hyper@link { link } }

explain:

\cs_new_protected_nopar:Npn \maoxuan_hyper_link:nn
                           ^
  { \hyper@link { link } }
   ^           ^ ^    ^ ^
^ means extra space
  1. code will alignment with '=' (it's better can be set, eg, '-') in code block:

code2:

\geometry
  {
    papersize  = { 130mm , 184mm } ,
    lines  = 25 ,
    hmargin = 15mm ,
    bindingoffset = 5mm ,
    headheight = 10pt ,
    headsep = \baselineskip ,
    includehead = true ,
    vcentering = true
  }

indent to:

\geometry
  {
    papersize     = { 130mm , 184mm } ,
    lines         = 25 ,
    hmargin       = 15mm ,
    bindingoffset = 5mm ,
    headheight    = 10pt ,
    headsep       = \baselineskip ,
    includehead   = true ,
    vcentering    = true
  }

code3:

\geometry
  \mybegin %%%%%%%% <-- can be customized begin and end
    papersize  = { 130mm , 184mm } ,
    lines  = 25 ,
    hmargin = 15mm ,
    bindingoffset = 5mm ,
    headheight = 10pt ,
    headsep = \baselineskip ,
    includehead = true ,
    vcentering = true
  \myend %%%%%%%% <-- can be customized begin and end

indent to:

\geometry
  \mybegin 
    papersize     = { 130mm , 184mm } ,
    lines         = 25 ,
    hmargin       = 15mm ,
    bindingoffset = 5mm ,
    headheight    = 10pt ,
    headsep       = \baselineskip ,
    includehead   = true ,
    vcentering    = true
  \myend

code4:

\dim_set:Nn \l_maoxuan_headsep_dim
  {
    \headsep - \box_ht:N \l_maoxuan_main_head_rule_box
    - \box_dp:N \l_maoxuan_main_head_rule_box %%%%%%%% <-- this line need extra indent
  }

indent to:

\dim_set:Nn \l_maoxuan_headsep_dim
  {
    \headsep - \box_ht:N \l_maoxuan_main_head_rule_box
             - \box_dp:N \l_maoxuan_main_head_rule_box %%%%%%%% <-- expected output
  }

code5:

\xeCJKsetup
  {
    AllowBreakBetweenPuncts = true ,
    CheckSingle             = true ,
    AutoFakeBold            = false ,
    AutoFakeSlant           = false ,
    CheckFullRight          = true ,
    NewLineCS+              = \mxendarticle \item \mnitem
    \maoxuan_endline_mark: , %%%%%%%% <-- this line need extra indent
    NoBreakCS+              = \mnote ,
    PunctStyle              = kaiming ,
    KaiMingPunct+           = :; ,
  }

indent to:

\xeCJKsetup
  {
    AllowBreakBetweenPuncts = true ,
    CheckSingle             = true ,
    AutoFakeBold            = false ,
    AutoFakeSlant           = false ,
    CheckFullRight          = true ,
    NewLineCS+              = \mxendarticle \item \mnitem
                              \maoxuan_endline_mark: , %%%%%%%% <-- expected output
    NoBreakCS+              = \mnote ,
    PunctStyle              = kaiming ,
    KaiMingPunct+           = :; ,
  }
@cmhughes
Copy link
Owner

Hello,
Thanks for this.

can you build 32bit latexindent.exe still?

Yes, it's available from the https://github.com/cmhughes/latexindent.pl/releases/tag/V3.14 page

code 1

replacements:
  -
    # change {\\... into { \\...
    substitution: |-
      s/\{\h*(\\|[a-z]|[A-Z])/\{ $1/sgx
    when: after
  -
    # change <letter>} into <letter> }
    substitution: |-
      s/([a-z]|[A-Z])\h*\}/$1 \}/sgx
    when: after
  -
    # change <letter>{ into <letter> {
    substitution: |-
      s/([a-z]|[A-Z])\h*\{/$1 \{/sgx
    when: after

indentRules:
  maoxuan_hyper_link:nn:
    body: '  '

called with latexindent.pl -r -l myfile.yaml myfile.tex gives

\cs_new_protected_nopar:Npn\maoxuan_hyper_link:nn
  { \hyper@link { link }}

code 2

lookForAlignDelims:
   geometry: 
      delimiterRegEx: '(=)'

specialBeginEnd:
    papersize:
        begin: '\{\h*[0-9]+'
        end: 'mm\h*\}'
    specialBeforeCommand: 1

indentRules:
  geometry:
    body: '  '

gives

\geometry
  {
	  papersize     = { 130mm , 184mm } ,
	  lines         = 25 ,
	  hmargin       = 15mm ,
	  bindingoffset = 5mm ,
	  headheight    = 10pt ,
	  headsep       = \baselineskip ,
	  includehead   = true ,
	  vcentering    = true
  }

code 3

lookForAlignDelims:
   mybegin: 
      delimiterRegEx: '(=)'

specialBeginEnd:
    mybegin:
        begin: '\\mybegin'
        end: '\\myend'

gives

\geometry
\mybegin %%%%%%%% <-- can be customized begin and end
	papersize     = { 130mm , 184mm } ,
	lines         = 25 ,
	hmargin       = 15mm ,
	bindingoffset = 5mm ,
	headheight    = 10pt ,
	headsep       = \baselineskip ,
	includehead   = true ,
	vcentering    = true
\myend %%%%%%%% <-- can be customized begin and end

code 4

lookForAlignDelims:
   l_maoxuan_headsep_dim: 
      delimiterRegEx: '(-)'

gives

\dim_set:Nn \l_maoxuan_headsep_dim
{
	\headsep - \box_ht:N \l_maoxuan_main_head_rule_box
	         - \box_dp:N \l_maoxuan_main_head_rule_box %%%%%%%% <-- this line need extra indent
}

code 5

lookForAlignDelims:
   xeCJKsetup: 
      delimiterRegEx: '(=)'

indentRules:
  xeCJKsetup:
    body: '  '

gives

\xeCJKsetup
  {
	  AllowBreakBetweenPuncts = true ,
	  CheckSingle             = true ,
	  AutoFakeBold            = false ,
	  AutoFakeSlant           = false ,
	  CheckFullRight          = true ,
	  NewLineCS+              = \mxendarticle \item \mnitem
	  \maoxuan_endline_mark: , %%%%%%%% <-- this line need extra indent
	  NoBreakCS+              = \mnote ,
	  PunctStyle              = kaiming ,
	  KaiMingPunct+           = :; ,
  }

I don't like the following, it's quite a hack, but

lookForAlignDelims:
   xeCJKsetup: 
      delimiterRegEx: '(=)'

indentRules:
  xeCJKsetup:
    body: '  '
  mxendarticle: '                          '

specialBeginEnd:
    mxendarticle:
        begin: '\\mxendarticle'
        end: ','

gives

\xeCJKsetup
  {
	  AllowBreakBetweenPuncts = true ,
	  CheckSingle             = true ,
	  AutoFakeBold            = false ,
	  AutoFakeSlant           = false ,
	  CheckFullRight          = true ,
	  NewLineCS+              = \mxendarticle \item \mnitem
	                            \maoxuan_endline_mark: , %%%%%%%% <-- this line need extra indent
	  NoBreakCS+              = \mnote ,
	  PunctStyle              = kaiming ,
	  KaiMingPunct+           = :; ,
  }

@cmhughes cmhughes added answered question has been answered question user-centred question about behaviour of latexindent.pl labels Jan 16, 2022
cmhughes added a commit that referenced this issue Jan 16, 2022
@ostaith
Copy link
Author

ostaith commented Jan 17, 2022

Hi cmhughes,

Thanks for your quick reply.

  1. I check this https://github.com/cmhughes/latexindent.pl/releases/tag/V3.14 link, but both standalone latexindent.exe and latexindent.exe in latexindent.zip are 64bit.

  2. update, for rule for latex3 code, can set such as 'add extra space' to each token to separate them., I expect latexindent can add extra space if two tokens are not separate, and delete redundant spaces if they have too many spaces:

    case 1: \token_one\token_two     --> \token_one \token_two % no space
    case 2: \token_one    \token_two --> \token_one \token_two % too many spaces
    
  3. I found you already give some yaml rules, but these rules are specific. I expect some general rules, then I don't need for different code blocks add different rules.

@ostaith
Copy link
Author

ostaith commented Jan 17, 2022

  1. OK, I almost understand your lookForAlignDelims rule. Before I thought it can only used in tabular environment. I'll learn the section of Aligning at delimiters in latexindex.pdf again.

  2. for the 'space separate' rule, I also try to understand solution firstly. but what's latexindent regex syntax? can u give the link in your documentation? for example your rule s/\{\h*(\\|[a-z]|[A-Z])/\{ $1/sgx, what s/, \h, /sgx mean?

  3. for standalone latexindent.exe in windows, seems the -l option is invalid. even I use -l localSettings.yaml, it still use the defaultSettings.yaml:

    latexindent -s -l localSettings.yaml -w maoxuan.cls
    FATAL Could not open defaultSettings.yaml
    

@cmhughes
Copy link
Owner

Thanks for this.

I check this https://github.com/cmhughes/latexindent.pl/releases/tag/V3.14 link, but both standalone latexindent.exe and latexindent.exe in latexindent.zip are 64bit.

latexindent.exe is produced by github actions. If you have a way for it to produce a 32bit version, let me know.

case 1: \token_one\token_two --> \token_one \token_two % no space
case 2: \token_one \token_two --> \token_one \token_two % too many spaces

We can adapt the code I provided above

replacements:
  -
    substitution: |-
      s/([a-z]|[A-Z])\h*\\/$1 \\/sgx
    when: after

This means that a letter followed 0 or more spaces, followed by a \ will be replaced by the letter, one space, and the backslash.

I found you already give some yaml rules, but these rules are specific. I expect some general rules, then I don't need for different code blocks add different rules.

There are no general rules for this. You should be able to adapt the code I provided on a per-case basis.

for the 'space separate' rule, I also try to understand solution firstly. but what's latexindent regex syntax? can u give the link in your documentation? for example your rule s/{\h*(\|[a-z]|[A-Z])/{ $1/sgx, what s/, \h, /sgx mean?

The regex syntax is standard, it's not particular to latexindent. The s/ means 'substitute', the \h means horizontal space, and the sgx are modifiers. You can read more about this at https://perldoc.perl.org/perlre, for example.

for standalone latexindent.exe in windows, seems the -l option is invalid. even I use -l localSettings.yaml, it still use the defaultSettings.yaml:

I tested this on a Windows laptop, and was not able to reproduce this error.

@ostaith
Copy link
Author

ostaith commented Jan 18, 2022

latexindent.exe is produced by github actions. If you have a way for it to produce a 32bit version, let me know.

I check your actions, your perl environment is 64bit, and the action's author said he have no plan to support x86-32 in issue 615. maybe we should find a way to install 32bit perl environment.

I test in my PC:

  1. I download strawberry-perl-5.32.1.1-32bit.zip, and install in my PC
  2. then I follow your actions,
cpanm -f PAR::Packer
cpanm YAML::Tiny
cpanm File::HomeDir
cpanm Unicode::GCString
copy helper-scripts/ppp.pl ./
perl ppp.pl -o latexindent.exe latexindent.pl

I build 32bit latexindent.exe successfully.
So I think we can research, how can we install both 32bit and 64bit strawberry perl in your project directly. and i see ya4ept give some comments in issue 615, maybe you can try.

And I google another way to install strawberry perl on windows, maybe you can also check.
for 32bit strawberry perl, looks like use choco install strawberryperl --x86 command; if you need specific version, use choco install strawberryperl --version=5.32.1.1; and set install dir, use choco install strawberryperl --install-arguments="INSTALLDIR=""C:\tools\Strawberry""". But sorry I'm not familiar with github, so I don't know how to test them.

I tested this on a Windows laptop, and was not able to reproduce this error.

I find the problem: I download latexindent.zip and extract to D:\latexindent, and run latexindent.exe with -l switch, latexindent.exe only look for the localSettings.yaml from .tex file path, but I put my localSettings.yaml in latexindent.exe path, so it failed.
So I think it's better search -l yaml file or defaultSettings.yaml in 3 paths:

  1. latexindent.exe file path
  2. latexindent.pl file path (maybe someone run perl latexindent.pl directly)
  3. .tex file path

And I think your logic is not best:
in GetYamlSettings.pm you read the default settings whatever option I use. but I think,

  1. if I use -l without -d, I think no need check defaultSettings.yaml, that's why I got the error FATAL Could not open defaultSettings.yaml, because I use -l and change the defaultSettings.yaml to localSettings.yaml, so latexindent can't find defaultSettings.yaml then exit.
  2. if I use -l with -d, or I don't use -l, yes, now need read defaultSettings.yaml.

@cmhughes
Copy link
Owner

defaultSettings.yaml is always needed.

The -l switch instructs latexindent.pl to look for a local settings file. You can see the schematic in https://latexindentpl.readthedocs.io/en/latest/sec-indent-config-and-settings.html

I'm open to trying to get a 32-bit version of latexindent.exe.

@cmhughes
Copy link
Owner

@cmhughes cmhughes changed the title expect some features latexindent.exe win32 Feb 12, 2022
@cmhughes cmhughes added 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 labels Feb 13, 2022
@cmhughes cmhughes added the Help-wanted I'd like assistance with this issue, please! label Mar 2, 2022
@cmhughes
Copy link
Owner

I'm sorry, I don't know how to progress this. I'm closing it for the moment, if you can progress it, pull requests to develop, please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request user-centred feature request for an enhancement to an existing feature, or for a new feature Help-wanted I'd like assistance with this issue, please!
Projects
None yet
Development

No branches or pull requests

2 participants