Code block width in output PDF.

I am trying to make the process of creating (more) accessible PDFs from rmarkdown smoother. (I am aware PDFs are not considered very accessible.)

I have figured out a few things, including how to make a local.theme file that you can customize to adjust the contrast of syntax highlighting and how to properly reference it for use in the YAML header, and also how to edit the intermediate .tex file to allow for the use of tagpdf.

What I want to figure out now is how to make it so that code chunks display the way I see them in an example document:

  • the "gray" of the code block in the final PDF is narrower than a line of regular text

  • the output of the code is printed inside the code block (inside the gray) right after each line of code.

  • if this could be done for figures as well, that would be helpful

This part of the process isn't directly a matter of accessibility, but the workflow would probably be more successful if it can accurately create the desired formatting. I am using Knit To PDF currently.

From what I understand, pandoc controls the conversion of the .Rmd to the .tex, and it uses fancyvrb to process code chunks. I'm not entirely sure what package or dependency is primarily controlling the width of the code blocks in the output PDF though. I know that I can edit the code produced by pandoc with fancyvrb to put the output of the code chunks in the same code block (on output PDF) as the source code (echo on for code chunks), but I don't think that fancyvrb handles the width of the code block. (It seems to mostly be a package that allows you to apply formatting to text that needs to be rendered verbatim?) [I rerun the .tex in lualatex after editing the .tex file]