I am using LaTeX to write my internship report (I started to learn it one month ago), and I have some issues using the package listings. I'm not sure if everything is possible:

  1. How can I add a specific highlighting to the code? I mean, I know how to colorize keywords or comments, but I want to add new characters or patterns (just like @, $1, $~2 for example). Please see attached file for more information.
  2. How can I switch between two languages (and therefore two different syntax highlightings) in my report? For now, I just use command.com (aka batch WinXP =D), but what if I want to write C++ then, and just after, command.com again?
  3. Then, my real problem: why do space characters become visibles at line 13 (see attachments)? To be specific, it start at line 12 when I use two double quotes (when I delete one everything is ok). I think LaTeX interprets everything as a string, but... it's not =D
  4. Finally (and I think it will be tricky, and maybe impossible), is it possible to add my own language to those interpreted by listings? In my internship, I use mainly WLangage (by PCSoft), and of course it is not known by the listings package. Currently, I avoid the problem by setting my code into a typewriter environment and by using \textcolor{mycolor}{mykeyword}, which is not the best. I lost line numbers and tabulations.

To understand better, here is what I got after compilation:

Result of the compilation

And here is a minimal code of what I do:





    % Things that define my style
    % I don't really think that fancypagestyle is the cause of the problem, but I let it


        @echo off   rem désactive l’affichage des commandes
        cls             rem efface les lignes précédentes

        rem on envoie les paramètres dans des variables
        rem l’ajout du tilde supprime les double quote entourantes ("")
        set requestType=%1
        set params=%~2
        set url=%3
        set redirect=%4

        rem remplacement de "" par " et de #egal# par =
        set params= %params:""="%
        set url= %url:#egal#==%

        curl -X "%requestType%" %params% %url% > %redirect%


I solved my issues.

To add specific highlighting to the code, I have to use morekeywords={my, new, keywords}, and to colorize it in an other way, I must write:

    keywords=[3]{\%1,\%~2,\%3,\%4, \%params\%, \%url\%, \%redirect\%},

And now, I know how to switch between two languages: I have to define two styles, and then use them when doing listings: \begin{lstlisting}[style=MyOtherStyle]

And finally, to escape my double quote, I can write escapechar={°} in the \lstset and then, escape the quote in the \begin{lstlisting} with °\color{mycolor}{"}°.

closed as unclear what you're asking by jubobs, Masroor, henrique, dustin, Benedikt Bauer May 23 '14 at 18:00

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Welcome to TeX.SX! Switching the language is done by \begin{lstlisting}[language=A] where A means a language of your choice – user31729 May 23 '14 at 7:33
  • 1
    Thanks @ChristianHupfer! I knew about the option [language=A], but since I use a \lstset, I would have wanted to change the colors of the syntax highlighting depending on the language I use. – bjorge May 23 '14 at 8:01
  • 1
    Welcome to TeX.SX! You don't have to sign with your name since it automatically appears in the lower right corner of your post. You seem to be asking several unrelated questions, here. On TeX.SX, we try to keep unrelated questions on separate pages. In the future, if you have multiple questions that are unrelated to one another, you should ask each in a separate TeX.SX "question". You'll stand a better chance of getting a satisfactory answer to each of your questions. – jubobs May 23 '14 at 9:47
  • 1
    Thank you @Jubobs! I signed with my name because when I posted first, it was user### =D Now I updated it. I also will remember to ask unrelated questions on separated pages in the future, for now I solved my main issue with listings documentation, 4.14 Escaping to LATEX, I hope it will help other people! – bjorge May 23 '14 at 9:58
  • 1
    Please update your question to reflect what the remaining problems are. – jubobs May 23 '14 at 10:01

Browse other questions tagged or ask your own question.