3

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?


Disclaimer

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.

rdllopes
  • 131
  • You really need to give some idea of what you want the output to look like -- draw it in inkscape for example. Arguably algorithms made up of English words and properly typeset maths are rather different to listings of source code -- in the latter, every character counts (1 vs I vs l can't be assumed to be inferrable from context, limiting your fonts and aesthetic formatting) – Chris H Jan 11 '17 at 16:24
  • Welcome to [tex.se]! Are you aware of the listings and minted packages? – Andrew Swann Jan 11 '17 at 16:33
  • Hi, @AndrewSwann. I have explicitly commented about listings package in the first line but same applies to minted. – rdllopes Jan 11 '17 at 16:38
  • 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
  • @DavidCarlisle, I am preparing a show case and I will update the question. – rdllopes Jan 11 '17 at 16:45
  • @AndrewSwann, I added another example of output that I was looking for. Basically, I want to exchange operators from a specific programming language to math operators. And ideally, other math symbols (e.g.: variable with greek letters, empty set, ...) – rdllopes Jan 11 '17 at 16:51
  • 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
  • @AndrewSwann, I need to admit that I was arrogant to say that we cannot achieve that with listings. Thanks. I am still working in a example and I will give you a better feedback. – rdllopes Jan 11 '17 at 17:34

0 Answers0