我正在尝试使用 pdflatex,并使用 XeLaTeX 和 pdflatex 将字体更改为希腊语。
XeLaTeX 运行完美,在章节标题中,它使用粗体选定的希腊语字体。但 pdflatex 无法使章节标题中的希腊语部分变为粗体。
我的代码(MWE 带有一些注释掉的替代测试)是这样的:
\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}
XeLaTeX 输出是预期的:
但是 pdflatex 给出(经过所有测试):
我做错了什么,还是字体问题?(字体应该是相同的,但 pdflatex 中的字体来自包)
答案1
使用\DeclareFontFamilySubstitution
。
我把所有内容都改成\ifnum
了\ifxetex
构造。这样,只需要根据编译文档的引擎来选择适当的分支,而不需要修改文档本身。
\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)
\DeclareFontFamilySubstitution{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}
您可以artemisia
使用任何支持希腊语的字体。