reddit / emacs

nov (ebook reader), problems with rendering

SnooPets20 · 2022-08-05 19:42
Hi I'm very new to emacs and I wanted to try some of the tools available. I saw it has an ebook reader called nov (which seems to be the only maintained one) so I gave it a shot. I immediately noticed some issues with the rendering of the document. Here's a side by side of the exact same position in the book, rendered by nov on the left, and by zathura on the right, this is not a PDF, it's an epub file: https://i.imgur.com/KcYblln.png Notice the complety lack of formatting on the first paragraph, or rather, at all. I don't think I need to point out the problems, they are pretty clear on their own. How can I fix this? Is it even possible to fix it? This is all the configuration I have for nov: (setq nov-text-width 60) (setq visual-fill-column-center-text t) (add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode)) I don't really know how to extend it to be honest, or anything at all. I understand very basic elisp (like function calls and setting variables) but that's it. I do have plenty of programming experience, I just don't know elisp well enough yet. I've searched through the internet but there's very few results, and the few there were kinda went over my head. Any help is appreciated, thanks.
karthink · 2022-08-05 20:15
> Notice the complety lack of formatting on the first paragraph, or rather, at all. I don't think I need to point out the problems, they are pretty clear on their own. You'll have to be more specific. What do you mean by "formatting", and what do you expect to see in the Emacs version?
[deleted] · 2022-08-05 20:18
[deleted]
SnooPets20 · 2022-08-05 20:19
Precisely what I see on Zathura. This is the same way its rendered on an ebook reader (Librera) on my phone. The first paragraph is a quote, so it's the text is slanted. The author of the quote should be in bold. The title is also not centered for some reason. And the paragraphs below have too much spacing between them and no indentation. Not to mention the complete lack of justification. I don't mean to offend you, but couldn't you tell by the screenshot alone? It's pretty obvious.
SnooPets20 · 2022-08-05 20:19
I have unzip. I did not verify the EPUB file, but since I'im using the same file for both programs (and on two different ebook readers on my phone) and they all render fine except for emacs... well, it's pretty clear the issue is emacs.
AlanYx · 2022-08-05 20:52
It's not possible to get it to look like Zathura if the ebook uses CSS. This is because nov.el uses shr for rendering, and shr doesn't support CSS. If you'd like to work entirely in emacs but want to retain formatting, you could always convert the epub to PDF and then use pdf-tools.
SnooPets20 · 2022-08-05 20:57
Is there any ebook reader for emacs that supports css? Note that I do not know if that's the case with this ebook, but since dedicated ebook readers render it fine, it seems likely.
AlanYx · 2022-08-05 21:08
Not that I know of. Another option would be to unzip the epub (epubs are just zip files containing XHTML) and then read individual chapters with xwidget-webkit-browse-url.
SnooPets20 · 2022-08-05 21:13
I just found this: https://github.com/chenyanming/nov-xwidget But it's not hosted on melpa. How do you install (and mantain) packages outside of melpa?
AlanYx · 2022-08-05 21:21
That looks great! You can manually install it (see [http://xahlee.info/emacs/emacs/emacs\_installing\_packages.html](http://xahlee.info/emacs/emacs/emacs_installing_packages.html)) or use something like straight.el. The straight.el github page has a good list of alternative options too.
karthink · 2022-08-05 21:21
> I don't mean to offend you, but couldn't you tell by the screenshot alone? It's pretty obvious. That the two outputs look different is obvious, but identifying what you expect here isn't. I need to understand your expectation before I can help you. "I want them to look identical" is very different from "I want the Emacs output to be centered as well". The former is nearly impossible, the latter is two lines of code. > Precisely what I see on Zathura. This isn't possible since Emacs' capabilities for rich text display are limited. You'll have to lower your expectations. > The first paragraph is a quote, so it's the text is slanted. The author of the quote should be in bold. This should be happening automatically. I'd check to ensure that your variable-pitch font being used by Emacs has italic and bold variants. It looks from the "Historia del mundo" line that the bold-italic variant exists. Try testing with a different variable-pitch font to be sure. > The title is also not centered for some reason. Neither `nov` nor `shr` (Simple HTML Renderer, the backend) will center headings for you automatically. Centering them is possible but requires some elisp. AFAIK there's no built-in option for this. If you're interested in doing this, you can modify the code in [my reply here](https://old.reddit.com/r/emacs/comments/wgx917/does_any_of_you_know_how_to_center_the_images_in/ij3bz42/) about centering images to center headings instead. Search for the text-property `face` (instead of `display`) with values `shr-h1` through `shr-h4`, and call `(center-line)` instead of `(indent-to ...)`. Centering the _entire body of text_ relative to your window is much simpler: you can use `visual-fill-column-mode`. You already have a `visual-fill-column-` setting above but you're not turning on the mode. Try: (defun my/nov-display-setup () (when (require 'visual-fill-column nil t) (setq-local visual-fill-column-center-text t visual-fill-column-width (1+ nov-text-width)) (visual-fill-column-mode 1))) (add-hook 'nov-mode-hook 'my/nov-display-setup) Be sure to install `visual-fill-column-mode` first. > And the paragraphs below have too much spacing between them and no indentation. `shr` renders the paragraphs unindented and separated by two line breaks, Zathura uses indentation and one line break instead. These are both valid, the epub does not specify how paragraphs should be rendered. This behavior is not configurable, but can be overridden with some elisp advice. If you're interested, the relevant function to advise is `shr-ensure-paragraph`. > Not to mention the complete lack of justification. The [nov.el website](https://depp.brause.cc/nov.el/) outlines a recipe to get text justification with the `justify-kp` library, you can use that.
SnooPets20 · 2022-08-05 21:25
Well, I simply cloned the repo, added it to the list to load packages, loaded it and it worked, but sadly my emacs was not compiled with xwidgets support apparently. I'm using the official package from the arch repos. Seems kind of a pain to have to compile the entire program with that. Arch has two other emacs packages, one with native compilation, and another one without X11 support. idk
SnooPets20 · 2022-08-05 21:35
Thank you, seems like I'll have to get my hands dirty with elisp. By the way what do you think about a solution involving [this](https://github.com/chenyanming/nov-xwidget) plugin I found? It seems expand nov to support css which would (hopefully) fix these issues, but I can't really try it since I lack support for xwidgets.
karthink · 2022-08-05 21:48
> Thank you, seems like I'll have to get my hands dirty with elisp. What you want can be hacked together, as most things in Emacs can. But I'd advise against it unless you're explicitly interested in learning elisp, otherwise it's going to be frustrating. If your _only_ goal is to read ebooks in Emacs, ignore the elisp bits of my above reply. > By the way what do you think about a solution involving this plugin I found? It seems expand nov to support css which would (hopefully) fix these issues, but I can't really try it since I lack support for xwidgets. You'll need a copy of Emacs compiled with xwidget support. I haven't had much luck with xwidgets in the past. I put up with Emacs' limitations because it's an easily hackable and fully self-integrated environment. Xwidgets break both these features. I'd rather use a specialized application (like Zathura) at that point.
[deleted] · 2022-08-06 01:38
[deleted]
SnooPets20 · 2022-08-06 04:52
You're thinking of Gentoo. On arch things are already precompiled.
[deleted] · 2022-08-06 06:53
[deleted]
_viz_ · 2022-08-06 07:06
Emacs 29's doc-view can render epub files using mupdf which translates to having fancy rendering.
ParticularAtmosphere · 2022-08-06 07:41
Not only binary. AUR contains many (many) pieces of software in source form, including emacs.
SnooPets20 · 2022-08-06 07:48
I know, but that's the AUR. All the packages on Arch's official repos are pre-compiled. It's a "binary release" distro, if you will. On gentoo absolutely everything must be compiled by yourself.
SnooPets20 · 2022-08-06 07:48
Seems emacs 29 is having more and more features I'm wanting. I've seen it also adds support for smooth scrolling which is great. Is there a release window?
SnooPets20 · 2022-08-06 19:23
Could you expand on this? I just compiled emacs from source and doc view does have some variables related to epub, but when trying to load an epub file it fails, it just displays garbage. I do have mupdf installed. EDIT: Ok it works after installing `mupdf-tools` but the image looks kinda blurry.
wasamasa · 2022-08-06 20:48
Yes, that's like the first issue every doc-view user runs into, the default resolution is a bit low. Customize `doc-view-resolution` to a higher value, at the cost of rendering becoming slower.
wasamasa · 2022-08-06 20:58
nov.el author here. As other people pointed out in here, it's using shr.el which is the built-in HTML renderer with very limited CSS support. If the ebook relies heavily on CSS, it will look different in anything using shr.el (which includes `M-x eww` and a lot more Emacs packages). Your options: - Improve shr.el to have better CSS support. This is probably pretty tricky and considering it's relatively slow already, I don't see much happening there. Remember, the popular browser engines are highly optimized pieces of software and shr.el doesn't even try to compete with them. It's literally a simple HTML renderer translating the HTML to text with faces. There is very little overlap between CSS stylesheets and face attributes, which doesn't help at all. - Swap out the existing renderer with something else than shr.el. The nov-xwidget hack does exactly that by using xwidget-webkit which uses an actual browser engine. - Use something else than nov.el, such as doc-view with mupdf. Note that it renders to images rather than text, which has its own unique upsides and downsides.
SnooPets20 · 2022-08-06 21:05
I see. It's still kind of unwieldy. It only renders one page at a time (although seeing how it performs that may be for the better) and it contains no references, inides or anything I'd expect an epub reader to contain. I know it's **not** and epub reader, it just renders pngs, but it's still kind of disappointing. I guess it does its job well enough if you want to preview documents, but not to actually consume them.
cmjennings · 2022-08-27 02:04
Many thanks for the pointers, u/karthink. I'm a heavy nov user and just updated my nov config with your advice above and your other advice in the centering images post. I'm loving my reading experience even more. I'm now itching to hack together further adjustments! I appreciate the ideas!