-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft mode colours don't work in OpTeX and ConTeXt #39
Comments
What interface do you think could be nicely abstracted / convenient? Extracted from diff --git a/source/lua-widow-control.lua b/source/lua-widow-control.lua
index 1ef8617..dafd868 100644
--- a/source/lua-widow-control.lua
+++ b/source/lua-widow-control.lua
@@ -69,7 +69,7 @@ elseif format:find("latex") then -- lualatex, lualatex-dev, ...
elseif format == "luatex" or format == "luahbtex" then -- Plain
plain = true
elseif format:find("optex") then -- OpTeX
- optex = true
+ optex = _G.optex
end
--[[
@@ -407,12 +407,21 @@ local function colour_list(head, colour)
return head
end
+ local pdf_literal = string.format("%.2f %.2f %.2f rg", table.unpack(colour))
+
+ if optex and optex.set_node_color then
+ for n in node.traverse(head) do
+ optex.set_node_color(n, pdf_literal)
+ end
+ 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))
+ start_colour.data = pdf_literal
local end_colour = new_node("whatsit", "pdf_colorstack")
end_colour.stack = 0 Through vlasakm/OpTeX@1b2070e. |
@vlasakm That looks great, thanks! I've committed your patch, although I won't do a release until the accompanying change is made in OpTeX. |
See #39. Depends on vlasakm/OpTeX@1b2070e.
Maybe if for all formats we can get the color attribute and a mapping from color to its number, there could be something like this loop instead: for n in node.traverse(head) do
node.setattribute(n, attribute, color)
end @gucci-on-fleek I modified your example from olsak/OpTeX#101 for ConTeXt, but it doesn't work as I expected. Do you have any ideas? I am mostly clueless about debugging ConTeXt. \setupcolors[state=start]
\starttext
\directlua{
local color = attributes.colors.register("mycolor", "rgb", 0, 1, 0)
local attribute = attributes.colors.attribute
callback.register("pre_output_filter", function (head)
for hlist in node.traverseid(node.id("hlist"), head) do
for n in node.traverse(head) do
node.setattribute(n, attribute, color)
end
end
return head
end)
}
Hello!
Hello!
Hello!
\page
Hello!
Hello!
Hello!
\stoptext |
Now draft mode colouring works for all lines in both MkIV/MkXL. See #39
"All formats" is a little tricky here though. TeX82 doesn't have any native colour support, so each format handles it very differently:
I think that this is just one of those places where we unfortunately need to keep completely different implementations for different formats.
ConTeXt luckily has a higher-level interface for setting node colours. Like most of the ConTeXt Lua interfaces, it is completely undocumented, but I found it by searching through the code. See ddb2258 for an implementation.
Just a small typo in your code: @@ -7,7 +7,7 @@
local attribute = attributes.colors.attribute
callback.register("pre_output_filter", function (head)
for hlist in node.traverseid(node.id("hlist"), head) do
- for n in node.traverse(head) do
+ for n in node.traverse(hlist.list) do
node.setattribute(n, attribute, color)
end
end With that change, it works as expected.
From the Lua end, you can run From the TeX end, you can try something like \tracingonline=2
\tracingnodes=2
\shownodedetails=2
\tracingoutput=1
\showboxdepth=\maxdimen
\showboxbreadth=\maxdimen which should show you the colour of each node. |
Sorry for my poor wording, I am familiar with the color situation, what I meant was all attribute based formats, i.e. the three ones we are dealing with in this issue. Those would allow common implementation if each exposed the color attribute and a possibility to map color to its attribute value.
Yeah, it's probably better to stick to higher level interfaces. I am not satisfied with the efficiency of
Thanks! I somehow missed that.
Thanks, very handy! I'll try to get olsak/OpTeX#101 merged as is. Give it a few days please. |
OpTeX: Cannot colour the first line of the page since OpTeX resets the colour there.
Can probably use something similar to
luaotfload.set_colorhandler
as a solution.ConTeXt MkIV: Same problem as OpTeX; however, this will require a different solution.
ConTeXt MkXL:
pdf_colorstack
literals are gone, so colour doesn't work at all. Not sure how to solve this one.The text was updated successfully, but these errors were encountered: