johanwk / elot

Emacs Literate Ontology Tool
GNU General Public License v3.0
6 stars 3 forks source link

image format: SVG vs PNG vs PDF; display images inline in Org #24

Open VladimirAlexiev opened 5 months ago

VladimirAlexiev commented 5 months ago

Currently rdfpuml is used to make images in PDF format for easier use by pdflatex. Then SVG is extracted using dvisvgm for use in HTML.

I think it's better to "first" produce SVG, i.e. to have a command to evaluate a single Org block (SPARQL query or Turtle piece), process it with rdfpuml and render it in the Org document (org-toggle-inline-images, org-redisplay-inline-images). Note: I have tried this with PNG, not SVG. Here are the keybindings I use:

(add-hook 'org-mode-hook
  (defun va/org-mode-hook ()
    (visual-line-mode 1)
    (setq fill-column 90)             ; was 80
    (local-unset-key (kbd "C-'")) ; was org-cycle-agenda-files; I prefer expand-abbrev
    (local-set-key [home] 'org-beginning-of-line)
    (local-set-key [end] 'org-end-of-line)
    (local-set-key (kbd "C-c i") 'va/link-img-insert)
    (local-set-key (kbd "C-c I") 'va/link-img-missing)
    (local-set-key (kbd "C-c C-i") 'org-table-toggle-column-width)
    (local-set-key (kbd "C-c M-i") 'org-toggle-inline-images)
    (local-set-key (kbd "C-c C-M-i") 'org-redisplay-inline-images)
    (local-set-key (kbd "C-S-f") 'org-footnote-action)
    (local-set-key (kbd "C-c d") 'org-babel-demarcate-block)
    (local-set-key (kbd "C-c <") 'org-insert-structure-template)
    (local-unset-key (kbd "C-c #"))
    (local-set-key (kbd "C-c # s") 'org-update-statistics-cookies)
    (local-set-key (kbd "C-c # a") 'va/org-add-headline-anchors)
    (local-set-key (kbd "C-c # t") 'va/org-toc-insert)
))

Google search svg to pdf -online finds several relevant matches:

johanwk commented 5 months ago

I agree, svg should be the default format.

(update: #23 is closed, ROBOT for sparql works. I'm currently looking at #23 how to invoke ROBOT, including for running sparql queries on ontology files. The challenge is to make something that feels natural to use. sparql-mode is made for querying endpoints -- it doesn't support calling ROBOT, ARQ, or other programs to query files. Maybe we could do something to add that functionality. If that can be made to work, then ELOT users will only need to install ROBOT and rdfpuml for a very powerful set of ontology tools. (What does work is to use a #+call in the org buffer that invokes sparql with robot, but I think it's not very elegant.))

johanwk commented 4 months ago

As a note for later: with recent Emacs versions SVGs are rendered inline, while PDFs are not. Here is how to ensure SVG files work in LaTeX exports. With the svg package for LaTeX, it's possible to get SVG files converted automatically.

  1. Add to the org file,

    #+latex_header: \usepackage[inkscapelatex=false]{svg}

    With this, svg files are included in org's LaTeX output with \includesvg instead of the normal \includegraphics command.

  2. Use M-x to customize-variable the variable org-latex-pdf-process: add -shell-escape into the listed command(s). (This customization may be difficult to automate properly as an ELOT default, since users are likely to have different, specialised commands for running LaTeX.) Example: image

  3. Install Inkscape, which is the default SVG to PDF converter for LaTeX.

  4. Add Inkscape to the PATH: on Windows, typically C:\Program Files\Inkscape\bin

After 1--4, the PDF produced by exporting from org to PDF will include the SVG images.

Note. The text in SVGs converted with Inkscape uses the Verdana font, which doesn't look as good as the Helvetica default from plantuml. Find out how to fix this; maybe try out options mentioned in Inkscape forum --pdf-font-strategy=keep and --pdf-font-strategy=substitute.

VladimirAlexiev commented 4 months ago
johanwk commented 4 months ago

Actually, I'm puzzled by this (have seen it before).

SVG images display in org-mode buffers with no problem, and this has already been in place at least for a couple of sub-versions. With 29.2 it was OK, with 29.3 it's OK. Resizing of SVG embedded images isn't possible without some extra effort, but I think that's not really crucial.

A minor change in ELOT should now ensure that images are displayed after they are generated.