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

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Post Reply