# Best way to write an xml tag

I'm writing a document about an XML schema, and I will be talking a lot of times about that <tag1> or that other <tag2>. Since I'm only mentioning them and not printing a whole XML file, it doesn't feel like a job for listings.

I suppose using $<tag1>$ wouldn't fit well either. So... which would be the best way of writing isolated XML tags in a document?

-

The definition of a new command would be the easiest way to go.

\newcommand*{\xml}[1]{\texttt{<#1>}}


Use it in your document as \xml{tag}.

-

With listings you can do the following:

\lstMakeShortInline{|}


And then use it thus: |<tag1>| and it will be printed using the listings style, and syntax highlighting and so on. You could use a symbol other than | if you so wished.

-
\documentclass[11pt]{article}

\def\<#1>{$\langle\texttt{#1}\rangle$}

\begin{document}
I will be talking a lot of times about that \<tag1> or that other \<tag2>.
\end{document}


-
I don't deal with XML a lot, but I've never seen \langle and \rangle used for the pointy brackets < and >. While the former are prettier in many cases, I think the latter are the standard, most importantly because they are the ones you actually use in code. Furthermore, your sample uses the normal font for the brackets and teletype for the tag, which seems typographo-semantically imprecise. – doncherry Nov 30 '11 at 15:07
Well, \def\<#1>{\texttt{<#1>}} would fix that and you could still have a notation that is very close to the literal strings. I precisely like \langle and \rangle because they don't take up as much space as < and >. But I'll admit that using \langle in body text and < in listings would be wrong. – Christian Lindig Nov 30 '11 at 17:37