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

[FR] automatically insert single space before and after single line comment % #58

Open
j-lakeman opened this issue Dec 2, 2024 · 5 comments

Comments

@j-lakeman
Copy link

First of all: awesome project, love it!

One more thing though: It'd be handy if single spaces before and after line comment % could be automatically inserted to increase readability and to be consistent to other programming languages.

I'd expect this:

latex%comment

to be formatted to that:

latex % comment

Would be nice if this could be implemented. Keep up the good work! 😉

@j-lakeman j-lakeman changed the title FR: automatically insert single space before and after single line comment % [FR] automatically insert single space before and after single line comment % Dec 2, 2024
@WGUNDERWOOD
Copy link
Owner

WGUNDERWOOD commented Dec 2, 2024

Thanks for the suggestion! We need to be a little careful with this as the first block below renders with a space between "latex" and "next", while the second block does not.

latex % comment
next line
latex%comment
next line

Perhaps we could format the first block to the following, which should not change the output.

latex% comment
next line

This trick of using a comment to elide a space on a line break is very common so we should definitely preserve this behavior.

@j-lakeman
Copy link
Author

I don’t understand what you mean sorry. Which space between "latex" and "next"?

@WGUNDERWOOD
Copy link
Owner

I mean when it is compiled to a PDF with pdflatex.

@j-lakeman
Copy link
Author

Oh that's right! Thx for clarifying!
Yeah I agree. It could be formatted to what you suggested.
That should also apply to lines starting with % then IMHO.

@WGUNDERWOOD
Copy link
Owner

I've put some more thought into this and it seems that there are some other cases where this is undesirable. Many people use "blocks" of comment symbols to navigate their source files more easily:

%%%%%%%%%%%%%%
%% SECTION ONE
%%%%%%%%%%%%%%

Sometimes people "block comment" a section which already contains comments. It is then convenient to be able to reverse this operation by deleting the first character in each line:

%This section has been commented out as a block.
%%This line was already commented out.
%Here is the end of this section.

It may also be the case that certain editor configuration statements depend on whitespace inside comments; I want to avoid risking breaking these:

%!TEX root = main.tex

Perhaps we can try to avoid these cases, but more thought is probably required!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants