![]() |
#1 |
Junior Member
![]() 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? |
![]() |
![]() |
![]() |
#2 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: Feb 2015
Device: Kindle Fire HD 7
|
Spoiler:
Last edited by theducks; 02-02-2015 at 07:50 AM. Reason: Wrapped long paste in Spoiler |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#4 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#5 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: Feb 2015
Device: Kindle Fire HD 7
|
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#7 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#8 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 If I convert the demo.docx to EPUB I see this. 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. |
![]() |
![]() |
![]() |
#9 |
Junior Member
![]() 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. |
![]() |
![]() |
![]() |
#10 |
Junior Member
![]() 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.
|
![]() |
![]() |
![]() |
#11 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#12 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
![]() |
#13 | |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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:
![]() You might want to take a look at the Snippets manager. |
|
![]() |
![]() |
![]() |
#14 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,198
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
|
![]() |
![]() |
![]() |
Tags |
html code fixed width |
|
![]() |
||||
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 |