Page 1 sur 2

lstlisting

Posté : ven. 1 févr. 2013, 07:16
par zariski
Bonjour , n'ayant pas eu de réponse sur mathematex, j'expose ici mon soucis!

Je souhaiterais voir apparaitre les commentaires suivis de % en gris clair, cependant le \ et le = reste en bleu.
Comment remédier au problème svp ?

Code : Tout sélectionner

%%%%%%%%% Code Latex %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{textcomp}
\usepackage{listings}

\lstdefinelanguage{Latex}{%
         sensitive=true,
         morekeywords =[1]{addtolength,arrayrulecolor,arrayrulewidth,arraystretch,
                          backslashbox,begin,bfseries,caption,cdashline,cellcolor,center,cline,
                          centering,color,colorbox, columncolor,dashlinedash,dashlinegap,definecolor,degres,
                         ding,doublerulesepcolor,doublerulesep,end,endfirsthead,endhead,
                         endfoot,extrarowheight,fcolorbox, hdashline,hline,hhline,hspace,itshape,jot,kill,multicolumn,
                         multirow, newlength,newpage,newcolumntype,newcommand,newcommandx,
                         pagecolor,par,raggedleft,raggedright,renewcommand,renewcommandx,rightarrow,rotatebox,rowcolor,
                         rowcolors,setlength,setlongtables,sidewaysfigure,tabcolsep,textcolor,textwidth,texteuro,texttt,the,tt,turn,
                         usepackage,vrule,b,c,l,p,m,r},     % en bleu fonce
         %
         morekeywords = [2]{array,arydshln,colortbl,document,eqnarray,graphicx,
                            longtable,minipage,pifont,quote,rotating,sideways,
                            sidewaystable,slashbox,tabbing,tabularx,tabular,table,turn,xcolor},    % en vert fonce
         %
         otherkeywords={|,&,<,>,$,@,\\,!, ; , +, -,=},
         literate=
            *{\{}{{\textcolor{orange}{\{}}}{1}
            {\}}{{\textcolor{orange}{\}}}}{1}
            {[}{{\textcolor{orange}{[}}}{1}
            {]}{{\textcolor{orange}{]}}}{1},
         escapeinside=§§,
         morecomment=[l] \% ,
         }[strings,keywords,comments]

\lstdefinestyle{LatexCode}{%
    language         = Latex,
    basicstyle       = \bf\ttfamily\color{black},
    commentstyle     = \color{grisclair},
    keywordstyle     = {[1]\color{bleufonce}},
    keywordstyle     = {[2]\color{vertfonce}\sffamily},
    keywordstyle     = {[3]\color{violet}},
    keywordstyle     = {[4]\color{red}\bfseries},
    extendedchars    = true,
    tabsize          = 4,
    showtabs         = false,
    showspaces       = false,
    showstringspaces = false,
    breakautoindent  = true,
    breaklines       = true,
    flexiblecolumns  = true,
    keepspaces       = true,
    }

\lstset{style = LatexCode,
        columns = flexible
       }

%%%%%%%%% Fin Code Latex %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Re: lstlisting

Posté : ven. 1 févr. 2013, 20:02
par GM
Personnellement... je ne suis pas un spécialiste de listings (même si je m'y suis intéressé lors des premières documentations sur Asymptote) donc je ne saurai répondre sans chercher un temps certain et sans faire des essais. Si c'est encore utile plus tard... je testerai mais pour l'instant le peu de temps dont je dispose m'oblige à me limiter aux questions où je sais répondre sans chercher. Désolé.

Re: lstlisting

Posté : ven. 1 févr. 2013, 22:33
par zariski
pas de soucis, merci tout de même !

Re: lstlisting

Posté : sam. 2 févr. 2013, 17:00
par GM
zariski a écrit :n'ayant pas eu de réponse


Le problème est que tu ne fournis pas un ECM (exemple complet minimum) que les personnes peuvent tester !

S'ils doivent aller ajouter les packages manquants, créer l'exemple que tu ne donnes pas... et aller deviner comment tu as défini tes couleurs persos (bleufonce, vertfonce ???)... ceux qui pourraient te répondre en testant... ne vont pas le faire car ils ne vont pas comprendre qu'ils doivent perdre du temps à créer l'exemple que toi, tu as trouvé trop fastidieux à proposer.

Donc avec un tel bout du code incomplet... tu ne t'adresses qu'à une très infime partie de spécialistes qui savent aider sans tester... et il ne faut pas être étonné que la réponse espérée tarde à arriver.

Mais tu as de la chance : je crois que pg vient de te répondre sur mathematex. ;-)

Re: lstlisting

Posté : sam. 2 févr. 2013, 17:07
par GM
Ceci :

Code : Tout sélectionner

% !TEX TS-program = latexmk
% !TEX encoding = UTF-8
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[a4paper,%
            hmargin={1cm,1cm},%
            vmargin={1cm,1cm},%
            nohead,nofoot]{geometry}
\setlength{\parindent}{0pt}

\usepackage{xcolor}
\usepackage{listings}

\lstdefinelanguage{Latex}{%
sensitive=true,
morekeywords =[1]{addtolength,arrayrulecolor,arrayrulewidth,arraystretch,
                  backslashbox,begin,bfseries,caption,cdashline,cellcolor,center,cline,
                  centering,color,colorbox, columncolor,dashlinedash,dashlinegap,definecolor,degres,
                  ding,doublerulesepcolor,doublerulesep,end,endfirsthead,endhead,
                  endfoot,extrarowheight,fcolorbox, hdashline,hline,hhline,hspace,itshape,jot,kill,multicolumn,
                  multirow, newlength,newpage,newcolumntype,newcommand,newcommandx,
                  pagecolor,par,raggedleft,raggedright,renewcommand,renewcommandx,rightarrow,rotatebox,rowcolor,
                  rowcolors,setlength,setlongtables,sidewaysfigure,tabcolsep,textcolor,textwidth,texteuro,texttt,the,tt,turn,
                  usepackage,vrule,b,c,l,p,m,r},     % en bleu fonce
         %
         morekeywords = [2]{array,arydshln,colortbl,document,eqnarray,graphicx,
                            longtable,minipage,pifont,quote,rotating,sideways,
                            sidewaystable,slashbox,tabbing,tabularx,tabular,table,turn,xcolor}, % en vert fonce
         %
         otherkeywords={|,&,<,>,$,@,\\,!, ; , +, -,=},
         literate=
            *{\{}{{\textcolor{orange}{\{}}}{1}
            {\}}{{\textcolor{orange}{\}}}}{1}
            {[}{{\textcolor{orange}{[}}}{1}
            {]}{{\textcolor{orange}{]}}}{1},
         escapeinside=§§,
         morecomment=[l] \% ,
}[strings,keywords,comments]

\lstdefinestyle{LatexCode}{%
    language         = [LaTeX]TeX,
    basicstyle       = \bf\ttfamily\color{black},
    commentstyle     = \color{lightgray},
    keywordstyle     = {[1]\color{blue}},
    keywordstyle     = {[2]\color{green}\sffamily},
    keywordstyle     = {[3]\color{purple}},
    keywordstyle     = {[4]\color{red}\bfseries},
    extendedchars    = true,
    tabsize          = 4,
    showtabs         = false,
    showspaces       = false,
    showstringspaces = false,
    breakautoindent  = true,
    breaklines       = true,
    flexiblecolumns  = true,
    keepspaces       = true,
    }

\lstset{style = LatexCode,
        columns = flexible
       }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\begin{lstlisting}
% Test de commentaire avec \ et =.
\documentclass{article}%           autres choix : report, book
\usepackage[utf8]{inputenc}%       encodage du fichier source
\usepackage[T1]{fontenc}%          gestion des accents (pour les pdf)
\end{lstlisting}

\end{document}


me donne cela :

Image

Re: lstlisting

Posté : sam. 2 févr. 2013, 19:16
par zariski
J'ai bien compris le message mais nul question, pour moi, de pester contre qui que ce soit, je suis bien trop content qu'on me réponde. Et tant pis si je n'ai pas ma réponse.
Au passage la seule réponse que j'ai eue (pg) ne me satisfait pas. Je perds les couleurs que j'ai définies.
Je ne souhaite pas utiliser [LaTeX]TeX puisque je définies moi même un "Latex".
En plus je souhaite profiter de "\lstinline" pour du code sur une seule ligne. :)
Aussi voici un autre extrait de mon ecm:


Code : Tout sélectionner

% couleurs personnelles
  \definecolor{vertclair}{rgb}{0.10,0.55,0.17}
  \definecolor{vertfonce}{rgb}{0,0.44,0}
  \definecolor{grisclair}{rgb}{0.68,0.68,0.68}
  \definecolor{prune}{rgb}{0.65,0.00,0.00}
  \definecolor{bleufonce}{rgb}{0.06,0.06,1.00}
  \definecolor{bleuNuit}{rgb}{0.15,0.14,0.43}
  \definecolor{violet}{rgb}{0.73,0.24,0.71}
  \definecolor{orange}{rgb}{1,0.36,0.00}

%%%%%%%%% Code Latex %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{textcomp}
\usepackage{listings}
\lstdefinelanguage{Latex}{%
         sensitive=true,
         morekeywords =[1]{addtolength,arrayrulecolor,arrayrulewidth,arraystretch,
                          backslashbox,baselineskip,begin,bfseries,caption,cdashline,
                          cellcolor,center,cline,centering,color,colorbox,
                         columncolor,dashlinedash,dashlinegap,definecolor,degres,
                         depth,ding,doublerulesepcolor,doublerulesep,end,endfirsthead,
                         endhead,endfoot,evensidemargin,extrarowheight,fcolorbox,
                         fbox,footskip,framebox,headheight,headsep,height,hdashline,
                         hline,hhline,hrulefill,hoffset,hspace,itshape,jot,kill,
                         layout,marginparwidth,marginparsep,mbox,makebox,multicolumn,
                         multirow,newlength,newenvironment,newpage,newcolumntype,
                         newcommand,newcommandx,
                         newsavebox,oddsidemargin,pagecolor,par,parskip,parbox,
                         raggedleft,
                         raggedright,raisebox,reflectbox,resizebox,renewcommand,
                         renewcommandx,rightarrow,rotatebox,rowcolor,rowcolors,rule,
                         scalebox,savebox,sbox,setlength,setlongtables,settowidth,
                         settoheight,settodepth,sidewaysfigure,tabcolsep,textcolor,
                         textheight,textwidth,texteuro,texttt,the,totalheight,topmargin,
                         topskip,tt,turn,usepackage,usebox,verb,voffset,vrule,width,
                         b,c,l,p,m,r}, % en bleu fonce
         %
         morekeywords = [2]{array,arydshln,colortbl,document,eqnarray,graphics,graphicx,
                            longtable,lrbox,minipage,pifont,quote,rotating,sideways,
                            sidewaystable,slashbox,tabbing,tabularx,tabular,table,turn,
                            xcolor}, % en vert fonce
         %
         otherkeywords={|,&,<,>,$,@,\\,!, ; , +, -,=}, % Mettre \{ pour avoir une parenthèse.
         literate=
            *{\{}{{\textcolor{orange}{\{}}}{1}
            {\}}{{\textcolor{orange}{\}}}}{1}
            {[}{{\textcolor{orange}{[}}}{1}
            {]}{{\textcolor{orange}{]}}}{1},
         escapeinside=§§, %Pour mettre du verbatim dans du verbatim
         morecomment=[l]\%,
      }[strings,keywords,comments]

\lstdefinestyle{LatexCode}{%
    language         = Latex,
    basicstyle       = \bf\ttfamily\color{black},
    %identifierstyle  = \color{couleuridentifier},
    %stringstyle      = \color{couleurstring},
    commentstyle     = \color{grisclair},
    keywordstyle     = {[1]\color{bleufonce}},
    keywordstyle     = {[2]\color{vertfonce}\sffamily},
    keywordstyle     = {[3]\color{violet}},
    keywordstyle     = {[4]\color{red}\bfseries},
    keywordstyle     = {[5]\color{black}},
    extendedchars    = true,
    tabsize          = 4,
    showtabs         = false,
    showspaces       = false,
    showstringspaces = false,
    breakautoindent  = true,
    breaklines       = true,
    flexiblecolumns  = true,
    keepspaces       = true,
    }

\lstset{style = LatexCode,
        columns = flexible
}

%%%%%%%%% Fin Code Latex %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Re: lstlisting

Posté : sam. 2 févr. 2013, 19:32
par GM
zariski a écrit :Aussi voici un autre extrait de mon ecm:


Là, tu m'as fait rire. :lol:
Ce n'est pas un extrait d'ECM que l'on a besoin dans toutes les demandes... mais un ECM complet (Il ne doit y avoir aucun package ou commande inutile... et il faut pouvoir se contenter de copier-coller le code et d'appuyer sur la touche de compilation) !!!

zariski a écrit :J'ai bien compris le message

Non, non. :lol: :mrgreen:

Re: lstlisting

Posté : sam. 2 févr. 2013, 20:30
par zariski
Bon là j'espère ne plus engendrer l'hilarité !
Le signe "=" apparait en bleu ainsi que "\" dans les commentaires et je voudrais qu'ils apparaissent en gris

Code : Tout sélectionner

\documentclass[12pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[francais]{babel}

\usepackage{lmodern}
\usepackage{amsmath,amsfonts,amssymb,amstext,pifont}
\usepackage{longtable}
\usepackage{color}
\usepackage[table,dvipsnames,svgnames]{xcolor}
\usepackage{array}
\usepackage{graphicx}
\usepackage{multirow}


% couleurs personnelles
  \definecolor{vertclair}{rgb}{0.10,0.55,0.17}
  \definecolor{vertfonce}{rgb}{0,0.44,0}
  \definecolor{grisclair}{rgb}{0.68,0.68,0.68}
  \definecolor{prune}{rgb}{0.65,0.00,0.00}
  \definecolor{bleufonce}{rgb}{0.06,0.06,1.00}
  \definecolor{bleuNuit}{rgb}{0.15,0.14,0.43}
  \definecolor{violet}{rgb}{0.73,0.24,0.71}
  \definecolor{orange}{rgb}{1,0.36,0.00}

%%%%%%%%% Code Latex %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{textcomp}
\usepackage{listings}

\lstdefinelanguage{Latex}{%
         sensitive=true,
         morekeywords =[1]{addtolength,arrayrulecolor,arrayrulewidth,arraystretch,
                          backslashbox,baselineskip,begin,bfseries,caption,cdashline,
                          cellcolor,center,cline,centering,color,colorbox,
                         columncolor,dashlinedash,dashlinegap,definecolor,degres,
                         depth,ding,doublerulesepcolor,doublerulesep,end,endfirsthead,
                         endhead,endfoot,evensidemargin,extrarowheight,fcolorbox,
                         fbox,footskip,framebox,headheight,headsep,height,hdashline,
                         hline,hhline,hrulefill,hoffset,hspace,itshape,jot,kill,
                         layout,marginparwidth,marginparsep,mbox,makebox,multicolumn,
                         multirow,newlength,newenvironment,newpage,newcolumntype,
                         newcommand,newcommandx,
                         newsavebox,oddsidemargin,pagecolor,par,parskip,parbox,
                         raggedleft,
                         raggedright,raisebox,reflectbox,resizebox,renewcommand,
                         renewcommandx,rightarrow,rotatebox,rowcolor,rowcolors,rule,
                         scalebox,savebox,sbox,setlength,setlongtables,settowidth,
                         settoheight,settodepth,sidewaysfigure,tabcolsep,textcolor,
                         textheight,textwidth,texteuro,texttt,the,totalheight,topmargin,
                         topskip,tt,turn,usepackage,usebox,verb,voffset,vrule,width,
                         b,c,l,p,m,r}, % en bleu fonce
         %
         morekeywords = [2]{array,arydshln,colortbl,document,eqnarray,graphics,graphicx,
                            longtable,lrbox,minipage,pifont,quote,rotating,sideways,
                            sidewaystable,slashbox,tabbing,tabularx,tabular,table,turn,
                            xcolor}, % en vert fonce
         %
         otherkeywords={|,&,<,>,$,@,\\,!, ; , +, -,=}, % Mettre \{ pour avoir une parenthèse.
         literate=
            *{\{}{{\textcolor{orange}{\{}}}{1}
            {\}}{{\textcolor{orange}{\}}}}{1}
            {[}{{\textcolor{orange}{[}}}{1}
            {]}{{\textcolor{orange}{]}}}{1},
         escapeinside=§§, %Pour mettre du verbatim dans du verbatim
         morecomment=[l]\%
         }[strings,keywords,comments]

\newcommand\lencolor[1]{\textcolor{red}{\bfseries\texttt{#1}}} %Commande pour mettre les unités en couleur

\lstdefinestyle{LatexCode}{%
    language         = Latex,
    basicstyle       = \bf\ttfamily\color{black},
    %identifierstyle  = \color{couleuridentifier},
    %stringstyle      = \color{couleurstring},
    commentstyle     = \color{grisclair},
    keywordstyle     = {[1]\color{bleufonce}},
    keywordstyle     = {[2]\color{vertfonce}\sffamily},
    keywordstyle     = {[3]\color{violet}},
    keywordstyle     = {[4]\color{red}\bfseries},
    keywordstyle     = {[5]\color{black}},
    extendedchars    = true,
    tabsize          = 4,
    showtabs         = false,
    showspaces       = false,
    showstringspaces = false,
    breakautoindent  = true,
    breaklines       = true,
    flexiblecolumns  = true,
    keepspaces       = true,
    }

\lstset{style = LatexCode,
        columns = flexible
    }

%%%%%%%%% Fin Code Latex %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{lstlisting}
\newlength{\mylen} %création de \mylen
Après création : mylen vaut \the\mylen %La valeur de mylen

\setlength{\mylen}{10mm} % \mylen= 10mm
Après setlength : mylen vaut \the\mylen

\addtolength{\mylen}{10mm}
Après addtolength : mylen vaut \the\mylen
\end{lstlisting}

\end{document}

Re: lstlisting

Posté : dim. 3 févr. 2013, 09:58
par GM
zariski a écrit :Bon là j'espère ne plus engendrer l'hilarité !

Pas l'hilarité... mais une nouvelle suggestion !

Avec un vrai ECM (complet et MINIMAL pour montrer le problème)...
... tu peux répondre à pg sur Mathematex : il va maintenant mieux comprendre ta demande... et d'autres répondront peut-être, cette fois.


Pourquoi j'insiste sur MINIMAL... car il faut toujours chercher à isoler le problème.
80% des "usepackage" n'ont rien à faire dans ton dernier exemple... pour ce que tu veux montrer.

J'ai commencé à lire la doc de listings (L'as tu lue ?), mais je n'ai pas encore trouvé si ce que tu veux sera possible.

-----------------------

Je sors un peu du sujet pour parler des couleurs :

  • pourquoi aller charger color avant xcolor ??
  • pourquoi passer dvipsnames et svgnames en option à xcolor... si à l'arrivée, c'est pour définir tes propres couleurs et si tu ne trouves pas ton bonheur dans ce que dvipsnames et svgnames proposent ?

    Image

    Image

Attention quand tu charges à la fois dvipsnames et svgnames : ils définissent pas exemple tous les deux Fushia... mais ce n'est pas le même.

Re: lstlisting

Posté : dim. 3 févr. 2013, 11:26
par GM
Qu'espères-tu au niveau des couleurs pour ta liste de "otherkeywords" ?
J'ai bien compris que s'ils sont dans des commentaires... tu les espères dans la couleur des commentaires.
Mais en dehors des commentaires... ?

Cela fait partie des choses que tu pourras préciser si tu complètes ta demande sur mathematex.