Skip to content
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

support for OpTeX #21

Open
Udi-Fogiel opened this issue Mar 10, 2024 · 2 comments
Open

support for OpTeX #21

Udi-Fogiel opened this issue Mar 10, 2024 · 2 comments

Comments

@Udi-Fogiel
Copy link

Udi-Fogiel commented Mar 10, 2024

It would be nice to be able to use this package together with the OpTeX format. If you will be willing to do so, i'll request the developer of the format to add the pre_append_to_vlist_filter call back so it would be easier to do so.

Just for a proof of concept:, the following diff works:

diff --git a/lua-ul.dtx b/lua-ul.dtx
index d389573..4cf09ed 100644
--- a/lua-ul.dtx
+++ b/lua-ul.dtx
@@ -455,6 +455,21 @@ local underline_types = {}
 local underline_strict_flag = {}
 local underline_over_flag = {}
 
+local format = tex.formatname
+local latex, optex
+
+if format:find("latex") then 
+	latex = true
+elseif format:find("optex") then
+	optex = true
+	function luatexbase.new_luafunction(name)
+	  return #functions + 1
+	end
+else
+	texerror("Unsupported format", {"Please use LaTeX or OpTeX."})
+end
+
+
 local vmode do
   for k, v in pairs(tex.getmodevalues()) do
   if v == "vertical" then
@@ -610,16 +625,16 @@ local function reset_underline()
   tex.attribute[j] = -0x7FFFFFFF
 end
 local new_underline_type_func =
-    luatexbase.new_luafunction"luaul.new_underline_type"
-local set_underline_func =
-    luatexbase.new_luafunction"luaul.set_underline_func"
-local reset_underline_func =
-    luatexbase.new_luafunction"luaul.reset_underline_func"
+	luatexbase.new_luafunction"luaul.new_underline_type"
 set_lua("LuaULNewUnderlineType", new_underline_type_func)
-set_lua("LuaULSetUnderline", set_underline_func, "protected")
-set_lua("LuaULResetUnderline", reset_underline_func, "protected")
 functions[new_underline_type_func] = new_underline_type
+local set_underline_func =
+	luatexbase.new_luafunction"luaul.set_underline_func"
+set_lua("LuaULSetUnderline", set_underline_func, "protected")
 functions[set_underline_func] = set_underline
+local reset_underline_func =
+	luatexbase.new_luafunction"luaul.reset_underline_func"
+set_lua("LuaULResetUnderline", reset_underline_func, "protected")
 functions[reset_underline_func] = reset_underline
 
 %    \end{macrocode}
@@ -846,8 +861,37 @@ function add_underline_hbox(head, attr, outervalue, set_height_depth)
   end
   set_attribute(head, attr, outervalue and -outervalue or 0)
 end
-require'pre_append_to_vlist_filter'
-luatexbase.add_to_callback('pre_append_to_vlist_filter',
+local filter_callback
+local filter_callback_return
+if optex then 
+	filter_callback = 'append_to_vlist_filter'
+	function filter_callback_return(b, prev, mirror)
+		local new_b = tonode(b)
+	  	local new_prev = mirror and new_b.height or new_b.depth
+		if prev > -65536000 then
+		  local lineglue = tex.baselineskip.width - prev - (mirror and new_b.depth or new_b.height)
+		  local skip
+		  if lineglue < tex.lineskiplimit then
+		    skip = node.new('glue', 1)
+		    node.setglue(skip, node.getglue(tex.lineskip))
+		  else
+		    skip = node.new('glue', 2)
+		    node.setglue(skip, node.getglue(tex.baselineskip))
+		    skip.width = lineglue
+		  end
+		  skip.next = new_b
+		  new_b = skip
+		end
+		return new_b, new_prev
+	end
+else
+	filter_callback = 'pre_append_to_vlist_filter'
+	function filter_callback_return(b, prev, mirror)
+		return tonode(b)
+	end
+	require'pre_append_to_vlist_filter'
+end
+luatexbase.add_to_callback(filter_callback,
     function(b, loc, prev, mirror)
       local props = properties[todirect(texnest.top.head)]
       props = props and props.luaul_attributes
@@ -875,7 +919,7 @@ luatexbase.add_to_callback('pre_append_to_vlist_filter',
           end
         end
       end
-      return tonode(b)
+	  return filter_callback_return(b, prev, mirror)
     end, 'add underlines to list')
 luatexbase.add_to_callback('hpack_filter',
     function(head, group, size, pack, dir, attr)

Test file

\fontfam[lm]
\directlua{require'lua-ul'}
\edef\underLine{\LuaULSetUnderline
		\LuaULNewUnderlineType{\leaders\vrule height-1ptdepth1.5pt\hskip0pt}}
		
{\underLine Hello} World!

\bye

A few notes... if OpTeX will add the pre_append_to_vlist_filter call back, the patch would be much smaller. The only problem is that OpTeX does not use luatexbase, and so it does not define luatexbase.new_luafunction. It only define a small subset of luatexbase functions (or aliases of them) for compatibility with luaotfload.

@Udi-Fogiel
Copy link
Author

Oh, and OpTeX adds italic correction via \_additcorr and \_afteritcorr, and I'm not sure if the output problem is also relavent for OpTeX.

@Udi-Fogiel
Copy link
Author

@zauguin Are you planing to do that eventually or it is not in your interest?
If it is the latter, will you mind if I'll public an adaption of luaul for OpTeX?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant