Skip to content

Commit b44f4cb

Browse files
committed
对前端网页添加 LaTeX 支持
1. 支持使用 MathJax 来渲染 LaTeX 公式 2. 添加物理实验0的习题和解析
1 parent f082e8e commit b44f4cb

File tree

4 files changed

+187
-7
lines changed

4 files changed

+187
-7
lines changed

mkdocs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ markdown_extensions:
4040
- pymdownx.tilde
4141
- pymdownx.tasklist:
4242
custom_checkbox: true
43+
- pymdownx.arithmatex:
44+
generic: true
45+
46+
extra_javascript:
47+
- javascripts/mathjax.js
48+
- https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js

update_dir.py

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
# LARGE_URL_PREFIX = f"https://gh-proxy.com/raw.githubusercontent.com/{repo_full}/refs/heads/{branch}/"
1616

1717
# 大文件阈值 15MB
18-
LARGE_THRESHOLD = 15 * 1024 * 1024
18+
# LARGE_THRESHOLD = 15 * 1024 * 1024
1919

2020
# 顶层排除目录
21-
EXCLUDE_TOP_DIRS = {'.git', 'docs', '.vscode', '.circleci', 'site', 'image'}
21+
EXCLUDE_TOP_DIRS = {'.git', 'docs', '.vscode', '.circleci', 'site', 'image', '.github'}
2222

2323
# 视为 README 的文件名
2424
README_CANDIDATES = {'README.md', 'readme.md', 'index.md'}
@@ -66,14 +66,15 @@ def process_directory(base_dir: str, rel_path: str):
6666
# blob 类文件链接
6767
if ext in BLOB_EXTS:
6868
file_url = BLOB_URL_PREFIX + quote(f"{rel_path}/{item}")
69+
download_url = BIN_URL_PREFIX + quote(f"{rel_path}/{item}")
70+
file_links.append((item, file_url, download_url))
6971
else:
7072
# 大文件链接
7173
# if file_size > LARGE_THRESHOLD:
7274
# file_url = LARGE_URL_PREFIX + quote(f"{rel_path}/{item}")
7375
# else:
7476
file_url = BIN_URL_PREFIX + quote(f"{rel_path}/{item}")
75-
76-
file_links.append((item, file_url))
77+
file_links.append((item, file_url))
7778
else:
7879
# 是子目录
7980
subdirs.append(item)
@@ -89,26 +90,64 @@ def process_directory(base_dir: str, rel_path: str):
8990
wf.write(readme_content.strip())
9091
wf.write("\n\n---\n\n") # 加点空行,避免直接跟标题混在一起
9192

92-
# 2) 输出大标题# 文件列表
93+
# 2) 输出大标题"# 文件列表"
9394
wf.write("# 文件列表\n")
9495

9596
# 3) 列出当前目录内的文件链接
96-
for fname, url in file_links:
97-
wf.write(f"- [{fname}]({url})\n")
97+
for link_info in file_links:
98+
if len(link_info) == 3:
99+
fname, preview_url, download_url = link_info
100+
wf.write(f"- [{fname}]({preview_url}) ([下载]({download_url}))\n")
101+
else:
102+
fname, url = link_info
103+
wf.write(f"- [{fname}]({url})\n")
98104

99105
# 递归处理子目录
100106
for subdir in subdirs:
101107
sub_rel_path = os.path.join(rel_path, subdir)
102108
full_subdir_path = os.path.join(base_dir, subdir)
103109
process_directory(full_subdir_path, sub_rel_path)
104110

111+
def create_mathjax_support():
112+
js_dir = os.path.join("docs", "javascripts")
113+
if not os.path.exists(js_dir):
114+
os.makedirs(js_dir)
115+
116+
mathjax_path = os.path.join(js_dir, "mathjax.js")
117+
mathjax_content = """window.MathJax = {
118+
tex: {
119+
inlineMath: [["\\\\(", "\\\\)"]],
120+
displayMath: [["\\\\[", "\\\\]"]],
121+
processEscapes: true,
122+
processEnvironments: true
123+
},
124+
options: {
125+
ignoreHtmlClass: ".*|",
126+
processHtmlClass: "arithmatex"
127+
}
128+
};
129+
130+
document$.subscribe(() => {
131+
MathJax.startup.output.clearCache()
132+
MathJax.typesetClear()
133+
MathJax.texReset()
134+
MathJax.typesetPromise()
135+
})
136+
"""
137+
138+
with open(mathjax_path, "w", encoding="utf-8") as f:
139+
f.write(mathjax_content)
140+
105141

106142
if __name__ == "__main__":
107143

108144
# 确保 docs 目录存在
109145
if not os.path.exists("docs"):
110146
os.mkdir("docs")
111147

148+
# MathJax 支持
149+
create_mathjax_support()
150+
112151
# 排除 EXCLUDE_TOP_DIRS
113152
top_dirs = []
114153
for d in sorted(os.listdir(".")):
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# 题目、解析及其他文件
2+
3+
###### ps:请在仓库[前端网页](https://royfor12.github.io/CQUT-Course-Guide-Sharing-Scheme/%E8%AF%BE%E7%A8%8B%E7%9B%AE%E5%BD%95/%E5%A4%A7%E5%AD%A6%E7%89%A9%E7%90%86%E5%AE%9E%E9%AA%8C/%E5%AE%9E%E9%AA%8C0-%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9%26%E6%B5%8B%E9%87%8F%E8%AF%AF%E5%B7%AE%E4%B8%8E%E5%AE%9E%E9%AA%8C%E6%95%B0%E6%8D%AE%E5%A4%84%E7%90%86/)中预览该文档,以免公式渲染不正确!
4+
5+
## 题目一
6+
用精度为 $1'$ 的分光计测量三棱镜的顶角 $A$,共测 8 次,其测得值分别为
7+
$60^\circ24'$, $60^\circ25'$, $60^\circ26'$, $60^\circ30'$, $60^\circ31'$, $60^\circ32'$, $60^\circ31'$, $60^\circ25'$。
8+
设已定系统误差为 $4'$,测顶角时,仪器误差限 $\Delta_{ins}$ 为 $2'$,试写出顶角 $A$ 测量结果 $A = \bar{A} \pm \Delta$。
9+
10+
### 解析
11+
1. **先求算术平均值**
12+
先把它们都转化为分钟形式后再加总除以 8,得到平均值:
13+
<br>
14+
$3624+3625+3626+3630+3631+3632+3631+3625 \;=\; 29024\,(\text{分})$
15+
<br>
16+
$\overline{A}_\text{测} \;=\;\frac{29024}{8} \;=\;3628\,(\text{分})$
17+
<br>
18+
转换回度分制:
19+
<br>
20+
$\overline{A}_{\text{测}} \;=\; 60^\circ28'$
21+
22+
2. **对已定系统误差 4′ 的修正**
23+
$A_{\text{修正}} \;=\; \overline{A}_{\text{测}} \;-\; 4'$
24+
<br>
25+
因此得到
26+
<br>
27+
$A_{\text{修正}} = 60^\circ28' - 4' = 60^\circ24'$
28+
29+
3. **计算不确定度**
30+
由于系统误差已修正,我们只需考虑修正后测量值的随机误差$\Delta_{random}$和仪器误差限$\Delta_{ins}$。
31+
<br>
32+
(1) 随机误差 $\Delta_{random}$
33+
随机误差可以通过测量值的标准偏差估计:
34+
<br>
35+
$\Delta_{random} = \frac{s}{\sqrt{n}}$
36+
<br>
37+
其中 $s = \sqrt{\frac{\sum (x_i - \bar{x})^2}{n - 1}}$ 是修正后测量值的标准偏差,$n = 8$ 是测量次数。
38+
这里 $\bar{x} = A_{\text{修正}}$,计算各测量值与平均值的偏差平方和并求和:
39+
<br>
40+
$\sum (x_i - \bar{x})^2 = 16 + 9 + 4 + 4 + 9 + 16 + 9 + 9 = 76$
41+
<br>
42+
标准偏差:
43+
<br>
44+
$s = \sqrt{\frac{76}{8 - 1}} = \sqrt{\frac{76}{7}} \approx \sqrt{10.857} \approx 3.294'$
45+
<br>
46+
标准误差:
47+
<br>
48+
$\Delta_{random} = \frac{s}{\sqrt{n}} = \frac{3.294'}{\sqrt{8}} \approx \frac{3.294}{2.828} \approx 1.165'$
49+
<br>
50+
(2) 仪器误差 $\Delta_{ins}$
51+
由于系统误差已单独给出并修正,我们假设 $\Delta_{ins} = 2'$ 是额外的系统性不确定度,对平均值直接贡献 $2'$。
52+
<br>
53+
(3) 总不确定度 $\Delta$
54+
55+
$$
56+
\begin{align*}
57+
\Delta &= \sqrt{(\Delta_{random})^2 + (\Delta_{ins})^2} \\
58+
&= \sqrt{(1.165')^2 + (2')^2} \\
59+
&= \sqrt{1.357 + 4} \\
60+
&= \sqrt{5.357} \approx 2'
61+
\end{align*}
62+
$$
63+
64+
**最终答案:**
65+
将系统误差扣除后的修正值作为测量值,并结合上一步得到的不确定度:
66+
67+
$$
68+
A \;=\; 60^\circ24' \;\pm\; 2'
69+
$$
70+
71+
---
72+
73+
## 题目二
74+
已知长方体质量 $m = (1260.5 \pm 0.6) \; g$,长宽高分别为:
75+
$a = (8.25 \pm 0.02) \; cm$,
76+
$b = (6.65 \pm 0.03) \; cm$,
77+
$c = (10.87 \pm 0.06) \; cm$,
78+
分别写出间接测量结果:
79+
80+
(1) 体积 $V = \bar{V} \pm \Delta$
81+
(2) 密度 $\rho = \bar{\rho} \pm \Delta$
82+
83+
### 解析
84+
首先计算长方体的体积:
85+
86+
$$
87+
\bar{V}=a\cdot b\cdot c=8.25\;cm\times6.65\;cm\times10.87\;cm\approx596.3\;cm^3
88+
$$
89+
90+
由乘积的不确定度传播公式,其相对不确定度为:
91+
92+
$$
93+
\frac{\Delta V}{V}\approx\sqrt{\left(\frac{0.02}{8.25}\right)^2+\left(\frac{0.03}{6.65}\right)^2+\left(\frac{0.06}{10.87}\right)^2}\approx0.00753
94+
$$
95+
96+
从而绝对不确定度为:
97+
98+
$$
99+
\Delta V\approx596.3\times0.00753\approx4.5\;cm^3
100+
$$
101+
102+
因此体积结果可写为:
103+
104+
$$
105+
V=(596.3\pm4.5)\;cm^3
106+
$$
107+
108+
接下来求密度:
109+
110+
$$
111+
\bar{\rho}=\frac{m}{V}\approx\frac{1260.5\;g}{596.3\;cm^3}\approx2.11\;g/cm^3
112+
$$
113+
114+
质量的相对不确定度为 $\frac{0.6}{1260.5}\approx0.00048$,体积的相对不确定度约为 $0.00753$,由除法的不确定度传播公式可得:
115+
116+
$$
117+
\frac{\Delta \rho}{\rho}\approx\sqrt{(0.00048)^2+(0.00753)^2}\approx0.00754
118+
$$
119+
120+
121+
122+
$$
123+
\Delta\rho\approx2.11\times0.00754\approx0.016\;g/cm^3
124+
$$
125+
126+
综上,密度写为:
127+
128+
$$
129+
\rho=(2.11\pm0.016)\;g/cm^3
130+
$$
131+
132+
最终结果为:
133+
134+
1. 体积:$V=(596.3\pm4.5)\;cm^3$
135+
2. 密度:$\rho=(2.11\pm0.016)\;g/cm^3$
Binary file not shown.

0 commit comments

Comments
 (0)