Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Kobo Reader

Notices

Reply
 
Thread Tools Search this Thread
Old 06-05-2023, 01:47 PM   #1
spartanhooah
Member
spartanhooah began at the beginning.
 
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
Unhappy 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
class was
Code:
font-size: x-small;
. I added
Code:
font-familly: Courier;
and this seems to have fixed it in Calibre's renderer, but on my Clara HD the font is still small and a non-monospaced serif font. How can I update the file (and/or my Kobo) so that the code snippets are displayed properly?
spartanhooah is offline   Reply With Quote
Old 06-05-2023, 02:54 PM   #2
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
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);
}
JSWolf is online now   Reply With Quote
Advert
Old 06-05-2023, 03:08 PM   #3
spartanhooah
Member
spartanhooah began at the beginning.
 
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.
spartanhooah is offline   Reply With Quote
Old 06-05-2023, 03:17 PM   #4
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
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:
Originally Posted by spartanhooah View Post
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.
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.
JSWolf is online now   Reply With Quote
Old 06-05-2023, 03:32 PM   #5
spartanhooah
Member
spartanhooah began at the beginning.
 
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
Quote:
Originally Posted by JSWolf View Post
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.
Ahh, I see a
Code:
cour.ttf
file in the fonts directory. I updated the code you provided to use that name instead, but still the same result.
spartanhooah is offline   Reply With Quote
Advert
Old 06-05-2023, 03:39 PM   #6
spartanhooah
Member
spartanhooah began at the beginning.
 
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
Quote:
Originally Posted by JSWolf View Post
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.
I did not (hadn't seen that directory before). That directory has files like
Code:
cour*.ttf
, so I modified the CSS snippet you provided accordingly, but still no change in the display.

I looked at the file system on my reader and I do see the file as having a weird double extension
Code:
.kepub.epub
, so I think it is indeed getting sent as the wrong format. I'll Google how to change that.
spartanhooah is offline   Reply With Quote
Old 06-05-2023, 03:51 PM   #7
spartanhooah
Member
spartanhooah began at the beginning.
 
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.
spartanhooah is offline   Reply With Quote
Old 06-05-2023, 05:57 PM   #8
hobnail
Running with scissors
hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.
 
Posts: 1,557
Karma: 14325282
Join Date: Nov 2019
Device: none
Code:
.kepub.epub
Is the correct extension for a KePub on the Kobo.
hobnail is offline   Reply With Quote
Old 06-05-2023, 06:29 PM   #9
spartanhooah
Member
spartanhooah began at the beginning.
 
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
Quote:
Originally Posted by hobnail View Post
Code:
.kepub.epub
Is the correct extension for a KePub on the Kobo.
Ok, that's good to know.
spartanhooah is offline   Reply With Quote
Old 06-05-2023, 07:03 PM   #10
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
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:
Originally Posted by spartanhooah View Post
Ok, that's good to know.
But it means the code I posted will not work. It doesn't work with a KePub eBook. Yo have to embed monospace fonts in a KePub. To use the code I posted, you have to be reading ePub.
JSWolf is online now   Reply With Quote
Old 06-05-2023, 07:12 PM   #11
spartanhooah
Member
spartanhooah began at the beginning.
 
Posts: 19
Karma: 10
Join Date: May 2020
Device: Kobo Clara HD
Quote:
Originally Posted by JSWolf View Post
But it means the code I posted will not work. It doesn't work with a KePub eBook. Yo have to embed monospace fonts in a KePub. To use the code I posted, you have to be reading ePub.
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?
spartanhooah is offline   Reply With Quote
Old 06-05-2023, 08:10 PM   #12
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
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.
DNSB is offline   Reply With Quote
Old 06-05-2023, 09:14 PM   #13
spartanhooah
Member
spartanhooah began at the beginning.
 
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);
}
What am I missing?

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?
spartanhooah is offline   Reply With Quote
Old 06-07-2023, 08:12 AM   #14
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
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:
Originally Posted by DNSB View Post
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.
I have the KoboTouchExtended set to send KePub based on a yes value in a custom column. Otherwise, it send ePub. It's perfect. No having to change drivers.

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.
JSWolf is online now   Reply With Quote
Old 06-07-2023, 09:08 PM   #15
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,220
Karma: 16536676
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
Quote:
Originally Posted by spartanhooah View Post
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);
}
What am I missing?
What you're missing is that those 4 CSS @font-face statements are completely wrong for monospace on a Kobo. I don't know why @JSWolf recommended them to you. They might have helped a user of a Sony eink device circa 2010 but they are of no use to a Kobo device of any vintage.

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:
  • You don't need any CSS extra @font-face statements.
  • To be on the safe side rename the 4 sideloaded .ttf files so they have external filenames:
    Courier-Regular.ttf (or Courier.ttf)
    Courier-Italic.ttf
    Courier-Bold.ttf
    Courier-BoldItalic.ttf
  • The *internal* font name of all 4 ttfs must be precisely Courier, i.e. none of these is suitable Courier New or Courier Prime or Dark Courier. If your current sideloaded font isn't internally named Courier then you need to use some kind of font editor (e.g. FontForge) or some other font utility (e.g. ttfedit) to change the internal font name to exactly Courier.

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.
jackie_w is offline   Reply With Quote
Reply

Tags
code, css, preformatted


Forum Jump

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


All times are GMT -4. The time now is 11:25 AM.


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