梅威瑟:
\directlua{%
local abs=math.abs
function gcd(x, y)
if y \csstring\~= 0 then
return gcd(y, x \csstring\% y)% I would like to write "≠" instead of "~=".
else
return abs(x)
end
end}
\directlua{tex.print(gcd(768,640))}% prints 128
\bye
有没有办法用 来代替≠
(~=
或者≥
用 来代替>=
里面)directlua{...}
?这样可以提高可读性。
谢谢。
答案1
{
\endlinechar=-1
\catcode`\≠\active
\catcode`\%\active
\gdef\zzz{\bgroup
\catcode`\≠\active\edef≠{\string~=}
\catcode`\%\active\edef%{\string%}
\zzzz}
\gdef\zzzz#1{\directlua{#1}\egroup}
}
\zzz{
local abs=math.abs
function gcd(x, y)
if y ≠ 0 then
return gcd(y, x % y)
else
return abs(x)
end
end}
\directlua{tex.print(gcd(768,640))}% prints 128
\bye