R Markdown转HTML时LaTeX矩阵显示异常问题求助
在R Markdown编辑器中矩阵显示正常,但转换为HTML输出时却显示R代码。我展示了beta_matrix的前20×6个元素,其形式如下:
其中$\hat{β}{j(k)}$是第k次迭代中$β_j$的估计值。
$$
\begin{equation}
\begin{pmatrix}
\hat{β}{0(1)} & \hat{β}{1(1)} & \cdots & \hat{β}{100(1)}\
\hat{β}{0(2)} & \ddots & & \
\vdots & & \ddots & \
\hat{β}{0(50)} & & & \hat{β}_{100(50)}
\end{pmatrix}
\end{equation}
$$
该矩阵在R Markdown视图中显示正常,但knit为HTML后显示异常,请问该如何解决?
以下是用户提供的xaringan幻灯片代码:
class: title-slide, center, middle background-image: url(https://us.123rf.com/450wm/giddavr/giddavr1405/giddavr140500043/28389662-en-diagonal-graduado-resumen-antecedentes-sin-forma-difusa-pink.jpg?ver=6) background-size: cover # EXERCISE 12 ## Ana ### University `r format(Sys.Date(), '%B %e, %Y')` --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) library(leaps) library(ggplot2) library(ggthemes) library(xaringanthemer) library(xaringanExtra) download.file( "https://raw.githubusercontent.com/daneden/animate.css/master/animate.css", "animate.css" ) knitr::opts_chunk$set(echo = TRUE,message = F,warning = F) options(htmltools.dir.version = FALSE) library(ISLR) library(xaringanthemer) library(xaringanExtra) library(tidyverse) style_solarized_light( text_bold_color = "#000000", header_color = "#D65DB1", inverse_text_color = "#ffffff", background_color = "#FBEAFF", code_highlight_color = "#D65DB1", text_color = "#000000" )
class: middle, center, animated, fadeIn
This problem is a continuation of the previous exercise. In a toy example with p=100, show that estimates of the multiple linear regression coefficients can be approximated by repeatedly performing simple linear regression in a backfitting procedure. How many backfitting iterations are needed to get a "good" approximation to the estimates of the multiple regression coefficients? Create a graph to justify your answer.
title: "Exercise 12"
subtitle: "statistics"
author: "Ana"
institute: "Universisity"
date: "27/03/2023"
output:
xaringan::moon_reader:
lib_dir: libs
css:
- xaringan-themer.css
- xaringan-themer.css
- "https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css"
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
seal: false
class: middle, animated, bounceInRight
# 解决方案 - **移除冲突的公式环境**:你同时使用了Markdown块级公式标记`$$`和LaTeX的`\begin{equation}`环境,这会导致渲染异常。只需保留其中一种格式即可,推荐修改为: ```latex $$ \begin{pmatrix} \hat{β}_{0(1)} & \hat{β}_{1(1)} & \cdots & \hat{β}_{100(1)}\\ \hat{β}_{0(2)} & \ddots & & \\ \vdots & & \ddots & \\ \hat{β}_{0(50)} & & & \hat{β}_{100(50)} \end{pmatrix} $$
- 显式启用MathJax渲染:xaringan依赖MathJax渲染LaTeX公式,若默认配置失效,可在输出配置中显式添加
mathjax: default:output: xaringan::moon_reader: lib_dir: libs css: - xaringan-themer.css - xaringan-themer.css - "https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css" nature: highlightStyle: github highlightLines: true countIncrementalSlides: false mathjax: default seal: false - 确认公式位置:确保LaTeX公式位于普通文本区域,而非R代码块内部。如果公式被错误包裹在代码块中,knit后会被当作代码显示。
内容的提问来源于stack exchange,提问作者user17050892

