Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to write some XML tags as part of my text but I can not get the < and > symbols to come out right in the output. What am I missing?

I have tried both <tag> and \<tag\>, the former results in ¡tag¿ and the later in error messages.

The document class is report and the environment is document.

share|improve this question
If you have a lot of source code in your document, consider tex.stackexchange.com/questions/867/syntax-coloring-in-latex. –  Alex May 4 '13 at 9:53
this, and other features of xml, are addressed in How to escape xml code? –  barbara beeton May 4 '13 at 12:37

2 Answers 2

up vote 6 down vote accepted

For formatting tags like <tag> prefer to wrap them into \verb|<tag>|.

Also, I'd recommend to create a custom command, like this (this will allow you to change the typesetting of all XML tags at once):

This is an XML \verb|<tag>| example.

This is an improved \tag{tag} example.


enter image description here

share|improve this answer

If you're going to have to type up more of these tags, the listings package may be well worth a try (employing colors for operators (or literals, or whatever) is tricky; if you'd like them, usually, one suggests the package minted, which unfortunately does not do inline stuff! catch 22!):


Some remarks about the code:

  1. ! is a delimiter for the code that goes between its two instances: so, this should be a symbol that does not appear in the code (cf. | that appears in \verb command in m0nhawk's solution). So,

    \lstinline<<tag>< % wrong
    \lstinline><tag>< % not wrong, but not what you want  
    \lstinline$<tag>$ % right 
    \lstinline+<tag>+ % right
    \lstinline|<tag>| % right 
  2. The delimiter cannot be this [ unless you do the following:


    (What is happening is that, the \lstinline looks for an optional list of key=value pairs, when it first encounters [.)

  3. I am posting this answer, mostly for the reason that, using \verb, you end up with different font family, which may well be your desire! In case, you'd like the same font family, this solution is open.



share|improve this answer
In this case I'm indifferent about the font or color, but it's good to know the options. It's just for a handful of tags in thi text and the font resulting from using \verb looks fine in the output so I'll stick to using that. –  LarsNielsen May 4 '13 at 13:55
Sure thing! :) As I said, I am posting this mostly for variety, but also we can refer to this later on. –  kan May 4 '13 at 13:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.