quarto-dev / quarto-cli

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

Formatting issue with R chunks with lst-label and lst-cap #8669

Open KevinShook opened 9 months ago

KevinShook commented 9 months ago

Bug description

When using lst-label and lst-cap, the formatting of R chunks is messed up.

When rendering to a pdf, the code is ugly (no syntax coloring, or background shading) but acceptable. When rendering to a .docx, the code is worse. It is centered, rather than being left-justified, there is no syntax coloring, although the background is shaded. In the docx file, the code is shown as using the "Source Code" style, but the style settings are over-ridden The messed up docx occurs whether or not a template docx file is used.

Steps to reproduce

---
title: "Reproducible Quarto Document"
format: docx
engine: knitr
---

This is a minimal self-contained reproducible Quarto document using `format: docx` and `knitr` engine.
It is written in Markdown and contains embedded R code.

This chunk uses the label and caption settings
```{r}
#| warning: false
#| output: false
#| eval: false
#| lst-label: lst-setpaths
#| lst-cap: Set file paths. The paths will need to be edited for your system.  
output_path <- "output/"
figure_path <- "figures/"

This one does not

output_path <- "output/"
figure_path <- "figures/"


### Expected behavior

The first chunk should be rendered in the same way as the second,i.e.  with syntax colouring, and left-justified text.

### Actual behavior

The second chunk renders correctly. The first chunk is not formatted properly. When rendered to a pdf there is no code syntax colouring. When rendered to a .docx, the code is centred and there is no syntax coloring.

### Your environment

IDE: Rstudio 2023.12.1 Build 402
OS: Linux Mint Linux Mint 21.3 

### Quarto check output

Quarto 1.4.549
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.4.549
      Path: /opt/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (external install)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /home/kevin/.TinyTeX/bin/x86_64-linux
      Version: 2023

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

[✓] Checking Python 3 installation....OK
      Version: 3.10.12
      Path: /usr/bin/python3
      Jupyter: 5.7.1
      Kernels: python3

[✓] Checking Jupyter engine render....OK

R scripting front-end version 4.1.2 (2021-11-01)
[✓] Checking R installation...........(None)

No idea why I get that message about not finding R.
R is running just fine in Rstudio.
Have not had any other issues running Quarto thru Rstudio
cscheid commented 9 months ago

The lack of syntax coloring in pdf is by design; we are using the most common formatting for code output in the case of code listings. If you want listings to be formatted in a particular way, you can use the div syntax for listings, separate from the code cell:

::: {#lst-setpaths}

```{.r}
output_path <- "output/"
figure_path <- "figures/"

Set file paths. The paths will need to be edited for your system.

:::



That will get the formatting.

The docx centering issue is a bug. I'll check when I have a computer with Office available.
edwintorok commented 9 months ago

Looks like the example from the manual doesn't work either though, or rather the 2nd one works (fenced div), but not the 1st one. It is a bit difficult to see with the sql code (for some reason the highlighting is quite subtle), but if you add some python code it all becomes obvious:

cat test.qmd
```{#lst-customers .python lst-cap="Customers Query"}
1 + 1

Then we query the customers database (@lst-customers).

::: {#lst-customers}

1 + 1

Customers Query

:::

1+1
SELECT * FROM Customers

Then we query the customers database (@lst-customers).

::: {#lst-customers}

SELECT * FROM Customers

Customers Query

:::

touch _quarto.yml quarto render quarto render --to docx quarto render --to pdf


[test.docx](https://github.com/quarto-dev/quarto-cli/files/14316844/test.docx)
[test.pdf](https://github.com/quarto-dev/quarto-cli/files/14316845/test.pdf)

docx and PDF have the problem (no highlighting for Listing 1 and 3; have highlighting for listing 2 and 4 ), HTML is fine.

Quarto 1.4.550.

I've noticed the centering too, that didn't happen with Quarto 1.3, 1.4 inserts a table now with 'w:jc .. center'