I know there is a very good package for listing code (listing package) but codes are ugly.

I know there are some good package for algorithms (algorithmics, algorithm2e, etc). But I want to write runnable code not only printable one.

So, is there any way to include programming code into a tex article that looks as nice as algorithms? Or, is there any (automatic) way to convert a programming code into a latex algorithm?

Some ideas that I have explored but so far they were not good enough.

Edit: Well, see the example below (I got from http://www.literateprogramming.com/cweb.pdf)

CWEB output

Why is this so nice? For example, the operator "!=" was converted to latex \neq. Or the "!" boolean operator was converted to "\neg". And so on...

Now, another example with algorithmicx package.

Agorithmics output

Can we achieve that with listing?


Since I copied this snippet from CWEB Manual, I have to put this copyright note here...

The printed form of this manual is copyright 1994 by Addison-Wesley Publishing Company, Inc. All rights reserved. The electronic form is copyright 1987, 1990, 1993, 2000 by Silvio Levy and Donald E. Knuth. Permission is granted to make and distribute verbatim copies of the electronic form of this document provided that the electronic copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of the electronic form of this document under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.

  • 1
    it would help if you provided a test document with a sample code (say in verbatim or listings or minted) – David Carlisle Jan 11 '17 at 16:39
  • 1
    listings is highly customisable. It will do the conversions you mention with appropriate customisations. What can't you achieve? – Andrew Swann Jan 11 '17 at 16:43
  • 1
    That goal is interesting, but after the process you describe, you don't have code any more, you have a sort of prettified pseudocode -- so your title doesn't really match the question. But more constructively, you can at least start by mapping some strings to appropriate characters using listings and its literate tools. You might also see Listings, Literate Programming, and Beautiful Typography – Chris H Jan 11 '17 at 16:58
  • 1
    You can do many of these symbol replacements with suitable minted or listings code, but without an example and a suggestion of what that example should look like hard to say (images of other code written in other languages less help) – David Carlisle Jan 11 '17 at 17:03
  • 1
    For listings see section 6.4 of the manual a literal replacements entitled "Literate programming" – Andrew Swann Jan 11 '17 at 17:06

Browse other questions tagged or ask your own question.