Skip to content

Instantly share code, notes, and snippets.

@kmaed

kmaed/length.tex

Created Sep 29, 2012
Embed
What would you like to do?
2012/09/17 の解答(!?)
%#! lualatex
\documentclass[a4paper]{article}
\def\length#1{%
\directlua{\unexpanded{
require('lualibs-unicode')
local input = [[#1]]
local state = 'r'
% print(input)
for i = 1, utf.len(input) do
local r = utf.byte(utf.sub(input, i, i))
if state == 'r' then
tex.write('*')
if tex.getcatcode(r) == 0 then state = 'csb' end
elseif state == 'csb' then
if tex.getcatcode(r) == 11 then state = 'cs' else state = 'r' end
elseif state == 'cs' then
if tex.getcatcode(r) == 10 then
state = 'r'
elseif tex.getcatcode(r) ~= 11 then
tex.write('*')
state = 'r'
end
end
end
}}}
\def\starxiii{*************}
\def\starxi{***********}
\begin{document}
\edef\result{\length{ \a {b\cd ef{g} }\h }}
\ifx\result\starxiii OK\else NG\fi
\edef\result{\length{{ }{ {}} {}}}
\ifx\result\starxi OK\else NG\fi
\end{document}
@kmaed

This comment has been minimized.

Copy link
Owner Author

@kmaed kmaed commented Sep 29, 2012

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