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'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?

share|improve this question

3 Answers 3

up vote 9 down vote accepted

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}.

share|improve this answer

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.

share|improve this answer
\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}

XML Tags

share|improve this answer
1  
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

Your Answer

 
discard

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.