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 Answers 4

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}
10
  • Thank you very much for your fast answer with clear examples! Nov 21, 2014 at 21:21
  • wouldn't inverted accent-grave be a bit better?
    – yo'
    Nov 22, 2014 at 15:38
  • @tohecz I don't think so, but it depends on preferences.
    – egreg
    Nov 22, 2014 at 15:52
  • 1
    @Masi I have a workaround (ugly). The best thing to do would be persuading the maintainer of europecv that using utf8 is good. A new question is surely necessary: other people might incur in the same problem.
    – egreg
    Dec 15, 2014 at 14:31
  • 1
    @Masi The game is the usual one: open a new question with a MWE
    – egreg
    Feb 26, 2015 at 14:10
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}
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)

11
  • 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. Nov 22, 2014 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. Nov 22, 2014 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, 2014 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, 2014 at 15:52
  • 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, 2014 at 9:09
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
  • 3
    I wouldn't recommend loading utf8x
    – egreg
    Nov 21, 2014 at 21:06
  • @egreg: I know... it's outdated
    – user31729
    Nov 21, 2014 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.) Nov 22, 2014 at 14:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .