Skip to content

Instantly share code, notes, and snippets.

@kmaed kmaed/length.tex
Created Sep 30, 2012

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

kmaed commented Sep 30, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.