Installing Listings Package for LaTeX

Ever wondered how you could insert code in a latex document/presentation. Read on to know how to do it without any hassle.

Listings is a awesome package for LaTeX which makes including code a breeze. No need to do formating, no need for copy paste too !! It has syntax highlighting too. Check out the links given below. I had some difficulty installing listings package and couldn’t find a nice way and hence this blog post.

Here is the code: ( Try it and check if you already have listings)


It has support for many languages and if you find one thats not there, you could perhaps write a patch for one, thereby contributing to FOSS.

“../Programs/4.cpp” is the exact file name with its path.


  1. Download the zip here : and listing.sty from
  2. Unzip it using your favourite archive manager.
  3. Then go to the location where you installed TeX. For linux users it is /usr/share/texmf/ . Windows users, figure it yourself
  4. Copy the following files as mentioned :
    1. listings.pdf              to      texmf/doc/latex/listings
    2. listings.dtx, listings.ins,listings.ind, lstpatch.sty,lstdrvrs.dtx          to            texmf/source/latex/listings
  5. Create the directory texmf/tex/latex/listings or, if it exists already,remove all files except lst<whatever>0.sty and lstlocal.cfg from it.
  6. Run listings.ins through LaTeX  i.e  type  sudo latex listings.ins in your terminal.
  7. Move the generated files to texmf/tex/latex/listings.

If all goes well, then you should have listings working properly. Try it out with the code given above. If you still have any problems, just ping me.

There are plenty of examples available over the net which illustrate the use of Listings package.

Check this pdf here :

Check out these too :

5 Responses to “Installing Listings Package for LaTeX”

  1. Varun Says:

    works perfectly….great way to make a presentation related to coding stuff…..

  2. Fer Says:

    i’m using miktex, command prompt says “cant find file” (listings) i think im not using the right directory calling listings with latex.exe

  3. David Says:

    Thank you!!!
    It worked fine.

  4. Yves Says:

    Thanks for your one and only description how and where to put the listing files.
    Everybody explains the use of listings and not to forget to include \usepackage{listings} etc. but nobody explains where to put the files.

    But even with your explanation I can’t get it run.
    I did everything as described. At step 4 however there is no “source” folder under “texmf/”. The only “source” folder I could find was under “texmf-dist/”.
    So I copied these files (listings.dtx, listings.ins,listings.ind, lstpatch.sty,lstdrvrs.dtx) into “texmf-dist/source/latex/listings”.

    I can’t figure out the problem but I still get the error message “! LaTeX Error: Environment lstlistings undefined.”.

    If you need some more information please let me know.

    I hope you can give me some advice.

  5. Yves Says:

    Ok, got it.

    On Mac you have to use the folder “texmf-dist/” for every step instead of “texmf/”.

    Thanks anyway for the nice description.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: