Graphics, Figures & Tables ⇒ listings | Problems with Greek Letters
listings | Problems with Greek Letters
Nice Ada source code, with Greek letter variables, UTF-8 encoded: And here is how LaTeX typesets it, via package listings: Note how line 49 is perfectly typeset, but the variables at the start of lines 42, 43 have moved to end of the previous line.
Any help greatly appreciated. Thanks.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Stefan Kottwitz
- Site Admin
- Posts: 10348
- Joined: Mon Mar 10, 2008 9:44 pm
Re: listings | Problems with Greek Letters
perhaps show a small compilable code example which produced that for you, so we also know your listings settings, possibly we would see the cause. Looking only at the output doesn't help much.
Stefan
listings | Problems with Greek Letters
Code: Select all
\documentclass[12pt,a4paper]{report}
\usepackage{ucs}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstloadlanguages{Ada,C}
\usepackage{textgreek}
\begin{document}
\lstset{
language=Ada,
basicstyle={\rmfamily\scriptsize},
numbers=left,
numberstyle=\tiny,
breaklines=true,
showstringspaces=false,
extendedchars=false
}
\lstinputlisting{adacode.txt}
\end{document}
Code: Select all
A : Real_Vector (1 .. N);
λ : Real_T := 1.0;
α : Real_T := 1.0;
I : Real_Matrix := Unit_Matrix (N, 1, 1);
M : Real_Matrix_Ptr_T;
Items : Page_Item_Array_T (1 .. N);
begin
-- Setup the matrix
M := new Real_Matrix (1 .. N, 1 .. N);
M.all := λ * I + α * Transpose (W.all);
- Stefan Kottwitz
- Site Admin
- Posts: 10348
- Joined: Mon Mar 10, 2008 9:44 pm
Re: listings | Problems with Greek Letters
Stefan
Re: LaTeX package listings bug with greek letters
You cannot use \lamba et al. either because the source code is in a distinct language from LaTeX (then it would not compile).
The solution is Unicode. I am only interested in fixing the Unicode in LaTeX. Thanks.
listings | Problems with Greek Letters
listings | Problems with Greek Letters
Thanks. Yes I've tried. No luck:-(shadgrind wrote:Have you tried adding inputencoding=utf8 in your \lstset command? Another thing to try is \usepackage[utf8x]{inputenc}, instead of \usepackage[utf8]{inputenc}, in the preamble.
listings | Problems with Greek Letters
Code: Select all
\documentclass[12pt,a4paper]{report}
\usepackage{fontspec}
\usepackage{minted}
\setmainfont{DejaVu Serif}
\setsansfont{DejaVu Sans}
\setmonofont{DejaVu Sans Mono}
\begin{document}
\usemintedstyle{emacs}
\inputminted[linenos=true]{ada}{adacode.txt}
\end{document}
Code: Select all
xelatex -shell-escape myfile.tex
Re: listings | Problems with Greek Letters
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
listings | Problems with Greek Letters
Code: Select all
\documentclass[12pt,a4paper]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstloadlanguages{Ada,C}
\lstset{%
language=Ada,
basicstyle=\scriptsize,
numbers=left,
numberstyle=\tiny,
breaklines=true,
showstringspaces=false,
mathescape=true
}
\begin{document}
\lstinputlisting{adacode.txt}
\end{document}
Code: Select all
A : Real_Vector (1 .. N);
$\lambda$ : Real_T := 1.0;
$\alpha$ : Real_T := 1.0;
I : Real_Matrix := Unit_Matrix (N, 1, 1);
M : Real_Matrix_Ptr_T;
Items : Page_Item_Array_T (1 .. N);
begin
-- Setup the matrix
M := new Real_Matrix (1 .. N, 1 .. N);
M.all := $\lambda$ * I + $\alpha$ * Transpose (W.all);
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10