11

I am puzzled with sections titled with Greek characters. They do appear in the pdf's Content list, though not correctly.

For example, in my thesis--written in English with LyX, based on the KOMA-script--I choose to include a translation of the summary in Greek (=Περίληψη). The "raw" code for the (unnumbered) chapter title reads: \addchap{\textgreek{Per\char208lhyh}}. In the final .pdf file (using pdflatex) the respective entry appears as Per208lhyh. Using the unicode option for the hyperref package does not fix the problem.

Update detail: the document (should) not only contain Chapter or Section titles in Greek, but normal text as well.

I have found some relevant references within tex.stackexchange and elsewhere (e.g., https://tex.stackexchange.com/a/21675/8272, the manual of the textgreek package, http://www.latex-community.org/forum/viewtopic.php?f=5&t=6059, http://newsgroups.derkeiler.com/Archive/Comp/comp.text.tex/2005-12/msg00944.html). However, I cannot extract a concrete answer.

How can Greek characters appear correctly as bookmarks in the .pdf's Content list?

Note, the information of this Q&A applies to/under LyX as well.

6
  • Did you try inputting \addchap{\textgreek{Per'ilhyh}}? This is the correct way to write accents inside \textgreek.
    – egreg
    Jan 19, 2012 at 16:50
  • It appears, in the pdf's Content list, as Per'ilhyh :-) Jan 19, 2012 at 18:28
  • 5
    I believe that this is the best you can get: hyperref doesn't understand \textgreek, in the sense that it only uses the character codes, while \textgreek uses a special font with suitable characters. A different approach requires to input both the Unicode version and the ASCII via \texorpdfstring{\textgreek{Per'ilhyh}}{Περίληψη}
    – egreg
    Jan 19, 2012 at 18:37
  • It is like \addchap{\texorpdfstring{\textgreek{Per'ilhyh}}{\textgreek{Per\char208lhyh}}}, right? It doesn't work :-( It gives errors (such as "Could not find LaTeX command for character 'Π'...). All this from within LyX. Will try another day pure LaTeX. Thanks. Jan 19, 2012 at 19:36
  • Of course not: I meant exactly to put the Greek characters in the second argument.
    – egreg
    Jan 19, 2012 at 20:39

4 Answers 4

12

The following works: one has to pass the unicode option to hyperref and also a correct Unicode string for the bookmark:

\documentclass{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[greek,english]{babel}
\usepackage[unicode]{hyperref}
\usepackage{bookmark}
\begin{document}
\mainmatter
\chapter{Introduction}
An introduction.

\cleardoublepage
\begin{otherlanguage}{greek}
\addchap{\texorpdfstring{Per'ilhyh}{Περίληψη}}
Per'ilhyh
\end{otherlanguage}

\end{document}

Unfortunately, the utf8x option to inputenc that would allow to use the Greek alphabet for the language is not compatible with the bookmark system of hyperref.

5
  • 3
    This seems like a perfect use case for xelatex or lualatex. Jan 20, 2012 at 7:29
  • Yep, it works! LyX doesn't want to co-operate though: the option english passed to the documentclass definition (using, as above, the scrbook class) forces all characters to be converted in Greek!? (yes, the word Introduction for example appears as Ιντροδυςτιον). Searching to overcome this since I can't just switch my huge LyX document into a pure LaTeX one. Jan 23, 2012 at 9:35
  • May I extend this question/problem as to cover LyX as well? Jan 23, 2012 at 9:37
  • I think there is something missing in the working minimal example: greek (body) text! After posting to LyX's public ML, a solution seems to be there but not quite. If I add any greek text to the body, the document fails to compile. FYI: mail-archive.com/[email protected]/msg91023.html Feb 9, 2012 at 18:19
  • Currently Greek can be used without utf8x (in another way): tex.stackexchange.com/a/69908/1340 And at least by now (TeXLive 2013) utf8x is compatible with hyperref. See the MWE in tex.stackexchange.com/q/142902/1340, and modify it according to the comments (it's trying to demonstrate another problem). Nov 8, 2013 at 7:40
6

With the new greek-fontenc and updated greek-inputenc packages, you are now able to use Greek Unicode characters in the LaTeX source (and the utf8 "LaTeX encoding" option in LyX).

Together with \usepackage[pdfencoding=auto]{hyperref} his solves the problem with PDF-strings.

Alternatively, Greek LICR macros (like \textalpha ... \textomega) can be used. See the package documentation.

1
  • A very good addition! I'm very happy that your proposals have been accepted and included in the system.
    – egreg
    Jun 14, 2013 at 12:19
5

A minimal working example that answers the raised question about Greek in a PDF's Content (index or bookmark or however it might be called correctly) along with Greek text in the body (of course!):

\documentclass[greek,english]{scrbook}
\usepackage[LGRx,T1]{fontenc} % define LGR and T1 encodings
\usepackage[utf8]{inputenc} % standard UTF-8 input encoding
\usepackage[greek,english]{babel}
\usepackage[unicode]{hyperref}
\usepackage{bookmark}


\begin{document}
\mainmatter

\addchap{\texorpdfstring{Ambivalence/\textgreek{Amfijum'ia}}{Ambivalence/Aμφιθυμία}}

\textit{Ambivalence}, catalyst in spreading the great disease which is called Fear.\\
\begin{otherlanguage}{greek}
\textit{Aμφιθυμία}, καταλύτης στην εξάπλωση της μεγάλης νόσου που ονομάζεται Φόβος.
\end{otherlanguage}

\end{document}

It also works when using [english,greek] (instead of [greek,english]):

\documentclass[english,greek]{scrbook}
\usepackage[LGRx,T1]{fontenc} % define LGR and T1 encodings
\usepackage[utf8]{inputenc} % standard UTF-8 input encoding
\usepackage[english,greek]{babel}
\usepackage[unicode]{hyperref}
\usepackage{bookmark}


\begin{document}
\mainmatter

\selectlanguage{english}
\addchap{\texorpdfstring{Ambivalence/\textgreek{Amfijum'ia}}{Ambivalence/Aμφιθυμία}}

\textit{Ambivalence}, catalyst in spreading the great disease which is called Fear.\\
\\
\begin{otherlanguage}{greek}
\textit{Aμφιθυμία}, καταλύτης στην εξάπλωση της μεγάλης νόσου που ονομάζεται Φόβος.
\end{otherlanguage}

\addsec{\texorpdfstring{Small and Ending sigma: \textgreek{σ}~and~\textgreek{ς},~\textgreek{Mikr'o kai Telik'o s'igma: sv kai s}}{Small and Ending sigma: σ and ς, Μικρό και Tελικό: σ και ς}}

\foreignlanguage{english}{However, in LyX, both sigma~(\textgreek{\textit{σ, ς}})~in a Greek text, do not appear correctly in the Contents of a PDF file}! Why?
\begin{otherlanguage}{greek}\\
\\
Ωστόσο, στο \foreignlanguage{english}{LyX}, και τα δυο σίγμα~(\textit{σ, ς})~σε ελληνικό κείμενο, δεν εμφανίζονται σωστά στα περιεχόμενα ενός αρχείου \end{otherlanguage} PDF! Γιατί;

\end{document}

A LyX (not-so-)Minimal Working Example

#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass scrbook
\begin_preamble
\usepackage{bookmark}
%\usepackage{kerkis}

\usepackage[LGRx,T1]{fontenc} % define LGR and T1 encodings
\usepackage[utf8]{inputenc} % standard UTF-8 input encoding
\end_preamble
\options iso-8859-7,latin9,utf8
\use_default_options true
\begin_modules
fixltx2e
fix-cm
logicalmkup
\end_modules
\maintain_unincluded_children false
\language greek
\language_package default
\inputencoding utf8
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf true
\font_sf_scale 100
\font_tt_scale 100

\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement h
\paperfontsize default
\spacing single
\use_hyperref true
\pdf_title "Ελληνικοί χαρακτήρες στα περιεχόμενα αρχείου PDF"
\pdf_author "Νίκος Αλεξανδρής"
\pdf_subject "Ελληνικοί χαρακτήρες στα περιεχόμενα αρχείου μορφής PDF"
\pdf_keywords "ελληνικά, ελληνικοί χαρακτήρες, pdf, latex, utf8, content, bookmarks, hyperref"
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks true
\pdf_pdfborder true
\pdf_colorlinks true
\pdf_backref page
\pdf_pdfusetitle true
\pdf_quoted_options "unicode=true"
\papersize a4paper
\use_geometry false
\use_amsmath 0
\use_esint 0
\use_mhchem 0
\use_mathdots 0
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date true
\use_refstyle 0
\boxbgcolor #f0f0f0
\index Index
\shortcut idx
\color #008000
\end_index
\leftmargin 10mm
\topmargin 20mm
\rightmargin 20mm
\bottommargin 15mm
\secnumdepth 1
\tocdepth 0
\paragraph_separation skip
\defskip medskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\bullet 0 0 9 -1
\bullet 1 0 8 -1
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Chapter

\lang english
Introduction
\end_layout

\begin_layout Standard

\lang english
Introductive text...
\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
addchap{
\backslash
texorpdfstring{Per'ilhyh}{
\backslash
textvarsigma~
\end_layout

\end_inset

 και 
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
textsigma}}
\end_layout

\end_inset


\end_layout

\begin_layout Standard

\lang english
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
textit{Ambivalence}, catalyst in spreading the great disease which is called
 Fear.
\backslash

\backslash

\end_layout

\begin_layout Plain Layout


\backslash

\backslash

\end_layout

\begin_layout Plain Layout


\backslash
begin{otherlanguage}{greek}
\end_layout

\end_inset


\end_layout

\begin_layout Standard

\lang english
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
textit{
\end_layout

\end_inset


\lang greek
Aμφιθυμία
\lang english

\begin_inset ERT
status open

\begin_layout Plain Layout

}
\end_layout

\end_inset


\lang greek
, καταλύτης στην εξάπλωση της μεγάλης νόσου που ονομάζεται Φόβος.
\end_layout

\begin_layout Standard

\lang english
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
end{otherlanguage}
\end_layout

\end_inset


\end_layout

\begin_layout Standard

\lang english
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
addsec{
\backslash
texorpdfstring{Small and Ending sigma: 
\backslash
textgreek{
\end_layout

\end_inset


\lang greek
σ
\lang english

\begin_inset ERT
status open

\begin_layout Plain Layout

}~and~
\backslash
textgreek{
\end_layout

\end_inset


\lang greek
ς
\lang english

\begin_inset ERT
status open

\begin_layout Plain Layout

},~
\backslash
textgreek{Mikr'o kai Telik'o s'igma: sv kai s}}{Small and Ending sigma:

\end_layout

\end_inset


\lang greek
σ
\lang english

\begin_inset ERT
status open

\begin_layout Plain Layout

 and 
\end_layout

\end_inset


\lang greek
ς
\lang english

\begin_inset ERT
status open

\begin_layout Plain Layout

, 
\end_layout

\end_inset


\lang greek
Μικρό και Tελικό: σ και ς
\lang english

\begin_inset ERT
status open

\begin_layout Plain Layout

}}
\end_layout

\end_inset


\end_layout

\begin_layout Standard

\lang english
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
foreignlanguage{english}{In LyX, the ending sigma~
\backslash
textgreek{
\backslash
textit{
\end_layout

\end_inset


\lang greek
ς
\lang english

\begin_inset ERT
status open

\begin_layout Plain Layout

}}~~in a text with greek does not appear correctly in the Contents of a
 PDF file}!
\end_layout

\end_inset


\end_layout

\begin_layout Standard

\lang english
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
begin{otherlanguage}{greek}
\end_layout

\end_inset


\end_layout

\begin_layout Standard
Στο

\lang english

\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
foreignlanguage{english}{LyX},
\end_layout

\end_inset


\lang greek
 το τελικό σίγμα σε κείμενο με ελληνικά δεν εμφανίζεται σωστά στα περιεχόμενα
 αρχείου
\lang english

\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
foreignlanguage{english}{PDF}
\end_layout

\end_inset


\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
end{otherlanguage}
\end_layout

\end_inset


\lang greek
!
\end_layout

\end_body
\end_document

Credits go to Günter Milde. See also:

1
  • Note: However, in LyX, both sigma (σ, ς) in a Greek text, do not appear correctly in the Contents of a PDF file! Why? Feb 10, 2012 at 18:38
2

As the other TeXnicians suggested, XeLaTeX and hyperref with the unicode option should work perfectly even without the \texorpdfstring command, both for utf8 and utf8x encodings (I have tried that many times without any problems). If not, check out your LyX settings (I don't know much about them since I don't use that program).

However, from experience I would recommend that you stick with iso-8859-7 encoding and pdflatex, because:

  1. Greek hyphenation in utf8, utf8x in (pdf)LaTeX is flawed for diphthongs containing an accented vowel, (e.g. ού, εί, οί). You will discover hyphenations like ε- ίναι, απορροφο- ύν, οπο- ίους etc. Of course, you could add a progressively longer \hyphenation{} list in your preamble, but this quickly becomes a mess. Note that this problem does not appear in XeLaTeX.
  2. If your text includes math formulas with extensive use of sub/superscripts, XeLaTeX with unicode-math gives suboptimal typesetting results.
  3. LuaLaTeX does not yet support greek hyphenation at all.

But then, how would you include greek bookmarks? As a minimal example, the following should do:

\documentclass{book}
\usepackage[LGR,T1]{fontenc}
\usepackage[iso-8859-7]{inputenc}
\usepackage[english,greek]{babel}
\usepackage[unicode]{hyperref}

\begin{document}

\chapter{\texorpdfstring{Περίληψις \textlatin{Summary}}{\textPi\textepsilon\textrho\textiota\textlambda\texteta\textpsi\textiota\textvarsigma Summary}}

\end{document}

That is, just use the LaTeX greek symbol name commands prefixed with "text". For me, it works perfectly, with the only drawback that I haven't found out (yet) how to include accented vowels (e.g έ, ί, ά). You can use an html editor to transform greek text to (roughly) the required pdf bookmark string, but you can of course type it directly as well.

I hope this helps.

7
  • I ran the code above through TeXmaker: the Greek word Περίληψις comes out incorrectly (=ΕΕϕΕλΕϕΠ́ΗΟ•) and the (Greek part of the) pdf bookmark as Περιληψις (ι not ί). Feb 12, 2012 at 13:37
  • \textsigma and \textvarsigma are correctly passed to the pdf bookmarks when using \usepackage[utf8]{inputenc}. Feb 12, 2012 at 13:42
  • 2
    Let me guess: You have probably copied and pasted the minimal example (which follows the encoding of this site, that is, UTF-8) directly to TeXmaker, and the default encoding of TeXmaker is also set in UTF-8. First make sure that your .tex file actually is saved and legible in ISO-8859-7 and then that TeXmaker opens it in the ISO-8859-7 encoding as well. There shouldn't be any problems then! As for the the accented ι, I think I have already made clear that I don't yet know how to enter accented vowels.
    – Atreides
    Feb 12, 2012 at 17:19
  • 2
    As a more general note, the \usepackage[encoding]{inputenc} encoding must always match the actual encoding of the .tex file itself.
    – Atreides
    Feb 12, 2012 at 17:28
  • Absolutely accurate comments Atreidi. Feb 21, 2012 at 8:24

You must log in to answer this question.

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