First we have to find a way to insert the needed glyph.
The standard font Computer Modern does not include a ſ, so another font is needed.
A good alternative is Latin Modern, which should be mostly compatible with Computer Modern but features a significantly wider range of characters.
Latin Modern has ſ
encoded in slot 115 (ASCII s) of the TS1
encoding.
To make the TS1
encoding available, replace
\usepackage[T1]{fontenc}
with
\usepackage[TS1,T1]{fontenc}
Then you have two options: Use Latin Modern for you entire document or only use one glyph from this font. If you want to use the complete font, add
\usepackage{lmodern}
\DeclareUnicodeCharacter{17F}{{%
\fontencoding{TS1}%
\selectfont s%
}}
To avoid changing the global font, you can instead add
\DeclareUnicodeCharacter{17F}{{%
\fontencoding{TS1}%
\fontfamily{lmr}%
\selectfont s%
}}
This tells LaTeX to use the s
from encoding TS1
(and family lmr
), whenever Unicode character U+017F
is requested.
\documentclass[english]{article}
\usepackage[TS1,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{lmodern}
\DeclareUnicodeCharacter{17F}{{%
\fontencoding{TS1}%
\selectfont s%
}}
\begin{document}
ſ
\end{document}
A more elegant solution would be switching to LuaLaTeX, there you can directly use ſ
as long as the character exists in your font.