Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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}

enter image description here

share|improve this answer
    
Looks great. But, I have a hundred or so of these. –  Yossi Gil Aug 8 at 11:01
    
@YossiGil A hundred or so of what? –  egreg Aug 8 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 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 at 13:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.