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.


2 Answers 2


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


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.



  • 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. May 4, 2013 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, 2013 at 13:56

You must log in to answer this question.

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