Fonts & Character SetsChanging mapping of single characters

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
Post Reply
untexnixal
Posts: 3
Joined: Sun Feb 01, 2009 2:12 am

Changing mapping of single characters

Post by untexnixal »

General question: how do I change the mapping of a single character?

Details: I want all instances of ``, '', and --- to output a left single quote, a right single quote, and an en dash respectively. I need to do this for one of two copies of a document I'm making. The other will retain the default mapping.

Thanks

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Changing mapping of single characters

Post by phi »

Generally, you should find a higher-level solution. The resolving of `` into “ is hard-coded in the font as a ligature. This cannot be easily changed. Consider defining semantic macros like \quote and \dash whose definition you can change easily.
Nevertheless, a crude hack makes it possible to change the meaning of characters. But this will most certainly fail if your document contains anything else than simple text. Sometimes hacks like this are fun to play with, but generally I strongly advise against them because they alter the most basic parts of LaTeX fundamentally and are highly fragile.

Code: Select all

\documentclass{article}

\makeatletter
\let\normal@asciigrave`
\let\normal@asciiapos'
\let\normal@asciihyphen-
\catcode96 13
\catcode39 13
\catcode45 13
\def`{\normal@asciigrave\@ifnextchar`\@gobble\@empty}
\def'{\normal@asciiapos\@ifnextchar'\@gobble\@empty}
\def-{\@ifnextchar-\check@emdash\normal@asciihyphen}
\def\check@emdash-{\textendash\@ifnextchar-\@gobble\@empty}
\makeatother

\begin{document}

``aa''---bb

\end{document}
Post Reply