# How to automatically replace one letter with another before rendering

## Short version

I use the letter X in my document. When I convert the *.tex to *.pdf, I want all occurrences of X to be replaced with Y, akin to if I opened the "search and replace" function in the text editor and replaced X with Y.

## Long version

There is a certain letter in Russian language known as Yo (ё) which is a cause of a long-running holywar. Some people use it everywhere where it is appropriate in accordance with the rules of orthography. Some people replace it with the letter Ye (е) everywhere where it is still possible to understand the word. And some people simply do not use it at all. Sadly, many scientific journals (for whatever reason) fall in the last category.

I want to write proper, grammatically correct text using ё everywhere it is needed, and still be able to easily tell LaTeX to compile the "umlautless" version of the document.

The following settings in the preamble

\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{0451}{\"{e}}


will produce ё as composed character. Of course this can be also used to produce the umlautless version

\DeclareUnicodeCharacter{0451}{e}

• Other suggestions caused obscure errors for my (admittedly troublesome) document, while yours worked. Please have a green tick good Sir. – ScumCoder May 26 '19 at 21:07

# 8-bit TeX engines, \usepackage[utf8]{inputenc}

% Redefine Yo/ye for umluatless version
\usepackage{newunicodechar}
\newunicodechar{Ё}{Е}
\newunicodechar{ё}{е}


# Unicode TeX engines (LuaTeX, XeTeX)

% Umlautless version
\catcode\Ё=\active
\defЁ{E}
\catcode\ё=\active
\defё{e}

• You are awesome. – ScumCoder Jul 16 '16 at 11:55

You can make it an active character, see TeX FAQ

\documentclass{article}

\catcode\X=\active
\def  X{Y}

\begin{document}
XZXZ
\end{document}
`