# Command names with utf-8/special characters

Is it possible to define

\newcommand{\√}[1]{\sqrt{#1}}


as commands like this one would sometimes be easier to use.

-
Which engine do you use? This is awkward in pdfTeX, but easy enough with a UTF-8 engine. –  Joseph Wright Sep 10 '11 at 14:21
i guess you mean something like luatex with a utf-8 engine, i'm using pdflatex. –  epsilonhalbe Sep 10 '11 at 15:06

If there were no argument to the macro, this would be just a matter of loading the newunicodechar package or using the \DeclareUnicodeCharacter macro. For the "character" to accept arguments, a slightly different approach is needed.

If you use XeTeX or LuaTeX, you can use either of

\catcode\√=\active
\newcommand{√}[1]{\sqrt{#1}}
…
$√{2}$


or

\newcommand{\√}[1]{\sqrt{#1}}
…
$\√{2}$


(The second approach is more robust.)

With pdfTeX the \√ syntax will not work because of the way pdfTeX handles input (it is theoretically possible to achieve this, though). This leaves the only way (taken and modified from newunicodechar documentation):

\documentclass{article}

\usepackage[utf8]{inputenc}

\expandafter\newcommand\csname u8:\detokenize{√}\endcsname[1]{%
\sqrt{#1}}

\begin{document}

$√{2}$

\end{document}

-
thanks - curiously with luatex characters like '⟨','⟩' don't work well but otherwise - it is great. Definitely something i should have a look at. till now i've worked with pdflatex –  epsilonhalbe Sep 10 '11 at 15:04
@epsilonhalbe: \newunicodechar{⟨}{\langle} \newunicodechar{⟩}{\rangle}` works for me in LuaTeX and TeX Live 2011. –  Andrey Vihrov Sep 10 '11 at 15:13
ah thanks - most definitely should look at LuaTeX - should i watch something when migrating from pdfTeX, are there any complications/breaking points - looking through 20 pages for errors would be gruesome. –  epsilonhalbe Sep 10 '11 at 15:28
@epsilonhalbe: See these questions: one two three –  Andrey Vihrov Sep 10 '11 at 16:08
the move to LuaLaTeX was the best thing TeXrelated I did in the last few months - thanks again. –  epsilonhalbe Dec 21 '11 at 0:56