Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure captions (LaTeX export) #193

Open
dschrempf opened this issue Aug 1, 2018 · 5 comments
Open

Figure captions (LaTeX export) #193

dschrempf opened this issue Aug 1, 2018 · 5 comments

Comments

@dschrempf
Copy link

dschrempf commented Aug 1, 2018

I am producing LaTeX documents using Org + IPython and I would like to add figure captions (and possibly labels). I can do this, e.g., by adding #+CAPTION: Bla just above the figure in the results block. E.g., with :results raw drawer:

#+RESULTS:
:RESULTS:
# Out[48]:
#+CAPTION: Test.
[[file:myFile.png]]
:END:

However, when reexecuting the source block, the results block gets replaced and the caption vanishes. Do you know a way around that?

Thanks,
Dominik

Edit: I just wanted to add, that I now use something like

#+BEGIN_SRC ipython :session :ipyfile FileName.png :exports none :results none
#+END_SRC

#+NAME: fig:file-name
#+CAPTION: Nice caption.
[[file:FileName.png]]

It needs too much user intervention for my taste, but it could be automated quite well. I leave this open, maybe you have a better suggestion, but please feel free to close the issue!

@AoifeHughes
Copy link

@dschrempf did you ever get any where with this? I have the exact same problem with adding other latex parameters to my outputs

@dschrempf
Copy link
Author

No, I am still using the code in the edit (essentially, I circumvent using the RESULT block, but rather directly link to the image file). Thereby, the caption and name do not get overridden.

@AoifeHughes
Copy link

Fair enough - I've found it super useful, so thank you!

I also made a simple snippet if anyone else stumbles on this

https://github.com/SirSharpest/.emacs.d/blob/master/snippets/org-mode/pyimg

@dschrempf
Copy link
Author

Hi! Thanks a lot for the comment. I added your idea to the snippet I am using! Just for completeness:

# -*- mode: snippet; require-final-newline: nil -*-
# name: ipython-figure
# key: ipy-fig
# --
#+NAME: ${1:`(make-temp-name "")`}
#+BEGIN_SRC ipython${2: :session ${3:`(file-name-base (buffer-file-name))`}} :ipyfile `(file-name-base (buffer-file-name))`-$1.svg :exports ${4:$$(yas-choose-value '("code" "none"))} :results none
$0
#+END_SRC

#+CAPTION: $6
#+LABEL: fig:$1
[[file:`(file-name-base (buffer-file-name))`-$1.svg]]

@moritzschaefer
Copy link

The only way I manage to get a Figure caption(instead of the Figure alone) is to use ":results file" in the header.
However, this has the undesired side effect that I get an additional output in my Latex file

[[#file:# Out[]: ]]

has anyone observed this issue? Here is my code:

* section
some text

#+NAME: fig:test_a
#+BEGIN_SRC ipython :session :results file :exports results 
  _=sns.barplot(x=[1,2,3,4,5])
#+END_SRC

#+CAPTION: This is a figure
#+LABEL: fig:test_a
#+ATTR_LaTeX: scale=0.75
#+RESULTS: fig:test_a
:results:
# Out[1094]:
[[file:./obipy-resources/b1mu0b.png]]
:end:

Here is a Figure [[fig:test_a]] and 

and the resulting PDF:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants