blacktex icon indicating copy to clipboard operation
blacktex copied to clipboard

Do not change \def

Open clason opened this issue 3 years ago • 7 comments

I know that using plain TeX \def is an anti-pattern considered by your source, and normally LaTeX macros should be defined by \newcommand instead. However, it is not safe to blindly replace the former with the latter -- for starters, since you can't know whether \renewcommand should have been used instead. There are also legitimate uses of \def. Running blacktex on such a file will break it.

I would therefore strongly recommend removing this transformation (or at least put it behind a feature flag, default false, with a prominent warning).

In general, it would be good to make blacktex more configurable by being able to toggling every single transformation rule separately -- ideally using a toml file (stylua can serve as a guide here) -- although I am aware that this would be (too) much work.

clason avatar Jul 15 '21 12:07 clason

In general, it would be good to make blacktex more configurable by being able to toggling every single transformation rule separately -- ideally using a toml file (stylua can serve as a guide here) -- although I am aware that this would be (too) much work.

Definitely a good idea and not too much work. I'll look into this. I'm not sure what I'll do about the defaults yet, but hopefully the configurability should already help you out.

nschloe avatar Jul 15 '21 12:07 nschloe

Current defaults should be safe, as far as I can tell, and need not be changed -- with the exception of the \def -> \newcommand issue here.

clason avatar Jul 15 '21 12:07 clason

People have different opinions about that. Every change can (and, if the user base is large, will) break workflows.

nschloe avatar Jul 15 '21 12:07 nschloe

True, but as far as I can tell, all other changes are transparent in the output. This is the only one that can actually break a file (which is how I stumbled across it).

But as you say, it's indeed better to err on the side of caution.

clason avatar Jul 15 '21 12:07 clason

(At the risk of beating a dead horse, but just to make it clear: I'm not saying that all other options should be enabled by default; I'm just adding a single data point that they could. On the other hand, I am saying that the \def transformation is too dangerous and should not be enabled by default.)

clason avatar Jul 15 '21 13:07 clason

it would be good to make blacktex more configurable by being able to toggling every single transformation rule separately

I imagine this project was inspired by the python formatter black, whose stated purpose is to be unconfigurable. There are a few exceptions, which blacktex could also have (for this case, the existing comments exception, and so on); just saying that ultimate configurability isn't necessarily a design goal.

clbarnes avatar Mar 17 '22 09:03 clbarnes

Sure, and that's fine -- my point is just that unlike black (and other code formatters), blacktex also makes changes that affect the output. This is something I do not want; I just want the code formatted (comments stripped for submission, mostly). So I'm hoping for a way to disable all such transformations and only apply those that are guaranteed to leave the output unchanged ("minimal mode", if you will).

clason avatar Mar 17 '22 10:03 clason