l3kn / org-fc

Spaced Repetition System for Emacs org-mode
https://www.leonrische.me/fc/index.html
GNU General Public License v3.0
258 stars 31 forks source link

Arithmetic overflow error with inline latex #121

Closed zorgick closed 7 months ago

zorgick commented 8 months ago

It seems that org-fc cannot process inline LaTeX with $ notation. The version of emacs is 29.1. Run on wsl2.

init.el:

;;; init.el --- Emacs configuration file  -*- lexical-binding: t -*-

;;; Commentary:

;; Personal Emacs configuration file

;;; Setup

;; Emacs builtin package manager
(require 'package)

;;; Code:

;; Set package.el repositories
(setopt package-archives
'(
   ("gnu" . "https://elpa.gnu.org/packages/")
   ("melpa" . "https://melpa.org/packages/")
))

;; Prefer GNU over MELPA (optional)
(setopt package-archive-priorities '(("gnu" . 20)("melpa" . 10)))

;; Initialize built-in package management
;; (package-initialize) ;; Is unnecessary since I have not disabled
;; package-enable-at-startup in early-init.

;; A list of extra packages
(setopt package-selected-packages '(
                    org-fc
                    ))

;; Packages configuration

(use-package tool-bar
  :custom
  (tool-bar-mode nil))
(use-package custom
  :config
  (load-theme 'leuven t))

(use-package org-fc
  :load-path "~/.emacs.d/local/org-fc"
  :custom
  (org-fc-directories '("~/Documents/notes/")))

(provide 'init)

Org file with a card example:

*** Test                                                                 :fc:
:PROPERTIES:
:FC_CREATED: 2023-12-28T13:24:11Z
:FC_TYPE:  normal
:ID:       2dbbe7ab-3367-47fe-91f1-d4418666fdf7
:END:
:REVIEW_DATA:
| position | ease | box | interval | due                  |
|----------+------+-----+----------+----------------------|
| front    |  2.5 |   0 |        0 | 2023-12-28T13:24:11Z |
:END:
test $a$
zorgick commented 8 months ago

Even after disabling latex preview with a file header, it gives the following error:

ID 2dbbe7ab-3367-47fe-91f1-d4418666fdf7 not found in ~/Documents/notes/src/test.org

for the file

#+startup: nolatexpreview
*** Test                                                                 :fc:
:PROPERTIES:
:FC_CREATED: 2023-12-28T13:24:11Z
:FC_TYPE:  normal
:ID:       2dbbe7ab-3367-47fe-91f1-d4418666fdf7
:END:
:REVIEW_DATA:
| position | ease | box | interval | due                  |
|----------+------+-----+----------+----------------------|
| front    |  2.5 |   0 |        0 | 2023-12-28T13:24:11Z |
:END:
test $a$
zorgick commented 8 months ago

Debugger shows, that it finds the position of the id in file, however later it still falls with the "ID" error:

(1) Debugger entered--entering a function:
* org-element-lineage((headline (:raw-value "Test" :begin 27 :end 433 :pre-blank 0 :contents-begin 105 :contents-end 433 :robust-begin 223 :robust-end 431 :level 3 :priority nil :tags (#("fc" 0 2 (fontified nil face org-level-3))) :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 27 :FC_CREATED "2023-12-28T13:37:40Z" :FC_TYPE "normal" :ID "0126ca19-f78b-480a-96ba-1ca42ba12993" :title (#("Test" 0 4 (:parent (headline #3)))) :parent (org-data (:begin 1 :contents-begin 1 :contents-end 433 :end 433 :robust-begin 3 :robust-end 431 :post-blank 0 :post-affiliated 1 :path "~/Documents/notes/src/test.org" :mode org-data :CATEGORY "test" :cached t)) :cached t :org-element--cache-sync-key (13 . 27))) (headline) t)
* org-before-first-heading-p()
* org-get-property-block()
* org-at-property-p()
* org-find-property("ID" "0126ca19-f78b-480a-96ba-1ca42ba12993")

...

(2)Debugger entered--returning value: 27
  org-find-entry-with-id("0126ca19-f78b-480a-96ba-1ca42ba12993")

....

(3) Debugger entered--returning value: ("~/Documents/notes/src/test.org" . 27)
  org-id-find-id-in-file("0126ca19-f78b-480a-96ba-1ca42ba12993" "~/Documents/notes/src/test.org")
l3kn commented 8 months ago

Is the same card working if you remove the latex code?

zorgick commented 8 months ago

Yes, without the latex code everything works.

zorgick commented 8 months ago

Even after disabling latex preview with a file header, it gives the following error:

ID 2dbbe7ab-3367-47fe-91f1-d4418666fdf7 not found in ~/Documents/notes/src/test.org

for the file

#+startup: nolatexpreview
*** Test                                                                 :fc:
:PROPERTIES:
:FC_CREATED: 2023-12-28T13:24:11Z
:FC_TYPE:  normal
:ID:       2dbbe7ab-3367-47fe-91f1-d4418666fdf7
:END:
:REVIEW_DATA:
| position | ease | box | interval | due                  |
|----------+------+-----+----------+----------------------|
| front    |  2.5 |   0 |        0 | 2023-12-28T13:24:11Z |
:END:
test $a$

It should be noted, that this startup header is ignored, when the buffer is narrowed to the subtree

l3kn commented 8 months ago

I've tried the heading you posted in my emacs/org-fc setup and I can review the card and the latex is rendered correctly. For reference, I'm using org 9.6.8 and Emacs 30.0.50.

The difference in the Emacs versions seems unlikely to cause any problems, what's your org version? (M-x org-version)

In the example you posted, the first headline of the file is at level 3 *** Test, does changing it to * Test fix the problem?

zorgick commented 8 months ago

My org version is 9.6.9.

I will try this card on my linux machine and share results in 10 minutes

zorgick commented 8 months ago

Yep, everything is working. I installed fresh texlive-latex-extra (Ubuntu 22.02), and it shows the card as expected. image

I believe, the problem is in system dependencies (on wsl I have Ubuntu 20 with texlive-latex-extra installed).

I will close this issue, but only after I manage to solve it on WSL. So bear with me a little bit.

l3kn commented 8 months ago

No worries, it will be useful to have a description of this error and possible solutions in case someone else runs into it.

zorgick commented 7 months ago

Hi! A quick update on the problem. I managed to solve it. The problem was in the emacs build, specifically in --with-pgtk option, that I used to build emacs from source. If I use X window system --with-x-toolkit=gtk3 (default), then latex previews are created and displayed correctly.

l3kn commented 7 months ago

That's good to hear!

Is this issue resolved then?

zorgick commented 7 months ago

Yes, but I still sometimes encounter such problem as:

ID 2dbbe7ab-3367-47fe-91f1-d4418666fdf7 not found in ~/Documents/notes/src/test.org

But as for the topic of the issue, everything works.

l3kn commented 7 months ago

Feel free to open up a new issue if the aforementioned error keeps occurring. If you're using the org-fc-cache, that might be the cause of this problem. It also might happen when trying to review a file that was edited in Emacs but not saved.