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 creating a custom language definition with the LaTeX listings package that should render Java's Jar-Manifest files (key: value Pairs) so that one can easily distinguish key and value.

My approach ("hacky" but alright for my problem) is to declare the space character as delimiter for comments (as // is in Java etc.) and style comments as normal text and normal text (what will everything left from the first space be - especially the key:) as keywords. So I'll even style multiline entries (by specification starting with a space) correctly. All by a one-line language definition.

a part of a sample manifest file

Manifest-Version: 1.0
Bundle-Description: The realization of the context bus on top of Sodapop
 7 as part of the universAAL Middleware (OSGi)

my language definition

\lstdefinelanguage{manifest}{
    morecomment=[l] % <-- this is the problem
}

My problem is: how can I declare the space char as the delimiter for comments?

Escaping it with a preceeding backslash (like recommended when using #, & or other TeX-reserved charaters) does not work. Hacking around with the unicode representation U+0020 and the inputenc package does neither.

Edit: Minimal Working Example

\documentclass{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage{listings}

\lstdefinelanguage{manifest}{
    morecomment=[l]: % works only for single-line entries, need 'space', not ':'
}

\begin{document}
\begin{lstlisting}[language=manifest, 
    basicstyle=\bfseries, 
    commentstyle=\normalfont]
Manifest-Version: 1.0
Bundle-Description: The realization of the context bus on top of Sodapop
 7 as part of the universAAL Middleware (OSGi)
\end{lstlisting}
\end{document}
share|improve this question

migrated from stackoverflow.com Nov 25 '12 at 20:46

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer

up vote 2 down vote accepted

Try this for single line comments:

morecomment=[l]{\ }
share|improve this answer
add comment

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.