Skip to content

Formatting Issues when rendering figures with Julia Engine #10469

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

Open
alecloudenback opened this issue Aug 5, 2024 · 11 comments
Open

Formatting Issues when rendering figures with Julia Engine #10469

alecloudenback opened this issue Aug 5, 2024 · 11 comments
Labels
bug Something isn't working julia

Comments

@alecloudenback
Copy link
Contributor

alecloudenback commented Aug 5, 2024

Bug description

When using the engine: julia the figures do not render as anticipated (they are very large and take up the whole page). In this MWE and attached PDF, see how the second chapter renders the figure as a whole page.

Perhaps the --- is interfering with the heading markdown syntax? Or should the --- section be recognized if it's below the heading?

Example output with issue.pdf, and screenshot here:

image

Steps to reproduce

A clonable MWE repo is here: https://github.com/alecloudenback/engine-mwe

When engine:julia is below the title (as in index.qmd), it uses Jupyter pipeline. When engine: julia is above the title (as in index2.qmd), the figures get overly large.

Terminal output of rendering:

alec@alecs-laptop engine-mwe % quarto render
[1/2] index.qmd


Executing 'index.quarto_ipynb'
  Cell 1/1: ''...Done


Executing 'index.quarto_ipynb'
  Cell 1/1: ''...Done

[2/2] index2.qmd
Starting julia control server process. This might take a while...
Julia server process started.
Running [1/1] at line 22:  using Pkg
Running [1/1] at line 22:  using Pkg

pandoc 
  to: latex
  output-file: index.tex
  standalone: true
  toc: true
  number-sections: true
  top-level-division: chapter
  pdf-engine: xelatex
  variables:
    graphics: true
    tables: true
  default-image-extension: pdf
  
metadata
  crossref:
    chapters: true
  documentclass: scrreprt
  papersize: letter
  classoption:
    - DIV=11
    - numbers=noendperiod
  header-includes:
    - '\KOMAoption{captions}{tableheading}'
  block-headings: true
  bibliography:
    - references.bib
  title: engine-mwe
  author: Norah Jones
  date: 8/5/2024
  

Rendering PDF
running xelatex - 1
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode
  
running xelatex - 2
  This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex)
   restricted \write18 enabled.
  entering extended mode
[engine-mwe.pdf](https://github.com/user-attachments/files/16502630/engine-mwe.pdf)

  

Output created: _book/index.html

Expected behavior

The renderer should use the Julia engine, not Jupyter, and the figure should not be the wrong size.

Actual behavior

The figure gets enlarged when using the Julia engine.

Your environment

Mac 14.5, M3. VS Code

alec@alecs-laptop engine-mwe % julia -v
julia version 1.10.4

Quarto check output

alec@alecs-laptop engine-mwe % quarto tools
[✓] Inspecting tools

Tool         Status         Installed       Latest     
chromium     Up to date     869685          869685     
tinytex      Up to date     v2024.07.03     v2024.07.03
alec@alecs-laptop engine-mwe % quarto check
Quarto 1.5.55
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.5.55
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: v2024.07.03
      Chromium: 869685

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/alec/Library/TinyTeX/bin/universal-darwin
      Version: 2024

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.4
      Path: /opt/homebrew/opt/python@3.12/bin/python3.12
      Jupyter: 5.7.2
      Kernels: julia-1.10

      NOTE: No Jupyter kernel for Python found

[✓] Checking R installation...........OK
      Version: 4.4.0
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
      knitr: 1.47
      rmarkdown: 2.27

[✓] Checking Knitr engine render......OK
@alecloudenback alecloudenback added the bug Something isn't working label Aug 5, 2024
@mcanouil
Copy link
Collaborator

mcanouil commented Aug 5, 2024

First, if you want to change the engine, moving around the front matter is really not the way.
Set engine: jupyter.

Second, I believe the issue (which does not require a book) is related if not the exact same issue as:

@mcanouil mcanouil added the julia label Aug 5, 2024
@alecloudenback
Copy link
Contributor Author

What’s the recommended place to set the engine to Julia? At the top of each qmd above all other content?

@mcanouil
Copy link
Collaborator

mcanouil commented Aug 5, 2024

It's called YAML frontmatter.
I don't believe there is anywhere in the documentation where it's not the first thing in a document.

Putting the block elsewhere means it's no longer the front matter but a simple metadata block.

@alecloudenback
Copy link
Contributor Author

I'm not sure that this is the same issue as #7817, is it? When using the engine: julia, is the IJulia startup run at all?

Further, adding set_theme!() as recommended in that issue after loading CairoMakie and the plotting call does not resolve the issue.

I think the issue could be resolved by manually setting the figure's size, but I'm not sure how to get the default figure sizes? It seems like these are defined outside of the normal code in the IJulia startup (referring to fig_width = {0}, etc.). Any idea how to get the default figure size within the Julia engine?

@mcanouil
Copy link
Collaborator

mcanouil commented Aug 6, 2024

I don't really use Julia and the native Julia engine is a community contribution.

@jkrumbiegel might be able to help here.

@jkrumbiegel
Copy link
Contributor

I'm just guessing here but it could be that the julia engine reports the pixel size of the image differently than ijulia, so the placed size in the pdf differs even though the actual figure size might be the same. Because at first glance it doesn't look like the figure size is huge (the text labels look reasonably sized compared to the plotting area). And zooming in, the picture seems pixelated, so that also points to the final size for the pdf being set incorrectly. I would maybe check the intermediate md with keep-md: true to see if there is a weird size annotation there or something.

@mcanouil
Copy link
Collaborator

mcanouil commented Aug 6, 2024

Thanks!

Additionally, to keep-md: true to get the content sent to Pandoc, keep-tex: true could also be used to investigate the actual content sent to LaTeX engine.

@alecloudenback
Copy link
Contributor Author

It looks like in the intermediate markdown files, the difference is:

First chapter which renders okay:

::: {.cell-output .cell-output-display execution_count=11}
![](index_files/figure-pdf/cell-2-output-2.png){fig-pos='H'}
:::

Second chapter which renders too big:

::: {.cell-output .cell-output-display execution_count=1}
![](index2_files/figure-pdf/cell-2-output-2.png){width=1650 height=1050 fig-pos='H'}
:::

Is there anyway to turn off the size annotation? I tried adding in the code settings like #| column: page or #| width: "80%" which did not change anything in the output.

@jkrumbiegel
Copy link
Contributor

Yeah this is exactly what I figured. Could be that ijulia doesn't send out the original size of the png at all? I remember that we did this explicitly for some reason, but it's just metadata and we don't force quarto to use it in this way. I don't remember what the precedence case was though, in general we tried to mirror the ijulia behavior where it was appropriate.

@olejorik
Copy link

olejorik commented Aug 23, 2024

seems to be fixed in Quarto 1.6.6, provided you add

format:
    pdf:
        fig-dpi: 72

in the YAML frontmatter.

@jkrumbiegel
Copy link
Contributor

At least with Makie, this issue can be considered fixed with QuartoNotebookRunner v0.12.2 and Makie#master. QuartoNotebookRunner now annotates pngs with dpi info with the corrected size. While quarto could in principle also read out png dpi, it doesn't seem to consistently do that and we don't have a "retina" mode, so the associated workarounds in quarto don't apply to us.

With those versions, Makie's pngs have the same visual size irrespective of their px_per_unit setting. You can see that in the following two images, once with fig-dpi: 50 and once with fig-dpi: 300. One is blurry, one is sharp, but both have the same visual size as it should be. Other plotting packages will have the same effect if they add dpi metadata to their output. For Makie, I enabled this with a PR to PNGFiles.jl.

Image

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working julia
Projects
None yet
Development

No branches or pull requests

4 participants