vedang / pdf-tools

Emacs support library for PDF files.
https://pdftools.wiki
GNU General Public License v3.0
625 stars 89 forks source link

Certain characters do not render correctly in pdf-view-mode, even though they are present in the tex file. (Pending Upstream Merge) #112

Open allenryb opened 2 years ago

allenryb commented 2 years ago

I come across some weird behavior of pdf-tools. If the tex file has some bold font, then pdf-tools will show the corrent PDF after the first compile on startup; but some characters will vanish after the second compile. For example,

This is my first tex file and PDF. It's corret Screenshot from 2022-05-17 19-11-00

But after some more characters and compile, the pdf-tools shows wrong. In the following picture, the bold "cccddd" disappears. Screenshot from 2022-05-17 19-11-15

Actually, the PDF file in the system PDF viewer is right.

My system is Archlinux and I use the following init file:

;; -*- lexical-binding: t; -*-
(tool-bar-mode 0)
(scroll-bar-mode 0)

(require 'package)
(setq package-enable-at-startup nil)

(package-initialize)

;; Bootstrap `use-package'
(unless (package-installed-p 'use-package) 
  (package-refresh-contents) 
  (package-install 'use-package))

(use-package pdf-tools 
  :init
  (pdf-tools-install))

(use-package latex
  :init
  (setq TeX-auto-save t) 
  (setq TeX-parse-self t)
  (setq-default TeX-master t)
  (setq TeX-source-correlate-method (quote synctex)
    TeX-source-correlate-mode t
    TeX-source-correlate-start-server t)
  ;; pdf-tools
  ;; to use pdfview with auctex
  (setq TeX-view-program-selection '((output-pdf "PDF Tools")))
  ;; to have the buffer refresh after compilation
  (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer))
tongjie-chen commented 2 years ago

The LaTeX you gave compiled and showed fine in my old build of epdfinfo.

\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
\textbf{aaa}

CCC

\textbf{cccddd}
\end{document}

I am not a maintainer. But I think for better assistance, it will be good to show your poppler version and pdf-tools version.

vedang commented 2 years ago

Yes, please share the version of poppler you have installed on your operating system, and the version of pdf-tools (if you have installed from somewhere other than Melpa or NonGNU Elpa)

9viz commented 2 years ago

I'm pretty sure that this is a bug in poppler. https://www.andrew.cmu.edu/course/03-231/LecF05/Lec06/Lec06.pdf -- in this pdf, none of the Greek letters are rendered by pdf-tools; the same goes for okular which I believe also uses poppler. The problem is not exhibited by ungoogled-chromium or zathura with the mupdf plugin. My poppler version is 21.06.1.

EDIT: Poppler 22.03.0 also renders the Greek letters as boxes.

ywwry66 commented 2 years ago

As others have said, this is an poppler bug. The upstream merge request is pending review: 1203 and hopefully it will be merged soon.

allenryb commented 2 years ago

Yes, please share the version of poppler you have installed on your operating system, and the version of pdf-tools (if you have installed from somewhere other than Melpa or NonGNU Elpa)

Thanks for your reply! My poppler version is 22.05.0-1, pdf-tools version is 20220512.145 from Melpa.

The following is the info by pacman -Qi poppler

Name            : poppler
Version         : 22.05.0-1
Description     : PDF rendering library based on xpdf 3.0
Architecture    : x86_64
URL             : https://poppler.freedesktop.org/
Licenses        : GPL
Groups          : None
Provides        : libpoppler.so=121-64  libpoppler-cpp.so=0-64
Depends On      : libjpeg  gcc-libs  cairo  fontconfig  openjpeg2  lcms2  nss  curl
Optional Deps   : poppler-data: highly recommended encoding data to display PDF documents with certain
                  encodings and characters [installed]
Required By     : cups-filters  libreoffice-still  manjaro-ranger-settings  poppler-glib  poppler-qt5
                  texlive-bin
Optional For    : ranger
Conflicts With  : poppler-qt3<22.05.0  poppler-qt4<22.05.0
Replaces        : None
Installed Size  : 6.03 MiB
Packager        : Andreas Radke <andyrtr@archlinux.org>
Build Date      : Fri 06 May 2022 04:01:13 AM CST
Install Date    : Sun 15 May 2022 07:15:33 PM CST
Install Reason  : Installed as a dependency for another package
Install Script  : No
Validated By    : Signature
JiaweiChenC commented 2 years ago

I think I have the same problem, this issue occurs when I write some characters and then I changed some of them.

image
marcel-becker commented 2 years ago

I am seeing the same behavior on Mac OS Monterey 12.4 Poppler version (from brew) poppler: stable 22.05.0 (bottled), HEAD Pdf-Tools: 20220512.145 Gnu Emacs: 29.0.50 (Built from source -- commit 961cec0a7d0d300df4405215d0a0ece35c52b4c1)

It is happening with both Latex and Lilypond pdf generated files. The first time I open the pdf file it looks ok. After I re-process the source file and the pdf file automatically refreshes on the visible buffer, then the images start to get messed up. Killing the emacs buffer does not solve the problem. I usually kill the epdinfo process in the shell, and open the pdf file again in emacs. Then the document renders correctly for a couple of times until the text starts to get all messed up again.
Screen Shot 2022-05-20 at 10 03 37 AM

allenryb commented 2 years ago

The problem may be solved after updating poppler 22.05.0-2 and pdf-tools 20220522.13

JiaweiChenC commented 2 years ago

The problem may be solved after updating poppler 22.05.0-2 and pdf-tools 20220522.13

How can I upgrade poppler 22.05.0-2 on mac?

marcel-becker commented 2 years ago

@JiaweiChenC I installed poppler from HEAD using brew. Or you can clone the poppler repo and follow the same steps the brew recipe uses. I tried building poppler using just cmake and make without any options but it failed to compile. BTW, @allenryb, I don't see version 22.05.0-2 tag in the poppler git repo.

$ brew uninstall poppler $ brew install --HEAD poppler ==> Downloading https://poppler.freedesktop.org/poppler-data-0.4.11.tar.gz Already downloaded: /Users/marcelbecker/Library/Caches/Homebrew/downloads/d0ce5fea7a038ced91deafbd2d9d78074b6123ce1571c4ff59e3c4f2c9142e0f--poppler-data-0.4.11.tar.gz ==> Cloning https://gitlab.freedesktop.org/poppler/poppler.git Updating /Users/marcelbecker/Library/Caches/Homebrew/poppler--git ==> Checking out branch master Already on 'master' Your branch is up to date with 'origin/master'. HEAD is now at b700e0b2 Forms: Fix crash in forms with their own DR ==> cmake . -DBUILD_GTK_TESTS=OFF -DENABLE_BOOST=OFF -DENABLE_CMS=lcms2 -DENABLE_GLIB=ON -DENABLE_QT5=OFF -DENABLE_QT6=ON -DENABLE_UNSTABLE_API_ABI_HEADERS ==> make install ==> make clean ==> cmake . -DBUILD_SHARED_LIBS=OFF -DBUILD_GTK_TESTS=OFF -DENABLE_BOOST=OFF -DENABLE_CMS=lcms2 -DENABLE_GLIB=ON -DENABLE_QT5=OFF -DENABLEQT6=ON -DENABLE ==> make ==> make install prefix=/usr/local/Cellar/poppler/HEAD-b700e0b 🍺 /usr/local/Cellar/poppler/HEAD-b700e0b: 476 files, 25.5MB, built in 3 minutes 22 seconds ==> Running brew cleanup poppler... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see man brew). Removing: /Users/marcelbecker/Library/Caches/Homebrew/poppler--22.05.0... (8.7MB)

allenryb commented 2 years ago

Sorry, I use Manjaro and have no Mac. The version poppler 22.05.0-2 appears here in Arch Repository which is also one repository of Manjaro.

JiaweiChenC commented 2 years ago

Does anyone with a mac solve this issue? I'm now using doc view mode instead, but I really want to know how can I fix this problem:)

mtreca commented 2 years ago

@JiaweiChenC Using the brew instructions given by @marcel-becker fixed my issue. I ran pdf-info-uninstall and pdf-info-install after updating just to make sure. Thanks for the tip @marcel-becker!

marcel-becker commented 2 years ago

@JiaweiChenC I emailed the maintainer of poppler for Arch Unix and he told me poppler version 22.05.0-2 is just the HEAD version patched with some changes related to Cairo fonts caching that were part of an open merge request. It seems the pending merge requests have been merged into poppler master 2 days ago. If you install poppler from from head: $ brew uninstall poppler $ brew install --HEAD poppler You should get the latest version. Then you need to re-compile the pdf-tools epdinfo. You can maybe re-install using pdf-info from emacs or just delete the epdinfo executable from the root of the folder where you have pdf-tools installed (e.g., ~/.emacs.d/elpa/pdf-tools-20220522.13). I did not find functions pdf-info-uninstall or pdf-info-install. Maybe mtreca meant pdf-tools-uninstall and pdf-tools-install. Hopefully this will work. I have been using a version of poppler I build from source and have not seen any of the weird rendering I was seeing before. I will try to re-install poppler from head now and see how it goes.

JiaweiChenC commented 2 years ago

Thank you for the information, the problem was solved after upgrading!

fedeinthemix commented 2 years ago

I would like to add that this happens with evince as well. Updating poppler should fix it as well.

j-minster commented 2 years ago

@marcel-becker Thank you so much. This fixed my issues on macOS. It looked as though pdfs were corrupt and the epdfinfo server was crashing intermittently.