LaTeX forum ⇒ Fonts & Character Setslistings | Accents in Comments

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

listings | Accents in Comments

Postby zweifel » Mon Apr 04, 2011 1:53 pm

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 :

  1. \documentclass[10pt]{article}
  2. \usepackage{a4wide}
  3. \usepackage[french]{babel}
  4. \usepackage[latin1]{inputenc}
  5. \usepackage{vmargin}
  6. \usepackage[dvips]{graphicx}
  7. %Ce package suivant pour l'insertion de code (HTML, PHP, MySQL,...)
  8. \usepackage{color,listings}
  9. \usepackage{array}
  10. \newcolumntype{M}[1]{>{\raggedright}m{#1}}
  11.  
  12.  
  13. %STYLE VIDE SUR LES PAGES DE GARDE
  14. \pagestyle{empty}
  15.  
  16. \setpapersize{A4}
  17. \setmarginsrb{15mm}{10mm}{15mm}{10mm}{5pt}{5mm}{5pt}{5mm}
  18. %gauche, haut, droite, bas, hauteur en-tête, sep avant entête, hauteur pied, sep avant pied page
  19. \begin{document}
  20. \pagestyle{empty}
  21.  
  22.  
  23.  
  24. \renewcommand{\baselinestretch}{2}
  25.  
  26. \setlength{\parskip}{1.5ex plus 0.5ex minus 0.2ex}
  27. \setlength{\parindent}{0pt}
  28. \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,},
  29. sensitive=false,
  30. morecomment=[l]Rem,
  31. morecomment=[l]',
  32. morestring=[b]",
  33. 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,},
  34. emphstyle=\itshape}
  35.  
  36. \lstloadlanguages{VBA, HTML}
  37. \lstset{%
  38. language=VBA,
  39. basicstyle=\small,
  40. keywordstyle=\color{blue}\bfseries,
  41. commentstyle=\color{green}\itshape,
  42. tabsize=1,
  43. extendedchars=false,
  44. inputencoding=latin1,
  45. breaklines=true,
  46. showstringspaces=false,
  47. stringstyle=\sffamily,
  48. numbers=left,
  49. numberstyle=\tiny,
  50. stepnumber=2,
  51. 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

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

Postby CDbile » Wed Apr 06, 2011 6:23 pm

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
  1. \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

Postby hanspeterzweifel » Wed Aug 31, 2011 8:30 am

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 :
  1. \documentclass[10pt]{article}
  2. \usepackage{a4wide}
  3. \usepackage[french]{babel}
  4. \usepackage[latin1]{inputenc}
  5. \usepackage{vmargin}
  6. \usepackage[dvips]{graphicx}
  7. %Ce package suivant pour l'insertion de code (HTML, PHP, MySQL,...)
  8. \usepackage{color,listings}
  9. \usepackage{array}
  10. \usepackage[T1]{fontenc}
  11. \newcolumntype{M}[1]{>{\raggedright}m{#1}}
  12.  
  13.  
  14. %STYLE VIDE SUR LES PAGES DE GARDE
  15. \pagestyle{empty}
  16.  
  17. \setpapersize{A4}
  18. \setmarginsrb{15mm}{10mm}{15mm}{10mm}{5pt}{5mm}{5pt}{5mm}
  19. %gauche, haut, droite, bas, hauteur en-tête, sep avant entête, hauteur pied, sep avant pied page
  20. \begin{document}
  21. \pagestyle{empty}
  22.  
  23.  
  24.  
  25. \renewcommand{\baselinestretch}{2}
  26.  
  27. \setlength{\parskip}{1.5ex plus 0.5ex minus 0.2ex}
  28. \setlength{\parindent}{0pt}
  29. \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,},
  30. sensitive=false,
  31. morecomment=[l]Rem,
  32. morecomment=[l]',
  33. morestring=[b]",
  34. 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,},
  35. emphstyle=\itshape}
  36.  
  37. \lstloadlanguages{VBA, HTML}
  38. \lstset{%
  39. language=VBA,
  40. basicstyle=\small,
  41. keywordstyle=\color{blue}\bfseries,
  42. commentstyle=\color{green}\itshape,
  43. tabsize=1,
  44. extendedchars=false,
  45. inputencoding=latin1,
  46. breaklines=true,
  47. showstringspaces=false,
  48. stringstyle=\sffamily,
  49. numbers=left,
  50. numberstyle=\tiny,
  51. stepnumber=2,
  52. numbersep=5pt}


Here is my main code :
  1. \subsubsection{La méthode Delete}\label{fin_listing_methode_attribut}
  2. 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.
  3.  
  4. 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.
  5.  
  6. \lstinputlisting[caption={[Effacer un objet Range]Effacer un objet Range},label={range_delete},language=VBA]{range_delete.src}
  7.  
  8. 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


Return to “Fonts & Character Sets”

Who is online

Users browsing this forum: No registered users and 2 guests