How can one compare a character (e.g. "U") with a character code in a certain font (e.g. "\char85").

I'd expect the following to work:

U looks like \char85, ...%
\if U \char85 { and U is \char85 } \else { but U is not \char85 } \fi

% Or using the `ifthen` package:    
\ifthenelse{\equal{U}{\char85}}{ then U is U too }{ then U is not U, too }

Alas, neither works as expected.

Thoughts and input are appreciated.


It is helpful to note that:

\meaning \char 85 \\
\meaning \char'U  \\
\meaning U

Produces the output:

the letter U

These are clearly different internally, and I presume must be normalized before comparison.

  • In the first two cases, the \meaning is just showing the meaning of \char. This is more obvious if you use \show. You can see that it hasn't looked at the 85 or 'U (Presumably, you mean <code>`U</code> anyway.) – TH. Jan 21 '11 at 21:43
  • @TH.: <code> doesn't work in comments. In this case, `U`` would have done it :-). – Hendrik Vogt Jan 22 '11 at 8:46
  • 1
    What exactly are you trying to determine? That is, when is this test not going to return true? When you type ``U, you'll always get 85` as the interpreted number. You can't ask the font for which character is at a certain slot; it just doesn't work that way. – Will Robertson Jan 23 '11 at 0:56
  • @Hendrik: I guess I knew it wouldn't work, but I couldn't be bothered trying to figure out how to get the markdown to work. I wish comments were consistent with answers and questions. (Just testing. ``U`.) – TH. Jan 23 '11 at 2:06

There isn't a notion of a character code in a font. I think what you're looking for is

\ifnum`U=85 ...\else ...\fi

Note that since U has ASCII value 85, U and \char85 are both going to give you character in position 85 of the current font.


do you mean something like this?


U looks like \char85, ...%
\ifx\tempA\tempB and U is \char85 \else but U is not \char85 \fi


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.