Skip to content

Instantly share code, notes, and snippets.

@kmaed
Created September 30, 2012 06:32
Show Gist options
  • Save kmaed/3806046 to your computer and use it in GitHub Desktop.
Save kmaed/3806046 to your computer and use it in GitHub Desktop.
2012/09/17 の解答(!!?)
%#! lualatex
\documentclass[a4paper]{article}
\makeatletter
\def\len@begin{\directlua{
local len_count = 0
local len_flag = true
while len_flag do
local t = token.get_next()
% print(token.csname_name(t))
if token.csname_name(t) == 'len@end' then
len_flag = false
for i = 1, len_count do
tex.write('*')
end
end
len_count = len_count + 1
end
}}
\def\len@end{done!}
\def\length#1{\len@begin#1\len@end}
\makeatother
\begin{document}
\def\check{\ifx\result\checkstr OK\else NG\fi}
\edef\result{\length{ \a {b\cd ef{g} }\h }}
\def\checkstr{*************}
\check
\edef\result{\length{{ }{ {}} {}}}
\def\checkstr{***********}
\check
\escapechar=-1
\edef\result{\length{\expandafter\expandafter\expandafter}}
\escapechar=`\\
\def\checkstr{***}
\check
\edef\result{\expandafter\length\expandafter{\csname ?TeX\endcsname}}
\def\checkstr{*}
\check
\end{document}
@kmaed
Copy link
Author

kmaed commented Sep 30, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment