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

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 09-24-2013, 01:23 AM   #1
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
Tutorial: Formulas to PNG

Programs that are required for this tutorial:

The problem:

You have finished converting a PDF to EPUB. The entire book is crisp, clear, digital font. BEAUTIFUL. And then you stumble upon a formula taken right from the original scan!

Usually the images of formulas are:
  • JPG
    • If you see this, RUN FOR THE HILLS!
  • The Resolution is Miniscule
    • Even ants cannot read this
  • Have horrible scanning artifacts.

Compare these two images:

Before: Click image for larger version

Name:	pg182-Formula2.png
Views:	794
Size:	17.1 KB
ID:	112018
After: Click image for larger version

Name:	MobileReadFormula2.png
Views:	892
Size:	7.6 KB
ID:	112017

Side Note: The "Before" picture is NOWHERE NEAR the horror that you will typically see.

Ultimately, you would want something that scales beautifully and according to user preferences, like MathML. Sadly, you cannot use MathML because this EPUB must be read on a multitude of different readers.

Something like SVG would be great, but it is quite complex, and can only be used in EPUB (and KF8).

You want this to be read on early Kindles (and older devices) as well, so you must settle on an image. This is where the high resolution PNG comes to save the day!

At the end of the tutorial:
  • You will have a high resolution, beautiful formula in PNG.
    • Since it is an image, this should work on all devices (EPUB, Kindle), and look quite clean big/small (PC/smartphone).
  • You will have a digital version of the formula in PDF form.
    • If your company ever does create a completely new Edition of the book. This digital formula will easily be able to fit right in.
    • You can generate ANY size/format image you need from this.
    • When MathML becomes more ubiquitous, it should be much easier to go from Libre Math to MathML than from a low resolution image to MathML.
  • No more hideous ant-sized formulas!!!

Step -1: The Source

This tutorial will be using pages 160, 174, and page 180 from "An Outline of International Price Theory" by Chi-Yuen Wu:

Click image for larger version

Name:	pg160.png
Views:	700
Size:	124.2 KB
ID:	111968 Click image for larger version

Name:	pg174.png
Views:	641
Size:	148.8 KB
ID:	111969 Click image for larger version

Name:	pg182.png
Views:	743
Size:	140.6 KB
ID:	111970

PDF: http://library.mises.org/books/Chi-Y...e%20Theory.pdf

I have attached an EPUB at the end of the tutorial which includes the final text + formulas for these three pages.

Step 0: Very basics of LibreOffice Math

I have marked three sections in the image, showing the Math UI:

Click image for larger version

Name:	Step0.Sections.png
Views:	686
Size:	11.7 KB
ID:	111973

Section 1: This is where you use buttons to create the formula. The dropdown menu allows you to change categories to many many different types.

Side Note: Press a button and see what it does! Try to see if you can go through the menus and make a "square root".

Section 2: This is where the formula is displayed.

Section 3: This is where the "code" goes to create a formula. Pressing a button in Section 1 will generate some "code" in Section 3. You will then have to replace the placeholder text with your actual numbers/letters. See:

Click image for larger version

Name:	Step0.Buttons.png
Views:	716
Size:	11.7 KB
ID:	111972

Now replace the first <?> with 2, and the second <?> with 2. (Or you could just type "2 + 2" directly into Section 3).

Click image for larger version

Name:	Step0.TwoPlusTwo.png
Views:	591
Size:	11.6 KB
ID:	111975

Code:
2 + 2
Side Note: I tend to wrap each side in squiggly brackets {}. This is EXTREMELY helpful when dealing with more complex equations. Best to start with following good practice right in the beginning!

Equivalent to 2 + 2:

Code:
{2} + {2}
Sample that is one step up in complexity:

Click image for larger version

Name:	Step0.TwoPlusAB.png
Views:	628
Size:	12.4 KB
ID:	111974

Code:
2 + {a over b}
OR:

Code:
{2} + {{a} over {b}}
Step 0.5 (Optional): Change Zoom level in LibreOffice Math:

Click image for larger version

Name:	Step0.5.Zoom.png
Views:	698
Size:	16.1 KB
ID:	111971

In the Menu, select View - Zoom.

From here, select whatever preset Zoom level you want (for example 200%). I personally press View - Zoom - Zoom... And then set the level to something large (like 300%, 400%). This will make it easier to see the displayed equation in Section 2.

Note: Zoom level DOES NOT effect the output, only the way that it looks while you are editing in LibreOffice Math.

(Optional) Official LibreOffice Math Help Documentation

Help Documents for LibreOffice Math: https://help.libreoffice.org/Math/We..._the_Math_Help
Complex Formula Examples: https://help.libreoffice.org/Math/Math_Examples

Step 1: Recreate the Formula Using LibreOffice Math:

Every formula you run across will be different. The buttons in Section 1 (see Step 0) will help guide you in creating the actual "code" to place in Section 3 (see Step 0).

Each of the images in this Step show an actual formula from a PDF scan, and the LibreOffice Math code to recreate it:

Formula #1:

Click image for larger version

Name:	Step1.Formula1.png
Views:	699
Size:	14.5 KB
ID:	111976

Click image for larger version

Name:	Step1.pg160-Formula1.png
Views:	596
Size:	8.2 KB
ID:	111977

Code:
{m_a} over {m_b} < {n_a} over {n_b} < {o_a} over {o_b} < {p_a} over {p_b} < ... < {q_a} over {q_b}
Formula #2:

Click image for larger version

Name:	Step1.pg182-Formula2.png
Views:	618
Size:	17.1 KB
ID:	111980

Code:
{Q_m over m_b} over {Q_n over n_a} " or " {Q_m over Q_n} times {n_a over m_b}
Formula #3:

Click image for larger version

Name:	Step1.pg174-Formula1.png
Views:	585
Size:	8.0 KB
ID:	111978

Code:
p = {pD_{am}} over {D_{am}} = {MP} over {OM} = {ON} over {OM},
Formula #4:

Click image for larger version

Name:	Step1.pg174-Formula2.png
Views:	647
Size:	20.3 KB
ID:	111979

Code:
{alignc "Price"} over {alignc "Price-Marginal Revenue"} = {{ON} over {OM}} over {{ON} over {OM} - {tN}over{OM}} = {ON} over {ON - tN} = {ON} over {Ot}
Step 2: LibreOffice Math: Export as PDF

After inserting the code for Formula #1. You want to press File - Export...:

Click image for larger version

Name:	Step2.ExportFormula1.png
Views:	615
Size:	18.3 KB
ID:	111981

Name your file and press Save.

Side Note: My preferable naming convention is "pg###-Formula#.pdf". Where pg### is the page number of the formula, and Formula# is used if there are multiple formulas per page. This allows for easy organization, and allows it to be easily found/fixed at a later date if needed.

Click image for larger version

Name:	Step2.FormulaSavePDF.png
Views:	597
Size:	15.1 KB
ID:	111983

After naming your PDF and pressing Save, you will reach this screen. Make sure "Lossless Compression" and "Tagged PDF" are chosen and then press Export.

Click image for larger version

Name:	Step2.ExportPDFDialog.png
Views:	598
Size:	11.2 KB
ID:	111982

Last edited by Tex2002ans; 09-24-2013 at 02:45 AM.
Tex2002ans is offline   Reply With Quote
Old 09-24-2013, 01:32 AM   #2
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
Step 3: Inkscape

When you open Inkscape, you should be greeted with a blank screen. Press File - Open. Go to where you saved your LibreOffice Math PDF files, and open the first one:

Click image for larger version

Name:	Step3.OpenFile.png
Views:	581
Size:	13.6 KB
ID:	112008

You will be greeted with this screen. Just press Ok:

Click image for larger version

Name:	Step3.OpenDialog.png
Views:	592
Size:	8.1 KB
ID:	112007

You can now see the PDF that LibreOffice created open in Inkscape.

Click image for larger version

Name:	Step3.JustOpened.png
Views:	607
Size:	35.7 KB
ID:	112005

Now you have to click on the formula, and arrows should appear around it:

Click image for larger version

Name:	Step3.FormulaArrows.png
Views:	605
Size:	36.3 KB
ID:	112003

Side Note: IF you are greeted with the entire thing surrounded by arrows. Press Object - Ungroup. This should split it into clickable sections. It should now be possible to press on the formula.

Click image for larger version

Name:	Step3.FormulaEntire.png
Views:	585
Size:	36.4 KB
ID:	112004 Click image for larger version

Name:	Step3Note.Ungroup.png
Views:	583
Size:	43.9 KB
ID:	112009

Make sure just the formula is selected and has arrows around it, and press File - Export Bitmap...

Click image for larger version

Name:	Step3.ExportBitmap.png
Views:	528
Size:	38.2 KB
ID:	112001

The Export Bitmap dialog should pop up. This is where you Inkscape what resolution the final PNG will be, and where to save the PNG.

IMPORTANT: Make sure along the top, that the "Selection" button is chosen. Selection means it will create a PNG of everything that is inside the "surrounding arrows".

Click image for larger version

Name:	Step3.ExportBitmapDialog.png
Views:	606
Size:	9.8 KB
ID:	112002

Personally, I have settled on "320" as a good DPI for formulas. This determines how large the letters/numbers will be in the final PNG (and thus, the EPUB). Feel free to raise/lower this to suit your liking.

You can also manually tell Inkscape which X/Y resolution you want created by changing the "Width" and "Height".

Side Note: I recommend keeping the DPI the same throughout an entire book, so when formula PNGs are scaled to their max width, they will all have the same size font.

After setting the DPI (or Width/Height), press Export. This will now save the file to the location you selected.

Side Note: Inkscape auto-names the file g#####.png. This is quite annoying. Make sure you change to a better filename so you can keep the images organized.

Repeat Step 3 for all formulas until you have 320 DPI PNGs generated for all Formulas.

Step 4: GIMP

Open GIMP, and open the PNG formulas created from Inkscape.

Click image for larger version

Name:	Step4.Open.png
Views:	609
Size:	38.6 KB
ID:	112014

Press Layer - Transparency - Remove Alpha Channel:

Click image for larger version

Name:	Step4.RemoveAlpha.png
Views:	640
Size:	47.2 KB
ID:	112015

This should result in the transparent background turning white:

Click image for larger version

Name:	Step4.RemovedTransparency.png
Views:	692
Size:	39.0 KB
ID:	112016

Since there is no color in this image, you want to change the mode from RGB to Grayscale.

Note: Going from RGB (nearly every color under the sun) to Grayscale will cut down the filesize DRAMATICALLY. "Grayscale" means it will be 256 shades of gray.

Press Image - Mode - Grayscale.

Click image for larger version

Name:	Step4.Grayscale.png
Views:	611
Size:	44.1 KB
ID:	112013

Now we have to save the PNG again. Press File - Export...

Click image for larger version

Name:	Step4.ExportMenu.png
Views:	571
Size:	35.4 KB
ID:	112011

Choose where you save your file and what to name it.
IMPORTANT: Make sure that ".png" is at the end of the filename. This will tell GIMP to Export this as a PNG.

Click image for larger version

Name:	Step4.ExportDialog.png
Views:	564
Size:	14.6 KB
ID:	112010

Uncheck all the boxes in the dialog box, and make sure Compression is set to max. Press Export.

Click image for larger version

Name:	Step4.ExportPNGDialog.png
Views:	572
Size:	6.1 KB
ID:	112012

Repeat Step 4 for all Formulas.

Step 5: Insert into the EPUB

That is all! Now you can insert the PNG into the EPUB just like you would any other image.

I have attached a sample EPUB full of the real world text, with two XHTML files: "Old" and "New". The "Old" has PNG snapshots taken from the PDF, while "New" has the new PNGs generated by this tutorial.

Feel free to compare them both for yourself.

Side Note: I have left an Extra Credit image (the formula at the top of Page 182: See Step -1). See if you can generate a new and improved version using the Tutorial above!

If you need a hint with the Libre Math "code" for the Extra Credit:

Spoiler:
"Barter terms of trade" = {W_a over n_a} div {{W_b times R} over m_b} = W_a over {W_b times R} times {m_b over n_a}"."
Attached Files
File Type: epub FormulaPNGTutorial.epub (118.0 KB, 463 views)

Last edited by Tex2002ans; 09-24-2013 at 02:34 AM.
Tex2002ans is offline   Reply With Quote
Advert
Old 09-24-2013, 01:34 AM   #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
Beyond Tutorial (Optional): Optimize Images Further

**** This is a placeholder. Squeezing KB out of the final image. Reducing to 16 shades of gray. ****

I hope to see some great success stories posted, with some beautified formulas!

Last edited by Tex2002ans; 09-24-2013 at 02:12 AM.
Tex2002ans is offline   Reply With Quote
Old 09-24-2013, 02:31 AM   #4
GrannyGrump
Obsessively Dedicated...
GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.
 
GrannyGrump's Avatar
 
Posts: 3,200
Karma: 34977896
Join Date: May 2011
Location: JAPAN (US expatriate)
Device: Sony PRS-T2, ADE on PC
Ah. Great tutorial. this could also be adapted for fragments of any special text in-line.

I do want to warn about 16-shade pngs though. They display badly on some readers and some apps. See the thread I posted recently https://www.mobileread.com/forums/sho...51#post2633151

Jellby responded that it is a bug in the ADE engine, dealing poorly with 2-bit and 4-bit color.

I tried GMcG's suggestion for reducing to 16-shades and then back to 256 (8-bit). It does make a smaller size than an image with the full 256 shades, and in my testing came out about 10-25% bigger than the original 16-shade png. The resulting display seems to work fine. I was not working with web-safe palettes --- those would be a lot smaller, and should be fine for text.
GrannyGrump is offline   Reply With Quote
Old 09-24-2013, 03:12 AM   #5
Toxaris
Wizard
Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.Toxaris ought to be getting tired of karma fortunes by now.
 
Toxaris's Avatar
 
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
Uhmmm, Why don't use the codecogs site? You can save it as gif/png/svg and others. That would only require one step.
Toxaris is offline   Reply With Quote
Advert
Old 09-24-2013, 03:14 AM   #6
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
The "Beyond" will be for the die-hards (like me) who like to squeeze out every last KB out of the EPUB (and where I can promote more ScriptPNG and/or other PNG optimization tools).

Or I might just split it into another Tutorial, and link to it from here, I haven't decided yet (need a few nights of rest, this was a lot of work).

I will definitely be doing a Tutorial on:

SVG -> PNG

(Was requested in this topic: https://www.mobileread.com/forums/sho...d.php?t=222825)

I might do:

Images of Tables -> LibreOffice Calc -> HTML

(Very wide tables, or pixelated JPG, or hideous ant-sized images with unreadable text).

and whatever else comes to my head.... I have stumbled upon so much stuff in my conversions, so I might as well teach others the methods that I use. Might save lots of people lots of time, and in the end, get higher quality books out there.

Quote:
Originally Posted by grannyGrumpy View Post
I do want to warn about 16-shade pngs though. They display badly on some readers and some apps. See the thread I posted recently https://www.mobileread.com/forums/sho...51#post2633151

Jellby responded that it is a bug in the ADE engine, dealing poorly with 2-bit and 4-bit color.
Indeed. I noticed the same thing months ago when reducing my formulas to 4 color grayscale, my Nook rendered the formula PNGs with large "streaks".

I was going to be posting some of my information/tests in your topic within the coming days.

Quote:
Originally Posted by grannyGrumpy View Post
I tried GMcG's suggestion for reducing to 16-shades and then back to 256 (8-bit). It does make a smaller size than an image with the full 256 shades, and in my testing came out about 10-25% bigger than the original 16-shade png. The resulting display seems to work fine. I was not working with web-safe palettes --- those would be a lot smaller, and should be fine for text.
Testing testing testing!!! I am glad to see you are still chipping away at those Tom Sawyer images.

Quote:
Originally Posted by Toxaris View Post
Uhmmm, Why don't use the codecogs site? You can save it as gif/png/svg and others. That would only require one step.
You have ruined me!

Last edited by Tex2002ans; 09-24-2013 at 03:23 AM.
Tex2002ans is offline   Reply With Quote
Old 09-24-2013, 03:37 AM   #7
GrannyGrump
Obsessively Dedicated...
GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.GrannyGrump ought to be getting tired of karma fortunes by now.
 
GrannyGrump's Avatar
 
Posts: 3,200
Karma: 34977896
Join Date: May 2011
Location: JAPAN (US expatriate)
Device: Sony PRS-T2, ADE on PC
Tex2002ans said
Quote:
Testing testing testing!!! I am glad to see you are still chipping away at those Tom Sawyer images.
Yup, still chipping. Got two more big Twain books in progress, with over 600 illustrations to clean and convert. (I'm either masochistic or insane!)


Quote:
I was going to be posting some of my information/tests in your topic within the coming days.
I am looking forward to it. I won't finalize any more images till I learn about your results.

Quote:
You have ruined me
ah, but it's only a tiny ruin. The rest of us can still use most of the tutorial for other kinds of text.

Last edited by GrannyGrump; 09-24-2013 at 03:39 AM.
GrannyGrump is offline   Reply With Quote
Old 09-24-2013, 05:26 AM   #8
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,515
Karma: 18512745
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Two cents:

1st ¢ You can skip Inkscape and open the PDF directly with GIMP. When asked, set the resolution to something high: 300 or 600 dpi, strong antialiasing everywhere and grayscale. You can then crop and resize the image in GIMP.

2nd ¢ If you know some LaTeX, it may be better to create the initial PDF with pdflatex.
Jellby is offline   Reply With Quote
Old 09-24-2013, 10:10 AM   #9
mrmikel
Color me gone
mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.
 
Posts: 2,089
Karma: 1445295
Join Date: Apr 2008
Location: Central Oregon Coast
Device: PRS-300
Thanks for pointing out that GIMP can open up PDFs this way. A time saver for multiple images to place into epubs.
mrmikel is offline   Reply With Quote
Old 09-24-2013, 04:38 PM   #10
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 Jellby View Post
1st ¢ You can skip Inkscape and open the PDF directly with GIMP. When asked, set the resolution to something high: 300 or 600 dpi, strong antialiasing everywhere and grayscale. You can then crop and resize the image in GIMP.
Hmmmm... I will have to do more testing. I think there was a reason a while back I jumped over to Inkscape to handle this. The reasons will probably come flowing back to me.

But yes, Math PDF -> GIMP is most likely even faster for this specific case. Lots of different ways to get from A to B. Hopefully the tutorials spawn some more discussion too, on how everyone else handles the situation, giving lots of A to B options for anyone who comes across the tutorial!

I can quickly think of two reasons why I went the Inkscape route:
  • Initially I used to just use the Width/Height for outputting the formulas instead of DPI. Inkscape allowed me to specify the exact size of the resultant PNG. GIMP lets you specify the X/Y of the entire "page" only.
    • Exporting only the "Selection" is helpful with vector graphs/tables that I want at a specified width.
  • IF needed, you could do some actual editing in Inkscape (changing font, etc. etc.). Although this would best be handled back at the actual source document stage.
    • GIMP is an image editor, not a vector editor.
      • This is probably the problem I ran into, I wanted to change some things around in some (not so clean) vector files I had gotten, and it was impossible/a complete pain to do in GIMP.

Quote:
Originally Posted by Jellby View Post
2nd ¢ If you know some LaTeX, it may be better to create the initial PDF with pdflatex.
Of course of course... LaTeX would be ultimate (I have to teach myself that, it would be EXTREMELY useful... although I deal with very formula heavy books rarely). Perhaps a better title for this would have been "Beginner's Guide to Formula to PNG".

This tutorial was just something I thought of within the day, perhaps next time I should plan out everything for a month!

"Step 1A: LibreOffice Math"
"Step 1B: LaTeX"
"Step 1C: Codecogs"
"Step 1D: This is a placeholder for something Jellby/Toxaris will mention after posting"
"Step 2: If you followed Step 1A, do this. Otherwise, skip this step!".

I think LaTeX would be WAY out of the league of someone just doing some basic formulas every so often in books they come across.

Using LibreOffice Math (or http://www.codecogs.com/latex/eqneditor.php as Toxaris pointed out) simplifies a lot of that initial creation.

Perhaps you want to write a tutorial on the basics of LaTeX -> high resolution images for EPUBs? I know that I would benefit.
Tex2002ans is offline   Reply With Quote
Old 09-24-2013, 06:22 PM   #11
Hitch
Bookmaker & Cat Slave
Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.
 
Hitch's Avatar
 
Posts: 11,460
Karma: 158448243
Join Date: Apr 2010
Location: Phoenix, AZ
Device: K2, iPad, KFire, PPW, Voyage, NookColor. 2 Droid, Oasis, Boox Note2
Gang:

And of course, in Kindle, all PNG's are converted to GIF images for the mobi files. Also remember that with the newer Kindle HD devices, you're goign to want the largest/highest-rez images you can manage, as otherwise, a 72dpi image of, say, 100px wide will be about half an inch wide on that KindleFire HD 8.9" screen.

(Yes, I saw that you were outputting the pngs at 320, but just as a reminder for those who don't deal with all the Amazon devices.)

Hitch
Hitch is offline   Reply With Quote
Old 09-25-2013, 12:07 AM   #12
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
I have attached a sample EPUB with four sets of images (times all four formulas), each inside of their own grey boxes:

Click image for larger version

Name:	TransparentTestPreview.png
Views:	994
Size:	32.2 KB
ID:	112084

#1. No Transparency (Removed and saved right from GIMP just like the tutorial) (8bpp Grayscale)
#2. Transparent formula (Inkscape -> GIMP -> Mode -> Grayscale -> Saved) (32bpp Grayscale)
#3. Transparent formula (Inkscape) (32bpp Grayscale)
#4. Transparent formula (fed through ScriptPNG to optimize) (Indexed 256)

Sadly, I don't have any physical Kindles to test on (I would not trust Kindle Previewer one iota when dealing with situations such as this).

Quote:
Originally Posted by Hitch View Post
And of course, in Kindle, all PNG's are converted to GIF images for the mobi files.
There used to be a KindlGen bug where transparent PNGs turned the transparency into a black background. I just looked up the changelog, and I see this was fixed in KindleGen 2.5:

https://kindlegen.s3.amazonaws.com/d...e%20Notes.html

Quote:
- Improved transparent PNG conversion: Transparent PNG images (now converted to JPEG) will use white background. This originally used black background during conversion causing degraded reading experience.
According to the documentation, I always thought that KindleGen:
  • All PNG -> GIF.
  • Transparent PNG -> GIF with white background.

No clue why they would go from Transparent PNG to JPG!!!

I fed my Transparency Test EPUB into Kindle Previewer, and I found a few things to note:
  • 32bpp Grayscale from GIMP turn into big black boxes. (This is the bug?)
  • I unpacked the Kindle file with "KindleUnpack", and I see that it converts
    • #3 and #4 to JPG with white background (GAH).
    • #1 gets converted to GIF.
    • #2 is a GIF, but is just a big black box.

The bug:

I believe these images will speak for themselves:

Click image for larger version

Name:	TransparentKindle.png
Views:	699
Size:	22.3 KB
ID:	112081 Click image for larger version

Name:	TransparentPaperwhite.png
Views:	659
Size:	22.3 KB
ID:	112083 Click image for larger version

Name:	TransparentKindleFireHD.png
Views:	651
Size:	46.8 KB
ID:	112082

On to the causes of the Bug:

This is all just educated guesses.

I used Imagemagick's "identify -verbose" on all 4 versions of Formula #1 (verbose output attached to this post). After comparing the output closely, I can see that the only major difference between Inkscape's version and GIMP's version is between color type:

https://en.wikipedia.org/wiki/Portab...cs#Color_depth

Inkscape's is set to 6 (RGB + Alpha) while GIMPs is set to the proper 4 (Grayscale + Alpha).

Guess: Perhaps KindleGen can't handle PNG Color Type 4 images?

Request:

Can someone with a lot more image experience create Grayscale + Alpha images and feed them into KindleGen/Previewer? Perhaps try to create them from a different program besides GIMP (maybe Photoshop, or the multitude of others).

Edit:

Click image for larger version

Name:	ADETransparency.png
Views:	643
Size:	30.8 KB
ID:	112087

I just tested this on my Nook + ADE, and it seems like ADE likes to break on the ScriptPNG (Indexed + Transparency), but works fine on the others. The causes of this one? No clue, maybe an Indexing + transparency is EXTREMELY rare.

I would say avoid Transparency PNGs for now.
Attached Files
File Type: epub TransparencyTest.epub (201.7 KB, 329 views)
File Type: zip ImageMagickVerboseOutput.zip (15.3 KB, 354 views)

Last edited by Tex2002ans; 09-25-2013 at 01:04 AM.
Tex2002ans is offline   Reply With Quote
Old 09-25-2013, 08:46 AM   #13
PoP
 curly᷂͓̫̙᷊̥̮̾ͯͤͭͬͦͨ ʎʌɹnɔ
PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.PoP ought to be getting tired of karma fortunes by now.
 
PoP's Avatar
 
Posts: 3,002
Karma: 50506927
Join Date: Dec 2010
Location: ♁ ᴺ₄₅°₃₀' ᵂ₇₃°₃₇' ±₆₀"
Device: K3₃.₄.₃ PW3&4₅.₁₃.₃
Quote:
Originally Posted by Tex2002ans View Post
...
Sadly, I don't have any physical Kindles to test on (I would not trust Kindle Previewer one iota when dealing with situations such as this).
...
If that can help I took screenshots on my K3W of

Your epub conversion to .azw3 by Calibre:
Spoiler:

Click image for larger version

Name:	screen_shot-63077.gif
Views:	531
Size:	21.8 KB
ID:	112097
Click image for larger version

Name:	screen_shot-63078.gif
Views:	526
Size:	19.0 KB
ID:	112098
Click image for larger version

Name:	screen_shot-63079.gif
Views:	542
Size:	12.2 KB
ID:	112099
Click image for larger version

Name:	screen_shot-63080.gif
Views:	532
Size:	11.4 KB
ID:	112100
Click image for larger version

Name:	screen_shot-63081.gif
Views:	549
Size:	11.6 KB
ID:	112101
Click image for larger version

Name:	screen_shot-63082.gif
Views:	543
Size:	19.1 KB
ID:	112102
Click image for larger version

Name:	screen_shot-63083.gif
Views:	530
Size:	25.6 KB
ID:	112103
Click image for larger version

Name:	screen_shot-63084.gif
Views:	521
Size:	19.0 KB
ID:	112104
Click image for larger version

Name:	screen_shot-63085.gif
Views:	551
Size:	13.0 KB
ID:	112105


Your epub conversion to .mobi by Kindle Previewer:
Spoiler:

Click image for larger version

Name:	screen_shot-63086.gif
Views:	525
Size:	18.4 KB
ID:	112106
Click image for larger version

Name:	screen_shot-63087.gif
Views:	559
Size:	21.5 KB
ID:	112107
Click image for larger version

Name:	screen_shot-63088.gif
Views:	531
Size:	12.2 KB
ID:	112108
Click image for larger version

Name:	screen_shot-63089.gif
Views:	528
Size:	8.3 KB
ID:	112109
Click image for larger version

Name:	screen_shot-63090.gif
Views:	516
Size:	12.8 KB
ID:	112110
Click image for larger version

Name:	screen_shot-63091.gif
Views:	516
Size:	18.9 KB
ID:	112111
Click image for larger version

Name:	screen_shot-63092.gif
Views:	529
Size:	15.8 KB
ID:	112112
Click image for larger version

Name:	screen_shot-63093.gif
Views:	518
Size:	18.2 KB
ID:	112113
Click image for larger version

Name:	screen_shot-63094.gif
Views:	505
Size:	18.2 KB
ID:	112114
PoP is offline   Reply With Quote
Old 09-25-2013, 02:49 PM   #14
Hitch
Bookmaker & Cat Slave
Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.Hitch ought to be getting tired of karma fortunes by now.
 
Hitch's Avatar
 
Posts: 11,460
Karma: 158448243
Join Date: Apr 2010
Location: Phoenix, AZ
Device: K2, iPad, KFire, PPW, Voyage, NookColor. 2 Droid, Oasis, Boox Note2
Hey, Tex:

The last time I unpacked a mobi we'd made with PNGs, what I got were gifs, across the board. I'd have to go back and research it, to see what the updates are doing (although...pretty sure I unpacked this after 2.5, mind you). We're a bit swamped right now, so it won't be immediate replies/response on this.

Hitch
Hitch is offline   Reply With Quote
Old 09-25-2013, 04:27 PM   #15
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 PoP View Post
If that can help I took screenshots on my K3W of
Fantastic, thank you for the real world images. (Forgive the overflowing formulas out of the boxes, I just whipped that EPUB together).

I just converted to AZW3 using Calibre as well, and then took it apart using KindleUnpack, and I see that Calibre leaves the images as PNGs.

I always thought KindleGen did PNGs -> GIFs because the old Kindles couldn't support the format... perhaps it is some leftover code from the old MOBI Pocket days?

Quote:
Originally Posted by Hitch View Post
The last time I unpacked a mobi we'd made with PNGs, what I got were gifs, across the board.
So I thought as well. I could have sworn that PNG -> GIF is what I read in the Kindle Documentation a long time ago, it was common knowledge that I absorbed from MR, and I knew that there was a KindleGen black background bug with PNG transparency.

I went to go look again at the Kindle Documentation specifically on PNG + changelog to see if that black background bug was fixed.... and then I stumbled across that JPG statement!

I might also want to see now what it does to a PNG that is > 128 KB (or whatever the limit is on images in KF7).

Quote:
Originally Posted by Hitch View Post
I'd have to go back and research it, to see what the updates are doing (although...pretty sure I unpacked this after 2.5, mind you). We're a bit swamped right now, so it won't be immediate replies/response on this.
Thank you, more tests are always welcome. And since you are in touch with all those Amazon people all the time, perhaps you can slip them a question about it please.
Tex2002ans 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
eBook with formulas aodor Workshop 13 11-18-2011 05:29 AM
Math formulas conversion help Sciamano Conversion 10 06-22-2011 06:33 AM
conversion of formulas paola Writer2ePub 5 01-03-2011 03:07 PM
What were the formulas for determining TOC lunixer Calibre 2 08-16-2010 11:14 AM
where to get autorun.xml, icon.png, key.png, lut.bin for PRS-505 obender Sony Reader Dev Corner 2 01-25-2009 03:20 PM


All times are GMT -4. The time now is 01:07 AM.


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