367 lines
9.3 KiB
CSS
367 lines
9.3 KiB
CSS
/* css/math-display-fix.css */
|
||
/* 专门修复数学公式显示问题的样式 */
|
||
|
||
/* 修复块级数学公式显示 */
|
||
.katex-display-fixed {
|
||
display: block !important;
|
||
margin: 16px auto !important;
|
||
text-align: center !important;
|
||
overflow-x: auto;
|
||
overflow-y: hidden;
|
||
padding: 8px 0;
|
||
line-height: 1.2;
|
||
}
|
||
|
||
/* 确保使用改进容器时,内部的 KaTeX display 元素也为右侧编号预留空间 */
|
||
.katex-display-fixed .katex-display {
|
||
display: block;
|
||
width: 100%;
|
||
position: relative;
|
||
padding-right: 4.25em;
|
||
text-align: center;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.katex-display-fixed .katex-display .katex-tag,
|
||
.katex-display-fixed .katex-display .tag,
|
||
.katex-display-fixed .katex .katex-tag,
|
||
.katex-display-fixed .katex .tag {
|
||
position: absolute;
|
||
right: 0;
|
||
top: 0;
|
||
height: 100%;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
white-space: nowrap;
|
||
margin-left: 0.5em;
|
||
}
|
||
|
||
/* 防止在改进容器下主体公式仍然占满右侧空间 */
|
||
.katex-display-fixed > .katex,
|
||
.katex-display-fixed .katex-display > .katex {
|
||
max-width: calc(100% - 4.25em);
|
||
}
|
||
|
||
/* 修复行内数学公式显示 */
|
||
.katex-inline-fixed {
|
||
display: inline !important;
|
||
margin: 0 2px !important;
|
||
vertical-align: baseline;
|
||
line-height: 1;
|
||
}
|
||
|
||
/* 改进的数学错误显示 */
|
||
.math-error-block {
|
||
display: block;
|
||
margin: 16px 0;
|
||
padding: 12px 16px;
|
||
background-color: #fff5f5;
|
||
border: 1px solid #feb2b2;
|
||
border-radius: 6px;
|
||
color: #c53030;
|
||
font-family: 'Courier New', Consolas, monospace;
|
||
font-size: 0.9em;
|
||
text-align: center;
|
||
cursor: help;
|
||
}
|
||
|
||
.math-error-inline {
|
||
display: inline;
|
||
margin: 0 2px;
|
||
padding: 2px 6px;
|
||
background-color: #fed7d7;
|
||
border: 1px solid #feb2b2;
|
||
border-radius: 3px;
|
||
color: #c53030;
|
||
font-family: 'Courier New', Consolas, monospace;
|
||
font-size: 0.85em;
|
||
cursor: help;
|
||
}
|
||
|
||
/* 段落内数学公式的间距修复 */
|
||
p .katex-inline-fixed,
|
||
p .katex-inline,
|
||
p .math-error-inline {
|
||
margin: 0 0.1em;
|
||
}
|
||
|
||
/* 防止数学公式在段落中造成不当换行 */
|
||
p {
|
||
line-height: 1.6;
|
||
word-wrap: break-word;
|
||
overflow-wrap: break-word;
|
||
}
|
||
|
||
/* 确保数学公式不会被截断 */
|
||
.katex {
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.katex-display,
|
||
.katex-display-fixed {
|
||
white-space: nowrap;
|
||
overflow-x: auto;
|
||
overflow-y: hidden;
|
||
/* 隐藏滚动条,但保留横向滚动能力 */
|
||
-ms-overflow-style: none; /* IE/Edge */
|
||
scrollbar-width: none; /* Firefox */
|
||
}
|
||
.katex-display::-webkit-scrollbar,
|
||
.katex-display-fixed::-webkit-scrollbar {
|
||
display: none; /* Chrome/Safari */
|
||
}
|
||
|
||
/* 移动设备上的数学公式优化 */
|
||
@media (max-width: 768px) {
|
||
.katex-display-fixed {
|
||
font-size: 0.9em;
|
||
margin: 12px auto;
|
||
padding: 6px 0;
|
||
}
|
||
|
||
.katex-inline-fixed {
|
||
font-size: 0.85em;
|
||
}
|
||
|
||
.math-error-block {
|
||
padding: 8px 12px;
|
||
font-size: 0.8em;
|
||
}
|
||
|
||
.math-error-inline {
|
||
font-size: 0.75em;
|
||
padding: 1px 4px;
|
||
}
|
||
|
||
/* 移动端(OCR/翻译):单行 + 横向滚动(更稳),避免换行过猛 */
|
||
.content-wrapper .katex-display,
|
||
.content-wrapper .katex-display-fixed {
|
||
padding-right: 3.25em !important;
|
||
font-size: 0.95em;
|
||
white-space: nowrap !important;
|
||
overflow-x: auto !important;
|
||
overflow-y: hidden !important;
|
||
line-height: 1.45 !important;
|
||
text-align: center;
|
||
}
|
||
.content-wrapper .katex-display > .katex,
|
||
.content-wrapper .katex-display-fixed > .katex {
|
||
display: inline-block;
|
||
white-space: nowrap !important;
|
||
line-height: 1.45 !important;
|
||
}
|
||
.content-wrapper .katex-display .katex-tag,
|
||
.content-wrapper .katex-display .tag,
|
||
.content-wrapper .katex .katex-tag,
|
||
.content-wrapper .katex .tag {
|
||
position: absolute !important;
|
||
right: 0 !important;
|
||
top: 50% !important;
|
||
transform: translateY(-50%);
|
||
white-space: nowrap;
|
||
}
|
||
}
|
||
|
||
/* OCR/翻译视图(content-wrapper)强制不裁剪多行公式(所有屏幕) */
|
||
.content-wrapper .katex-display,
|
||
.content-wrapper .katex-display-fixed {
|
||
overflow-y: visible !important;
|
||
white-space: normal !important;
|
||
height: auto !important;
|
||
line-height: 1.5 !important;
|
||
padding-bottom: 0.25em;
|
||
}
|
||
.content-wrapper .katex { overflow: visible !important; white-space: normal !important; }
|
||
|
||
/* 超小屏(手机)布局:将右侧编号换到下一行右对齐,释放公式宽度 */
|
||
@media (max-width: 640px) {
|
||
/* 释放右侧留白,主体公式可占满整行 */
|
||
.markdown-body .katex-display,
|
||
.align-content.markdown-body .katex-display,
|
||
.katex-block .katex-display,
|
||
.katex-display-fixed,
|
||
.katex-display {
|
||
padding-right: 0 !important;
|
||
}
|
||
|
||
.markdown-body .katex-display > .katex,
|
||
.align-content.markdown-body .katex-display > .katex,
|
||
.katex-block .katex-display > .katex,
|
||
.katex-display-fixed > .katex,
|
||
.katex-display > .katex {
|
||
max-width: 100% !important;
|
||
}
|
||
|
||
/* 将标签/编号移到公式下方,靠右对齐 */
|
||
.markdown-body .katex-display .tag,
|
||
.markdown-body .katex-display .katex-tag,
|
||
.align-content.markdown-body .katex-display .tag,
|
||
.align-content.markdown-body .katex-display .katex-tag,
|
||
.katex-block .katex-display .tag,
|
||
.katex-block .katex-display .katex-tag,
|
||
.katex-display-fixed .tag,
|
||
.katex-display-fixed .katex-tag,
|
||
.katex-display .tag,
|
||
.katex-display .katex-tag {
|
||
position: static !important;
|
||
display: block !important;
|
||
transform: none !important;
|
||
height: auto !important;
|
||
margin: 6px 0 0 0 !important;
|
||
text-align: right !important;
|
||
}
|
||
|
||
/* 手机端适度放大以提升可读性 */
|
||
.katex-display,
|
||
.katex-display-fixed {
|
||
font-size: 1.05em;
|
||
}
|
||
}
|
||
|
||
/* 数学公式和中文文本的间距优化 */
|
||
.katex-inline-fixed + .katex-inline-fixed,
|
||
.katex-inline + .katex-inline-fixed,
|
||
.katex-inline-fixed + .katex-inline {
|
||
margin-left: 0.2em;
|
||
}
|
||
|
||
/* 修复长公式在容器中的显示 */
|
||
.markdown-body .katex-display-fixed,
|
||
.content-wrapper .katex-display-fixed {
|
||
max-width: 100%;
|
||
margin-left: auto;
|
||
margin-right: auto;
|
||
}
|
||
|
||
/* 公式渲染加载状态 */
|
||
.math-loading {
|
||
background-color: #f7fafc;
|
||
border-radius: 4px;
|
||
padding: 4px 8px;
|
||
color: #718096;
|
||
font-style: italic;
|
||
animation: pulse 1.5s ease-in-out infinite;
|
||
}
|
||
|
||
@keyframes pulse {
|
||
0%, 100% { opacity: 1; }
|
||
50% { opacity: 0.5; }
|
||
}
|
||
|
||
/* 深色模式下的数学错误样式 */
|
||
@media (prefers-color-scheme: dark) {
|
||
.math-error-block {
|
||
background-color: #742a2a;
|
||
border-color: #e53e3e;
|
||
color: #feb2b2;
|
||
}
|
||
|
||
.math-error-inline {
|
||
background-color: #822727;
|
||
border-color: #e53e3e;
|
||
color: #feb2b2;
|
||
}
|
||
|
||
.math-loading {
|
||
background-color: #2d3748;
|
||
color: #a0aec0;
|
||
}
|
||
}
|
||
|
||
/* 高对比度模式支持 */
|
||
@media (prefers-contrast: high) {
|
||
.katex-display-fixed,
|
||
.katex-inline-fixed {
|
||
border: 1px solid currentColor;
|
||
padding: 2px 4px;
|
||
}
|
||
|
||
.math-error-block,
|
||
.math-error-inline {
|
||
border-width: 2px;
|
||
font-weight: bold;
|
||
}
|
||
}
|
||
|
||
/* 无障碍支持 */
|
||
.katex-display-fixed:focus,
|
||
.katex-inline-fixed:focus,
|
||
.math-error-block:focus,
|
||
.math-error-inline:focus {
|
||
outline: 2px solid #4299e1;
|
||
outline-offset: 2px;
|
||
}
|
||
|
||
/* 打印样式 */
|
||
@media print {
|
||
.katex-display-fixed,
|
||
.katex-inline-fixed {
|
||
break-inside: avoid;
|
||
}
|
||
|
||
.math-error-block,
|
||
.math-error-inline {
|
||
border: 2px solid #000;
|
||
background: #fff;
|
||
color: #000;
|
||
}
|
||
}
|
||
|
||
/* 修复特定容器中的数学公式显示 */
|
||
.align-content.markdown-body .katex-display-fixed {
|
||
margin: 12px 0;
|
||
}
|
||
|
||
.align-content.markdown-body .katex-inline-fixed {
|
||
margin: 0 1px;
|
||
}
|
||
|
||
/* 防止数学公式影响行高 */
|
||
.align-content.markdown-body p {
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.align-content.markdown-body p .katex-inline-fixed {
|
||
vertical-align: middle;
|
||
}
|
||
|
||
/* ===== 最终覆盖:强制行间公式为块级并为右标留足空间 ===== */
|
||
.markdown-body .katex-display,
|
||
.align-content.markdown-body .katex-display,
|
||
.katex-block .katex-display,
|
||
.katex-display-fixed,
|
||
.katex-display {
|
||
display: block !important;
|
||
width: 100% !important;
|
||
position: relative !important;
|
||
text-align: center !important;
|
||
padding-right: 5em !important; /* 为右侧编号预留空间 */
|
||
box-sizing: border-box !important;
|
||
}
|
||
|
||
.markdown-body .katex-display > .katex,
|
||
.align-content.markdown-body .katex-display > .katex,
|
||
.katex-block .katex-display > .katex,
|
||
.katex-display-fixed > .katex,
|
||
.katex-display > .katex {
|
||
max-width: calc(100% - 5em) !important; /* 防止主体覆盖右标 */
|
||
}
|
||
|
||
.markdown-body .katex-display .tag,
|
||
.markdown-body .katex-display .katex-tag,
|
||
.align-content.markdown-body .katex-display .tag,
|
||
.align-content.markdown-body .katex-display .katex-tag,
|
||
.katex-block .katex-display .tag,
|
||
.katex-block .katex-display .katex-tag,
|
||
.katex-display-fixed .tag,
|
||
.katex-display-fixed .katex-tag,
|
||
.katex-display .tag,
|
||
.katex-display .katex-tag {
|
||
position: absolute !important;
|
||
right: 0 !important;
|
||
top: 50% !important;
|
||
transform: translateY(-50%);
|
||
white-space: nowrap;
|
||
margin-left: 0.5em;
|
||
}
|