dfeich / org-babel-examples

Examples using emacs org mode babel inline source code with different backend languages
570 stars 116 forks source link

SVG does not render in pdf org-export #6

Closed lljr closed 5 years ago

lljr commented 5 years ago

OS: macOS Org-version: 9.1.9 plantuml: working

I followed your example in the latex folder


   #+BEGIN_SRC plantuml :file svg-sequence1.svg :exports both
     ' this is a comment
     Alice -> Bob: Authentication Request
     Bob --> Alice: Authentication Response
     John --> Alice: another Authentication Request
     Alice --> John: another Authentication Response
   #+END_SRC

   #+RESULTS:
   [[file:svg-sequence1.svg]]

I also included the package \usepackage{svg} and org export does not render the svg in my pdf. I followed the instructions by exporting the svg file in the same directory as my org file and I also included the svg package. PNG images get rendered but not SVG. After I inspected the .tex file, I see that there is no inclusion of \includegraphics{svg-sequence1.svg}, but I do see that line for my png files. Do you know why the SVG does not get added to its tex doc but png images do get added?

dfeich commented 5 years ago

Hi, could it be that you have not installed the dependecy "inkscape" that is needed by the LaTeX svg package?

I tested the whole file with a current version of plantuml. I noted that my Emacs/Org was not able to render the file in the buffer, but the PDF was produced nicely. I adapted the Org file a bit to account for changes that have been done in plantuml.

lljr commented 5 years ago

@dfeich hi. thanks for responding. Yes, I can confirm the svg images do not render in Emacs buffer with C-c C-o but my concern is with images not rendered when I org-export to tex->PDF. I'm very new to Org-Mode and LaTeX (actually reason I am using Org-Mode is that I do not really know LaTeX). So, could you please guide me to checking if "inkscape" dependency is installed? Since I'm on macOS, I thought that MacTeX included all the LaTeX major packages .

dfeich commented 5 years ago

@avocadoras Hi. Inkscape is an external program (https://inkscape.org/) that the latex svg plugin invokes to produce the files that it can integrate into the produced PDF. You just need to install that dependecy. I just checked, and there seems to be a Mac version.

lljr commented 5 years ago

Thanks. I actually installed inkscape and still have the same problem. I ran brew install caskformula/caskformula/inkscape --HEAD --branch-0.92 and then C-c C-e l p in my org file. Do I need to do some configuration?

EDIT: ok so I inspected my .tex file and I noticed .svg does not get appended to the file name: \includesvg[width=.9\linewidth]{svg-sequence1}

EDIT 2: OK in *Org PDF LaTeX Output* buffer I get this error:

Package svg Warning: You didn't enable `shell escape' (or `write18')
(svg)                so it wasn't possible to launch the Inkscape export
(svg)                for `svg-sequence1.svg' on input line 107.

! Package svg Error: File `svg-sequence1_svg-tex.pdf' is missing.

See the svg package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.107 ...udesvg[width=.9\linewidth]{svg-sequence1}

! Package svg Error: File `svg-sequence1_svg-tex.pdf_tex' is missing.

See the svg package documentation for explanation.
Type  H <return>  for immediate help.

but now how do I enable --shell-escape with org-export 🙃?

dfeich commented 5 years ago

@avocadoras Hi. You already identified the issue and you investigated the right file that contain the information (the PDF Latex Output file). So, you need to configure emacs so that it calls pdflatex with the --shell-escape argument. This you can do in your emacs configuration file (either ~/.emacs or ~/.emacs.d/init.el) by setting the org-latex-pdf-process variable.

This for example is my own setting for this variable:

     (setq org-latex-pdf-process
       (let
           ((cmd (concat "pdflatex -shell-escape -interaction nonstopmode"
                 " --synctex=1"
                 " -output-directory %o %f")))
         (list cmd
           "cd %o; if test -r %b.idx; then makeindex %b.idx; fi"
           "cd %o; bibtex %b"
           cmd
           cmd)))

I do not know whether you understand emacs-lisp, but basically I define a temporary variable cmd which contains the pdflatex command with all the options. This I then use to construct the full list of commands to run: 1) pdflatex 2) test whether makeindex should be run and run it 3) run bibtex 4) run pdflatex for resolving any references. 5) run pdflatex for resolving any references.

Latex often needs to run multiple times on the files because previous runs produce output files (resolve references) which than can be used in subsequent runs.

lljr commented 5 years ago

Thank you so much for your genorsity. I very much appreciate it. I think I know enough. However, how did you get to knowing all this? I feel like it would be very helpful to have this in the manual or do you have a blog post by someone that talks about how to set up SVG images in pdf files via org-export? @dfeich

lljr commented 5 years ago

@dfeich will close because your code snippet solved my issue.

dfeich commented 5 years ago

@avocadoras I do not remember exactly how I found the SVG information, but I think I googled for SVG and LaTeX and ended up with the latex pluging. And in its documentation you will find the requirements. The configuration of org mode for LaTeX is described in various places. But yes, emacs needs a bit of effort for some customizations, but there is a stron community. And you have StackExchange for Emacs and the Emacs Reddit Channel.

zaz commented 12 months ago

I had the same issue, but also needed to add a LaTeX header \usepackage{svg}:

#+LATEX_HEADER: \usepackage{svg}

I think this should be reopened as this should work by default. Or at least there should be a clear message explaining why it failed and what needs to be done.