I am using LaTeX for very first time and have very basic knowledge about it. I am using the template from here to write my thesis. I am using Ubuntu 12.04.

When I try to include a small XML file in LaTeX with the following code, it shows the file just in one line (I am not able to see the full file in line though). But I want it to be displayed as a typical XML file (showing hierarchy).


Could someone please tell me how I can make LaTeX treat that file as an XML and show properly?

  • 1
    Are you sure that your xml file consists newlines?
    – Eddy_Em
    Jan 11, 2013 at 10:33
  • A've just tried 2 variants: Xml and XML works similar.
    – Eddy_Em
    Jan 11, 2013 at 10:37
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers.
    – jub0bs
    Mar 1, 2014 at 22:30
  • I just wanted to advice (for people with languages like spanish,german,french) that include, > á,í,ó,Ü,etc.. inside the file xml. \lstinputlisting will give you an error referring to mathematical symbols, which can be confused. The real error are those characters.
    – bheatcoker
    May 28, 2014 at 7:51

1 Answer 1


Try this code:



This is a sample file:



Using the above code I have results like this:

enter image description here

Please note that the I've added "price", "name" and "food" as keywords. Credits for sample XML file: http://www.w3schools.com/xml/xml_examples.asp

  • I am sorry but I need to ask u this silly thing. I have main file named Thesis.tex and I import different chapter files in it (like chap1.tex, chap2.tex etc.). And I want this xml file in my chap2.tex. So I am not allowed to write the code u specified over there. So where should I write it ? may be in Thesis.tex ? but then I dont want it to affect the settings adversely somewhere else.
    – Ragini
    Jan 11, 2013 at 11:19
  • 4
    No question is silly ;) You can do this: Add the necessary packages (i.e. listing, color, etc) to the main file. Then add the rest to the chap2.tex. I hope this solves the problem. Let me know if it's not clear.
    – Pouya
    Jan 11, 2013 at 11:27
  • Thanks Pouya ! I did like u said. IT shows proper colouring n all but no proper indentation, the hierarchy. May be newline character is missing or something in original file ? How to view neline symbol of file in ubuntu 12.04 ?
    – Ragini
    Jan 11, 2013 at 11:56
  • 5
    @Ragini listings is only choosing colours and fonts it assumes the file has been indented already. There are several tools and editors that can indent the file nicely if it is not already indented (you could get tex to parse the xml and indent but it's easier to just use an xml tool for that job) Jan 11, 2013 at 12:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .