Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book General > Writers' Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 10-14-2010, 09:17 AM   #1
Connochaetes
Junior Member
Connochaetes began at the beginning.
 
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!
Connochaetes is offline   Reply With Quote
Old 10-14-2010, 09:42 PM   #2
Steven Lake
Sci-Fi Author
Steven Lake ought to be getting tired of karma fortunes by now.Steven Lake ought to be getting tired of karma fortunes by now.Steven Lake ought to be getting tired of karma fortunes by now.Steven Lake ought to be getting tired of karma fortunes by now.Steven Lake ought to be getting tired of karma fortunes by now.Steven Lake ought to be getting tired of karma fortunes by now.Steven Lake ought to be getting tired of karma fortunes by now.Steven Lake ought to be getting tired of karma fortunes by now.Steven Lake ought to be getting tired of karma fortunes by now.Steven Lake ought to be getting tired of karma fortunes by now.Steven Lake ought to be getting tired of karma fortunes by now.
 
Steven Lake's Avatar
 
Posts: 1,083
Karma: 14319765
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.
Steven Lake is offline   Reply With Quote
Old 10-14-2010, 09:45 PM   #3
MrPLD
Author's pet-geek
MrPLD ought to be getting tired of karma fortunes by now.MrPLD ought to be getting tired of karma fortunes by now.MrPLD ought to be getting tired of karma fortunes by now.MrPLD ought to be getting tired of karma fortunes by now.MrPLD ought to be getting tired of karma fortunes by now.MrPLD ought to be getting tired of karma fortunes by now.MrPLD ought to be getting tired of karma fortunes by now.MrPLD ought to be getting tired of karma fortunes by now.MrPLD ought to be getting tired of karma fortunes by now.MrPLD ought to be getting tired of karma fortunes by now.MrPLD ought to be getting tired of karma fortunes by now.
 
MrPLD's Avatar
 
Posts: 917
Karma: 1040670
Join Date: Sep 2010
Location: North Queensland, Australia
Device: Kindle 3 Wifi
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.
MrPLD is offline   Reply With Quote
Old 10-14-2010, 10:43 PM   #4
Worldwalker
Curmudgeon
Worldwalker ought to be getting tired of karma fortunes by now.Worldwalker ought to be getting tired of karma fortunes by now.Worldwalker ought to be getting tired of karma fortunes by now.Worldwalker ought to be getting tired of karma fortunes by now.Worldwalker ought to be getting tired of karma fortunes by now.Worldwalker ought to be getting tired of karma fortunes by now.Worldwalker ought to be getting tired of karma fortunes by now.Worldwalker ought to be getting tired of karma fortunes by now.Worldwalker ought to be getting tired of karma fortunes by now.Worldwalker ought to be getting tired of karma fortunes by now.Worldwalker ought to be getting tired of karma fortunes by now.
 
Posts: 3,087
Karma: 722357
Join Date: Feb 2010
Device: PRS-505
Take a look at how O'Reilly does it.
Worldwalker is offline   Reply With Quote
Old 10-14-2010, 10:47 PM   #5
Falcao
Banned
Falcao ought to be getting tired of karma fortunes by now.Falcao ought to be getting tired of karma fortunes by now.Falcao ought to be getting tired of karma fortunes by now.Falcao ought to be getting tired of karma fortunes by now.Falcao ought to be getting tired of karma fortunes by now.Falcao ought to be getting tired of karma fortunes by now.Falcao ought to be getting tired of karma fortunes by now.Falcao ought to be getting tired of karma fortunes by now.Falcao ought to be getting tired of karma fortunes by now.Falcao ought to be getting tired of karma fortunes by now.Falcao ought to be getting tired of karma fortunes by now.
 
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.
Falcao is offline   Reply With Quote
Old 10-15-2010, 12:37 AM   #6
twobits
Addict
twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.
 
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?
twobits is offline   Reply With Quote
Old 10-15-2010, 05:41 AM   #7
Connochaetes
Junior Member
Connochaetes began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Sep 2010
Device: PRS-300
Quote:
Originally Posted by twobits View Post
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?
They don't do the same thing. <pre> preserves the layout (line breaks, whitespace) from the source file. <code> designates a phrase as code. An easy way to display indented code is to nest <code> within <pre>.

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.
Connochaetes is offline   Reply With Quote
Old 10-18-2010, 02:43 PM   #8
twobits
Addict
twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.twobits ought to be getting tired of karma fortunes by now.
 
Posts: 223
Karma: 1057019
Join Date: Oct 2010
Device: none
Quote:
Originally Posted by Connochaetes View Post
They don't do the same thing. <pre> preserves the layout (line breaks, whitespace) from the source file. <code> designates a phrase as code. An easy way to display indented code is to nest <code> within <pre>.

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.

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 03:56 PM.
twobits is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
epub code snippets (html / css) zelda_pinwheel ePub 179 10-05-2012 06:37 PM
Options to show programming source code in ePub pedgarcia ePub 2 07-21-2010 10:41 AM
Programming language for development Pablo Workshop 35 09-02-2009 11:28 AM
Ebooks language parasit Feedback 12 06-11-2009 01:00 PM


All times are GMT -4. The time now is 11:26 AM.


MobileRead.com is a privately owned, operated and funded community.