# Changing unknown characters into known ones in Latin1

I'm currently trying to create a problem set for some students, so it involves copy-pasting from several places. But, for instance, for geometry problems, when I copy a gamma, I get "Γ", which isn't supported by Latin1... I want to stay in Latin1 because it has all the accents which I need...

The problem is that when I compile, "Γ" gets to "?", and then I have to change it all manually...

Could there possibly be a function adding signs to Latin1, or replacing signs as "Γ" to "$\Gamma$"?

I've found this:

\documentclass[11pt]{article}
\usepackage[latin1]{inputenc}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\myreplace}{m}
{
\tl_set:Nn \l__maxd_argument_tl { #1 }
\tl_replace_all:Nnn \l__maxd_argument_tl { - } { . }
\tl_replace_all:Nnn \l__maxd_argument_tl { Γ } { $\Gamma$ }
\tl_use:N \l__maxd_argument_tl
}
\tl_new:N \l__maxd_argument_tl
\ExplSyntaxOff

\begin{document}
\myreplace{---}
\myreplace{Γ}
\end{document}


This code searches for all "-" and "Γ" and replaces them by "." and "$\Gamma$" respectively So I get "...$\Gamma$", as wanted.

But this doesn't actually search for the "Γ" and replaces them, but it searches for what it knows as "Γ", thus "?"... So my function should be done before the Latex compiles

Thus if I want to create a code replacing more than one unknown characters, this won't work. Does anyone have an idea?

• "replacing signs as "Γ" to "$\Gamma$" Wouldn't that be a simple editor function? – Steven B. Segletes Feb 8 '18 at 20:04
• Well yes, but how do you create that one? I want it to be part of my Latex code, so I don't have to pass through a third party app, but it has to change before it compiles... – Taumen Feb 8 '18 at 20:06
• You say "if I want to create a code replacing more than one unknown characters, this won't work". But \myreplace{Γ-Γ-Γ} substitutes for multiple instances of both, so what exactly do you mean? – Steven B. Segletes Feb 8 '18 at 20:08
• how about newunicodechar? – Peater de Xel Feb 8 '18 at 20:10
• this question seems very confused! If there is Γ in the file then the file is clearly not in latin1 so the inputenc declaration is wrong. Is your file in UTF-8 (the file as posted to this website is always in UTF-8 so it is not possible to tell your original encoding) – David Carlisle Feb 8 '18 at 20:18

Despite your inputenc declaration, your input file can not be in latin1 encoding. I will make an assumption here that it is UTF-8 (like the version posted in the question) If so you can simply declare the character to use the math font character:

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{newunicodechar}
\newunicodechar{Γ}{\ensuremath{\Gamma}}
\begin{document}

some text with é and ü and Γ
\end{document}

• What, no suggestion to switch to LuaLaTeX with fontenc? – user139954 Feb 8 '18 at 22:39
• @RobtAll given the confusion in the question suggesting switching to a somewhat experimental system (especially for mathematics) without further background detail wouldn't be necessarily a good idea. – David Carlisle Feb 8 '18 at 22:43
• @Davislor in general but T1 is preloaded so it is known to inputenc already – David Carlisle Mar 31 '18 at 11:14
• Looking it up, my previous comment was out of date as of inputenc v1.2c. The documentation now says, “At the start of the document (\begin{document}) it examines all font encodings that are being used within the current document" when you use [utf8]. I seem to recall that previous versions needed to be loaded after fontenc, but what you wrote is fine. – Davislor Mar 31 '18 at 18:21
• @Davislor you might want to also look who's edited inputenc in recent years:-) – David Carlisle Mar 31 '18 at 18:50

There are a few packages that do what David Carlisle’s answer recommends, more systematically. In particular, the alphabeta package with a font that supports the LGR encoding will define the macros you want for Greek letters and allow you to use Greek input in both text mode and math mode. All the text-mode characters should be handled by inputenc.

You still might want to use newunicode character for certain math symbols in PDFTeX, as his answer suggests, because inputenc does not set them up. For example, to write ∈ℝ, you would create the mappings \newunicodechar{∈}{\ensuremath\in} and \newunicodechar{ℝ}{\ensuremath\mathbb{R}}.

This example uses unicode-math if run in either LuaLaTeX or XeLaTeX. I highly recommend it unless you have to use PDFTeX. It’s more powerful, supports more fonts and is easier to use.

I also highly recommend that you save all new source files in UTF-8.

\RequirePackage{luatex85} % Workaround for standalone 1.2 and LuaTeX.
\documentclass[preview,varwidth]{standalone}
\usepackage{iftex}

\ifPDFTeX
\usepackage[LGR,T1]{fontenc}
\usepackage{textcomp}
\usepackage[utf8]{inputenc}
\usepackage{alphabeta}
\usepackage{lmodern}
\else
\usepackage[math-style=TeX]{unicode-math}
\fi

\begin{document}
Some text with é and ü and Γ.  $$α = r \sin φ \cos θ$$.
\end{document}