Enter single unicode code point in (dvi)latex and latin1 input

For various reasons, I'm stuck with (dvi)latex and inputencoding latin1. I still want to enter unicode codepoints (I have the hex/decimal numbers ready).

I have seen http://tex.stackexchange.com/a/32514/24158 but this does not seem to work for me:

\documentclass{article}
\usepackage[latin1]{inputenc}
\begin{document}
\symbol{324}
\end{document}


I just get some ! Bad character code (324)..

-

\symbol{324} can only take values in the 8-bit range and refers directly to the underlying font not going through latex's encoding mechanisms.

Any symbol for which there is support in \usepackage[utf8]{inputenc} will have a mapping from the Unicode number to a TeX definition in the utf8 files in the base distribution, or you can directly code something. so Unicode 324 is LATIN SMALL LETTER N WITH ACUTE so you can use \'{n} which corresponds to this line in utf8enc.dfu in the base latex distribution

\DeclareUnicodeCharacter{0144}{\@tabacckludge'n}


decimal 324 being hex 144

If you don't want to look up the definitions in the file, you can load the file with a local definition that removes the utf8 decoding part:

\documentclass{article}
\usepackage[latin1]{inputenc}
\def\DeclareUnicodeCharacter#1#2{%
\expandafter\def\csname ut-#1\endcsname{#2}}
\def\UseUnicodeCharacter#1{\csname ut-#1\endcsname}

\makeatletter\input{utf8enc.dfu}\makeatother
\begin{document}

aaaa\UseUnicodeCharacter{0144}bbb

\end{document}


produces

-
The interesting question is: Can I use the tables in the base distribution? Like how can I use that \DeclareUnicodeCharacter{0144}{\@tabacckludge'n} and have something like a \InsertUnicode{0144} which goes through those tables and finally does the \@tabacckludge'n? Using \'{n} is an option for individual characters, but I would prefer to be able to enter unicode codepoints, because those are in my sources. –  Elrond Apr 15 '13 at 15:44
@Elrond see updated code –  David Carlisle Apr 15 '13 at 15:56

Input the relevant file, for instance t1enc.dfu for the characters obtainable in the T1 encoding. Just assign a suitable definition to \DeclareUnicodeCharacter.

\documentclass{article}
\usepackage[T2A,T1]{fontenc}
\usepackage[latin1]{inputenc}
\begingroup
\def\DeclareUnicodeCharacter##1##2{%
\expandafter\gdef\csname uni\number"##1\endcsname
{{\fontencoding{#1}\selectfont##2}}}
\makeatletter
\lowercase{\input{#1enc.dfu}}%
\endgroup}
\newcommand\unisymbol[1]{\csname uni\number#1\endcsname}

\begin{document}
\unisymbol{324} \unisymbol{"0144} \unisymbol{"0428}
\end{document}


This will print

ń ń Ш

-