06-05-2023, 01:47 PM | #1 |
Member
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
|
How to get preformatted/code font to stick
I have an epub that has code snippets that are displaying as just smaller version of the regular font face. When I opened the file in Calibre, I noticed that the only CSS applied to the
Code:
pre Code:
font-size: x-small; Code:
font-familly: Courier; |
06-05-2023, 02:54 PM | #2 |
Resident Curmudgeon
Posts: 76,374
Karma: 136466962
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
If you are using KePub, you have to embed a monospace font.
If you are using a ePub you want to put a font with the name Courier in the fonts directory. In the ePub, put the following code in the CSS. That will link the fonts to the ePub without the need to embed. Code:
@font-face { font-family:monospace; font-weight: normal; font-style: normal; src: url(res:///Data/fonts/Courier-Regular.ttf); } @font-face { font-family:monospace; font-weight: bold; font-style: normal; src: url(res:///Data/fonts/Courier-Bold.ttf); } @font-face { font-family:monospace; font-weight: normal; font-style: italic; src: url(res:///Data/fonts/Courier-Italic.ttf); } @font-face { font-family:monospace; font-weight: bold; font-style: italic; src: url(res:///Data/fonts/Courier-BoldItalic.ttf); } |
Advert | |
|
06-05-2023, 03:08 PM | #3 |
Member
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
|
Forgive my ignorance, but how do I know which format Calibre is sending to my device? I just use the "Send to device" button which doesn't ask if I want to convert.
I tried adding the code you provided, but it didn't make a difference. |
06-05-2023, 03:17 PM | #4 |
Resident Curmudgeon
Posts: 76,374
Karma: 136466962
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Did you put a font family named Courier in the fonts directory? Also, you have to be reading ePub. That code will not work with KePub.
|
06-05-2023, 03:32 PM | #5 | |
Member
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
|
Quote:
Code:
cour.ttf |
|
Advert | |
|
06-05-2023, 03:39 PM | #6 | |
Member
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
|
Quote:
Code:
cour*.ttf I looked at the file system on my reader and I do see the file as having a weird double extension Code:
.kepub.epub |
|
06-05-2023, 03:51 PM | #7 |
Member
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
|
I found a reddit thread that says to just copy the epub file from my computer's file system to the reader, but that just results in a file that locks up the reader for several seconds if I try to navigate using the table of contents, and the code is still not monospaced.
|
06-05-2023, 05:57 PM | #8 |
Running with scissors
Posts: 1,557
Karma: 14325282
Join Date: Nov 2019
Device: none
|
Code:
.kepub.epub |
06-05-2023, 06:29 PM | #9 |
Member
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
|
|
06-05-2023, 07:03 PM | #10 |
Resident Curmudgeon
Posts: 76,374
Karma: 136466962
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
|
06-05-2023, 07:12 PM | #11 |
Member
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
|
I understand that. That's why I looked for a way to send an epub to the Kobo (and have it stay as that extension). That however didn't work. Since it looks like I'll have to stick with KePub, how do I embed the monospace fonts like you suggest?
|
06-05-2023, 08:10 PM | #12 |
Bibliophagist
Posts: 40,487
Karma: 156983616
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Which KoboTouch driver are you using to send the ebook to your Kobo? If you are using the KoboTouch driver, it will send epubs. If you are using the KoboTouchExtended driver, it will send kepubs (.kepub.epub file extension).
If you have KoboUtilities installed, you can switch the active driver from it's menu. Otherwise, you can open Preferences => Plugins, search for kobot and disable the KoboTouchExtended driver and enable the KoboTouch driver. If you have done any customization in the driver, you will need to copy it over. |
06-05-2023, 09:14 PM | #13 |
Member
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
|
I suspect my CSS is not up to snuff. Here's what I have in the style file:
Code:
.pre { font-family: monospace; } @font-face { font-family: monospace; font-weight: normal; font-style: normal; src: url(res:///Data/fonts/cour.ttf); } @font-face { font-family: monospace; font-weight: bold; font-style: normal; src: url(res:///Data/fonts/courbd.ttf); } @font-face { font-family: monospace; font-weight: normal; font-style: italic; src: url(res:///Data/fonts/couri.ttf); } @font-face { font-family: monospace; font-weight: bold; font-style: italic; src: url(res:///Data/fonts/courbi.ttf); } Also, the regular epub format doesn't seem to play very nicely. As I mentioned earlier, trying to use the table of contents (either in the book or the reader's ToC function) just locks up the reader for ~30 seconds, after which it automatically restarts. If this is because it's an epub vs a kepub, then how can I get the font to work correctly in a kepub? |
06-07-2023, 08:12 AM | #14 | |
Resident Curmudgeon
Posts: 76,374
Karma: 136466962
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
In the KoboTouchExtended driver, go to the Extended tab and check Use template for kepubification. This is the code I am using for the template. Code:
program: $#kepub == 'yes' Last edited by JSWolf; 06-07-2023 at 08:15 AM. |
|
06-07-2023, 09:08 PM | #15 | |
Grand Sorcerer
Posts: 6,220
Karma: 16536676
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Quote:
Assuming that you're using one of the stock Kobo reading apps (i.e. not KOReader) then the following is the way to get a monospace font working on any Kobo firmware >= 4.32.xxxxx: Epub:
Kepub: Ever since firmware 4.32.xxxxx, the only option is to embed a monospace font into each book that needs it. If you embed the font then it should work equally well as either epub or kepub. Last edited by jackie_w; 06-07-2023 at 09:10 PM. |
|
Tags |
code, css, preformatted |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Code View font choices | tetrault | Sigil | 3 | 05-28-2019 04:11 PM |
Change to interface font doesn't stick | eater | Calibre | 3 | 02-21-2018 04:46 PM |
Can't set preferred font in Sigil Code Editor window | GrannyGrump | Sigil | 2 | 01-27-2014 12:43 AM |
Calling all font and code experts | ltr | Kobo Reader | 7 | 12-09-2011 09:28 PM |
Changing font for code view mode | matthewyi | Sigil | 2 | 11-05-2009 03:20 PM |