justify-kp icon indicating copy to clipboard operation
justify-kp copied to clipboard

Support justification with indent

Open wasamasa opened this issue 6 years ago • 5 comments

Regular rendering

Justified rendering

I'd like to preserve indentation by telling pj-justify that it should insert extra whitespace in front of every filled line and take it into account when calculating the width. I haven't found any way of doing this. Do you know how TeX does it?

wasamasa avatar Sep 19 '17 17:09 wasamasa

It works actually in a very simple way:

  1. render the paragraph normally but with adjusted witdh (page - offset)
  2. insert unstretchable glue whitespace in front of every line.

You can do this by changing the width variable this package uses (there is one isn't there?) and then loop over the lines and insert the required stuff (a display property with empty space, see how the whitespace glue is generated).

This way you can actually render arbitrary shapes. It always works going from left to right with zero offset but the line width changes with each linebreak (you can have a lookup line number -> width)... the final thing is then offset for each line as necessary. So if you want something like this

you just pretend that it starts on a vertical line with the width changing and then offset the beginnings.

Fuco1 avatar Sep 19 '17 19:09 Fuco1

And to loop over the lines it should be possible to use the output of the pj--justify function, that should already contain the best break (or does it not?). Then just insert extra tokens into the stream and render as usual.

Fuco1 avatar Sep 19 '17 19:09 Fuco1

Perhaps I didn't make myself clear, but I'd like to have official API for this instead of touching functions with double dashes that might very well be gone with the next rewrite.

wasamasa avatar Sep 20 '17 05:09 wasamasa

Yea, you asked how TeX does it :D

Would it be enough for you for now to have a version of the justify command where you can specify margins (left and right... the width is determined by window width automatically it seems but we can also add an explicit specification).

I'm thinking of something very lightly resembling CSS, probably a plist you would pass to the main justify function.

Fuco1 avatar Sep 20 '17 11:09 Fuco1

I'v rather thought of a customizable or a variable you dynamically bind to override this. A plist argument (or any kind of argument) would work as well.

wasamasa avatar Sep 20 '17 16:09 wasamasa