I'm using the current (as of a few minutes ago) Subversion repository for TextMate bundles, and I'm having a problem with the LaTeX mode's highlighting. The problem is with the "lstlisting" environment (and possibly others).
With the default Mac Classic theme, this environment is supposed to have a light blue background. However, while writing a recent paper, the highlighting often did not work the way it's supposed to. To demonstrate the problem, I've attached three LaTeX files. The rightway.tex file shows how the highlighting is supposed to be; the wrongway1.tex and wrongway2.tex files show incorrect highlighting. Is there a simple fix for these problems?
Thanks,
Trevor
P.S. Although the rightway.tex file highlights the environment in blue as it should, it also changes the word "is" to bold. Why does it do this?
Trevor,
1. You can check the current scope of text by placing the caret there plus pressing ctrl-shift-p. You will see that there are different selectors active in your examples.
2. With a version of brilliance black it looks like this:
I don't see your problem… the left two examples have embedded source code which is correctly marked up and has a blue background in MacClassic, black here. The right example has no embedded source and thus no blue.
??
Dan
On Oct 14, 2006, at 5:59 PM, Trevor Harmon wrote:
With the default Mac Classic theme, this environment is supposed to have a light blue background. However, while writing a recent paper, the highlighting often did not work the way it's supposed to. To demonstrate the problem, I've attached three LaTeX files. The rightway.tex file shows how the highlighting is supposed to be; the wrongway1.tex and wrongway2.tex files show incorrect highlighting. Is there a simple fix for these problems?
I fixed the problem with wrongway2.tex. Basically the rule for lstlisting environments was matching starting at the \begin {lstlisting} part. However, the generic rule was matching earlier, because it was also matching the spaces in front of the \begin, if any. So the lstlisting rule didn't have any chance.
The second problem you are having doesn't have a very elegant solution. The problem is that one needs to specify what language the code is to be highlighted as. Right now, it assumes the code is Python code, basically because the developer who added the rule needed that. This is what causes your other problems (for instance "is" is a keyword in Python), and there is no elegant fix for this atm. We could perhaps come up with some convention, like having to precede the \begin{lstlisting} line with a command line like:
# Java code
and so on. Then we could put a couple of rules in place, each matching one of the common languages, though as you can imagine this can quickly get out of hand and bloat the grammar to twice its size at least.
To "fix" this locally, you have two options. The one is to change the LaTeX language grammar, so that the rule matching lstlisting changes to include your preferred language instead. This will cost you losing any updates to the language grammar that may come.
A more robust solution is to create a new grammar, perhaps called JavaLaTeX or some such, which first has a rule for an lstlisting environment, essentially copying the one from the LaTeX bundle and changing the include rules in it. After this one rule, JavaLaTeX simply includes the LaTeX grammar.
Thanks,
Trevor
Haris
On 15. Oct 2006, at 03:10, Charilaos Skiadas wrote:
[...] it assumes the code is Python code [...] We could perhaps come up with some convention, like having to precede the \begin {lstlisting} line with a command line like:
# Java code
and so on. Then we could put a couple of rules in place, each matching one of the common languages, though as you can imagine this can quickly get out of hand and bloat the grammar to twice its size at least.
There are two (distant future) features which combined will address the problem:
1. Scope names can include captures from the match (and full $- notation for transforming them etc.). 2. The previously mentioned scope injection.
This means the convention we come up with now should, to take advantage of this in the future, include the grammar name, and preferably be on the same line, in the simplest case:
\begin{lstlisting}{} % Java
So don’t worry about presently having to create a rule per thing we want to support, as that’s only a (somewhat) short-term solution.
On Oct 14, 2006, at 10:43 PM, Allan Odgaard wrote:
\begin{lstlisting}{} % Java
So don’t worry about presently having to create a rule per thing we want to support, as that’s only a (somewhat) short-term solution.
Ok, I have now added support for Java lstlistings with this comment type. We will be adding other languages on a need basis, so let me know if you need lstlistings in some other language.
Haris
Hi Haris,
I've just been doing a bunch of writing again and I noticed that there is a problem with the strategy of putting % Java or % Python at the end of the lstliting line.
When I do this, I lose the first line of code inside the listing. to get everything I expect I have to add a blank line right after the \begin{lstlisting}
For example:
\begin{lstlisting][caption=lkjasdfjk,label=lst:foo,float=htb] % python def bar(baz): print 'hello' \end{lstlisting}
Latex outputs the listing as: print 'hello'
I think this must have something to do with how LaTeX interprets comment characters but I've never really dug into that bit of TeX complexity before. Any thoughts? Are others seeing this same behavior?
Brad
On 10/20/06, Charilaos Skiadas skiadas@hanover.edu wrote:
On Oct 14, 2006, at 10:43 PM, Allan Odgaard wrote:
\begin{lstlisting}{} % Java
So don't worry about presently having to create a rule per thing we want to support, as that's only a (somewhat) short-term solution.
Ok, I have now added support for Java lstlistings with this comment type. We will be adding other languages on a need basis, so let me know if you need lstlistings in some other language.
Haris
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
Hey Brad, On Nov 19, 2006, at 7:11 PM, Brad Miller wrote:
Hi Haris,
When I do this, I lose the first line of code inside the listing. to get everything I expect I have to add a blank line right after the \begin{lstlisting}
I think this must have something to do with how LaTeX interprets comment characters but I've never really dug into that bit of TeX complexity before. Any thoughts? Are others seeing this same behavior?
yes I am noticing this as well. Interesting. I guess we could place the comment line in the line right before the environment instead?
Brad
Haris