惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
量子位
D
DataBreaches.Net
博客园 - 司徒正美
J
Java Code Geeks
博客园 - 【当耐特】
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
B
Blog
The Cloudflare Blog
D
Docker
I
InfoQ
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
腾讯CDC
月光博客
月光博客
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
S
SegmentFault 最新的问题
GbyAI
GbyAI
有赞技术团队
有赞技术团队

Homepage on Yihui Xie | 谢益辉

Should I Ask for Sponsorship? - Yihui Xie | 谢益辉 A Review of **rmarkdown** Updates from 2024 to 2026 - Yihui Xie | 谢益辉 A Review of **knitr** Updates from 2024 to 2026 - Yihui Xie | 谢益辉 The lt Package: Lightweight HTML Tables for R (and Beyond) - Yihui Xie | 谢益辉 Bye, Stack Overflow - Yihui Xie | 谢益辉 Converting testthat Tests to testit - Yihui Xie | 谢益辉 Reflections on AI-assisted Programming - Yihui Xie | 谢益辉 R.I.P., Tomas Kalibera - Yihui Xie | 谢益辉 An Introduction to xfun - Yihui Xie | 谢益辉 tinyimg: An R Package for Compressing Images - Yihui Xie | 谢益辉 The Surprising Slowness of `textConnection()` in R - Yihui Xie | 谢益辉 A CDN-backed CTAN Mirror: `tlnet.yihui.org` - Yihui Xie | 谢益辉 TinyTeX on macOS: No More Messing with `/usr/local/bin` - Yihui Xie | 谢益辉
Preliminary Support for Typst in knitr - Yihui Xie | 谢益辉
Yihui Xie · 2026-04-27 · via Homepage on Yihui Xie | 谢益辉

A few weeks ago I added preliminary support for Typst to knitr. The way it works is simple: if your file has the extension .Rtyp, knitr will recognize it as a Typst document, knit it, and produce a .typ output file. The chunk syntax follows the same Markdown-style fenced code block convention: ```{r} to start a chunk and ``` to end it, with inline R expressions written as `r expr`. A minimal example (hello.Rtyp):

#set page(paper: "a4")
#set text(font: "New Computer Modern", size: 11pt)

= Hello, Typst!

```{r}
x = rnorm(10)
summary(x)
```

The mean is `r round(mean(x), 3)`.

Install the latest development version of knitr and restart R:

install.packages('knitr', repos = 'https://yihui.r-universe.dev')

Then you run either:

knitr::knit("hello.Rtyp")      # produces hello.typ
knitr::knit2pdf("hello.Rtyp")  # produces hello.pdf

That’s about it. I called this “preliminary” support because I have not done extensive testing, and there are probably rough edges. If give this a try and run into any problems, please feel free to leave comments below or file issues to the knitr repo on Github.

On Typst itself

Typst is quite impressive and its rendering speed seems to be unbeatable. I understand why so many people in the R community are excited about it. However, for knitr / rmarkdown / Quarto users, I think the bottleneck in dynamic documents (.Rtyp, .Rmd, .qmd) is almost never the typesetting step—it’s the computation in code chunks. The speed argument for Typst is compelling for pure writing workflows; for data analysis documents, I’m skeptical it matters much in practice.

And then there is the larger question of whether you need PDF at all.

In HTML I Still Trust

I have believed for a long time that HTML is the better target for almost everything, including what people typically reach for PDF to accomplish: typesetting for reading, sharing, and archiving. You get hyperlinks, search, accessibility, reflowable text, responsive layout, and zero installation requirements—free, in a browser that everyone already has.

If you really need paginated output that looks like a printed document, it is more achievable from HTML than you’d imagine. I have a small script pages.js that typesets a continuous HTML page into individual pages—you can press P (or Ctrl/Cmd + P) on any page at yihui.org/litedown/ to see the effect. The result is not perfect, but it is good enough for many use cases, and you get to keep all the benefits of HTML along the way. BTW, I handcrafted pages.js from scratch in 2024 without AI assistance, and I have to confess that while the code is relatively short, it was the most challenging piece of JavaScript I had ever written (again, the recursion almost killed me). I guess today’s AI can do a much better job than me.

The accessibility angle is one I keep hearing more about, and rightly so. HTML is dramatically better than PDF on this front—screen readers, keyboard navigation, zoom, high-contrast mode, all of it works because browsers have been doing this for decades. LaTeX has finally made some progress here, too (e.g., the tagpdf package), which is great, but still there are so many things that I doubt would ever become possible in LaTeX.

Bye, LaTeX (and Typst, although we never met)

Typst support in knitr is there if you want it, and I think Typst is a great tool. I wouldn’t use it myself but I’m happy to serve those who do use it. I gave up MS Office around 2009 after becoming a LaTeX fan for a few years. In 2024, I decided that I wouldn’t use LaTeX anymore (when I need PDF, I just use pages.js to print HTML). I believe HTML still has a lot of potential that I need to explore further, and I really look forward to it.

Again, this doesn’t mean I’m abandoning my support for LaTeX. Actually I still work quite hard in this regard, as you can tell from some of my previous posts this year.

Donate

As a freelancer (currently working as a contractor) and a dad of three kids, I truly appreciate your donation to support my writing and open-source software development! Your contribution helps me cope with financial uncertainty better, so I can spend more time on producing high-quality content and software. You can make a donation through methods below.

  • Venmo: @yihui_xie, or Zelle: [email protected]

  • Paypal

    • If you have a Paypal account, you can follow the link https://paypal.me/YihuiXie or find me on Paypal via my email [email protected]. Please choose the payment type as “Family and Friends” (instead of “Goods and Services”) to avoid extra fees.

    • If you don’t have Paypal, you may donate through this link via your debit or credit card. Paypal will charge a fee on my side.

  • Other ways:

    WeChat Pay (微信支付:谢益辉) Alipay (支付宝:谢益辉)
    WeChat Pay QR code Alipay QR code

When sending money, please be sure to add a note “gift” or “donation” if possible, so it won’t be treated as my taxable income but a genuine gift. Needless to say, donation is completely voluntary and I appreciate any amount you can give.

Please feel free to email me if you prefer a different way to give. Thank you very much!

I’ll give back a significant portion of the donations to the open-source community and charities. For the record, I received about $30,000 in total (before tax) in 2024-25, and gave back about $15,000 (after tax).