5

I was trying to install minted package in TeXLive. I installed it and then run sudo tlmgr update --all. It was running slow so I stopped it using Ctrl+Z in an ubuntu terminal and then I run sudo tlmgr update --list. After that I installed texlive-latex-extra and python-pygments. Later on I run sudo tlmgr update --all again and let it finish.

After that I am trying to run a simple code using listings and greek but I get an error

Bad Character code (256)

A MWE that illustrated the problem is the following

\documentclass{book}

\usepackage[english,greek]{babel}
\usepackage[iso-8859-7]{inputenc}
% %\usepackage[utf8]{inputenc}
\usepackage{kerkis}
\usepackage{pifont}
% % 
\newcommand{\sw}{\selectlanguage{english}}
\newcommand{\sq}{\selectlanguage{greek}}
\newcommand{\eng}[1]{\latintext#1\greektext}
\newcommand{\gre}[1]{\greektext#1\latintext}

\usepackage{xcolor}
\usepackage{listings}
\usepackage{textcomp}

\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}

\lstdefinestyle{JavaStyle}{
        backgroundcolor=\color{lbcolor},
    tabsize=4,
%   rulecolor=,
    language=Java,      % choose the language of the code
        basicstyle=\scriptsize,     % the size of the fonts that are used for the code
        upquote=true,
        aboveskip={1.5\baselineskip},
        columns=fixed,
        showstringspaces=false,
        extendedchars=false,
        breaklines=true,
        prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
        frame=single,
        numbers=left,
        showtabs=false,
        showspaces=false,
        showstringspaces=false,
        identifierstyle=\ttfamily,
        keywordstyle=\color[rgb]{0,0,1},
        %commentstyle=\color[rgb]{0.026,0.112,0.095},
        commentstyle=\itshape\color{green!40!black},
        stringstyle=\itshape\color{red!90!black},
        numberstyle=\itshape\color{yellow!50!black}
}

\lstdefinestyle{CppStyle}{
        backgroundcolor=\color{lbcolor},
    tabsize=4,
%   rulecolor=,
    language=C++,       % choose the language of the code
        basicstyle=\scriptsize,     % the size of the fonts that are used for the code
        upquote=true,
        aboveskip={1.5\baselineskip},
        columns=fixed,
        showstringspaces=false,
        extendedchars=false,
        breaklines=true,
        prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
        frame=single,
        numbers=left,
        showtabs=false,
        showspaces=false,
        showstringspaces=false,
        identifierstyle=\ttfamily,
        keywordstyle=\color[rgb]{0,0,1},
        %commentstyle=\color[rgb]{0.026,0.112,0.095},
        commentstyle=\itshape\color{green!40!black},
        stringstyle=\itshape\color{red!90!black},
        numberstyle=\itshape\color{yellow!50!black}
}
\begin{document}
 This is a dummy text. kjhbki
\end{document}

The .aux file says

\relax 
\select@language{greek}
\@writefile{toc}{\select@language{greek}}
\@writefile{lof}{\select@language{greek}}
\@writefile{lot}{\select@language{greek}}

while the .log file can be found here

Any idea why is this happening and how to fix this? Note that if I remove the listings preamble, delete all produced files and build the document, everything works fine.

  • 1
    You should use UTF-8 as the encoding for your files, not iso-8859-7 – egreg Sep 9 '14 at 9:55
  • @egreg:Even if I use utf8 the result is the same. I get the same error. – Thanos Sep 9 '14 at 10:21
  • I have added to my answer a proposed bug fix for greek.ldf and also a better temporary fix. – egreg Sep 9 '14 at 15:10
  • The babel-greek suite has been updated, but unfortunately the bug still remains. – egreg Sep 20 '14 at 22:42
  • That's bad... I have already sent a bug report... – Thanos Sep 21 '14 at 6:41
5

UPDATE

The problem has been fixed with babel-greek version 1.9e, released on 2015/11/27

Original answer

Here's a temporary fix, that should work if Greek is the last language loaded; it just restores the value of \@tempcnta to what it would be if listings is not loaded. However, this is a bug in babel-greek: no package should rely on any particular value of \@tempcnta; my impression is that some code has been added that is useless.

\documentclass{article}
\usepackage[greek]{babel}
\usepackage{listings}

\makeatletter
\AtBeginDocument{%
  \expandafter\def\expandafter\originalTeX\expandafter{%
    \expandafter\@tempcnta\number253\expandafter\relax\originalTeX}%
}
\makeatother

\begin{document}
a
\end{document}

The bad code is in line 376 of greek.ldf that says

376       \babel@savevariable{\lccode\@tempcnta}\lccode\@tempcnta=\@tempcnta

while it should be

376       \expandafter\babel@savevariable\expandafter{\expandafter\lccode\the\@tempcnta}\lccode\@tempcnta=\@tempcnta

so the correct instructions

\babel@savevariable{\lccode128}
\babel@savevariable{\lccode129}
...
\babel@savevariable{\lccode252}

are executed instead of doing several times the useless (and wrong)

\babel@savevariable{\lccode\@tempcnta}

Thus a better temporary fix would be

\documentclass{article}
\usepackage[greek]{babel}
\usepackage{listings}

\makeatletter
% Avoid the spurious error
\AtBeginDocument{%
  \expandafter\def\expandafter\originalTeX\expandafter{%
    \expandafter\@tempcnta\number253\expandafter\relax\originalTeX}%
}
% apply the fix
\addto\extrasgreek{%
  \@tempcnta=128
  \@whilenum\@tempcnta<253\do{%
    \expandafter\babel@savevariable\expandafter{\expandafter\lccode\the\@tempcnta}%
    \lccode\@tempcnta=\@tempcnta
    \advance\@tempcnta\@ne
  }%
}
\makeatother
\begin{document}
a
b
\end{document}
5

(Too long for a comment). It is a babel bug. It relies on a temporary counter and fails when listings sets it to 256:

\documentclass{book}

\usepackage[english,greek]{babel}

\begin{document}
\makeatletter
\@tempcnta=256
\selectlanguage{greek}

\end{document}

Sent a bug report to the babel maintainer or the babel-greek maintainer.

  • Thank you very much for your shocking answer! First of all, this happened because I've updated my packages? Secondly, is \makeatletter \@tempcnta=256 \selectlanguage{greek} suppossed to fix this? I've added this right after begin{document} but I get the exact same error... Last but not least, how to give a bug report? Is there a certain way or I'll just to communicate with the creator via email? – Thanos Sep 9 '14 at 11:06
  • No the example doesn't fix it, it shows that the error can be triggered easily without listings. Try \makeatletter \AtBeginDocument{\@tempcnta=10} \makeatother after `\usepackage{listings}. And write a message here tex-tipografia.com/contact.html – Ulrike Fischer Sep 9 '14 at 11:46
  • Yes, when \originalTeX is executed, a number of \lccode\@tempcnta=<number> instructions are performed without any initialization to \@tempcnta; I'm not sure where they come from and what they're for. – egreg Sep 9 '14 at 11:52
  • @UlrikeFischer : Yes you are right. It fixes the issue. I'll contact the developers! Thank you very much! – Thanos Sep 9 '14 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.