Re: Choice of processor
Joseph Wright <[email protected]> Wed, 5 Mar 2025 11:50:42 +0000
| Newsgroups | gmane.comp.tex.texhax |
|---|---|
| Message-ID | <[email protected]> |
On 05/03/2025 11:24, David Carlisle wrote: > On Wed, 5 Mar 2025 at 11:07, Philip Taylor <[email protected]> > wrote: > >> OK, adding "\input luaotfload.sty" appears to allow access to some (but >> not yet all) system fonts (LuaTeX states that it cannot find "Avenir LT Std >> 45 Book") >> >> luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: Font >> "Avenir LT Std 45 Book" not found. >> >> luaotfload | resolve : sequence of 3 lookups yielded nothing appropriate. >> >> ! Font \mlfont=Avenir LT Std 45 Book at 6pt not loadable: metric data not >> found >> >> or bad. >> >> l.66 \font \mlfont = "Avenir LT Std 45 Book" at 6 pt >> >> — the reason for that remains to be investigated. However, I now have >> another problem. I make frequent use of XeTeX's \strcmp primitive — is >> there a LuaTeX equivalent ? >> > > LaTeX has been providing a strcmp implementation in Lua for decades so for > the vast majority of users such issues (the point of the thread started by > Peter) simply don't exist. If you choose to use plain tex and ignore > decades of development by other people that's fine but you then need to > actually do the work of doing those implementations, but to give you a > start latex uses > > \begin{macro}[no-user-doc]{\tex_strcmp:D} > % Compare two strings, expanding to |0| if they are equal, > % |-1| if the first one is smaller and |1| if the second one is smaller. > % Here \enquote{smaller} refers to codepoint order which does not > correspond to > % the user expected order for most non-ASCII strings. > % \begin{macrocode} > local minus_tok = token_new(string.byte'-', 12) > local zero_tok = token_new(string.byte'0', 12) > local one_tok = token_new(string.byte'1', 12) > luacmd('tex_strcmp:D', function() > local first = scan_string() > local second = scan_string() > if first < second then > put_next(minus_tok, one_tok) > else > put_next(first == second and zero_tok or one_tok) > end > end, 'global') > % \end{macrocode} > % \end{macro} > > You might want to call it \strcmp rather than \tex_strcmp:D but otherwise > it should work put it inside \directlua{...} The above relies on various other bits of Lua as LaTeX does various bits of emulation and tracks things. For a one-off use, you could go with \directlua{ local t = lua.get_functions_table() local minus_tok = token.new(string.byte('-'), 12) local zero_tok = token.new(string.byte('0'), 12) local one_tok = token.new(string.byte('1'), 12) t[1] = function() local first = token.scan_string() local second = token.scan_string() if first < second then token.put_next(minus_tok, one_tok) else token.put_next(first == second and zero_tok or one_tok) end end } \luadef\strcmp 1 % \strcmp{A}{A} \strcmp{A}{B} \strcmp{B}{A} \bye which hard-codes that we are using a known Lua function - done like this, \strcmp has the same behaviour as a primitive. Joseph