Generallistings package: defining own language

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
mychi
Posts: 7
Joined: Tue Mar 02, 2010 4:54 am

listings package: defining own language

Post by mychi »

I want to define rules for the programming language XQuery that build on top of the already defined rules for XML. The User's Guide already helped a lot in certain things I wanted to do with the listings package. But now I'm at a loss with the following problem (simplified as much as possible):

Code: Select all

\documentclass{article}
\usepackage{listings}
\lstdefinelanguage{XQuery}[]{XML}{
	tag=[s]<>,	% =*: also apply styles within tag, =**: cumulate styles
	morekeywords={text},
	sensitive=false
}
\lstset{%
	language=XQuery,
	tagstyle=\bfseries,
	keywordstyle=\underbar,
	stringstyle=\itshape,
	showstringspaces=false
}
\begin{document}
\begin{lstlisting}
text <hello type='text/plain'>world</hello>/text()
\end{lstlisting}
\end{document}
which results in:
text <hello type='text/plain'>world</hello>/text()
whereas the desired output would be:
text <hello type='text/plain'>world</hello>/text()
In particular the word "text" within the hello-tag should NOT be underlined (because there are no * or ** in the definition of "tag=[s]<>"). In fact if you put one or two *, that part works as expected ("text" is in stringstyle (italics) or stringstyle+tagstyle (italics and bold) respectively).

But the "text" words outside don't get their keywordstyle in either of the cases.

I did have a look at lstdrvrs.dtx, where XML is defined. But I couldn't work out what the cause could be.

Does anyone have an idea? Is there somebody in this forum who already did (try to) define an own language as well?

Cheers

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Post Reply