10-14-2010, 10:17 AM | #1 |
Junior Member
Posts: 4
Karma: 10
Join Date: Sep 2010
Device: PRS-300
|
Programming language code snippets in ebooks?
Hi all,
I have some experience teaching undergraduate level programming and I'm toying with the idea of self-publishing a programming book. But, code snippets don't seem to render well on my PRS-300 and I notice that books on programming are rare on Smashwords. So, is putting source code in an ebook feasible at all? Thanks! |
10-14-2010, 10:42 PM | #2 |
Sci-Fi Author
Posts: 1,157
Karma: 14743509
Join Date: Sep 2009
Location: Michigan
Device: PC (Calibre)
|
Typically using <pre> code </pre> works best, although even that can be a bit problematic at times. But it's one option for displaying the code correctly.
|
Advert | |
|
10-14-2010, 10:45 PM | #3 |
Author's pet-geek
Posts: 933
Karma: 1040670
Join Date: Sep 2010
Location: North Queensland, Australia
Device: Kindle 3 Wifi, Onyx Boox M96
|
Might be worth looking at how to format code-snippets on WWW pages is done as well. PRE is a good start, or you can create a specific style using monospace font (does the PRS-300 support that?) and encoding all the ambiguous characters (like < > / & etc into their HTML safe versions.
Paul. |
10-14-2010, 11:43 PM | #4 |
Curmudgeon
Posts: 3,085
Karma: 722357
Join Date: Feb 2010
Device: PRS-505
|
Take a look at how O'Reilly does it.
|
10-14-2010, 11:47 PM | #5 |
Banned
Posts: 1,344
Karma: 1028477047
Join Date: Aug 2010
Location: Nueva Andalucía
Device: Sony PRS 650
|
Some years ago I wrote using MS Word some notes about Java. My first approach was convert them to mobi using Calibre. The code snippets looks decent (at least in Kindle for PC, I still don't have an ereader), but there are some strange page breaks and some blank space.
The PRE tag probably do the work, but I guess one needs to take care about long lines. Another approach I probably will follow is to limit code inside the notes and upload it in a companion web site. |
Advert | |
|
10-15-2010, 01:37 AM | #6 |
Addict
Posts: 223
Karma: 1057019
Join Date: Oct 2010
Device: none
|
no <code> tag?
In html you are supposed to use the code tag instead of the pre tag, though the effect in browsers is usually the same. Does the epub xhtml not support that tag?
|
10-15-2010, 06:41 AM | #7 | |
Junior Member
Posts: 4
Karma: 10
Join Date: Sep 2010
Device: PRS-300
|
Quote:
It is problematic at times on an eReader. I'll probably go with Falcao's solution - offer longer code snippets as a separate download. If I decide to take the plunge, that is. |
|
10-18-2010, 03:43 PM | #8 | |
Addict
Posts: 223
Karma: 1057019
Join Date: Oct 2010
Device: none
|
Quote:
Depends on the browser of course. <pre> is a bit out of place in some ways, since it moves formating into the markup which is something to try and avoid. <code> is more semantic so seems more the right way to mark up a code segment. Though it is not a block element, so I would probably do something like <p><code class="php"> <?php phpinfo(); ?> </code></p> Of course I would be changing the < and such into the proper entities in the source. For indents I would throw in a blockquote for html 3.2, but with css I would just put it in the css. I put in the class="php" to add a bit more info to the tag, and maybe a future css would get enough features added to it , that a pretty printer could be done etc... Idea is to make the markup code not have 'hacks' in it... The w3c documents in fact give the same recommended css default for <pre> and <code>. It should be up to the device/renderer to pick its best way to render/format them. If there really is a current device that messes up with the <code> tag, then you could add in the css to make it work like pre I would think. Then when enough devices are fixed, change the css and not have to edit the html everywhere. Last edited by twobits; 10-18-2010 at 04:56 PM. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
epub code snippets (html / css) | zelda_pinwheel | ePub | 196 | 10-09-2016 05:21 AM |
Options to show programming source code in ePub | pedgarcia | ePub | 2 | 07-21-2010 11:41 AM |
Programming language for development | Pablo | Workshop | 35 | 09-02-2009 12:28 PM |
Ebooks language | parasit | Feedback | 12 | 06-11-2009 02:00 PM |