最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Change how inline code is formatted in quarto PDF output - Stack Overflow

programmeradmin1浏览0评论

Quarto renders inline code (specified using backticks) in a very clear way when output to html: it changes the font, text color, and background color. But when outputting to PDF, it only changes the font, which is so subtle a change that most readers won't even notice. How do I manually change the formatting of inline code in a PDF document to match the formatting used in html documents?

Here's the default formatting of inline code in a quarto html document:

---
title: "test"
format: html
---

Use something like `this code` to do something.

And here's the default formatting when output to PDF:

---
title: "test"
format: pdf
---

Use something like `this code` to do something.

Quarto renders inline code (specified using backticks) in a very clear way when output to html: it changes the font, text color, and background color. But when outputting to PDF, it only changes the font, which is so subtle a change that most readers won't even notice. How do I manually change the formatting of inline code in a PDF document to match the formatting used in html documents?

Here's the default formatting of inline code in a quarto html document:

---
title: "test"
format: html
---

Use something like `this code` to do something.

And here's the default formatting when output to PDF:

---
title: "test"
format: pdf
---

Use something like `this code` to do something.

Share Improve this question asked Jan 17 at 16:10 filups21filups21 1,9471 gold badge23 silver badges30 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You can tweak \texttt, e.g. providing the gray background color and the purple font color from HTML output:

\definecolor{codefontcolor}{RGB}{125,18,186}
\definecolor{codebggray}{HTML}{f8f9fa}
\let\textttOrig\texttt
\renewcommand{\texttt}[1]{\textttOrig{\colorbox{codebggray}{\textcolor{codefontcolor}{#1}}}}

Using the default font, it would look like this in a .pdf:

Compared to the output in a .html:

You can also change the used font in .pdf output, one example is Source Code Pro:

\usepackage{sourcecodepro}

---
title: "test"
format: 
  pdf:
    include-in-header:
      text: |
        \usepackage{sourcecodepro}
        \definecolor{codefontcolor}{RGB}{125,18,186}
        \definecolor{codebggray}{HTML}{f8f9fa}
        \let\textttOrig\texttt
        \renewcommand{\texttt}[1]{\textttOrig{\colorbox{codebggray}{\textcolor{codefontcolor}{#1}}}}
---

Use something like `this code` to do something.
发布评论

评论列表(0)

  1. 暂无评论