Fonts & Character Setslistings | Accents in Comments

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
Post Reply
zweifel
Posts: 1
Joined: Mon Apr 04, 2011 1:38 pm

listings | Accents in Comments

Post by zweifel »

Hi,

I have for a long time a problem with the accents (i write in french) in the comments of my source code (VBA). I spend many hours on it but i was unsuccessful so I hope somebody can help me and thank you for that in advance.

My document has this following header :

Code: Select all

\documentclass[10pt]{article}
\usepackage{a4wide}
\usepackage[french]{babel}
\usepackage[latin1]{inputenc}
\usepackage{vmargin}
\usepackage[dvips]{graphicx}
%Ce package suivant pour l'insertion de code (HTML, PHP, MySQL,...)
\usepackage{color,listings}
\usepackage{array}
\newcolumntype{M}[1]{>{\raggedright}m{#1}}


%STYLE VIDE SUR LES PAGES DE GARDE
\pagestyle{empty}

\setpapersize{A4}
\setmarginsrb{15mm}{10mm}{15mm}{10mm}{5pt}{5mm}{5pt}{5mm}
%gauche, haut, droite, bas, hauteur en-tête, sep avant entête, hauteur pied, sep avant pied page
\begin{document}
\pagestyle{empty}



\renewcommand{\baselinestretch}{2}

\setlength{\parskip}{1.5ex plus 0.5ex minus 0.2ex}
\setlength{\parindent}{0pt}
\lstdefinelanguage{VBA}{morekeywords={And, As, Byte, Call, Case, Compare, CDbl, Datebase, Date, Dim, Else, ElseIf, End, Error, Exit, Explicit, False, Function, GoTo, If, IIF, Integer, Not, Nothing, Null, Object, On, Option, Or, Private, Resume, String, Single, Select, Set, Static, Sub, Then, True, To,},
   sensitive=false,
   morecomment=[l]Rem,
   morecomment=[l]',
   morestring=[b]",
   emph={acFormBar, acEditMenu, acCurrent, acEntire, acMenuVer70, acSaveYes, acViewNormal, acForm, acDataErrAdded, acNewRec, acDataErrContinue, Cancel, CancelEvent, Close, CurrentDb, DefaultValue, DateValue, DAO, Description, DoCmd, DoMenuItem, Err, Error, Error$, $, Execute,  FindRecord, Forms, FindFirst, IsNull, Me, MsgBox, GoToControl, GoToRecord, NewData, Nz, Maximize, Number, OpenForm, Parent, Recordset, Requery, Response, SetFocus, stDocName, stLinkCriteria, Value, vbExclamation, vbOK, vbOKCancel, vbInformation, vbYes, vbNo, vbYesNo, vbCancel, vbQuestion, vbYesNoCancel, Visible,},
   emphstyle=\itshape}

\lstloadlanguages{VBA, HTML}
\lstset{%
   language=VBA,
   basicstyle=\small,
   keywordstyle=\color{blue}\bfseries,
   commentstyle=\color{green}\itshape,
   tabsize=1,
   extendedchars=false,
   inputencoding=latin1,
   breaklines=true,
   showstringspaces=false,
   stringstyle=\sffamily,
   numbers=left,
   numberstyle=\tiny,
   stepnumber=2,
   numbersep=5pt}
Everything works fine except the comments. If i comment something like "sélection" it comes out like "éslection". It means that the é comes first as well as others characters with accent.

Thank you in advance for your precious help.

Best regards

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

CDbile
Posts: 19
Joined: Mon Jan 31, 2011 6:48 pm

listings | Accents in Comments

Post by CDbile »

Hi,

Could you provide a real Minimal Working Example which shows what the problem is ?

However, I still have a hint for you : read the log ! Babel is warning you that you should add

Code: Select all

\usepackage[T1]{fontenc}
in your preamble when using the Babel french package.

If that doesn't solve the problem, come back with a MWE.
CDbile
hanspeterzweifel
Posts: 1
Joined: Wed Aug 31, 2011 8:16 am

listings | Accents in Comments

Post by hanspeterzweifel »

Hello i have the same problem and adding \usepackage[T1]{fontenc} doesn't change anything. I'm getting mad about all this so please help me.

Here is the beginning of my document :

Code: Select all

\documentclass[10pt]{article}
\usepackage{a4wide}
\usepackage[french]{babel}
\usepackage[latin1]{inputenc}
\usepackage{vmargin}
\usepackage[dvips]{graphicx}
%Ce package suivant pour l'insertion de code (HTML, PHP, MySQL,...)
\usepackage{color,listings}
\usepackage{array}
\usepackage[T1]{fontenc}
\newcolumntype{M}[1]{>{\raggedright}m{#1}}


%STYLE VIDE SUR LES PAGES DE GARDE
\pagestyle{empty}

\setpapersize{A4}
\setmarginsrb{15mm}{10mm}{15mm}{10mm}{5pt}{5mm}{5pt}{5mm}
%gauche, haut, droite, bas, hauteur en-tête, sep avant entête, hauteur pied, sep avant pied page
\begin{document}
\pagestyle{empty}



\renewcommand{\baselinestretch}{2}

\setlength{\parskip}{1.5ex plus 0.5ex minus 0.2ex}
\setlength{\parindent}{0pt}
\lstdefinelanguage{VBA}{morekeywords={And, As, Byte, Call, Case, Compare, CDbl, Datebase, Date, Dim, Else, ElseIf, End, Error, Exit, Explicit, False, Function, GoTo, If, IIF, Integer, Not, Nothing, Null, Object, On, Option, Or, Private, Resume, String, Single, Select, Set, Static, Sub, Then, True, To,},
   sensitive=false,
   morecomment=[l]Rem,
   morecomment=[l]',
   morestring=[b]",
   emph={acFormBar, acEditMenu, acCurrent, acEntire, acMenuVer70, acSaveYes, acViewNormal, acForm, acDataErrAdded, acNewRec, acDataErrContinue, Cancel, CancelEvent, Close, CurrentDb, DefaultValue, DateValue, DAO, Description, DoCmd, DoMenuItem, Err, Error, Error$, $, Execute,  FindRecord, Forms, FindFirst, IsNull, Me, MsgBox, GoToControl, GoToRecord, NewData, Nz, Maximize, Number, OpenForm, Parent, Recordset, Requery, Response, SetFocus, stDocName, stLinkCriteria, Value, vbExclamation, vbOK, vbOKCancel, vbInformation, vbYes, vbNo, vbYesNo, vbCancel, vbQuestion, vbYesNoCancel, Visible,},
   emphstyle=\itshape}

\lstloadlanguages{VBA, HTML}
\lstset{%
   language=VBA,
   basicstyle=\small,
   keywordstyle=\color{blue}\bfseries,
   commentstyle=\color{green}\itshape,
   tabsize=1,
   extendedchars=false,
   inputencoding=latin1,
   breaklines=true,
   showstringspaces=false,
   stringstyle=\sffamily,
   numbers=left,
   numberstyle=\tiny,
   stepnumber=2,
   numbersep=5pt}
Here is my main code :

Code: Select all

   \subsubsection{La méthode Delete}\label{fin_listing_methode_attribut}
        La méthode Delete permet de supprimer un objet Range. Il convient de différencier la suppression d'un objet range, possible grâce à la méthode Delete, de la suppression du contenu et de la mise en forme, possible grâce à la méthode Clear. En effet en utilisant Delete, vous allez modifier la structure d'un tableau puisque les cellules vont disparaître et les cellules avoisinantes seront décalées pour combler le vide. L'utilisation de la méthode Clear quand a elle ne va pas influencer la structure du tableau puisqu'elle ne fait qu'effacer le contenu et non pas la cellule en soi.

        Il s'agit encore de préciser comment décaler les cellules, soit vers le haut grâce à l'instruction xlUp, soit vers la gauche, l'option par défaut, grâce à l'instruction xlToLeft.

        \lstinputlisting[caption={[Effacer un objet Range]Effacer un objet Range},label={range_delete},language=VBA]{range_delete.src}

        Le listing \ref{range_delete} de la page \pageref{range_delete} détruit la cellule A1 et décale le contenu des cellules B1, C1,...,XFD1 en A1, B1,...,XFC1, et détruit la cellule B2 et décale le contenu des cellules B3,...,B1048575 vers le haut dans les cellules B2,...,B1048574.
Here is the content of the file range_copy.src :
Sub range_delete()
'Suppression de la cellule A1 avec décalage vers la gauche
Range("A1").Delete xlLeft
'Suppression de la cellule B2 avec décalage vers le haut
Range("B2").Delete xlUp
End Sub
Once the file is compiled to dvi the comment of the vba code says instead of Suppression de la cellule A1 avec décalage... Suppression de la cellule A1 avec édcalage...

That's pretty annoying, can someone please help me?

Thanks in advance
Post Reply