View Single Post
Old 01-29-2015, 04:37 PM   #27
EbokJunkie
Addict
EbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blueEbokJunkie can differentiate black from dark navy blue
 
Posts: 230
Karma: 13495
Join Date: Feb 2009
Location: SoCal
Device: Kindle 3, Kindle PW, Pocketbook 301+, Pocketbook Touch, Sony 950, 350
Automated insertion of negative side margin tag html{...}

Please take a look at automated insertion of negative side margin tag html{...} in ePub->azw3 conversion flow. It is similar to those presented in post#8.
In that post Windows batch file provided only partial automation because it demanded user to determine the CSS class name used for paragraph rendering in intermediate ePub file.

Now that new idea of universal negative margin tag is suggested it looks as small change to batch file code from post #8 may provide fully automated operation.
Read preamble to post #8, download new Python app negmarg2.py, and try this batch file (uses Python 2.7):
Code:
:: Parameter #1: epub file name
:: Parameter #2: negative margin (enter POSITIVE decimal value in pt). Default is 9
::
:: How to call:
::1.  epub2azw3 book.epub
::   Provides default negative margins of 9 pt
::2.  epub2azw3 book.epub negative_margin
::   Provides  negative side margins equal to value of parameter "negative_margin" (value must be positive) 

ebook-convert %1 "%~n1_embed.epub" --output-profile kindle_pw^
   --embed-font-family "Charis SIL ModifiedLarger" --subset-embedded-fonts --minimum-line-height 125^
   --base-font-size 17 --font-size-mapping 13,13,17,17,18,22,24^
   --remove-paragraph-spacing --change-justification justify --margin-top -1 --margin-bottom -1

:: call python applet that inserts negative margin to css file.
:: margin is in positive number of points and comes from second parameter of this batch file
:: IF SECOND PARAMETER IS MISSING/BLANK DEFAULT VALUE 9 IS SET

if [%2]==[] (goto mdef) else goto mspec
:mspec 
:: Parameter #2 is in place
py -2.7 "%~dp0negmarg2.py" -e "%~n1_embed.epub" -m %2 
goto pass
:mdef
:: Parameter #2 is blank
py -2.7 "%~dp0negmarg2.py" -e "%~n1_embed.epub" -m 9
:pass

:: convert epub to mobi
kindlegen "%~n1_embed.epub" -locale en -o "%~n1.mobi"

:: extract azw3
py -2.7  "%~dp0\lib\kindleunpack.py" -s "%~n1.mobi" "%~n1"
:: copy mobi8-*.azw3 file into the current directory
copy ".\%~n1\*.azw?" ".\"
:: check if old  file *.azw3 exists and delete it
if exist "%~n1.azw3" del "%~n1.azw3"

:: rename mobi8-*.azw3 file
call renazw3 "mobi8-%~n1.azw3" 

:: remove intermediate file
del "%~n1_embed.epub"
del "%~n1.mobi"
:: remove scratch directory with unpacked files
rmdir "%~n1" /s /q
Please address post #8 for details.
Note that value of parameter --embed-font-family "Charis SIL ModifiedLarger" you should replace with the name of your favorite font (registered with Windows).
Also, you can remove this parameter if you don't want to embed your font.
Hope that someone will figure out how to convert this batch file to bash script and migrate it to Mac.

Last edited by EbokJunkie; 11-19-2018 at 02:03 PM.
EbokJunkie is offline   Reply With Quote