Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Conversion

Notices

Reply
 
Thread Tools Search this Thread
Old 02-01-2015, 11:52 PM   #1
grepnick
Junior Member
grepnick began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Feb 2015
Device: Kindle Fire HD 7
DOCX to MOBI Problems with Fixed Width Code Style

First let me say that Calibre is great. I'm preparing to make a donation to support this wonderful application. I'm using it to publish an eBook on Amazon KDP and I've run into an issue with fixed-width fonts used in code examples.

Word has a built-in style for <code> "fixed width" fonts. Calibre converts this to MOBI beautifully with no issues if you use the default settings. If you try to set a base font size however, or set a font size key, the application strips multiple spaces from the <code> examples and condenses everything. It's really strange because if you don't set a base font size the multiple spaces work fine.

I'm not trying to go crazy with using spaces to control formatting. But just having 2 or 3 together works wonders in <code> style examples to improve readability.

Starting with a default small size helps prevent excessive wrapping in <code> examples. I use 8pt in Word, but Calibre seems to convert this to 12pt in the MOBI (old) output. That is why I was trying to use the base font size, but I can't do it if it strips the spaces.

Any idea what I'm doing wrong?
grepnick is offline   Reply With Quote
Old 02-02-2015, 12:02 AM   #2
grepnick
Junior Member
grepnick began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Feb 2015
Device: Kindle Fire HD 7
Spoiler:
Convert book 1 of 1 (eBook)
Resolved conversion options
calibre version: 2.17.0
{'asciiize': False,
'author_sort': None,
'authors': None,
'base_font_size': 10.0,
'book_producer': None,
'change_justification': u'original',
'chapter': u"//*[((name()='h1' or name()='h2') and re:test(., '\\s*((chapter|book|section|part)\\s+)|((prolog|pr ologue|epilogue)(\\s+|$))', 'i')) or @class = 'chapter']",
'chapter_mark': u'pagebreak',
'comments': None,
'cover': u'C:\\Users\\Nick\\AppData\\Local\\Temp\\calibre_j 7bgau\\j7be75.jpeg',
'debug_pipeline': None,
'dehyphenate': True,
'delete_blank_paragraphs': True,
'disable_font_rescaling': False,
'docx_no_cover': False,
'dont_compress': False,
'duplicate_links_in_toc': False,
'embed_all_fonts': False,
'embed_font_family': None,
'enable_heuristics': False,
'expand_css': False,
'extra_css': None,
'extract_to': None,
'filter_css': u'',
'fix_indents': True,
'font_size_mapping': u'8.0, 10.0, 12.0, 12.0, 14.0',
'format_scene_breaks': True,
'html_unwrap_factor': 0.4,
'input_encoding': None,
'input_profile': <calibre.customize.profiles.InputProfile object at 0x02603710>,
'insert_blank_line': False,
'insert_blank_line_size': 0.5,
'insert_metadata': False,
'isbn': None,
'italicize_common_cases': True,
'keep_ligatures': False,
'language': None,
'level1_toc': None,
'level2_toc': None,
'level3_toc': None,
'line_height': 0.0,
'linearize_tables': False,
'margin_bottom': 5.0,
'margin_left': 5.0,
'margin_right': 5.0,
'margin_top': 5.0,
'markup_chapter_headings': True,
'max_toc_links': 50,
'minimum_line_height': 100.0,
'mobi_file_type': u'old',
'mobi_ignore_margins': False,
'mobi_keep_original_images': False,
'mobi_toc_at_start': False,
'no_chapters_in_toc': False,
'no_inline_navbars': True,
'no_inline_toc': False,
'output_profile': <calibre.customize.profiles.KindlePaperWhiteOutp ut object at 0x02603AB0>,
'page_breaks_before': u'/',
'personal_doc': u'[PDOC]',
'prefer_author_sort': False,
'prefer_metadata_cover': False,
'pretty_print': False,
'pubdate': None,
'publisher': None,
'rating': None,
'read_metadata_from_opf': u'C:\\Users\\Nick\\AppData\\Local\\Temp\\calibre_j 7bgau\\w0t4s3.opf',
'remove_fake_margins': True,
'remove_first_image': False,
'remove_paragraph_spacing': False,
'remove_paragraph_spacing_indent_size': 1.5,
'renumber_headings': True,
'replace_scene_breaks': u'',
'search_replace': '[]',
'series': None,
'series_index': None,
'share_not_sync': False,
'smarten_punctuation': False,
'sr1_replace': None,
'sr1_search': None,
'sr2_replace': None,
'sr2_search': None,
'sr3_replace': None,
'sr3_search': None,
'start_reading_at': None,
'subset_embedded_fonts': False,
'tags': None,
'timestamp': None,
'title': None,
'title_sort': None,
'toc_filter': None,
'toc_threshold': 6,
'toc_title': None,
'unsmarten_punctuation': False,
'unwrap_lines': True,
'use_auto_toc': False,
'verbose': 2}
InputFormatPlugin: DOCX Input running
on C:\Users\Nick\AppData\Local\Temp\calibre_j7bgau\nu 6x_i.docx
Converting Word markup to HTML
Converting styles to CSS
Cleaning up redundant markup generated by Word
Generating Table of Contents from headings
Parsing all content...
Parsing index.html ...
Initial parse failed, using more forgiving parsers
Parsing index.html as HTML
Parsing docx.css ...
Reading TOC from NCX...
Merging user specified metadata...
Detecting structure...
Detected chapter: Section 0: Internet Protocol Suite
Detected chapter: Section 1: Installing Nmap
Detected chapter: Section 2: Basic Scanning Techniques
Detected chapter: Section 3: Discovery Options
Detected chapter: Section 4: Advanced Scanning Options
Detected chapter: Section 5: Port Scanning Options
Detected chapter: Section 6: Operating System and Service Detection
Detected chapter: Section 7: Timing Options
Detected chapter: Section 8: Evading Firewalls
Detected chapter: Section 9: Output Options
Detected chapter: Section 10: Troubleshooting and Debugging
Detected chapter: Section 11: Zenmap
Detected chapter: Section 12: Nmap Scripting Engine (NSE)
Detected chapter: Section 13: Ndiff
Detected chapter: Section 14: Nping
Detected chapter: Section 15: Ncat
Detected chapter: Section 16: Tips and Tricks
Flattening CSS and remapping font sizes...
Source base font size is 10.00000pt
Removing fake margins...
Found 17 items of level: div_1
Found 3128 items of level: p_1
div_1 left margin stats: Counter()
div_1 right margin stats: Counter()
p_1 left margin stats: Counter({u'0': 3128})
p_1 right margin stats: Counter({u'0': 3128})
Cleaning up manifest...
Trimming unused files from manifest...
Creating MOBI Output...
Serializing resources...
Creating MOBI 6 output
Generating in-line TOC...
Applying case-transforming CSS...
Parsing manglecase.css ...
Parsing tocstyle.css ...
Rasterizing SVG images...
Converting XHTML to Mobipocket markup...
Serializing markup content...
Compressing markup content...
Generating MOBI index for a book
MOBI output written to C:\Users\Nick\AppData\Local\Temp\calibre_j7bgau\dp vvqt.mobi

Last edited by theducks; 02-02-2015 at 07:50 AM. Reason: Wrapped long paste in Spoiler
grepnick is offline   Reply With Quote
Advert
Old 02-02-2015, 12:03 AM   #3
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
If you are planning on selling on KDP, Amazon will want you to use their own homegrown kindlegen tool.
I suggest you import your DOCX asa new book in the calibre Edit Book tool, save it as an EPUB, then make sure the CSS is what you want it to be before using kindlegen/Kindle Previewer to test the book and upload it.
eschwartz is offline   Reply With Quote
Old 02-02-2015, 12:08 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,198
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
See https://www.mobileread.com/forums/sho...d.php?t=186697

Hard to say anything without a demo DOCX file.
kovidgoyal is offline   Reply With Quote
Old 02-02-2015, 12:23 AM   #5
grepnick
Junior Member
grepnick began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Feb 2015
Device: Kindle Fire HD 7
Demo files attached. Thanks for your help.

demo.zip

demo - Nick.mobi
grepnick is offline   Reply With Quote
Advert
Old 02-02-2015, 01:00 AM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,198
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I assume you are referring to the use of spaces to line up the columns in the output from nmap. Converting the attached docx with no options other than kindle output profile like this:

ebook-convert demo.docx .mobi --output-profile kindle

does not preserve the multiple spaces. So how are you getting them preserved in the first place?

As far as I can tell, looking inside the docx file, there is no instruction to preserve multiple spaces there. The docx file is a simply zip file, open it up and look at document.xml, you will see that there is no xml:space="preserve" on the <w:t> elements containing the nmap output.

I dont really understand why word itself preserves the spaces when displaying those sections at all, must be some undocumented feature, as I can find nothing in the docx spec about it.
kovidgoyal is offline   Reply With Quote
Old 02-02-2015, 02:05 AM   #7
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,198
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Ah, found it, it uses a global word setting,
<w:characterSpacingControl w:val="doNotCompress"/>

I will have to look into adding support for that to the DOCX input plugin.

EDIT: No never mind, that only applies to text-justify-trim

Last edited by kovidgoyal; 02-02-2015 at 02:08 AM.
kovidgoyal is offline   Reply With Quote
Old 02-02-2015, 02:37 AM   #8
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,633
Karma: 29710510
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Does this give a clue

If I save the demo.docx as filtered HTML and convert that to EPUB I see this

Click image for larger version

Name:	Capture.JPG
Views:	303
Size:	71.5 KB
ID:	134426

If I convert the demo.docx to EPUB I see this.

Click image for larger version

Name:	Capture2.JPG
Views:	310
Size:	72.9 KB
ID:	134427

I rarely use MOBI so I'm not sure what happens with it, it looks a bit messy in Mobipocket Reader - but I may have messed up the conversion from ZIP to MOBI

Added : I use Word 2007, I believe the Code style is a 2013 feature.

BR

Last edited by BetterRed; 02-02-2015 at 02:39 AM.
BetterRed is offline   Reply With Quote
Old 02-02-2015, 03:04 AM   #9
grepnick
Junior Member
grepnick began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Feb 2015
Device: Kindle Fire HD 7
I chose to left align and it kind of worked. Some items were compressed and others were not.
LeftAlign.mobi

Saving as filtered HTML seems to work 100% and I can set font sizes.
FilteredHTML.mobi

Thanks for the help.
grepnick is offline   Reply With Quote
Old 02-02-2015, 03:09 AM   #10
grepnick
Junior Member
grepnick began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Feb 2015
Device: Kindle Fire HD 7
PS. The Editor looks like a nice feature. I'm going to look into that. I didn't see where it supported <code> or <pre> without having to manually insert it. I'll read up on it though. Thanks again.
grepnick is offline   Reply With Quote
Old 02-02-2015, 03:12 AM   #11
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,198
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
@BR: Yeah that's basically what I found. The question is to try to deduce what rules Word uses for the parsing of <w:t> elements that contain collapsible sequences of white space and no xml:space="preserve" attribute.

When I have some time, I will need to setup a few test cases and see what Word does, and try to mimic it in the DOCX input plugin.
kovidgoyal is offline   Reply With Quote
Old 02-02-2015, 03:32 AM   #12
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,633
Karma: 29710510
Join Date: Mar 2012
Location: Sydney Australia
Device: none
@Kovid - I doubt I can be of any further help, but I'll have a play 2mora... if necessary

@grepnick - I stumbled on this ==>> Creating a style in Word 2013 for code snippets

BR
BetterRed is offline   Reply With Quote
Old 02-02-2015, 10:06 AM   #13
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by grepnick View Post
PS. The Editor looks like a nice feature. I'm going to look into that. I didn't see where it supported <code> or <pre> without having to manually insert it. I'll read up on it though. Thanks again.
Usually it is used to touch up pre-existing code (from conversions).
You might want to take a look at the Snippets manager.
eschwartz is offline   Reply With Quote
Old 02-03-2015, 12:44 AM   #14
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,198
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
https://github.com/kovidgoyal/calibr...5db8f36e3af7c1
kovidgoyal is offline   Reply With Quote
Reply

Tags
html code fixed width


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Aura HD new to aura hd.. (annotation/fixed width fonts) kbahd260 Kobo Reader 12 02-15-2014 06:35 PM
PRS-300 Fixed-width fonts for text files. seanhennessy Sony Reader 0 09-24-2010 11:41 AM
How to apply fixed-width fonts EnergyLens Calibre 5 04-17-2010 12:41 PM
single HTML to ePub with fixed width font skyfish Calibre 8 12-10-2009 01:30 PM
Fixed-width txt to fluid one vitalyb Workshop 5 12-05-2009 08:06 AM


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


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