latex-lsp / texlab

An implementation of the Language Server Protocol for LaTeX
GNU General Public License v3.0
1.51k stars 52 forks source link

Question: Work on texlab latex formatter #497

Open ModProg opened 2 years ago

ModProg commented 2 years ago

This is more a question than an issue, but discussions aren't enabled in this repository.

In the options documentation, it says that the texlab formatter for latex is not yet implemented.

Are there any concrete plans on doing so?

pfoerster commented 2 years ago

In the options documentation, it says that the texlab formatter for latex is not yet implemented.

That's correct. At the moment, texlab uses latexindent under the hood. However, I am bit unhappy with the fact that latexindent is very slow and is awkward to configure. Ideally, we would have our own formatter but it is a lot of effort to create a fast (and reliable) formatter. Besides that, we need some changes in the parser (for example we treat "&" as ordinary text in the parser).

Are there any concrete plans on doing so?

Not at the moment. In the meantime, I would be very happy to include a contributed formatter (either here in this repository or as a separate tool/library).

but discussions aren't enabled in this repository.

They should be enabled now 👍 .

ModProg commented 2 years ago

Makes sense, I just didn't find anything on this. Thanks for the answer.

alxiong commented 2 years ago

Upvote for releasing a fast latex & bibtex formatter as a separate executable.

(Ideally I'd like to configure my emacs/lsp to use this formatter by default, and use pre-commit hooks to enforce formatting on other developers' machine where they don't use emacs)

clason commented 2 years ago

But if it's an external tool (of which there already are several, like https://github.com/nschloe/blacktex), why should it be shoehorned into an independent LSP server instead of going through standard editor hooks for formatting (like Vim's 'formatprg', which I'm sure Emacs has an analogue of)?

use pre-commit hooks to enforce formatting on other developers' machine where they don't use emacs

And, if I may say so, that would be the quickest method of getting me to stop collaborating with you on a paper ;) If you have that restrictive ideas about writing LaTeX, you get to write all of it by yourself...

alxiong commented 2 years ago

thanks for the suggestion @clason, I'm quite a noob when it comes to Tex tooling,

may I ask what's the benefit of an independent formatter in latex-lsp over hooking up with an existing external formatter?

if you have that restrictive ideas about writing LaTeX, you get to write all of it by yourself...

haha, good to know the objection, in my mind, the formatting rules can be agreeable among all authors right? it's more about being consistent than being autocratic on style, would you agree? (I guess I won't complain about a project with pyproject.toml or .prettierjs.json or rustfmt.toml, if anything I'd hope they explicitly states their idiosyncrasies and enforce them automatically)

clason commented 2 years ago

may I ask what's the benefit of an independent formatter in latex-lsp over hooking up with an existing external formatter?

There is none -- an external formatter should be independent, hooking it up with a language server is just extra work and complexity for no gain.

clason commented 2 years ago

in my mind, the formatting rules can be agreeable among all authors right

Oh, you sweet summer child...

it's more about being consistent than being autocratic on style, would you agree?

In the end, people will only care about the compiled PDF -- and if it's for publication, the publisher will take the TeX files and put them through their own thresher, anyway. I'd concentrate on the contents rather than the code style...

ModProg commented 2 years ago

In the end, people will only care about the compiled PDF -- and if it's for publication, the publisher will take the TeX files and put them through their own thresher, anyway. I'd concentrate on the contents rather than the code style...

You could say that about any code formatting, still many people use formatters to help them write more readable code. And depending on your workflow it could also help with e.g. merging changes.

There is none -- an external formatter should be independent, hooking it up with a language server is just extra work and complexity for no gain.

Well depending on how you use them and what editor you use, it might help if the LSP knows how to use the formatter, but I think it does make sense to implement it separately and just use it as a library in here and make it available stand alone as well.

clason commented 2 years ago

You could say that about any code formatting, still many people use formatters to help them write more readable code. And depending on your workflow it could also help with e.g. merging changes.

The difference is that a codebase needs to be maintained long-term, while a paper or book is hopefully done at some point.

Well depending on how you use them and what editor you use, it might help if the LSP knows how to use the formatter, but I think it does make sense to implement it separately and just use it as a library in here and make it available stand alone as well.

I don't see how the LSP should know how to use the formatter if it's external -- it's just passing the command through, so you might as well bypass the middleman. It's different if the internal tooling of the server generates an intermediate representation that can be leveraged for code formatting, but that doesn't sound like it's the case here.