6

I type in English but I need the following few Latvian letters.

Minimal case

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
diņš 
\end{document}

which gives di only.

How can you have those Latvian letters?

4 Answers4

11

The letter š is supported by the T1 encoding and you should load

\usepackage[T1]{fontenc}

anyway. The “n with cedilla” is not supported by the fonts, so it must be composed. With newunicodechar it's pretty easy:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{newunicodechar}
\newunicodechar{Ņ}{\c{N}}
\newunicodechar{ņ}{\c{n}}

\begin{document}
diņš DIŅŠ
\end{document}

However you might prefer a comma below, instead of a cedilla.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{newunicodechar}

\makeatletter
\ProvideTextCommandDefault\textlatviancommabelow[1]
  {\hmode@bgroup\ooalign{\null#1\crcr\hidewidth
     \raise-.15ex\hbox{\check@mathfonts
                       \fontsize\ssf@size\z@
                       \math@fontsfalse\selectfont,}\hidewidth}\egroup}
\makeatother

\newunicodechar{Ņ}{\textlatviancommabelow{N}}
\newunicodechar{ņ}{\textlatviancommabelow{n}}

\begin{document}
diņš DIŅŠ
\end{document}

enter image description here

With some more work you can make the composite character copyable (provided the PDF viewer supports the feature; Adobe Reader does); the following is similar to my answer to Unable to search word with Romanian characters in output pdf

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{accsupp}
\usepackage{newunicodechar}

\makeatletter
\ProvideTextCommandDefault\textlatviancommabelow[1]
  {\hmode@bgroup\ooalign{\null#1\crcr\hidewidth
     \raise-.15ex\hbox{\check@mathfonts
                       \fontsize\ssf@size\z@
                       \math@fontsfalse\selectfont,}\hidewidth}\egroup}
\makeatother

\newunicodechar{Ņ}{%
  \BeginAccSupp{method=hex,unicode,ActualText=0145}%
    \textlatviancommabelow{N}%
  \EndAccSupp{}%
}
\newunicodechar{ņ}{%
  \BeginAccSupp{method=hex,unicode,ActualText=0146}%
    \textlatviancommabelow{n}%
  \EndAccSupp{}%
}
\begin{document}
diņš DIŅŠ
\end{document}
egreg
  • 1,121,712
7

UTF-8 input is fine, you just need to tell tex what to do with that character:

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\DeclareUnicodeCharacter{0146}{\c{n}}
\begin{document}
diņš 
\end{document}
David Carlisle
  • 757,742
6

If you can use XeLaTeX or LuaLaTeX, I would like to welcome you to current century:

\documentclass{article}
\usepackage{polyglossia} % also loads package fontspec
\setmainfont{Minion Pro} % or whatever OTF you have on your system
\setmainlanguage{latvian} % loads language hyphenation rules and such

\usepackage{unicode-math} % if you also need maths
\setmathfont{Cambria Math} % or whatever math OTF you have on your system

\begin{document}
diņš
\end{document}

(and save your files in utf8)

morbusg
  • 25,490
  • 4
  • 81
  • 162
  • I really like this answer! Kiitos! @egrep What do you think about this? I think the typography here is better. What are possible side-effects etc? I only need those Latvian characters to type the name of my university. Mostly, I am writing English. I like the math-things there too. – Léo Léopold Hertz 준영 Nov 22 '14 at 15:42
  • I set the language to be english as \setmainlanguage{english} and I still get the correct symbols for the name of my university. So "Contents" is seen correctly, and not in Latvian. – Léo Léopold Hertz 준영 Nov 22 '14 at 15:45
  • @Masi: Jūs esat laipni. (I hope Google translate did that correctly). But yes, I assumed your text would've been in Latvian, but I see you already found out how to change that :) – morbusg Nov 22 '14 at 15:49
  • 1
    @Masi If you're bound to pdflatex this is nothing you can make profit of. If you can use XeLaTeX or LuaLaTeX, of course you get the “real” glyph. – egreg Nov 22 '14 at 15:52
  • @egreg I am not bound to pdflatex. I am using XeLaTeX at the moment. It is very nice to understand these different environments. I just need the best typography for my application. – Léo Léopold Hertz 준영 Nov 22 '14 at 17:36
  • @Masi Your question assumed pdflatex, though. – egreg Nov 22 '14 at 17:37
  • @egrep How can you see it? I am such an newbie still that I did not intend to make such an assumption. – Léo Léopold Hertz 준영 Nov 22 '14 at 17:38
  • 1
    @Masi: I guess egreg didn't see your question because you misspelled his handle, but I think what he meant is that the line: \usepackage[utf8]{inputenc} would assume PDFLaTeX because you wouldn't use it with (Lua/Xe)LaTeX. Although, to know that already requires some amount of expertise. I think it would be helpful to draw some kind of diagram regarding different engine choices and link it to our help pages. – morbusg Nov 29 '14 at 09:09
  • @morbusg Can you draw such a diagram? Or know any sources? It would be very useful. – Léo Léopold Hertz 준영 Nov 29 '14 at 11:43
  • @Masi: yes, I'll work something out and put it on meta for discussion. – morbusg Nov 30 '14 at 17:26
  • @morbusg Please, point me to a link when it is done or started. – Léo Léopold Hertz 준영 Dec 01 '14 at 17:30
2

It's the older version: utf8x, but this works with pdflatex

\documentclass{article}
\usepackage[T1]{fontenc}%
\usepackage[utf8x]{inputenc}
\begin{document}
diņš 
\end{document}

enter image description here

  • 3
    I wouldn't recommend loading utf8x – egreg Nov 21 '14 at 21:06
  • @egreg: I know... it's outdated –  Nov 21 '14 at 21:07
  • @ChristianHupfer ... it’s outdated, but it works here. if the user agrees to sign a declaration that he’ll never use the package elsewhere, perhaps he should be allowed to use it. after all, it saves him typing. (in fact, errors with utf8x are pretty rare, so they tend to “throw” us when they do appear.) – wasteofspace Nov 22 '14 at 14:40