Image export

Hi,

I am trying to export my notebook as a pdf (via tex) which fails (already opened a ticket for that). When I download the tex file, the image references (with html tags in a markdown cell) are not included. How can I include the images in the tex file ?

Many thanks !

Markus

Hi,

You have few problems in your notebook:

  1. Somehow Latex cannot understand cell with, causing it to crash, please remove all such crossbones
    ------

  2. If you want to have your images, you need to output them, the best way is to do

from IPython.display import display, Markdown

display(Markdown("""
### Applicable area dose limits
#### based on: Ordonnance sur les accélérateurs (OrAc), Ordonnance sur l’utilisation des matières radioactives (OUMR) and Ordonnance sur la radioprotection (ORaP)

|                                                 |*Non-designated area*                            |*Radiation area*                                 |
|-------------------------------------------------|-------------------------------------------------|-------------------------------------------------|
|Inside premises                                  |permanent/fixed workplace/non-permanent          |adjacent/fixed workplace/accessible/non-permanent|
|Outside premises                                 |permanent/non-permanent/ -                       |-/-/-                                            |
|**Hour (OUMR)**                                  |0.1 µSv / 0.5 µSv / 2.5 µSv                      |2.5 µSv / 5 µSv / 10 µSv / 25 µSv                |
|                                                 |                                                 |                                                 |
|Inside premises                                  |permanent, fixed workplace/non-permanent         |fixed workplace, accessible, non-permanent       |
|**Week (ORaP/OrAc)**                             |20 µSv / 100 µSv                                 |100 µSv                                          |
|**Year (ORaP)**                                  |1 mSv                                            |n.a.                                  |

"""))
  1. If you want to hide the code lines in the output, best would be to convert your notebook and download from CERNBOX
jupyter nbconvert FLASH_parameters_for_RP.ipynb --to=pdf --TemplateExporter.exclude_input=True

Hi Piotr,

thanks for the suggestions.

  1. I confirm, without the ----- separation lines the pdf via latex is well produced - however still withouth images.
  2. The display/output of images works fine with markdown cells in the Jupyter notebook. The proposed solution will display the images in an awkward sub-window in the Jupyter notebook, while still not including them in the pdf export. (independent if I use the SWAN export or the command line jupyter nbconvert). Downloading a html export to the same folder however does correctly reference and display the images in the html page.

Hi Markus,

I see, images are still not displayed - maybe because it is markdown. Can you try IPython.display.Latex or something different instead of IPython.display. Markdown [1][2] ?

from IPython.display import Latex
Latex(r"""\begin{eqnarray}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\
\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = 0 
\end{eqnarray}""")

[1] https://stackoverflow.com/questions/13208286/how-to-write-latex-in-ipython-notebook
[2] https://stackoverflow.com/questions/19470099/view-pdf-image-in-an-ipython-notebook

But in case you show images with latex, maybe better that you use jupyter nbconvert FLASH_parameters_for_RP.ipynb --to=pdf --TemplateExporter.exclude_input=True to hide code

Interesting enough … when I include the image twice, once as html reference and once as latex reference, the latex reference does not find the image in the Jupyter nb but is kept in the tex export and correctly interpreted.

<img src="flash_toy_beam_NC_X_real_5perc.png" width="800"/>

\begin{figure}[htbp]
\includegraphics[width=0.8\textwidth,trim={0cm 0cm 0cm 0cm},clip]{flash_toy_beam_NC_X_real_5perc.png}
\end{figure}

So this somehow solves (not very elegantly) my issue.

1 Like

Just one more thing.

In the notebook code, you can do
! jupyter nbconvert...

You do not need to use SWAN terminal, you can do it from the notebook. You can execute any bash command like it, even with redirection of output to not show in the PDF.

I found why the latex includegraphics command did not work. It does not like the trim={} parameter.

Including a figure in Markdown cell just like this:

\begin{figure}[H]
\includegraphics[width=0.8\textwidth]{flash_toy_beam_NC_X_real_5perc.png}
\end{figure}

does work both in Jupyter nb and converted to Latex.

The width parameter is not taken into account in the Jupyter nb display, but well in the Latex/pdf file.

Thanks !

However, when I run the nbconvert locally on my machine on the jupyter notebook, the pdf file is correctly produced including images.

If I run from SWAN (from the notebook ) it is not (only 2 out of 8 pages, not images).

Markus, make sure to save the file in SWAN. I actually do not see the reason why on your laptop it should work, and in SWAN not. I can check in your shared project

Yes. I have created two pdf: one on SWAN and one locally on my PC on the same notebook using the same command.

SWAN gives me a critical error: “CRITICAL | xelatex failed:” and terminates with an Emergency Stop.

I would really recommend inserting proper code cell and doing

from IPython.display import Latex
Latex(r"""
code
""")

OK, thanks, that works now, but I need to include in addition the html tag to plot the figures in the Jupyter nb.

Another issue: While locally produced pdf display correctly greek letter µ, the SWAN output gives some gibberish.

How do you have this in the code for greek letter? Maybe it needs to be written different

I am typing Option+m (mac), which gives me µ and which is well displayed in the markdown cell and pdf output (if compiled locally and not on SWAN).

I would recommend latex syntax https://latex.wikia.org/wiki/List_of_LaTeX_symbols . Remember SWAN is not MacOS :slight_smile: Your container in swan runs CENTOS Linux :slight_smile:

:slight_smile:

so it’s working with \mu

Thanks & Cheers.