代码之家  ›  专栏  ›  技术社区  ›  Eric Krantz

.css使用RStudio Quarto指定数学字体并编织成HTML

  •  1
  • Eric Krantz  · 技术社区  · 6 月前

    我在用 .css 文件来设置我的样式 R Quarto 使用Aktiv-Grotesk字体渲染报告。然而,当我插入一个方程式时,我想使用不同的字体,因为平方根符号的呈现方式如下:

    enter image description here

    这是我的Quarto文件:

    ---
    format: 
      html:
        css: styles2.css
    ---
    
    Tilt magnitude is calculated using $Mag = \sqrt{N^{2} + W^{2}}$.
    

    这是我的 styles2.css 文件:

    p {
      font-size: 11pt;
      font-family: 'Aktiv Grotesk';
      color:black
    
    }
    * {
      font-family: 'Aktiv Grotesk', Times, serif ;
    }
    

    有没有 .css 命令,允许我单独设置公式字体的样式?如果没有,我如何在不改变报告字体的情况下实现教科书方程式?

    1 回复  |  直到 6 月前
        1
  •  1
  •   Jan    6 月前

    相关 css 您可以使用的选择器是

    • 内联数学: span.math.inline 或者,为了排除某些事物, span:not(.math.inline) ,
    • 显示数学: span.math.display 或者,为了排除某些事物, span:not(.math.display) .

    在您的示例中,我们可以禁用 css 使用特殊字体并设置单独的颜色,如下所示:

    文档.qmd

    ---
    format: 
      html:
        css: styles2.css
    ---
    
    Tilt magnitude is calculated using $Mag = \sqrt{N^{2} + W^{2}}$.
    

    样式2.css

    p, span:not(.math.inline) {
        font-size: 11pt;
        font-family: 'Aktiv Grotesk';
        color:black
    }
    
    span:not(.math.inline) {
        font-family: 'Aktiv Grotesk', Times, serif ;
    }
    
    span.math.inline {
        color: red;
    }
    

    enter image description here

    推荐文章