我有以下xelatex
文件:
\documentclass{article}
\usepackage[cm-default]{fontspec}
\setromanfont{FreeSerif}
\setsansfont{FreeSans}
\setmonofont{FreeMono}
\setmainfont{FreeSans}
\usepackage{polyglossia}
\setmainlanguage{greek}
\setotherlanguage{english}
\usepackage{listings}
\lstset{
basicstyle=\fontsize{11}{13}\selectfont\ttfamily
}
\usepackage[utf8]{inputenc}
\begin{document}
Αρχικοποίηση του SESSION ώστε να
Initializing of the SESSION so
\begin{lstlisting}[caption=protected.php,frame=tlrb]{Name}
<?php
session_start(); # Αρχικοποίηση του SESSION ώστε να
session_start(); # Initializing of the SESSION so
\end{lstlisting}
\end{document}
但问题是代码清单中的希腊文本缺少空格。代码清单外的文本则有正确的间距:
我怎样才能修复列表中的文本以使空格正常显示?
答案1
例如,https://tex.stackexchange.com/a/25396/4427
您需要添加希腊字母块 U+0370–U+03FF。可能还需要添加希腊字母扩展 U+1F00–U+1FFF。
\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{listings}
\setmainfont{FreeSans}
\setsansfont{FreeSans}
\setmonofont{FreeMono}
\setmainlanguage{greek}
\setotherlanguage{english}
\lstset{
basicstyle=\fontsize{11}{13}\ttfamily,
extendedchars=true,
}
\makeatletter
\lst@InputCatcodes
\def\lst@DefEC{%
\lst@CCECUse \lst@ProcessLetter
^^80^^81^^82^^83^^84^^85^^86^^87^^88^^89^^8a^^8b^^8c^^8d^^8e^^8f%
^^90^^91^^92^^93^^94^^95^^96^^97^^98^^99^^9a^^9b^^9c^^9d^^9e^^9f%
^^a0^^a1^^a2^^a3^^a4^^a5^^a6^^a7^^a8^^a9^^aa^^ab^^ac^^ad^^ae^^af%
^^b0^^b1^^b2^^b3^^b4^^b5^^b6^^b7^^b8^^b9^^ba^^bb^^bc^^bd^^be^^bf%
^^c0^^c1^^c2^^c3^^c4^^c5^^c6^^c7^^c8^^c9^^ca^^cb^^cc^^cd^^ce^^cf%
^^d0^^d1^^d2^^d3^^d4^^d5^^d6^^d7^^d8^^d9^^da^^db^^dc^^dd^^de^^df%
^^e0^^e1^^e2^^e3^^e4^^e5^^e6^^e7^^e8^^e9^^ea^^eb^^ec^^ed^^ee^^ef%
^^f0^^f1^^f2^^f3^^f4^^f5^^f6^^f7^^f8^^f9^^fa^^fb^^fc^^fd^^fe^^ff%
% add Greek
^^^^0370^^^^0371^^^^0372^^^^0373^^^^0374^^^^0375^^^^0376^^^^0377%
^^^^0378^^^^0379^^^^037a^^^^037b^^^^037c^^^^037d^^^^037e^^^^037f%
^^^^0380^^^^0381^^^^0382^^^^0383^^^^0384^^^^0385^^^^0386^^^^0387%
^^^^0388^^^^0389^^^^038a^^^^038b^^^^038c^^^^038d^^^^038e^^^^038f%
^^^^0390^^^^0391^^^^0392^^^^0393^^^^0394^^^^0395^^^^0396^^^^0397%
^^^^0398^^^^0399^^^^039a^^^^039b^^^^039c^^^^039d^^^^039e^^^^039f%
^^^^03a0^^^^03a1^^^^03a2^^^^03a3^^^^03a4^^^^03a5^^^^03a6^^^^03a7%
^^^^03a8^^^^03a9^^^^03aa^^^^03ab^^^^03ac^^^^03ad^^^^03ae^^^^03af%
^^^^03b0^^^^03b1^^^^03b2^^^^03b3^^^^03b4^^^^03b5^^^^03b6^^^^03b7%
^^^^03b8^^^^03b9^^^^03ba^^^^03bb^^^^03bc^^^^03bd^^^^03be^^^^03bf%
^^^^03c0^^^^03c1^^^^03c2^^^^03c3^^^^03c4^^^^03c5^^^^03c6^^^^03c7%
^^^^03c8^^^^03c9^^^^03ca^^^^03cb^^^^03cc^^^^03cd^^^^03ce^^^^03cf%
^^^^03d0^^^^03d1^^^^03d2^^^^03d3^^^^03d4^^^^03d5^^^^03d6^^^^03d7%
^^^^03d8^^^^03d9^^^^03da^^^^03db^^^^03dc^^^^03dd^^^^03de^^^^03df%
^^^^03e0^^^^03e1^^^^03e2^^^^03e3^^^^03e4^^^^03e5^^^^03e6^^^^03e7%
^^^^03e8^^^^03e9^^^^03ea^^^^03eb^^^^03ec^^^^03ed^^^^03ee^^^^03ef%
^^^^03f0^^^^03f1^^^^03f2^^^^03f3^^^^03f4^^^^03f5^^^^03f6^^^^03f7%
^^^^03f8^^^^03f9^^^^03fa^^^^03fb^^^^03fc^^^^03fd^^^^03fe^^^^03ff%
% the end
^^00}
\lst@RestoreCatcodes
\makeatother
\begin{document}
Αρχικοποίηση του SESSION ώστε να
Initializing of the SESSION so
\begin{lstlisting}[caption=protected.php,frame=tlrb]{Name}
<?php
session_start(); # Αρχικοποίηση του SESSION ώστε να
session_start(); # Initializing of the SESSION so
\end{lstlisting}
\end{document}
我使用是geometry
为了避免线路过满。