4

I know that there is minted and listings for displaying nice code in .tex documents. However, I'd like to use the style that is used for Stackoverflow code: example. Are there any packages for this, or do I need to create something customized?

1
  • Have you tried using a tcolorbox wrapped around your listings or minted environment? You can use a hook from the etoolbox package that automatically embeds your code in such a box. You can set the box to whatever you like, including a plain greyish background. – 1010011010 Jul 10 '14 at 8:55
5

stackexchange uses google prettify

https://code.google.com/p/google-code-prettify/wiki/GettingStarted

to format code blocks.

It can't be too hard, if you format your code with that first to convert the generated html markup back to tex, but I don't know of an existing package that does it

UPDATE

Note Google has abandoned prettify and stackexchange now uses highlight.js

6
  • 3
    Wouldn’t it be (much!) easier just to adapt the stylesheet used by Stack Overflow into a minted or listings style definition? – Konrad Rudolph Jul 10 '14 at 9:11
  • 2
    @KonradRudolph, perhaps but perhaps the context is the OP is using a language for which google does a better job than minted or listings, and writing a new language customisation for minted might be a lot harder than getting tex to understand the google output. the javascript makes very regular output with no complicated html just specific classes around tokens so latex support for that would be pretty trivial just mapping the classes to fonts/colours – David Carlisle Jul 10 '14 at 9:15
  • Okay, that’s of course possible but given the implementation of Google Prettify, I seriously doubt that it performs better than (or even as good as) Pygments lexer definitions – it’s in fact rather primitive for many languages, treating (not so) similar as identical using crude approximations. – Konrad Rudolph Jul 10 '14 at 9:32
  • 1
    @KonradRudolph I'm just answering the question:-) – David Carlisle Jul 10 '14 at 9:35
  • It actually uses highlight.js now. – Ollie Oct 4 '20 at 14:58

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.