Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 10-14-2010, 10: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, 10: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,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.
Steven Lake is offline   Reply With Quote
Advert
Old 10-14-2010, 10: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: 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.
MrPLD is offline   Reply With Quote
Old 10-14-2010, 11: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,085
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, 11: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
Advert
Old 10-15-2010, 01: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, 06: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, 03: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 04:56 PM.
twobits is offline   Reply With Quote
Reply


Forum Jump

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


All times are GMT -4. The time now is 03:23 AM.


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