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

PDF has bad display of code-line-numbers combined with code-block-border-left #10798

Open
lvxvvv opened this issue Sep 13, 2024 · 1 comment
Open
Labels
bug Something isn't working code-blocks latex LaTeX engines related libraries and technologies needs-design
Milestone

Comments

@lvxvvv
Copy link

lvxvvv commented Sep 13, 2024

Bug description

Description

When code-line-numbers is true and code-block-border-left is some color, the numbers overlay and overflow the border, resulting in something like this:

quarto-pdf-ln-bl

Steps to reproduce

File: mwe.qmd

---
title: "MWE"
format:
  pdf:
    code-line-numbers: true
    code-block-bg: false
    code-block-border-left: "#F0F0F0"
---


```{.python}
print("This is a MWE.")

while True:
    print("code-line-numbers and code-block-border-left mwe.")
```

Then run:

quarto render mwe.qmd --to pdf

Expected behavior

The numbers should not overlay the left border. Instead, they should be completely on its left, with some margin (something like what happens with the epub output). Or, alternatively, the numbers could overlay the border, but not overflow it. That is, the border width must large enough to accommodate the numbers within its limits.

Actual behavior

The numbers overlay and overflow the left border.

Your environment

  • OS: Debian 12.7

Quarto check output

Quarto 1.5.57
[✓] 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.57
Path: /opt/quarto/bin

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

[✓] Checking LaTeX....................OK
Using: Installation From Path
Path: /usr/bin
Version: 2022

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

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

(-) Checking Jupyter engine render....[IPKernelApp] ERROR | No such comm target registered: quarto_kernel_setup
[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
Version: 4.2.2
Path: /usr/lib/R
LibPaths:
- /home/lux/R/x86_64-pc-linux-gnu-library/4.2
- /usr/local/lib/R/site-library
- /usr/lib/R/site-library
- /usr/lib/R/library
knitr: 1.48
rmarkdown: 2.28

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

@lvxvvv lvxvvv added the bug Something isn't working label Sep 13, 2024
@cscheid cscheid added code-blocks latex LaTeX engines related libraries and technologies labels Sep 13, 2024
@cscheid cscheid added this to the Future milestone Sep 13, 2024
@cderv
Copy link
Collaborator

cderv commented Sep 18, 2024

Some notes for us when dealing with this.

I wanted to understand how are this would be to tweak, so I had a quick look.

Here are some notes


For the context on this, we are using tcolorbox package to add this border.

Currently we do

if useCodeBlockBorder then
options['borderline west'] = '{3pt}{0pt}{shadecolor}'
end

With 0pt for the offset. This means the the border is at the same place as the code line numbered added by Pandoc feature.

Full Tex code is

\begin{Shaded}
\begin{Highlighting}[numbers=left,,]
\BuiltInTok{print}\NormalTok{(}\StringTok{"This is a MWE."}\NormalTok{)}

\ControlFlowTok{while} \VariableTok{True}\NormalTok{:}
    \BuiltInTok{print}\NormalTok{(}\StringTok{"code{-}line{-}numbers and code{-}block{-}border{-}left mwe."}\NormalTok{)}
\end{Highlighting}
\end{Shaded}

With

\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{241,243,245}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}

(...)

\ifdefined\Shaded\renewenvironment{Shaded}{\begin{tcolorbox}[borderline west={3pt}{0pt}{shadecolor}, breakable, frame hidden, sharp corners, interior hidden, boxrule=0pt, enhanced]}{\end{tcolorbox}}\fi

If we use borderline west={3pt}{-9pt}{shadecolor} for example, this would avoid the problem (but also move left the boder in all case)

image

Not so visible when no background
image

But will be different when one
image

compare to now
image

At the end this is a styling decision.

Though code-line-numbers feature will conflict with any tcolorbox customization that we are doing.
No border here, but background changed
image

We could also customize how the numbers are shown but we don't control that line for now.
fancyvrb package is used and numbers=left config is written by Pandoc LaTeX writer directly
https://github.com/jgm/pandoc/blob/56854c22f49df806625c5971e82d2e1ccc6f7127/src/Text/Pandoc/Writers/LaTeX.hs#L466-L468

We don't control this, so tweaking the option for this would require some LaTeX postprocessing.

Example of customization

  • Numbers on the right (still impacted by tcolorbox
    image
  • Reducing the offset - still with number on the right
    image
  • Reducing the offset with current behavior (number on the left and border without offset)
    image

Not that robust, but we already do some line postprocessing to tweak some content. So maybe it is not that hard to catch \begin{Highlighting}[numbers=left,] and replace by \begin{Highlighting}[numbers=left,numbersep=6pt,] when tcolorbox is added and used by Quarto.

Again, styling decision. Then we can do the necessary tweak.

Hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working code-blocks latex LaTeX engines related libraries and technologies needs-design
Projects
None yet
Development

No branches or pull requests

3 participants