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 have defined several structures and types in a C++ project. I have to write some documentation for this code, and I use the minted package to typeset my code.

I would like to be able to add some keywords to the minted database, so minted will also recognize these and give them the appropriate color. (I would like to have them colored in the same way a type, eg. double would be colored.)

share|improve this question
add comment

3 Answers

up vote 9 down vote accepted

Minted uses Pygments to parse source-code, so one way to go about this is by modifying pygments/lexers/compiled.py and adding your types there (Somewhere about line 210 looks reasonable to me). This is what I had to do when Pygments was incorrectly parsing a symbol in some Erlang I'd written.

The obvious disadvantage of this is that Pygments is now non-standard. This will mean a number of things:

  • This change has to be made on all PCs that want to compile this document, meaning the document will be built inconsistantly or lots of people have to have modified Pygments installations.
  • Future updates to Pygments could break your modifications and so your document may not be correctly syntax-highlighted in the future.
  • You may incorrectly parse/highlight future documents if you use these keywords in a different way (So it may print a variable name in the same way it prints a type, for example).
share|improve this answer
    
@Edd another disadvantage is that the modifications will only be valid on a single pc. –  pmav99 May 12 '11 at 16:31
    
@pmav99 Thanks. I know it's not a good method it's just the only way I know. I've converted the disadvantages to a list and included yours to try and make it clear this is very non-ideal. –  Edd May 12 '11 at 16:35
    
@Edd I think that the change doesn't mean that the document is not compilable, but rather that the output will not be the expected one (i.e. no highlighting). –  pmav99 May 12 '11 at 17:16
    
@pmav99 Yes of course. Sorry; brain really wasn't engaged. –  Edd May 12 '11 at 17:49
    
yeah it's just for a school project, so there's only one computer used to compile the file. Actually the class is vectorwhich I would want to be highlighted every time, so there's no problem in the future. –  romeovs May 12 '11 at 18:24
show 3 more comments

May be late for you but can help others.

The better solution is to write your own lexer, as pmav99 said, but on top of another lexer (in your case the CppLexer).

It's very simple! I did this very quickly to add some extra keywords for ruby.

share|improve this answer
add comment

Another (obvious) solution would be to write your own lexer (i.e. a superset of c++)

share|improve this answer
    
This seems a nice way to do it, but I don't have time to spend on learning how to write the lexer.. –  romeovs May 12 '11 at 19:39
    
Yeah of course, I just added it for reference. –  pmav99 May 12 '11 at 20:09
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.