quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.76k stars 306 forks source link

Formatting Issues when rendering figures with Julia Engine #10469

Open alecloudenback opened 1 month ago

alecloudenback commented 1 month ago

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
mcanouil commented 1 month ago

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:

alecloudenback commented 1 month ago

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

mcanouil commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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

@jkrumbiegel might be able to help here.

jkrumbiegel commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 3 weeks ago

seems to be fixed in Quarto 1.6.6, provided you add

format:
    pdf:
        fig-dpi: 72

in the YAML frontmatter.