I want to use \futurelet to test the following token. Towards this end I have a setup that looks like the following:
\makeatletter
\def\@ExpandSub{%
\typeout{Given Input: \meaning\@input}%
\typeout{Followup command: \meaning\@following}%
\ifx\@following\UTFviii@three@octets% <--- doesn't work!
\typeout{>>> That's unicode!}%
\else%
\typeout{>>> That's NOT unicode...}%
\fi%
}
\protected\def\sub#1{%
\let@input#1%
\futurelet@following@ExpandSub%
}
\makeatother
- How can I test if the next token is a Unicode character
\ifx\@following\UTFviii@three@octetsdoesn't work, I think because\@followingholds a protected macro that holds\UTFviii@three@octetsinstead of\UTFviii@three@octetsitself. The logs say:Followup command: \protected macro:->\UTFviii@three@octets �, but I want the replacement macro as it was specified inside\newunicodecharinstead. - If this is the case, how can I get the substitute macro, as defined by
\newunicodechar?
This is an attempt to implement Automatically combine unicode double subscripts aᵢⱼ = a_{i}_{j} as a_{ij}.
Full Demo\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}
\usepackage{newunicodechar}
\makeatletter
\newtoggle{insub}
\def@ExpandSub{%
\typeout{Given Input: \meaning@input}%
\typeout{Followup command: \meaning@following}%
% if \@following is \UTFviii@three@octets, get the replacement text
\ifx\@following\UTFviii@three@octets% <--- doesn't work!
\typeout{>>> That's unicode!}%
\else%
\typeout{>>> That's NOT unicode...}%
\let\@actual\@following
\fi%
\iftoggle{insub}{
\@input%
}{
\toggletrue{insub}%
\sb\bgroup\@input%
}%
\ifx\@actual\sub%
\typeout{keep going!}%
\else%
\typeout{Stop!}%
\egroup\togglefalse{insub}%
\fi%
}
% \DeclareRobustCommand*{\sub}[1]{\futurelet@following@ExpandSub{#1}}
\protected\def\sub#1{%
\let@input#1%
\futurelet@following@ExpandSub%
}
\makeatother
\AtBeginDocument{
\newunicodechar{ᵢ}{\sub{i}}
\newunicodechar{ⱼ}{\sub{j}}
\newunicodechar{ₖ}{\sub{k}}
\newunicodechar{ₗ}{\sub{l}}
\newunicodechar{ₘ}{\sub{m}}
\newunicodechar{ₙ}{\sub{n}}
}
\begin{document}
\begin{tabular}{l}
$a_{ijklmn}$ \
%$a\chain{i}\chain{j}\chain{k}\chain{l}\chain{m}\chain{n}$ \
$a\sub{i}\sub{j}\sub{k}\sub{l}\sub{m}\sub{n}$ \
% $a\sub[i]\sub[j]\sub[k]\sub[l]\sub[m]\sub[n]$ \
$aᵢⱼₖₗₘₙ$
\end{tabular}
\end{document}
Related:
\@followingwhile it could be a unicode byte as well as primitive commands such as\mathrmor\kern. – Symbol 1 Feb 14 '24 at 20:35\csname u8:α\endcsnamefor the characterα. – user202729 Feb 15 '24 at 01:32\let\@input#1??? This undefines\inputnot even within a group, did you intend that? – David Carlisle Feb 15 '24 at 14:38