Cambio de idioma dentro del entorno alltt en xelatex

Cambio de idioma dentro del entorno alltt en xelatex

¿Cómo se puede utilizar más de un idioma en XeLaTeX dentro del \allttentorno?

Tengo problemas para hacer esto usando babel y compilando con pdfLaTeX

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[greek,english]{babel}
\usepackage{alltt}
\begin{document}
\begin{alltt}
 this is a test
\foreignlanguage{greek}{αυτό είναι μια δοκιμή}
\end{alltt}
\end{document}

pero si intento algo similar al compilar con XeLaTeX: (ver ejemplo en ShareLateX) el texto en griego no aparece en el pdf compilado

\documentclass[12pt]{article}
\usepackage{fontspec}
\usepackage{alltt}
% Times New Roman
\setmainfont[BoldFont=timesbd.ttf, ItalicFont=timesi.ttf, BoldItalicFont=timesbi.ttf
]{times.ttf}
\begin{document}
\begin{alltt}
this is a test 
αυτό είναι μια δοκιμή 
\end{alltt}
\end{document}

Respuesta1

Tienes que definir una fuente monoespaciada que tenga caracteres griegos. Por ejemplo

\documentclass[12pt]{article}
\usepackage{fontspec}
\usepackage{alltt}

\setmainfont[
  Extension=.ttf,
  UprightFont=*,
  BoldFont=*bd,
  ItalicFont=*i,
  BoldItalicFont=*bi,
]{times}

\setmonofont{cmuntt.otf} % or any other monospaced font supporting Greek

\begin{document}
\begin{alltt}
this is a test
αυτό είναι μια δοκιμή
\end{alltt}
\end{document}

ingrese la descripción de la imagen aquí

información relacionada