justify-kp
justify-kp copied to clipboard
Support justification with indent
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?
It works actually in a very simple way:
- render the paragraph normally but with adjusted witdh (page - offset)
- 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.
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.
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.
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.
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.