Closed peske closed 10 months ago
Thanks for this, it's an interesting situation :)
I'm not familiar ChkTeX
but it sounds like it needs specific comments tied to specific lines to indicate specific things. Your proposal of trying to keep comments in precisely the right place during text wrapping sounds very difficult.
Instead, I propose a solution using the replacement switch. Specific details:
I'm writing about the minimal value of some beautiful quantity, and
I put it in inline math like $Q_{min}$. After that I write more and more % chktex 35
about it. And more, and more, and more, and more. And even more.
modifyLineBreaks:
textWrapOptions:
columns: 60
replacements:
-
when: after
substitution: |-
s/(\$Q_\{min\}\$.*$)/$1 % chktex 35/mg
latexindent.pl
latexindent.pl -l -m -r issue-489.tex
I'm writing about the minimal value of some beautiful
quantity, and I put it in inline math like $Q_{min}$. After % chktex 35
that I write more and more about it. And more, and more,
and more, and more. And even more.% chktex 35
These settings add the % chktex 35
to the end of the line in which the $Q_{min}$
part is.
Perhaps you could combine this by removing the existing % chktex 35
comments beofre indentation:
modifyLineBreaks:
textWrapOptions:
columns: 60
replacements:
-
when: before
substitution: |-
s/%\h*chktex\h*35//sg
-
when: after
substitution: |-
s/(\$Q_\{min\}\$.*$)/$1 % chktex 35/mg
gives
I'm writing about the minimal value of some beautiful
quantity, and I put it in inline math like $Q_{min}$. After % chktex 35
that I write more and more about it. And more, and more,
and more, and more. And even more.
Wow! Fast response and effective solution! It solved my problem. I'm closing this issue.
Thank you very much @cmhughes!
Great stuff, glad it helped!
First: thanks for the great work!
Problem
Let's say we have a paragraph like (note the trailing comment):
Note that comment
% chktex 35
is there to disable a particular ChkTeX warning. (It warns me that I should probably use\min
instead of simple textmin
, which is not true in this particular case.) With the comment in place, the warning is disabled and everything is OK. However, if I dolatexindent
with-m
switch, with configured wrapping, I get something like (note the comment location):The warning reappears since the comment is not in the same line as the part that causes the warning. (And my CI/CD start failing :)) The only workaround currently is to disable this warning on the file level instead of on the line level. However, this obviously isn't an ideal solution - we wanted to disable the error only for one particular occurrence, not for the whole file.
Requested feature
It would be ideal if the output looks like (note the comment location):
Implementation
I'm aware that implementing fixed comments while wrapping the block is not a trivial problem - the question is where to put the comment when the commented line is wrapped. Logically this can be solved in several different ways, some being simple, some trying to be "smart". Nevertheless, one possible implementation (that I would like to see) is to avoid moving certain comments if the command does not change the uncommented part. In other words, if a particular block needs to be changed by wrapping lines differently, then keep the current behavior (all the comments go after the end of the block). But if the block does not need any changes in line wrapping, avoid moving some trailing comments. This can be configurable by using regex, in the same way it is done for
fineTuning.trailingComments.afterComment
.Thanks!