4

In my document, I need to include code written in Macaulay2, which is not a predefined language in listings.

To define it myself, I started looking for a list of keywords, and found the variable describing the syntax highlighting in Emacs. I have uploaded the file here.

This contains a list of keywords, which is great, but it also includes regular expressions. I know nothing about regular expressions, so I am unsure of how to handle them. I can of course delete the regular expressions and simply add the keywords in the usual manner:

\lstdefinelanguage{Macaulay2}
{
    morekeywords = {FirstKeyword, 
                    SecondKeyword}
}

But if the regular expressions give Emacs additional information about how the keywords should be treated, then I would like listings to have that information as well.

1
1

I can verify that the regular expressions in M2-symbols.el do not give Emacs any additional information other than what the words mean. There are four categories listed in M2-mode-font-lock-keywords:

  • Types (ComplexField, ...)
  • Function names (associatedPrimes, ...)
  • Constants (CallLimit, ...)
  • Generic keywords (and, break, catch, ...)

That's the only 'extra' information Emacs has (and that extra information has nothing to do with the regular expressions themselves).

In listings, I don't believe there is a way to provide this information built-in (in, e.g., a morefunctions key). Refer to the documentation (particularly section 4) for other ways to set these keywords apart (like the emph and moreemph keys).

0

Instead of using listings, you could try to use the package minted, that relies on the external program pygmentize (http://pygments.org/). As the homepage states:

support for new languages and formats are added easily; most languages use a simple regex-based lexing mechanism

0

I created a lstlang0.sty with the list of keywords from M2-symbols.el. When stored locally, listings will automatically import the file and then it is possible to highlight keywords using language = Macaulay2.

The keywords are divided into four groups, as explained in Sean's answer. By default, these typeset in the same manner. However, you can distinguish them in \lsetset{} like this:

keywordstyle = [1]\color{red},
keywordstyle = [2]\color{blue},
keywordstyle = [3]\color{green},
keywordstyle = [4]\color{yellow}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.