04-20-2013, 03:11 PM | #1 |
Member
Posts: 21
Karma: 493474
Join Date: Mar 2011
Location: Northern California
Device: Acer A500
|
Program listings in ePub
Has anyone been successful at producing good looking program listings in ePub?
I have self-published (at Lulu) one programming book that has over 100 program listings. I wrote that book in LaTeX, and the ebook version is pdf. It looks great. I am starting my second programming book. There is not a good workflow from LaTeX to ePub, so I have started with restructuredtext and processed it with Sphinx. The HTML version is very nice. The ePub version is nice in Calibre, but when I load it onto my Andorid tablet, things are pretty bad. For example, the line numbers do not align with their respective code lines. Line wrapping makes it very difficult to read the code. The equations I use in the book are simple algebra, so I can probably live with the lack of math support in ePub. I converted the vector graphics to svg, and that seems to display nicely. I hope that ePub3 will solve some of these issues, but there are still many ePub2 devices out there. Is pdf still the format of choice for books that have lots of computer programming code? |
04-21-2013, 12:02 PM | #2 |
Connoisseur
Posts: 70
Karma: 515184
Join Date: Sep 2011
Location: Brasília
Device: Kindle3, iPad, Nook, Kobo, Positivo Alfa
|
You could use something like Highlight to generate a beautifully formatted version of your code in SVG or HTML, ready to embed in your ePUB.
Here's a simple example of the code generated by Highlight inside an ePUB: http://bit.ly/11tFJly It's a free program, with lots of great customization options. |
04-21-2013, 12:24 PM | #3 | |||
Wizard
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Quote:
Also, what reader are you using to read it on Android? There are many of them out there, and it could be rendering errors with the reading program itself. If the lines of code are not too long, perhaps you could take advantage of some negative indents to help clarify seperate lines of code. (See attached test EPUB + image). Quote:
http://www.mathjax.org/resources/epub-readers/ Although, doing this will limit the programs the users will actually be able to use to read the EPUB... but you will get beautiful scalable/copy/pastable equations. There was also this topic a while back, you might get some tips out of it: https://www.mobileread.com/forums/showthread.php?t=73914 Quote:
As a last resort, you would be able to create an image of sections of code, and have those throughout the EPUB (very ugly... but compatible). Text in images though does not scale very well on the tiny devices. |
|||
04-21-2013, 01:05 PM | #4 |
frumious Bandersnatch
Posts: 7,515
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Note, anyway, that PDF does not mean letter/A4 size pages. You can create a PDF with a page size of 9×12cm and almost no margins, that would be quite readable in most devices.
|
04-21-2013, 01:35 PM | #5 | |
Resident Curmudgeon
Posts: 73,887
Karma: 128597114
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
04-21-2013, 05:49 PM | #6 |
Connoisseur
Posts: 70
Karma: 515184
Join Date: Sep 2011
Location: Brasília
Device: Kindle3, iPad, Nook, Kobo, Positivo Alfa
|
Well, Highlight can do that, but there's an option (which is shown in the example ePub file) to use ordered lists instead of <pre> tags. Works nicely – but the code is crowded.
|
04-21-2013, 10:13 PM | #7 |
Resident Curmudgeon
Posts: 73,887
Karma: 128597114
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
All I can say (without looking at the code) is one of the lines did go past the edge of the ADE window. So whatever was done doesn't work.
|
04-22-2013, 07:31 AM | #8 |
Connoisseur
Posts: 70
Karma: 515184
Join Date: Sep 2011
Location: Brasília
Device: Kindle3, iPad, Nook, Kobo, Positivo Alfa
|
|
04-23-2013, 07:54 PM | #9 |
Grand Sorcerer
Posts: 11,470
Karma: 13095790
Join Date: Aug 2007
Location: Grass Valley, CA
Device: EB 1150, EZ Reader, Literati, iPad 2 & Air 2, iPhone 7
|
You can use CSS to prewrap a pre section where your code resides. You should also use monospaced fonts for best results. This will usually result in readable code but expect some lines to wrap and that is usually ok in code.
Dale |
04-27-2013, 02:13 PM | #10 | |
Member
Posts: 21
Karma: 493474
Join Date: Mar 2011
Location: Northern California
Device: Acer A500
|
Quote:
Code:
<div class="highlight-c"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41</pre></div></td><td class="code"><div class="highlight"><pre><span class="cm">/*</span> <span class="cm"> * convertHex.c</span> <span class="cm"> * Asks user to enter a number in hexadecimal</span> <span class="cm"> * then echoes it in hexadecimal and in decimal.</span> <span class="cm"> * Assumes that user does not make mistakes.</span> <span class="cm"> * Bob Plantz - 4 June 2009</span> <span class="cm"> */</span> <span class="cp">#include <stdio.h></span> <span class="cp">#include <unistd.h></span> <span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> <span class="p">{</span> <span class="kt">int</span> <span class="n">x</span><span class="p">;</span> <span class="kt">unsigned</span> <span class="kt">char</span> <span class="n">aChar</span><span class="p">;</span> <span class="n">printf</span><span class="p">(</span><span class="s">"Enter an integer in hexadecimal: "</span><span class="p">);</span> <span class="n">fflush</span><span class="p">(</span><span class="n">stdout</span><span class="p">);</span> ... |
|
04-27-2013, 02:20 PM | #11 | |
Member
Posts: 21
Karma: 493474
Join Date: Mar 2011
Location: Northern California
Device: Acer A500
|
Quote:
--Bob |
|
Tags |
code, listings, programming |
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
New program: EPub Metadata Editor | BenChen | ePub | 281 | 02-06-2024 05:07 PM |
A program for converting HTML pages into EPUB on a server side | Chang | ePub | 6 | 09-29-2012 10:59 AM |
best program for correcting typos / spelling in epub & mobi books ? | cybmole | Calibre | 15 | 11-16-2010 06:22 AM |
New Program to download blogs and other feeds to Kindle/Epub | rsteckly | Reading and Management | 4 | 11-15-2010 08:53 PM |
which is the best program to convert files to epub ?? | ornillo | General Discussions | 16 | 06-28-2010 09:29 AM |