Quarto Blog

输出多种格式

介绍

设置举例

yaml设置

post的index.qmd的yaml设置
warning: false
format-links: [docx]
format: 
  html: 
    toc: true
    code-fold: true
    toc-depth: 5
  docx:
    reference-doc: custom-reference-doc.docx
    number-sections: true 
    number-depth: 3
  pdf:
    documentclass: scrartcl
    papersize: A4

生成docx

生成docx

The Render buttons in RStudio and VS Code will not automatically render all formats if the document isn’t part of a Quarto website. To render all formats use quarto render on the command line:

quarto render multi-format.qmd

创建与应用word样式模板

创建与应用word样式模板

Pandoc自带一个样式文件,在样式文件的基础上修改样式,在样式文件对应的样式文本基础上修改,样式文本不要删除。样式文件通过以下代码导出:

quarto pandoc -o custom-reference-doc.docx --print-default-data-file reference.docx

修改样式后,将文件上传覆盖好可应用新样式。

生成PDF

安装tinytex

wget -qO- "https://yihui.org/tinytex/install-bin-unix.sh" | sh

作者列表

安装插件

cd ~/posts/her2    # qmd所在文件夹
quarto add kapsner/authors-block
authors设置
title: Her2

authors:
  - name: Yating Hou
    affiliations:
      - ref: mmph
    corresponding: false
    email: stuythou@163.com
    orcid: 0000-1111-2222-3333
    equal-contributor: true
    
  - name: Zichuan Liu
    affiliations:
      - ref: gmui
    orcid: 0000-3333-2222-1111
    email: 13719063021@126.com
    equal-contributor: true
    
  - name: Xingyang Xue
    affiliations:
      - ref: gmui
      - ref: gmut
    orcid: 0000-2222-1111-3333
    email: xxy1023970@126.com
    equal-contributor: true
    
  - name: Yisheng Huang
    affiliations:
      - ref: mmph
    orcid: 0000-2222-1111-3333
    email: hysd0760@163.com
    corresponding: true   
    
affiliations:
  - id: mmph
    name: Department of Oncology, Maoming People's Hospital, 101 Weimin Road, Maoming, 525000, Guangdong, China.
  - id: gmut
    name: Department of Thoracic Surgery, Affiliated Cancer Hospital & Institute of Guangzhou Medical University, Guangzhou, 510095, Guangdong, China.
  - id: gmui
    name: Internal Medicine Section 2, Affiliated Cancer Hospital & Institute of Guangzhou Medical University, Guangzhou, 510030, Guangdong, China.

filters:
  - authors-block  

经测试发现: 1. authors要跟在title后面。 2. 最后只能隔一行

Callout Blocks

折叠

参考官网 https://quarto.org/docs/authoring/callouts.html

  • Expand To Learn About Collapse

This is an example of a ‘folded’ caution callout that can be expanded by the user. You can use collapse="true" to collapse it by default or collapse="false" to make a collapsible callout that is expanded by default.

引用

快捷键

  • Ctrl + Q,在Tools \(\rightarrow\) Modify Keyboard Shortcuts 搜索blockquote,设置为Ctrl + Q

引文

bibliography: 'https://api.citedrive.com/bib/5bf3dbf3-77b6-4f56-99a3-9f6a2677dcce/references.bib?x=eyJpZCI6ICI1YmYzZGJmMy03N2I2LTRmNTYtOTlhMy05ZjZhMjY3N2RjY2UiLCAidXNlciI6ICI2NTk4IiwgInNpZ25hdHVyZSI6ICI3NDViNzNkNTBjOGJjZmUyNzdkNThhZjQ5Yzc3MTdjZjYzN2RmZmUyMzk2NzdjOTQwZGM2YjVhZjdlMmE5OTFjIn0=/bibliography.bib'
csl: "data/critical-care.csl"

评论

comments:
  hypothesis: true

发现

  • posts各下级文件夹里的index.qmd可以命名为具体的名称,方便选项卡的分辨,不影响blog的正确显示,如数据环境建设.qmd

  • quarto在render整数时,可能出现少1的情况。如以下代码中的出院天数,转换为字符型则问题消失。出院天数是由as.integer(Sys.Date() - as.Date(df$出院时间))得到的。

    • 更新:@转换为字符型仍然不能解决问题,本质是RenderRun的执行环境不一样,解决问题的根本方法为在qmd文件开头执行Sys.setenv(TZ="Asia/Shanghai")
Code
archivableDocuments5days <- outp_m %>%
  filter(是否归档=='未归档' & 出院天数<=5) %>%
  select(c(住院号, 病人姓名, 出院时间, 住院天数, 类型, 出院天数, 到期时间_5天, 管床医生)) %>% 
  arrange(desc(出院天数), 住院天数)  %>% 
  mutate(出院天数 = as.character(出院天数))  # 没搞明白,出院天数不转换为字符型时,出院天数都会少1。

适应化

修改index.qmd

Code
# 获取posts目录下所有子文件夹名称
subdirs <- dir("posts", full.names = FALSE)

# 循环遍历所有子文件夹,并重命名其下存在的index.qmd文件
for (subdir in subdirs) {
  index_file <- paste0("posts/", subdir, "/index.qmd")
  
  # 检测index.qmd文件是否存在
  if (file.exists(index_file)) {
    new_name <- paste0("posts/", subdir, "/", subdir, ".qmd")
    
    # 重命名文件
    file.rename(index_file, new_name)
  }
}

重置搜索

删除_site文件夹下的listing.json, search.json_freeze/posts文件下的所有子文件夹。再通过生成任意一个posts下的qmd文件以重新生成。

采集

幻灯

Cheatsheet