2

I am trying to use pdflatex and change the font to greek by using both XeLaTeX and pdflatex.

XeLaTeX works perfect and inside section title it uses bold selected font for greek. But pdflatex fails to make the greek part inside the section title bold.

My code (MWE with some commented out alternative tests) is this:

\def\UseXeLaTeX{1}

\documentclass[12pt]{article}

\ifnum\UseXeLaTeX=0
\usepackage[utf8]{inputenc} % utf8 is the preferred input encoding
\usepackage[greek.ancient,english]{babel} %koleygr:BF4 These coammnds are for LaTeX and pdflatex but we can't change font while changing language and thus we will use XeLaTeX
\usepackage[LGR,T1]{fontenc} %koleygr:BF4 Same as above
\else
\usepackage{polyglossia} %koleygr: Replacing commands to use XeLaTeX
\setmainlanguage{english}
\setotherlanguage{greek}
\fi

\ifnum\UseXeLaTeX=0
\usepackage{tgpagella} % Set the font TEX Gyre Pagella
\usepackage[scaled=0.875]{helvet} % Use helvetica for sans serif (phv)
\renewcommand{\sfdefault}{phv}
\usepackage{tgheros} %Use TeX Gyre Heros for greek (qhv)
\newcommand*{\mygreekfont}{\fontfamily{qhv}\selectfont}
\else
\setmainfont{TeX Gyre Pagella} 
\setsansfont[Ligatures=TeX]{TeX Gyre Heros}
\newfontfamily\helvet[Mapping=tex-text]{TeX Gyre Heros}
\newfontfamily\greekfont[Mapping=tex-text]{GFS Didot}
\fi

\newcommand{\fgreek}[1]{\ifnum\UseXeLaTeX=1 \textgreek{#1}\else\foreignlanguage{greek}{%\fontfamily{qhv}\selectfont
%\renewcommand{\familydefault}{qhv}
\mygreekfont #1}\fi}

\newenvironment{mygreek}{\ifnum\UseXeLaTeX=1 \begin{greek}\else\begin{otherlanguage}{greek}%\fontfamily{qhv}\selectfont
%\renewcommand{\familydefault}{qhv}
\mygreekfont
\fi}{\ifnum\UseXeLaTeX=1 \end{greek}\else\end{otherlanguage}\fi}

\begin{document}

\tableofcontents

\section{Test Section}
Test english text

\section{A phrase from \fgreek{Σωκράτης}}

\begin{mygreek}
 Ἓν οἶδα ὅτι οὐδὲν οἶδα
\end{mygreek}

\end{document}

The XeLaTeX output is the expected:

enter image description here

But pdflatex gives (with all tests):

enter image description here

Am I doing something wrong, or it is a font matter? (Font supposed to be the same but in pdflatex comes from the package)

  • To test the code with pdflatex replace first the initial definition command (\def\UseXeLaTeX{1}) with \def\UseXeLaTeX{0} ... – koleygr Dec 5 '18 at 21:03
  • 1
    There is no LGR-support in tgheros. – Ulrike Fischer Dec 5 '18 at 21:44
  • Thanks @UlrikeFischer... So, I suppose I have to test other fonts... You may add it as an answer and if you want you may suggest a font too near to the others if existing... Otherwise we could close the question as answered in comments – koleygr Dec 5 '18 at 21:48
  • Tried even with cmr and the problem remains... I forgot to add a \protect comand there too. This solves the problem with other fonts. Thanks – koleygr Dec 5 '18 at 22:25
2

Use substitutefont.

I changed all \ifnum into \ifxetex constructs. This way the appropriate branch is taken only depending on the engine used for compiling the document, rather than needing to modify the document itself.

\documentclass[12pt]{article}
\usepackage{ifxetex}

\ifxetex
  \usepackage{polyglossia} %koleygr: Replacing commands to use XeLaTeX
  \setmainlanguage{english}
  \setotherlanguage{greek}
\else
  \usepackage[LGR,T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage[greek.ancient,english]{babel}
\fi

\ifxetex
  \setmainfont{TeX Gyre Pagella} 
  \setsansfont[Ligatures=TeX]{TeX Gyre Heros}
  \newfontfamily\helvet[Mapping=tex-text]{TeX Gyre Heros}
  \newfontfamily\greekfont[Mapping=tex-text]{GFS Didot}
\else
  \usepackage{tgpagella} % Set the font TEX Gyre Pagella
  \usepackage[scaled=0.875]{helvet} % Use helvetica for sans serif (phv)
  \renewcommand{\sfdefault}{phv}
  \usepackage{tgheros} %Use TeX Gyre Heros for greek (qhv)
  \usepackage{substitutefont}
  \substitutefont{LGR}{\rmdefault}{artemisia}
\fi

\ifxetex
  \newcommand{\fgreek}[1]{\textgreek{#1}}
  \newenvironment{mygreek}{\begin{greek}}{\end{greek}}
\else
  \newcommand{\fgreek}[1]{\foreignlanguage{greek}{#1}}
  \newenvironment{mygreek}
    {\begin{otherlanguage}{greek}}
    {\end{otherlanguage}}
\fi

\begin{document}

\tableofcontents

\section{Test Section}
Test english text

\section{A phrase from \fgreek{Σωκράτης}}

\begin{mygreek}
 Ἓν οἶδα ὅτι οὐδὲν οἶδα
\end{mygreek}

\end{document}

Instead of artemisia you can use any font with Greek support.

Output with pdflatex

enter image description here

Output with xelatex

enter image description here

  • 2
    Suggest also supporting LuaLaTeX. It might be better to have a branch only for \ifPDFTeX, on the assumption that any new TeX engine will also support fontspec. – Davislor Dec 6 '18 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.