From adriana2022alarma at gmail.com Fri Dec 2 14:50:04 2022 From: adriana2022alarma at gmail.com (Adriana Adriana) Date: Fri, 2 Dec 2022 14:50:04 +0100 Subject: [luatex] scanning for undefined command names Message-ID: Adriana Adriana te ha enviado un correo mediante el modo Confidencial de Gmail: [image: Logotipo de Gmail]Re: [luatex] scanning for undefined command names Este mensaje se envi? el 2 dic 2022 a las 5:50:17 GMT-8 Para abrirlo, haz clic en el siguiente enlace (solo se puede ver con luatex at tug.org). Ver el correo El modo Confidencial de Gmail te permite controlar mejor los mensajes que env?as. El remitente puede establecer una fecha de vencimiento, inhabilitar la impresi?n o el reenv?o o realizar un seguimiento del acceso al mensaje. M?s informaci?n Gmail: el correo electr?nico de Google El uso est? sujeto a la pol?tica de privacidad de Google Google LLC, 1600 Amphitheatre Parkway, Mountain View, CA 94043, EE. UU. Has recibido este mensaje porque alguien te ha enviado un correo mediante el modo Confidencial de Gmail. [image: Logotipo de Google] -------------- next part -------------- An HTML attachment was scrubbed... URL: From wl at gnu.org Thu Dec 8 11:10:16 2022 From: wl at gnu.org (Werner LEMBERG) Date: Thu, 08 Dec 2022 10:10:16 +0000 (UTC) Subject: [luatex] adjusting `hyphenate` callback for single function Message-ID: <20221208.111016.2158980477876909393.wl@gnu.org> Folks, being a complete newbie who wants to experiment a little with LuaTeX, I ask for some help to improve `texinfo.tex` for generating the documentation of LilyPond. Within the `@code` macro, I want to do two things. (a) Hook into the `hyphenate` callback to insert hyphenation discretionaries based on some constraints. (b) Hook into `pre_linebreak_filter` (or rather `contribute_filter`?) to inhibit line breaks before/after a single character if preceded/followed by a (single) space. In other words, this space should be replaced with `@tie{}`. How can I do that? I guess I have to do the following. (1) Write hooks `code_hyphenate` and `code_pre_linebreak_filter`. (2) At the beginning of `@code`, append the `code_hyphenate` hook. (3) At the end of `@code`, remove the `code_hyphenate` hook. Assuming this is the correct approach I have some questions. * It's not written explicitly in the LuaTeX manual but I guess that the argument to the `hyphenate` hook is a single word. * I couldn't find information in the manual about the order of hooks. It seems that I have to save the original hook by myself and call it before/after, right? * Is there already some code available that I could use as a starting point? Werner From j.hagen at xs4all.nl Thu Dec 8 11:20:16 2022 From: j.hagen at xs4all.nl (Hans Hagen) Date: Thu, 8 Dec 2022 11:20:16 +0100 Subject: [luatex] adjusting `hyphenate` callback for single function In-Reply-To: <20221208.111016.2158980477876909393.wl@gnu.org> References: <20221208.111016.2158980477876909393.wl@gnu.org> Message-ID: <918fc56b-901c-9fb0-aae6-bb7e2584edfc@xs4all.nl> On 12/8/2022 11:10 AM, Werner LEMBERG wrote: > > Folks, > > > being a complete newbie who wants to experiment a little with LuaTeX, > I ask for some help to improve `texinfo.tex` for generating the > documentation of LilyPond. > > Within the `@code` macro, I want to do two things. > > (a) Hook into the `hyphenate` callback to insert hyphenation > discretionaries based on some constraints. > > (b) Hook into `pre_linebreak_filter` (or rather `contribute_filter`?) > to inhibit line breaks before/after a single character if > preceded/followed by a (single) space. In other words, this space > should be replaced with `@tie{}`. > > How can I do that? I guess I have to do the following. > > (1) Write hooks `code_hyphenate` and `code_pre_linebreak_filter`. > > (2) At the beginning of `@code`, append the `code_hyphenate` hook. > > (3) At the end of `@code`, remove the `code_hyphenate` hook. > > Assuming this is the correct approach I have some questions. > > * It's not written explicitly in the LuaTeX manual but I guess that > the argument to the `hyphenate` hook is a single word. > > * I couldn't find information in the manual about the order of hooks. > It seems that I have to save the original hook by myself and call it > before/after, right? > > * Is there already some code available that I could use as a starting > point? talking of luatex, if you want to influence hyphenation, you can best plug into the pre_linebreak_filter and hpack_filter callbacks and just do some interpretation of the node lists (glyph nodes) and bases on what you want to do inject or replace them by disc nodes that then control the hyphenator later on as we as the linbebreak routine it's all up to the macro package how to organize and order things and they all do things differently Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl ----------------------------------------------------------------- From jbezosl at gmail.com Thu Dec 8 16:43:40 2022 From: jbezosl at gmail.com (Javier Bezos) Date: Thu, 8 Dec 2022 16:43:40 +0100 Subject: [luatex] adjusting `hyphenate` callback for single function In-Reply-To: <20221208.111016.2158980477876909393.wl@gnu.org> References: <20221208.111016.2158980477876909393.wl@gnu.org> Message-ID: > * I couldn't find information in the manual about the order of hooks. > It seems that I have to save the original hook by myself and call it > before/after, right? > > * Is there already some code available that I could use as a starting > point? They are very old and the syntax has changed in some lua commands (and a callback is no longer available), but I found the following articles very useful when I was learning how the callbacks work: https://tug.org/tugboat/tb31-3/tb99isambert.pdf https://tug.org/TUGboat/tb32-1/tb100isambert.pdf Javier From wl at gnu.org Sat Dec 10 07:52:00 2022 From: wl at gnu.org (Werner LEMBERG) Date: Sat, 10 Dec 2022 06:52:00 +0000 (UTC) Subject: [luatex] adjusting `hyphenate` callback for single function In-Reply-To: References: <20221208.111016.2158980477876909393.wl@gnu.org> Message-ID: <20221210.075200.998317492464157930.wl@gnu.org> > They are very old and the syntax has changed in some lua commands > (and a callback is no longer available), but I found the following > articles very useful when I was learning how the callbacks work: > > https://tug.org/tugboat/tb31-3/tb99isambert.pdf > > https://tug.org/TUGboat/tb32-1/tb100isambert.pdf Thanks a lot! This is indeed very helpful. Werner From wl at gnu.org Sat Dec 10 07:53:19 2022 From: wl at gnu.org (Werner LEMBERG) Date: Sat, 10 Dec 2022 06:53:19 +0000 (UTC) Subject: [luatex] adjusting `hyphenate` callback for single function In-Reply-To: <918fc56b-901c-9fb0-aae6-bb7e2584edfc@xs4all.nl> References: <20221208.111016.2158980477876909393.wl@gnu.org> <918fc56b-901c-9fb0-aae6-bb7e2584edfc@xs4all.nl> Message-ID: <20221210.075319.1550071107934351786.wl@gnu.org> > talking of luatex, if you want to influence hyphenation, you can > best plug into the pre_linebreak_filter and hpack_filter callbacks > and just do some interpretation of the node lists (glyph nodes) and > bases on what you want to do inject or replace them by disc nodes > that then control the hyphenator later on as we as the linbebreak > routine Yes, something along this route, thanks! Werner From wl at gnu.org Sun Dec 18 20:58:28 2022 From: wl at gnu.org (Werner LEMBERG) Date: Sun, 18 Dec 2022 19:58:28 +0000 (UTC) Subject: [luatex] asking for style/code critique Message-ID: <20221218.205828.653521420936900135.wl@gnu.org> Folks, attached is my first serious attempt to write a 'hyphenate' callback (to be used for LilyPond's Texinfo documentation). It is actually my first Lua program ever. Fortunately, initial tests indicate that it works aas expected :-) Please have a quick look and check whether you can see any big problems ? mainly stylewise (besides using two spaces for indentation instead of three) but perhaps codewise, too. Thanks in advance. Werner -------------- next part -------------- -- code.lua -- -- Written 2022 by Werner Lemberg . -- -- If the LilyPond documentation is compiled with LuaTeX (which is the -- default), Texinfo's `@code` macro gets enhanced by this Lua code to -- do the following things. -- -- (0) For further analysis, break the argument to `@code` into words. -- Words that already contain discretionaries and penalties (for -- example, by inserting `@/` or `@-`) are ignored. -- (1) Insert hyphenation points in camel-case words. -- (2) Add possible line breaks after `-` and `_`. -- (3) Avoid that single-character words at the start or the end of -- the `@code` argument are positioned at the end or start of an -- output line, respectively. A typical case with LilyPond code -- is `@code{@{ ... @}}`. -- -- There will be at least two characters at the start or the end of a -- word before inserting a hyphenation point or a possible line break. -- -- Note that this code only works if `@allowcodebreaks false` is set. -- Some shorthands. char_hyphen = 0x2d umatch = unicode.utf8.match uchar = unicode.utf8.char DISC = node.id("disc") GLUE = node.id("glue") GLYPH = node.id("glyph") HLIST = node.id("hlist") PENALTY = node.id("penalty") -- This value must be the same as set in `common-macros.itexi` (using -- `\attribute`). code_attribute = 200 typography = function(head) local words = {} local idx = 1 local word_start = 0 local word_end = 0 local word_len = 0 local prev_font = -1 local only_characters = true -- Loop over all nodes to find start, end, and length of words, to -- be stored in array `words`. for n in node.traverse(head) do local in_word = false -- Handle only stuff in `@code`. if node.has_attribute(n, code_attribute) then -- Only characters typeset with same font are considered to be -- in the same word. if n.id == GLYPH and (prev_font == -1 or prev_font == n.font) then in_word = true end -- We don't handle discretionaries and penalties outside of a -- word. if (n.id == DISC or n.id == PENALTY) and word_len > 0 then in_word = true only_characters = false end end if in_word then if word_len == 0 then word_start = n end word_end = n word_len = word_len + 1 if n.id == GLYPH then prev_font = n.font end else -- Ignore words that already contain discretionaries or -- penalties. if word_len > 0 and only_characters then words[idx] = { word_start, word_end, word_len } idx = idx + 1 end only_characters = true -- The current node might still start a new word. if node.has_attribute(n, code_attribute) and n.id == GLYPH then in_word = true word_start = n word_end = n word_len = 1 prev_font = n.font else word_len = 0 prev_font = -1 end end end -- Now loop over all collected words. for _, word in ipairs(words) do word_start, word_end, word_len = table.unpack(word) -- Check for `[_] [_] [-_] [_]` -- and insert a penalty after `-` (or `_`) if we have a hit. if word_len >= 5 then local start = word_start local len = word_len while len >= 5 do local c1 = start local c2 = c1.next local c3 = c2.next local c4 = c3.next local c5 = c4.next if umatch(uchar(c1.char), "[%l%u_]") and umatch(uchar(c2.char), "[%l%u_]") and umatch(uchar(c3.char), "[_-]") and umatch(uchar(c4.char), "[%l%u]") and umatch(uchar(c5.char), "[%l%u_]") then local pen = node.new(PENALTY) pen.penalty = tex.hyphenpenalty node.set_attribute(pen, code_attribute, 1) node.insert_after(head, c3, pen) len = len - 3 start = c4 else len = len - 1 start = c2 end end end -- Check for ` ` and -- insert the equivalent to `\discretionary{-}{}{}` after -- `` if we have a hit. if word_len >= 4 then local start = word_start local len = word_len while len >= 4 do local c1 = start local c2 = c1.next local c3 = c2.next local c4 = c3.next -- The previous while-loop might have inserted penalty nodes; -- we thus have to additionally check `c1` to `c4` for -- validness. if c1.id == GLYPH and c2.id == GLYPH and c3.id == GLYPH and c4.id == GLYPH and umatch(uchar(c1.char), "[%l%u]") and umatch(uchar(c2.char), "%l") and umatch(uchar(c3.char), "%u") and umatch(uchar(c4.char), "[%l%u]") then local hyphen = node.new(GLYPH) hyphen.subtype = 1 hyphen.font = c2.font hyphen.char = char_hyphen local disc = node.new(DISC) disc.subtype = 1 disc.penalty = tex.hyphenpenalty disc.pre = hyphen node.set_attribute(disc, code_attribute, 1) node.insert_after(head, c2, disc) len = len - 2 start = c3 else len = len - 1 start = c2 end end end end -- end of for-loop for n in node.traverse(head) do -- Check whether there is a single character at the beginning of -- `@code`, followed by a space. If we have a hit, insert a -- penalty after the character. local non_code = n if not node.has_attribute(non_code, code_attribute) then local char = non_code.next if char and node.has_attribute(char, code_attribute) and char.id == GLYPH then local space = char.next if space and node.has_attribute(space, code_attribute) and space.id == GLUE then local pen = node.new(PENALTY) pen.penalty = 10000 node.set_attribute(pen, code_attribute, 1) node.insert_after(head, char, pen) end end end -- Check whether there is a single character at the end of -- `@code`, preceded by a space. If we have a hit, insert a -- penalty before the space. local space = n if node.has_attribute(space, code_attribute) and space.id == GLUE then local char = space.next if char and node.has_attribute(char, code_attribute) and char.id == GLYPH then -- We actually have to check for one more node because `@code` -- ends with a call to `\null`, which creates an empty hbox. local hbox = char.next if hbox and node.has_attribute(hbox, code_attribute) and hbox.id == HLIST then local non_code = hbox.next if non_code and not node.has_attribute(non_code, code_attribute) then local pen = node.new(PENALTY) pen.penalty = 10000 node.set_attribute(pen, code_attribute, 1) node.insert_before(head, space, pen) end end end end end -- end of for-loop end -- eof From j.hagen at xs4all.nl Sun Dec 18 21:20:55 2022 From: j.hagen at xs4all.nl (Hans Hagen) Date: Sun, 18 Dec 2022 21:20:55 +0100 Subject: [luatex] asking for style/code critique In-Reply-To: <20221218.205828.653521420936900135.wl@gnu.org> References: <20221218.205828.653521420936900135.wl@gnu.org> Message-ID: <9670b495-000e-36c8-2422-d6fe645c5b7f@xs4all.nl> On 12/18/2022 8:58 PM, Werner LEMBERG wrote: > attached is my first serious attempt to write a 'hyphenate' callback > (to be used for LilyPond's Texinfo documentation). It is actually my > first Lua program ever. Fortunately, initial tests indicate that it > works aas expected :-) > > Please have a quick look and check whether you can see any big > problems ? mainly stylewise (besides using two spaces for indentation > instead of three) but perhaps codewise, too. it's not my habit to comment publicly on coding styles so i limit myself to suggesting to make your shorthands local, so local DISC = node.id("disc") just to avoid a clash with someone elses code Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl ----------------------------------------------------------------- From wl at gnu.org Mon Dec 19 07:23:29 2022 From: wl at gnu.org (Werner LEMBERG) Date: Mon, 19 Dec 2022 06:23:29 +0000 (UTC) Subject: [luatex] asking for style/code critique In-Reply-To: <9670b495-000e-36c8-2422-d6fe645c5b7f@xs4all.nl> References: <20221218.205828.653521420936900135.wl@gnu.org> <9670b495-000e-36c8-2422-d6fe645c5b7f@xs4all.nl> Message-ID: <20221219.072329.1212661339896272580.wl@gnu.org> > it's not my habit to comment publicly on coding styles :-) > so i limit myself to suggesting to make your shorthands local, so > > local DISC = node.id("disc") > > just to avoid a clash with someone elses code Thanks! Werner From witiko at gmail.com Mon Dec 19 16:33:37 2022 From: witiko at gmail.com (=?UTF-8?B?VsOtdCBOb3ZvdG7DvQ==?=) Date: Mon, 19 Dec 2022 16:33:37 +0100 Subject: [luatex] asking for style/code critique In-Reply-To: <20221218.205828.653521420936900135.wl@gnu.org> References: <20221218.205828.653521420936900135.wl@gnu.org> Message-ID: Dear Werner, there is a useful piece of software called luacheck that you can use to go over your Lua code and point out any and all stylewise gaffes it comes across. I use it as part of continuous integration of my LuaTeX package and it has definitely improved my code and helped me discover bugs that would have otherwise gone unnoticed. Best, Vit ne 18. 12. 2022 v 20:59 odes?latel Werner LEMBERG napsal: > > Folks, > > > attached is my first serious attempt to write a 'hyphenate' callback > (to be used for LilyPond's Texinfo documentation). It is actually my > first Lua program ever. Fortunately, initial tests indicate that it > works aas expected :-) > > Please have a quick look and check whether you can see any big > problems ? mainly stylewise (besides using two spaces for indentation > instead of three) but perhaps codewise, too. > > Thanks in advance. > > > Werner > -------------- next part -------------- An HTML attachment was scrubbed... URL: From wl at gnu.org Mon Dec 19 16:48:48 2022 From: wl at gnu.org (Werner LEMBERG) Date: Mon, 19 Dec 2022 15:48:48 +0000 (UTC) Subject: [luatex] asking for style/code critique In-Reply-To: References: <20221218.205828.653521420936900135.wl@gnu.org> Message-ID: <20221219.164848.471142226678455166.wl@gnu.org> > there is a useful piece of software called luacheck > that you can use to go over > your Lua code and point out any and all stylewise gaffes it comes > across. I use it as part of continuous integration of my LuaTeX > package and it has definitely improved my code and helped me > discover bugs that would have otherwise gone unnoticed. Thanks a lot! Will test soon. Werner