0

I would like to use listlisting and post commented source code in french. This is the complete document :

\documentclass{article}

\usepackage{listings,xcolor}
%% Langage et police utilisée
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{frame=tb,
  language=Java,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  escapebegin={/**},
  escapeend={*/},
  tabsize=3
  }

\begin{document}
Test écriture.
\begin{lstlisting}
 /**
     * Compilation problem because there is é or ç or ê or ï
     * @param Description
     * @return Description
     */
    public static void main(String argc[]) {
        System.out.println("_Compilation problem"); // This create a compilation problem
    }
\end{lstlisting}
\end{document}

I have two errors : Babel error

unknow option 'francais'

(I tried frenchb but same problem).

The second error is !

Package inputenc Error: Unicode char �\lst@EC� (U+9EA9) ! Package inputenc Error: Unicode char �\lst@EC� (U+9EA7)

...

  • Welcome to TeX.SX! Please also have a look at the various examples of the literate option out there. – TeXnician Feb 23 '17 at 18:21
1

First let me reference the manual of babel and listings:

babel says

4.6 Changes in babel version 3.6

Support for typesetting french texts is much enhanced; the file francais.ldf is now replaced by frenchb.ldf which is maintained by Daniel Flipo.

However both options french and francais will work. babel.sty says:

\DeclareOption{francais}{\bbl@load@language{frenchb}}
\DeclareOption{french}{\bbl@load@language{frenchb}}%

listings says (page 15)

Thus, if you use the a package that supports multibyte characters, such as the CJK or ucs packages for Chinese and UTF-8 characters, you must avoid let- ting listings process the extended characters

However you can work with the option literate to get an output.

\documentclass{article}

\usepackage[french]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{listings,xcolor}
%% Langage et police utilisée

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{%
            inputencoding=utf8,
            extendedchars=true,
            literate=%
            {é}{{\'{e}}}1
            {è}{{\`{e}}}1
            {ê}{{\^{e}}}1
            {ë}{{\¨{e}}}1
            {û}{{\^{u}}}1
            {ù}{{\`{u}}}1
            {â}{{\^{a}}}1
            {à}{{\`{a}}}1
            {î}{{\^{i}}}1
            {ô}{{\^{o}}}1
            {ç}{{\c{c}}}1
            {Ç}{{\c{C}}}1
            {É}{{\'{E}}}1
            {Ê}{{\^{E}}}1
            {À}{{\`{A}}}1
            {Â}{{\^{A}}}1
            {Î}{{\^{I}}}1,
    }


\lstset{frame=tb,
  language=Java,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\small\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  keywordstyle=\color{blue},
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  escapebegin={/**},
  escapeend={*/},
  tabsize=3
  }

\begin{document}
Test écriture. 
\begin{lstlisting}
 /**
     * Compilation problem because there is é\ or ç\ or ê\ or\ î
     * @param Description
     * @return Description
     */
    public static void main(String argc[]) {
        System.out.println("_Compilation problem"); // This create a compilation problem
    }
\end{lstlisting}
\end{document}
  • I think that \usepackage[francais]{babel} should work. – egreg Feb 23 '17 at 18:38
  • @egreg: Thanks. You are right. It's always the best to have a look at the sty file ;-) – Marco Daniel Feb 23 '17 at 18:42

Your Answer

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