Hi Al and all,

>>>>> Al Haji-Ali <abdo.haji....@gmail.com> writes:
> I just made public an auctex preview package that I have been working on for 
> some time. It essentially shows the preview locally and temporarily in a 
> frame or as an 'after-string, similar to what Overleaf has been doing 
> recently.

> https://github.com/haji-ali/preview-point

> Any feedback/bug reports are appreciated.

Thank you for your contribution. I briefly tested the code and it works
for simple documents.
However, for circ.tex included in AUCTeX, it fails with the following
error and no images are produced upon C-c C-p C-d
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Output written on circ.pdf (103 pages, 201000 bytes).
Transcript written on circ.log.

TeX Output exited as expected with code 1 at Thu Aug 28 22:52:45
LaTeX: preview-image-type setting ’nil unsupported by this Emacs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
with the following config in init.el:
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
(add-to-list 'load-path "~/repo/auctex/preview-point")
(require 'preview-point)
;; Minimum configuration to enable point-preview
(setq preview-image-type 'point-dvisvgm)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

After I added the following config into init.el,
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
;; Configuration of preview for optimal behavior -- Optional
(setq
   preview-leave-open-previews-visible t
   ;; preview-auto-cache-preamble t
   preview-locating-previews-message nil)

;; Always use DVI to generate cleaner previews. Requires special handling of 
`hyperref`
(setq preview-LaTeX-command-replacements '(preview-LaTeX-disable-pdfoutput))

;; Customize behavior of point-preview
(setq preview-point-show-in 'buframe ;; or 'after-string for an inline preview 
intead.
      preview-point-progress-indicators 'faces)

;; Enable automatic preview update on change.
(add-hook 'LaTeX-mode-hook
          (lambda () (add-hook 'after-change-functions
                               #'preview-point-buf-change nil t)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
, then the error became:
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Output written on circ.dvi (103 pages, 42684 bytes).
Transcript written on circ.log.

TeX Output exited as expected with code 1 at Thu Aug 28 23:07:03
Running `Preview-DviSVGM' with ``dvisvgm --no-fonts circ.dvi --page=- 
--output="circ.prv/tmpbG7QrL/prev%3p.svg" --scale=0.98 ''
pre-processing DVI file (format version 2)
processing page 1
  computing extents based on data set by preview package (version 14.0.6)
  width=123.49603pt, height=9.738831pt, depth=2.743329pt
  graphic size: 123.49603pt x 12.48216pt (123.03465bp x 12.435527bp)
  output written to circ.prv/tmpbG7QrL/prev001.svg
[...]
processing page 35
  PostScript error: undefined in junk
  Operand stack:
      -32891  -32891  32891  32891  455111  127431  2102611

Preview-DviSVGM exited abnormally with code 254 at Thu Aug 28 23:07:03
DVI sentinel: Removing directory: Directory not empty, 
/home/keita/repo/auctex/auctex/circ.prv/tmpbG7QrL
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Maybe the reason why Paul can't run preview-point as expected is common
to this issue.

> One of the "helper" packages that I wrote is `preview-dvi` which fixes what I 
> think are several issues with preview related to robustness and ensuring 
> files/folders are not orphaned in the preview directory.

I suppose some treatment isn't working for circ.tex case. Can you look
into it?

> In addition to plugging my package here, I wanted to check if these are 
> indeed real issues, and if there is interest in implementing those fixes in 
> preview.el. I'll try to summarize the issues here. The fixes are all marked 
> by "NOTE" in my preview-dvi.el

> - In `preview-dvipng-process-setup`, `TeX-sentinel-function` is set 
> temporarily to a function which just shows a message. This is corrected 
> immediately in `preview-start-dvipng` where `preview-dvipng-sentinel` is 
> used. This is an issue becasue `sit-for` is called in `preview-start-dvipng` 
> which may process output of running processes (through timers for example) 
> which means that a process that is done by that time could have the temporary 
> sentinel being called.

> - In `preview-dvipng-place-all`, the `filenames` property in overwritten in 
> two places. This lead in some cases (which I haven't been able to pin down 
> exactly yet) to orphaned files. I think checking this property and deleting 
> corresponding files before they are overwritten is better.

> - When the preview command is aborted, there is a chance that this happens 
> before the previews are generated but after a temp directory is create, in 
> this case an empty folder is left behind. I think `preview-dvi-abort` should 
> delete the folder if it is empty. This also happens in preview-gs-place.

> - `preview-place-preview` calls `preview-clearout` which deletes old overlays 
> and their associated files. But I think this creates an issue when 
> `preview-leave-open-previews-visible` is non-nil, where the same file is used 
> in the new overlay causing image display errors in some cases.

> Let me know if you agree that these issues need fixing. I note that I 
> tested/"fixed" dvipng part, but other processes have similar code.

I don't have detailed knowledge about the internal of preview-latex, so
I basically trust your analysis. After circ.tex issue is addressed, I
think we can incorporate your work into AUCTeX.

Here are very minor comments:
1. In .dir-locals.el in AUCTeX repository, we have
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
((nil . ((tab-width . 8)
         (sentence-end-double-space . t)
[...]
 (emacs-lisp-mode . ((mode . bug-reference-prog)
[...]
                     (indent-tabs-mode . nil)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
. So please put two spaces, not one, after period ending sentences in
the doc strings and comments in the elisp files. Also, please turn tabs
into spaces in the elisp files. For later purpose, `untabify' command
would be handy.

2. preview-dvi.el
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
(defun preview-dvi-place (ov &rest args)
[...]
    (dolist (ov ovl)
    ;; [...]
      (when preview-leave-open-previews-visible
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
All operations are done only when `preview-leave-open-previews-visible'
is non-nil, so I think we can interchange the order of `dolist' and
`when'.

3. preview-point.el
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
(defun preview-point-popup-frame (ov str)
[...]
    (funcall 'buframe-make
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I suppose (buframe-make ARGS) is enough here. Am I missing something?

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
(defun preview-point-inside-overlay-p (ov &optional pt)
  "Return PT if inside overlay OV, nil otherwise.
If PT is nil, use point of OV's buffer."
  (let ((pt (or pt
                (and
                 (overlay-buffer ov)
                 (with-current-buffer (overlay-buffer ov)
                   (point))))))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Since `pt' is already a lexical variable as an argument of the function,
you don't have to shadow it with `let'. If I understand correctly, we
can just overwrite it by `setq' like
  (or pt
      (setq pt (and
                 (overlay-buffer ov)
[...]
without `let'.

4. You can compare buffers by `eq' in cases like
     (equal (overlay-buffer ov) (window-buffer))
. Similar comment goes for overlays as well like
     (equal preview-point--frame-overlay ov))
.

5. When you quote a constant function name like
(apply 'preview-gs-place ov args)
, #' would be better for quotation.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW

Reply via email to