# Implementing \DeclareUnicodeCharacter in LuaLaTeX an XeLaTeX

In my code, I used to write

\DeclareUnicodeCharacter{27E6}{\begin{description}} % ⟦
\DeclareUnicodeCharacter{27E7}{\end{description}} % ⟧
\DeclareUnicodeCharacter{2022}{\item} %  •


which worked great with pdflatex. Moving to lualatex the command does not compile. Is there a way I can define my version of \DeclareUnicodeCharacer so that it still works?

-

I'd consider

⟦
•[Gnats] are small animals
•[Gnus] are big animals
⟧


as code obfuscation. Anyway, this works with all engines. However, for pdflatex it requires utf8 passed to inputenc or inputenx (as opposed to utf8x).

\usepackage{newunicodechar}
\newunicodechar{⟦}{\begin{description}}
\newunicodechar{⟧}{\end{description}}
\newunicodechar{•}{\item}


If you want to reuse the declarations you already have, you could do like this:

\documentclass{article}
\usepackage{ifxetex,ifluatex}

\newif\ifunicode
\ifxetex\unicodetrue\fi
\ifluatex\unicodetrue\fi

\ifunicode
\usepackage{fontspec}
\usepackage{newunicodechar}
\newcommand{\DeclareUnicodeCharacter}[2]{%
\begingroup\lccode|=\string"#1\relax
\lowercase{\endgroup\newunicodechar{|}}{#2}%
}
\else
\usepackage[utf8]{inputenc}
\fi

\DeclareUnicodeCharacter{27E6}{\begin{description}} % ⟦
\DeclareUnicodeCharacter{27E7}{\end{description}} % ⟧
\DeclareUnicodeCharacter{2022}{\item} %  •

\begin{document}

Some text
⟦
•[Gnats] are small animals
•[Gnus] are big animals
⟧
and some other text

\end{document}
`

-
Looks great. But, I have a hundred or so of these. – Yossi Gil Aug 8 '14 at 11:01
@YossiGil A hundred or so of what? – egreg Aug 8 '14 at 11:02
I have a hundred or so of these macros. So, it would require some manual work to convert \DeclareUnicodeCharacter to a simple \newunicodechar. But your final macro solved this. – Yossi Gil Aug 8 '14 at 12:57
I wonder why you consider this obfuscation? I use macros of this sort extensively, and it does help to remove clutter from the LaTeX code. It comes in very handy in making beamer applications. I have macros that convert control sequences to unicode, so typing is never an issue. – Yossi Gil Aug 8 '14 at 13:18