# Non-ascii character as argument

I want to do something special with some characters in the text. In this example that is just boldfacing them:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\newcommand\<[1]{\textbf{#1}}

\begin{document}
f\<oo b\<ar b\<öll
\end{document}


This works fine for the two first cases, but not for the non-ascci character "ö". There is an error message

! Package inputenc Error: Unicode char \u8:\check@icr not set up for use with LaTeX.


which is reported between the two bytes making up "ö" in utf8.

1. I know this works with XeLaTeX or LuaLaTeX (just by removing the inputenc line). It does not work in pdfLaTeX and (DVI)LaTeX.

2. One workaround is to write \<{ö}.

3. But is there a way to get this to work with pdflatex without that workaround?

(In the actual application an active character is used, since the point is to have something that disturbs the view of the source text as little as possible.)

-
I think the short answer here is 'no': something like ö is two bytes and thus two args for pdfTeX, while a 'normal' letter such as o is only one byte. Thus you can't grab an undelimited argument 'safely' while allowing for UTF-8 with an 8-bit engine. –  Joseph Wright May 12 at 9:18
I feared that, but hoped that it would be possible to let the command catch just the first byte and then do something more. –  pst May 12 at 9:20
You can imagine partial solutions, e.g. grab one token, test catcode, if active grab second token and re-insert. The problem is that you leave open edge cases where it will fail: no truly general solution exists, I think. –  Joseph Wright May 12 at 9:22
@pst obviously it is possible to do that but you would have to do it for every command, that is you could define \< such that if its argument was an active character with definition that used the utf8 two byte handler macro, that it called a helper macro that grabbed the utf8 sequence braced it and then called the original \< but how many commands would you need to redefine? –  David Carlisle May 12 at 9:23

You can do this, but I'm not sure you should:-)

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

%\newcommand\<[1]{\textbf{#1}}
\makeatletter
\def\<{\expandafter\zz}
\def\zz#1{%
\ifx\UTFviii@two@octets#1% could be 3 or 4 octets, but not today
\expandafter\zztwo
\else
\expandafter\zzone{#1}%
\fi}
\def\zztwo#1#2{\zzone{\UTFviii@two@octets#1#2}}
\makeatother
\def\zzone#1{\textbf{#1}}

\begin{document}

f\<oo b\<ar b\<öll

f\<{o}o b\<ar b\<{ö}ll

\end{document}

-