benjamin-hodgson / pygments-mathematica

Mathematica lexer for Pygments
11 stars 1 forks source link

Variables in Mathematic #4

Closed patrickvogt closed 11 years ago

patrickvogt commented 11 years ago

Hi,

first I want to thank you for the Mathematica Lexer. I've used it to typeset a Mathematica code in my master thesis and the LaTeX-package minted (which uses pygmentize).

I don't know if this is a bug or not, so you should double check on that.

I've typeset an algorithm with your v1.0 lexer and the result is: https://dl.dropboxusercontent.com/u/15732252/mintedlll_v1_0.pdf

The name of the variables are not highlighted correctly (in my opinion).

Therefore I cloned the lexer and changed line 95 in mathematica_lexer.py from

(r'[a-z][A-Za-z0-9]*', Name)

to

(r'[a-z][A-Za-z0-9]*', Name.Variable)

For my understand this is a variable (name) in Mathematica.

The changed algorithm looks like this: https://dl.dropboxusercontent.com/u/15732252/mintedlll_v1_0_manipulated.pdf

The regex in line 96 (r'#[0-9]*', Name.Variable) is in my opinion not a variable it is a formal parameter of an anonymous function. I don't know, if there is a correct way to map this to pygmentize and I don't know if this is hair-splitting.

I just wanted to let you know that this could be an issue

PS: I used the murphy-style for typesetting.

PPS: I don't know if this is the correct way to contact you but I couldn't find another way on GitHub.

Best Regards Patrick

benjamin-hodgson commented 11 years ago

Hey Patrick,

Thanks for getting in touch! I wasn't expecting anyone except myself to use it at all, so it's good to know my work has been helpful to you.

I basically just threw this together to satisfy my own needs for my Masters thesis, and it's bound to be incomplete in some ways. So I'm perfectly happy for you to make any changes you like. (You can hit 'fork' at the top of the page and set up your own copy on GitHub if you like.)

Anyway, I personally quite like the way the LHS of assignments are highlighted at the moment (it makes sense for how I'm using it), but I can understand why you might find it problematic.

If you've made a change that you think would be beneficial to everyone, you can set up a pull request and I'll import your changes into my repo. Please write unit tests for your changes and make sure they all pass first.

All the best, Benjamin