org emacs org-mode

emacs - Imágenes PDF en línea en modo org.



org mode vim (3)

En emacs + org-mode , al ver un búfer de org-mode, puede alinear imágenes vinculadas con el comando org-toggle-inline-images . Esto incluye varios formatos listos para usar, pero aparentemente las imágenes en PDF aún no están incluidas.

Dado que emacs es perfectamente capaz de representar archivos PDF, ¿es posible crear archivos PDF en línea en modo org como lo hace con imágenes (png, jpeg, etc.)?

Algunos antecedentes: las imágenes en PDF son más convenientes para mí por varias razones, la más importante es que se ajustan bien y funcionan bien con látex, desde papeles pequeños hasta carteles grandes.


Déjame terminar esta pregunta.

En primer lugar, el modo Org no admite ninguna función de visualización en línea de pdf consigo mismo. Sin embargo, es posible modificar org-display-inline-images para lograr lo que desea. Primero debe referirse a esta respuesta: configurar emacs para mostrar imágenes en línea de ancho fijo , lo que me inspiró mucho. Luego modifiqué ligeramente la función, por lo que es compatible con pdf, pantalla bmp en modo org. Mi función está en la parte inferior.

(setq image-file-name-extensions (quote ("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm" "xpm" "pbm" "pgm" "ppm" "pnm" "svg" "pdf" "bmp"))) (setq org-image-actual-width 600) (setq org-imagemagick-display-command "convert -density 600 /"%s/" -thumbnail /"%sx%s>/" /"%s/"") (defun org-display-inline-images (&optional include-linked refresh beg end) "Display inline images. Normally only links without a description part are inlined, because this is how it will work for export. When INCLUDE-LINKED is set, also links with a description part will be inlined. This can be nice for a quick look at those images, but it does not reflect what exported files will look like. When REFRESH is set, refresh existing images between BEG and END. This will create new image displays only if necessary. BEG and END default to the buffer boundaries." (interactive "P") (unless refresh (org-remove-inline-images) (if (fboundp ''clear-image-cache) (clear-image-cache))) (save-excursion (save-restriction (widen) (setq beg (or beg (point-min)) end (or end (point-max))) (goto-char beg) (let ((re (concat "//[//[//(//(file://)//|//([./~]//)//)//([^]/n]+?" (substring (org-image-file-name-regexp) 0 -2) "//)//]" (if include-linked "" "//]"))) old file ov img) (while (re-search-forward re end t) (setq old (get-char-property-and-overlay (match-beginning 1) ''org-image-overlay) file (expand-file-name (concat (or (match-string 3) "") (match-string 4)))) (when (file-exists-p file) (let ((file-thumb (format "%s%s_thumb.png" (file-name-directory file) (file-name-base file)))) (if (file-exists-p file-thumb) (let ((thumb-time (nth 5 (file-attributes file-thumb ''string))) (file-time (nth 5 (file-attributes file ''string)))) (if (time-less-p thumb-time file-time) (shell-command (format org-imagemagick-display-command file org-image-actual-width org-image-actual-width file-thumb) nil nil))) (shell-command (format org-imagemagick-display-command file org-image-actual-width org-image-actual-width file-thumb) nil nil)) (if (and (car-safe old) refresh) (image-refresh (overlay-get (cdr old) ''display)) (setq img (save-match-data (create-image file-thumb))) (when img (setq ov (make-overlay (match-beginning 0) (match-end 0))) (overlay-put ov ''display img) (overlay-put ov ''face ''default) (overlay-put ov ''org-image-overlay t) (overlay-put ov ''modification-hooks (list ''org-display-inline-remove-overlay)) (push ov org-inline-image-overlays))))))))))

La función usa el convert file.pdf -thumbnail "400x400>" file_thumb.png para generar un archivo_thumb con la imagen en miniatura en su carpeta para sustituir la superposición de pdf, y forzar org-mode para mostrar pdf con file_thumb sin ninguna modificación al archivo org.

Además, porque utilizo babel para generar imágenes con python. Siempre necesito que actualice el archivo _thumb, así que agrego una condición if para decir si este archivo en miniatura existió o no, y si el archivo pdf cambió, necesito cambiar el archivo en miniatura al mismo tiempo ... ¡y así sucesivamente!

Espero que te ayude.


Me encontré con el mismo problema y, después de hurgarme un poco, lo hice funcionar agregando lo siguiente a mi archivo .emacs:

(add-to-list ''image-type-file-name-regexps ''("//.pdf//'" . imagemagick)) (add-to-list ''image-file-name-extensions "pdf") (setq imagemagick-types-inhibit (remove ''PDF imagemagick-types-inhibit)) (setq org-image-actual-width 600)

No estoy seguro aún, si hay algún problema para otros modos por estos cambios. Mis archivos PDF en modo org son creados por Python src code blocks y los trabajos anteriores, pero las imágenes no se actualizan cuando cambio algo en el modo python y necesito ejecutar org-display-inline-images manualmente.

Esto supone que tienes un emacs con soporte para imagemagick, algo similar también debería funcionar para usar ghostscript (quizás con algunas ediciones más en org.el).


Respuesta corta: no hay soporte para imágenes en línea PDF.

La función org-image-file-name-regexp tiene las extensiones de archivo de imagen codificadas (y no incluye PDF). Esta función es utilizada por org-display-inline-images , que a su vez llama a create-image .

He intentado agregar PDF a org-image-file-name-regexp, y eliminar PDF de imagemagik-types-inhibit sin suerte.

Puede intentar seguir investigando o solicitar la función a la lista de correo en modo org.