Search code examples
latexnon-englishlstlisting

Output code with english characters instead of non-english in lstlisting latex?


i wanna insert an ansys apdl code code text in my thesis. I have tried the \begin{lstlisting} for my code (english) since i have tha package. My thesis template is put to have greek as default language so when i compile the lstlisting in latex i get this output latex output (greek characters). I have tried use \eng{} inside or outside of the \begin{lstlisting} but i get greek characters either way. this the code :

\begin{lstlisting}
/AUX15  
/UNITS,SI 
IOPTN,IGES,SMOOTH   
IOPTN,MERGE,YES 
IOPTN,SOLID,YES 
IOPTN,SMALL,YES 
IOPTN,GTOLER, DEFA  
IGESIN,'.arc_nosup_2','igs',' '  
! APLOT   
!*  
FINISH 
\end{lstlisting}

Anyone has any idea how can i get an ouput of this code with english characters instead of greek?

a minimal example is like that :

\documentclass[11pt,a4paper,fleqn]{article}
\usepackage{multicol}
\usepackage{xspace}
\usepackage[unicode,linktocpage,breaklinks]{hyperref}
\usepackage{textcomp}
\usepackage{breakurl}

% >> Math package:
\usepackage{amsmath}
\usepackage{amsbsy}
\usepackage{amstext}
\usepackage{amssymb}
\usepackage{nicefrac}

\usepackage[english,greek]{babel}
\usepackage[utf8x]{inputenc}
%\usepackage[iso-8859-7]{inputenc}
%\usepackage{kerkis}
\usepackage{parskip}

% improved layout of figure captions with extra margin, smaller font than text
\usepackage[margin=10pt,font=small,labelfont=bf,textfont = it]{caption}
%\usepackage{xltxtra}

\usepackage{graphicx}
\usepackage{latexsym}
\usepackage{babel,varioref}
\usepackage{setspace}
\usepackage{subcaption}
\usepackage{fixltx2e}
\usepackage{pstricks}
\usepackage{latexsym} 
\usepackage{multirow}
\usepackage{array}
\usepackage{color}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{listings}
\usepackage{enumerate}

\usepackage{babelbib}
\usepackage{url}
% \usepackage{multibib}

\usepackage{caption}

% TABLE OF CONTENTS PACKAGES
\usepackage[subfigure]{tocloft}
\usepackage{tocbibind}

% Line Spacing
\usepackage{setspace}

% fancy header
\usepackage{fancyhdr} 
%\usepackage[unicode]{hyperref}

% footnotes: waring in case of splitted footnote
\usepackage{fnbreak}

% extra controlabity for enumerators
\usepackage{enumitem}

% Section headings format
\usepackage{titlesec}
%\usepackage{sectsty}

% appendix
\usepackage{appendix}


\begin{lstlisting}
/AUX15  
/UNITS,SI 
IOPTN,IGES,SMOOTH   
IOPTN,MERGE,YES 
IOPTN,SOLID,YES 
IOPTN,SMALL,YES 
IOPTN,GTOLER, DEFA  
IGESIN,'.arc_nosup_2','igs',' '  
! APLOT   
!*  
FINISH
\end{lstlisting}

Solution

  • You can use \selectlanguage{english} to temporarily switch to English:

    \documentclass[11pt,a4paper,fleqn]{article}
    \usepackage{multicol}
    \usepackage{xspace}
    \usepackage[unicode,linktocpage,breaklinks]{hyperref}
    \usepackage{textcomp}
    \usepackage{breakurl}
    
    % >> Math package:
    \usepackage{amsmath}
    \usepackage{amsbsy}
    \usepackage{amstext}
    \usepackage{amssymb}
    \usepackage{nicefrac}
    
    \usepackage[english,greek]{babel}
    \usepackage[utf8x]{inputenc}
    %\usepackage[iso-8859-7]{inputenc}
    %\usepackage{kerkis}
    \usepackage{parskip}
    
    % improved layout of figure captions with extra margin, smaller font than text
    \usepackage[margin=10pt,font=small,labelfont=bf,textfont = it]{caption}
    %\usepackage{xltxtra}
    
    \usepackage{graphicx}
    \usepackage{latexsym}
    \usepackage{babel,varioref}
    \usepackage{setspace}
    \usepackage{subcaption}
    \usepackage{fixltx2e}
    \usepackage{pstricks}
    \usepackage{latexsym} 
    \usepackage{multirow}
    \usepackage{array}
    \usepackage{color}
    \usepackage{algorithm}
    \usepackage{algorithmicx}
    \usepackage{algpseudocode}
    \usepackage{listings}
    \usepackage{enumerate}
    
    \usepackage{babelbib}
    \usepackage{url}
    % \usepackage{multibib}
    
    \usepackage{caption}
    
    % TABLE OF CONTENTS PACKAGES
    \usepackage[subfigure]{tocloft}
    \usepackage{tocbibind}
    
    % Line Spacing
    \usepackage{setspace}
    
    % fancy header
    \usepackage{fancyhdr} 
    %\usepackage[unicode]{hyperref}
    
    % footnotes: waring in case of splitted footnote
    \usepackage{fnbreak}
    
    % extra controlabity for enumerators
    \usepackage{enumitem}
    
    % Section headings format
    \usepackage{titlesec}
    %\usepackage{sectsty}
    
    % appendix
    \usepackage{appendix}
    \begin{document}
    
    Greek
    
    {
    \selectlanguage{english}
    \begin{lstlisting}
    /AUX15  
    /UNITS,SI 
    IOPTN,IGES,SMOOTH   
    IOPTN,MERGE,YES 
    IOPTN,SOLID,YES 
    IOPTN,SMALL,YES 
    IOPTN,GTOLER, DEFA  
    IGESIN,'.arc_nosup_2','igs',' '  
    ! APLOT   
    !*  
    FINISH
    \end{lstlisting}
    }
    
    Greek
    
    \end{document}