Open hpvd opened 2 years ago
Nice idea. It seems that it should be possible to use the Luacolor package for this task: https://tex.stackexchange.com/a/539268/2891 I need to finish other tasks now, but will look at this in the near future.
Another interesting article about coloring for the future reference: https://tug.org/TUGboat/tb31-3/tb99isambert.pdf. I hope it still works, as it is 12 years old.
great to here you like it :-)
this seems to be the approach the author of lua-widow-control has just adapted to do something similar: https://tex.stackexchange.com/a/372437
in https://github.com/gucci-on-fleek/lua-widow-control/commit/5a43e4ea09c012d1eaaaa87bebed12388bcb14d6
result: https://github.com/gucci-on-fleek/lua-widow-control/issues/36#issuecomment-1154821652
Another interesting article about coloring for the future reference: https://tug.org/TUGboat/tb31-3/tb99isambert.pdf. I hope it still works, as it is 12 years old.
Yep, the colour stuff there still works. (Well, not with LuaMetaTeX, but everything is more complicated there...)
The implementation is reasonably simple. I currently have
--- Changes the text colour in a node list if draft mode is active
---
--- @param head node The first node to colour
--- @param colour table<number> A 3-tuple of RGB values
--- @return node head The coloured node
local function colour_list(head, colour)
if not lwc.draft_mode then
return head
end
-- Adapted from https://tex.stackexchange.com/a/372437
-- \\pdfextension colorstack is ignored in LMTX
local start_colour = new_node("whatsit", "pdf_colorstack")
start_colour.stack = 0
start_colour.command = 1
start_colour.data = string.format("%.2f %.2f %.2f rg", table.unpack(colour))
local end_colour = new_node("whatsit", "pdf_colorstack")
end_colour.stack = 0
end_colour.command = 2
start_colour.next = head
last(head).next = end_colour
return start_colour
end
(source)
which I use like this:
for n in traverse_id(hlist_id, saved_node) do
n.list = colour_list(n.list, lwc.colours.expanded)
end
(source)
(Feel free to copy any of this code, although it is probably buggy)
You can place the pdf_colorstack
nodes around the hlist
nodes (vmode
-ish), but I'd prefer putting the pdf_colorstack
nodes inside the hlist
nodes (hmode
-ish) just to make sure that the colour start and end nodes are always on the same page.
would be great to have some feedback about the work of this awesome package, and also benefit from done analyses.
One way would be to add an option (e.g. draft) to enable a coloring of the text e.g.