View Single Post
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,306
Karma: 13057279
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:	933
Size:	17.1 KB
ID:	112018
After: Click image for larger version

Name:	MobileReadFormula2.png
Views:	1023
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:	832
Size:	124.2 KB
ID:	111968 Click image for larger version

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

Name:	pg182.png
Views:	858
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:	809
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:	841
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:	714
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:	760
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:	825
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:	816
Size:	14.5 KB
ID:	111976

Click image for larger version

Name:	Step1.pg160-Formula1.png
Views:	718
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:	744
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:	700
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:	770
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:	736
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:	724
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:	716
Size:	11.2 KB
ID:	111982

Last edited by Tex2002ans; 09-24-2013 at 02:45 AM.
Tex2002ans is offline   Reply With Quote