# 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. Sep 10, 2011 at 14:21
• i guess you mean something like luatex with a utf-8 engine, i'm using pdflatex. Sep 10, 2011 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 Sep 10, 2011 at 15:04
• @epsilonhalbe: \newunicodechar{⟨}{\langle} \newunicodechar{⟩}{\rangle}` works for me in LuaTeX and TeX Live 2011. Sep 10, 2011 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. Sep 10, 2011 at 15:28
• @epsilonhalbe: See these questions: one two three Sep 10, 2011 at 16:08
• the move to LuaLaTeX was the best thing TeXrelated I did in the last few months - thanks again. Dec 21, 2011 at 0:56