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

Go Back   MobileRead Forums > E-Book Formats > Workshop

Notices

Reply
 
Thread Tools Search this Thread
Old 04-20-2013, 03:11 PM   #1
rplantz
Member
rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.
 
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?
rplantz is offline   Reply With Quote
Old 04-21-2013, 12:02 PM   #2
PageLab
Connoisseur
PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.
 
PageLab's Avatar
 
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.
PageLab is offline   Reply With Quote
Advert
Old 04-21-2013, 12:24 PM   #3
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,297
Karma: 12126329
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by rplantz View Post
There is not a good workflow from LaTeX to ePub, [...] 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 format is just not suited for this sort of thing (reflowable text + extremely precise layouts for code sections). You say that the HTML version looks fine, but the EPUB looks horrible (on Android)... Mind giving a sample of the HTML code that looks nice? It could be that the way that the HTML is laid out is something that does not work in EPUB at all.

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:
Originally Posted by rplantz View Post
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.
There is this thing called Mathjax, which you can use to embed in your books:

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:
Originally Posted by rplantz View Post
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?
Yes. PDF would still be your best bet. EPUB is just not well suited for complex documents such as this... BUT, you might be able to make it look ok.

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.
Attached Thumbnails
Click image for larger version

Name:	CodeBlock.png
Views:	342
Size:	27.9 KB
ID:	104684  
Attached Files
File Type: epub CodeBlockExample.epub (2.2 KB, 225 views)
Tex2002ans is offline   Reply With Quote
Old 04-21-2013, 01:05 PM   #4
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,514
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.
Jellby is offline   Reply With Quote
Old 04-21-2013, 01:35 PM   #5
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 73,660
Karma: 127838196
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by PageLab View Post
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.
I'm betting the that code inside the ePub uses a <pre></pre> and that causes one of the lines to be too long and not wrap. That just doesn't work.
JSWolf is offline   Reply With Quote
Advert
Old 04-21-2013, 05:49 PM   #6
PageLab
Connoisseur
PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.
 
PageLab's Avatar
 
Posts: 70
Karma: 515184
Join Date: Sep 2011
Location: Brasília
Device: Kindle3, iPad, Nook, Kobo, Positivo Alfa
Quote:
Originally Posted by JSWolf View Post
I'm betting the that code inside the ePub uses a <pre></pre> and that causes one of the lines to be too long and not wrap. That just doesn't work.
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.
PageLab is offline   Reply With Quote
Old 04-21-2013, 10:13 PM   #7
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 73,660
Karma: 127838196
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by PageLab View Post
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.
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.
JSWolf is offline   Reply With Quote
Old 04-22-2013, 07:31 AM   #8
PageLab
Connoisseur
PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.PageLab ought to be getting tired of karma fortunes by now.
 
PageLab's Avatar
 
Posts: 70
Karma: 515184
Join Date: Sep 2011
Location: Brasília
Device: Kindle3, iPad, Nook, Kobo, Positivo Alfa
Quote:
Originally Posted by JSWolf View Post
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.
Did you look at the page 2? There it is.
PageLab is offline   Reply With Quote
Old 04-23-2013, 07:54 PM   #9
DaleDe
Grand Sorcerer
DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.DaleDe ought to be getting tired of karma fortunes by now.
 
DaleDe's Avatar
 
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
DaleDe is offline   Reply With Quote
Old 04-27-2013, 02:13 PM   #10
rplantz
Member
rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.
 
Posts: 21
Karma: 493474
Join Date: Mar 2011
Location: Northern California
Device: Acer A500
Quote:
Originally Posted by Tex2002ans View Post
The format is just not suited for this sort of thing (reflowable text + extremely precise layouts for code sections). You say that the HTML version looks fine, but the EPUB looks horrible (on Android)... Mind giving a sample of the HTML code that looks nice? It could be that the way that the HTML is laid out is something that does not work in EPUB at all.
Ah, I see what it's doing, creating a table for the line numbering:
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 &lt;stdio.h&gt;</span>
<span class="cp">#include &lt;unistd.h&gt;</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">&quot;Enter an integer in hexadecimal: &quot;</span><span class="p">);</span>
    <span class="n">fflush</span><span class="p">(</span><span class="n">stdout</span><span class="p">);</span>
...
rplantz is offline   Reply With Quote
Old 04-27-2013, 02:20 PM   #11
rplantz
Member
rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.rplantz ought to be getting tired of karma fortunes by now.
 
Posts: 21
Karma: 493474
Join Date: Mar 2011
Location: Northern California
Device: Acer A500
Quote:
Originally Posted by Jellby View Post
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.
My current book, written with LaTeX, was designed for 8-1/2 x 11, double-sided printing. When I first made the pdf available, students pointed out that the margins were too wide, and the binding gutter was a hassle. With a little arithmetic, I gave the pdf version 0.1" uniform margins but kept the pagination the same as with the print version. So the professor can refer to a page number, and that works for both the pdf and paperback versions.

--Bob
rplantz is offline   Reply With Quote
Reply

Tags
code, listings, programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


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


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