9

(Please take the following question rather for a moot point than for an everyday-problem.)

Is there an expandable method for distinguishing an arbitrary explicit non-active character token from its active pendant while the active pendant is let equal to the arbitrary explicit non-active character token in question?

In other words:

Assume, you have, e.g.,

\catcode`\A=11\relax
\let\Mytemp=A
\catcode`\A=13\relax
\let A=\Mytemp

Is there an expandable method for in such circumstances distinguishing, e.g., an A of catcode 11(letter) from an A of catcode 13(active)?

The method should also work out in pure expansion contexts, e.g., within \csname..\endcsname, within \edef, ...

The method should also work out in situations where Lua-extensions are not available.

The method should also work out in situations where eTeX-extensions are not available.

The method should also work out in situations where pdfTeX-extensions are not available.

The method should also work out in situations where you cannot rely on \escapechar or the like parameters having specific values.

The method should also work out with unicode-based TeX-engines like XeTeX or LuaTeX.

The method should also work out with arbitrary explicit character tokens, not just with A.

(If the character in question was specified at the time of implementing the routine, you could use delimited arguments for the check.

With 8bit-encoding-based engines where you have 256 code points, you could probably have 256 macros, each of these macros having another active character as argument-delimiter...

I doubt this is feasible with unicode-based/utf8-encoding-based engines where you have 1114112 possible code-points and thus would need 1114112 macros, each of these macros having another active character as argument-delimiter...)


Another similar problem:

\escapechar=-1
\catcode`\A=11
\catcode`\B=11
\let\A=A
\let\B=B

How to expandably distinguish \A from A? How to expandably distinguish \B from B? (Same requirements as in the previous question.)

  • May I suggest that you rephrase the title of the question like this “How to distinguish an explicit active character from its implicit equivalent with purely expandable methods”? – GuM Aug 26 '18 at 23:19
  • @GuM No. What is an implicit equivalent of an active character? When letting an active-X equal to a letter-X, then the active-X is also an implicit letter-X ... That's why distinguishing them is difficult. The implicit equivalent of an active-X let equal to a letter-X (here the active-X would itself be an implicit letter-X) would be some other implicit character, e.g., the control-word-token \foobar after \let\foobar=X... – Ulrich Diez Aug 26 '18 at 23:44
  • I surrender… :-) I’m going to add the “tex-core” tag, however: I’ve just tried to look up this question through that tag, and I’ve been a bit surprised not to find it. – GuM Aug 27 '18 at 0:54
  • I don't understand "I doubt this is feasible with utf8-encoding... ". What is not feasible then? anyhow your question does not seem to be about multi-bytes like é is in utf-8 ? – user4686 Aug 29 '18 at 8:53
  • @jfbu In 8-bit-encodings you have 2^8=256 possible code-points. Thus in 8-bit encodings could probably do with 256 macros, each of them having another active character as delimited argument. utf8 is one of several methods of representing the 1114112 possible code-points of unicode by means of byte-patterns/bit-patterns. With 1114112 possible codepoints 114112 different characters are possible, thus you'd need 1114112 macros, each of them having another active character as delimited argument... – Ulrich Diez Aug 29 '18 at 9:16
8

Bit of a cheat as it doesn't work for an arbitrary token, but for A-F

The following expandable test in a \write produces

A is a special A: no
A is a special A: yes

from

\def\fooz#1{%
 \immediate\write20{%
  #1 is a special A: \if A\ifnum0="0#1\fi yes\else no\fi}}


\fooz{A}

\catcode`\A=11\relax
\let\Mytemp=A
\catcode`\A=13\relax
\let A=\Mytemp


\fooz{A}

\bye
  • Very clever, but, indeed, too specific! Cannot decide whether to upvote or not! :-( :-| :-) – GuM Aug 26 '18 at 22:44
  • @GuM I posted my question for the fun that comes from the inherent bizarreness. I did not post for whatsoever votes. :-) – Ulrich Diez Aug 26 '18 at 23:48
  • @UlrichDiez: Actually, in the end I did upvote this answer, exactly because of its bizarreness… and because it teaches something very subtle! – GuM Aug 27 '18 at 0:58
  • @GuM While my question is sort of bizarre, David Carlisle's answer is intriguing. In matters of (La)TeX I often encounter the phenomenon of getting fascinating answers to my bizarre questions. :-) – Ulrich Diez Aug 27 '18 at 1:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.