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.

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)..

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

\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

enter image description here

share|improve this answer
    
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
add comment

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}
\newcommand{\loadencoding}[1]{%
  \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}

\loadencoding{T1}
\loadencoding{T2A}


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

This will print

ń ń Ш

share|improve this answer
add comment

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.