I'm trying to create an lstlisting that contains both english and greek letters.
I have set this style.
\lstset{
basicstyle=\normalsize\selectlanguage{english}\ttfamily, % COURIER NEW?
frame=tb, % draw a frame at the top and bottom of the code block
tabsize=4, % tab space width
showstringspaces=false, % don't mark spaces in strings
numbers=left, % display line numbers on the left
commentstyle=\color{black}, % comment color
keywordstyle=\color{black}, % keyword color
stringstyle=\color{black} % string color
}
and I want to include this code inside the lstlisting. As you can see there is greek text: 'Σύνθετη Αναζήτηση'. However when i run the pdfLatex compiler, it is rendered in latin character.
\begin{lstlisting}
<?php
function custom_toolbar_link($wp_admin_bar) {
$args = array(
'id' => 'advanced_search',
'title' => 'Σύνθετη Αναζήτηση',
'href' => 'admin.php?page=advanced-search',
'meta' => array(
'class' => 'advanced_search',
'title' => 'advanced search'
)
);
$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'custom_toolbar_link', 10);
\end{lstlisting}
Can you help me?
*** A full minimal example of the text:
\documentclass[11pt,a4paper,fleqn]{article}
\usepackage{listings}
\usepackage{dirtree}
\usepackage{indentfirst}
\usepackage[greek,english]{babel}
\usepackage[iso-8859-7]{inputenc}
\usepackage{chicago}
\usepackage[section]{placeins}
\lstset{
basicstyle=\normalsize\selectlanguage{english}\ttfamily, % COURIER NEW?
frame=tb, % draw a frame at the top and bottom of the code block
tabsize=4, % tab space width
showstringspaces=false, % don't mark spaces in strings
numbers=left, % display line numbers on the left
commentstyle=\color{black}, % comment color
keywordstyle=\color{black}, % keyword color
stringstyle=\color{black} % string color
}
% This concludes the preamble
\begin{document}
\begin{lstlisting}[label=some-code,caption=Some Code]
<?php
function custom_toolbar_link($wp_admin_bar) {
$args = array(
'id' => 'advanced_search',
'title' => 'Σύνθετη Αναζήτηση',
'href' => 'admin.php?page=advanced-search',
'meta' => array(
'class' => 'advanced_search',
'title' => 'advanced search'
)
);
$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'custom_toolbar_link', 10);
\end{lstlisting}
\end{document}
xelatex
instead ofpdflatex
? On my system, your example works well if I remove yourinputenc
line, and replace it with\usepackage{fontspec}\setmonofont{Courier New}
, then compile withxelatex
.