Epub output text in frames all leading space gone, how to make this work?

I have computer source code examples in a large document intended to be an .epub book. The source code is inside of frames, and has style frame contents. The .odt .docx and .pdf all look fine, but the .epub export removes the leading spaces from every line.

This inside a frame, using a monospaced font:

int main( ){
    printf("hello!")
    if ( you == good ){
        printf("blessings to you all!")
    }
}

Turns into this in the exported to .epub file:

main( ){
printf("hello!")
if ( you == good ){
printf("blessings to you all!")
}
}

I tried pulling the .odt into Calibre but Calibre crashes when convert to epub is selected. I tried saving as .docx but converting to .epub then has line breaks in it where there were page breaks in the .odt file.

You should really give more information. There are several versions of LibreOffice in use, some of them recently developed and somewhat buggy, others more stable. They may work differently on different distros of Linux or on Windows, etc. Always include version information in your question.

You convert to docx and then try to export to epub from LibreOffice, I suppose. That doesn’t make any sense. You first convert to docx, then you open the docx, which means that it is internally converted to the native document format of LibreOffice - so you’re back where you started - then try the export again. That will merely expose the differences in file format and conversion issues.

Anyway, I copied part of your post into a blank Writer document and into a blank Calligra Words document and exported as ebook. The best that did was preserve the first space on the indented lines in the xhtml file in the e-book archive. Then I replaced the spaces with tabs, and after that the text was converted into an svg image in the e-book, with the correct formatting. If you use non-breaking spaces (Ctrl+Shift+space), you get indented text in the xhtml, but the indentation is too small. :thinking: I also found that the files in the epub archive have the wrong time stamp, it’s two hours off. EDIT I finally exported to xhtml directly, and that yielded the correct indentation.

1 Like