Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llm_web_kit/extractor/html/recognizer/cc_math/tag_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def modify_tree(cm: CCMATH, math_render: str, o_html: str, node: HtmlElement, pa
mathml = re.sub(r'([^\s])\s+([^\s])', r'\1 \2', mathml) # remove extra spaces

latex = cm.mml_to_latex(mathml)
# 处理未转义的%为\%
if latex:
latex = re.sub(r'(?<!\\)%', r'\\%', latex)
text = cm.wrap_math_md(latex)
if text:
# Set the html of the new span tag to the text
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mathematical Formulas with Percent Symbol</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script>
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
displayMath: [['$$', '$$'], ['\\[', '\\]']]
}
};
</script>
</head>
<body>
<h1>Mathematical Formulas Containing % Symbol</h1>

<h2>1. LaTeX Format Examples</h2>

<h3>Inline LaTeX formulas:</h3>
<p>The percentage increase is calculated as $\frac{new - old}{old} \times 100\%$.</p>

<h3>Display LaTeX formulas:</h3>
<p>Compound interest formula:</p>
$$A = P\left(1 + \frac{r\%}{n}\right)^{nt}$$

<h2>2. MathML Format Examples</h2>

<p>Percentage change in MathML:</p>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>Δ</mi>
<mo>%</mo>
<mo>=</mo>
<mfrac>
<mrow>
<mi>new</mi>
<mo>-</mo>
<mi>old</mi>
</mrow>
<mi>old</mi>
</mfrac>
<mo>×</mo>
<mn>100</mn>
<mo>%</mo>
</mrow>
</math>

<p>Discount percentage:</p>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline">
<mrow>
<mi>Discount</mi>
<mo>%</mo>
<mo>=</mo>
<mfrac>
<mrow>
<mi>Original</mi>
<mo>-</mo>
<mi>Sale</mi>
</mrow>
<mi>Original</mi>
</mfrac>
<mo>×</mo>
<mn>100</mn>
<mo>%</mo>
</mrow>
</math>

<p>Puyu badcase:</p>
<math display="block">
<mtable xmlns="http://www.w3.org/1998/Math/MathML" columnalign="left">
<mtr>
<mtd class="align-1">
<mi>%</mi>
<mspace width="0.25em"/>
<mtext>Cell Death</mtext>
<mo>=</mo>
</mtd>
<mtd class="align-2">
<mo>(</mo>
<mn>1</mn>
<mo>−</mo>
<mo>(</mo>
<mtext>Post treatment cell counts</mtext>
</mtd>
</mtr>
<mtr>

<mtd class="align-2">
<mo>/</mo>
<mtext>initial cell counts</mtext>
<mo>)</mo>
<mo>)</mo>
<mo>*</mo>
<mn>100</mn>
</mtd>
</mtr>
</mtable>
</math>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A = P\left(1 + \frac{r\%}{n}\right)^{nt}
\Delta \%=\frac{\mathrm{new}-\mathrm{old}}{\mathrm{old}}×100\%
\begin{array}{ll}\%\text{Cell Death}=& \left(1-\left(\text{Post treatment cell counts}\\ /\text{initial cell counts}\right)\right)*100\end{array}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\frac{new - old}{old} \times 100\%
\mathrm{Discount}\%=\frac{\mathrm{Original}-\mathrm{Sale}}{\mathrm{Original}}×100\%
8 changes: 8 additions & 0 deletions tests/llm_web_kit/extractor/html/recognizer/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@
'base_url': 'https://convertoctopus.com/4-7-years-to-minutes',
'expected': 'assets/ccmath/math_class_math_1.html',
'expected_inline': 'assets/ccmath/math_class_math_inline_1.html'
},
{
'input': [
'assets/ccmath/math_percentage.html',
],
'base_url': 'https://test.com/',
'expected': 'assets/ccmath/math_percentage_1.html',
'expected_inline': 'assets/ccmath/math_percentage_inline_1.html'
}
]

Expand Down