Search code examples
c#html-agility-pack

LoadHtml() messes up MathJax syntax


I'm trying to load a page with the following code:

<p>Generally for $n$ events $A_1, A_2,\cdots,A_n$, we have</p><br>

$P\biggl(\bigcup_{i=1}^n A_i\biggr) =\sum_{i=1}^n P(A_i)-\sum_{i < j}P(A_i\cap A_j) $
$ \hspace{32pt} +\sum_{i < j < k}P(A_i\cap A_j\cap A_k)-\ \cdots\ +(-1)^{n-1}\, P\biggl(\bigcap_{i=1}^n A_i\biggr)$

<hr />

However, after using doc.LoadHtml(html), the InnerHtml is now:

<p>Generally for $n$ events $A_1, A_2,\cdots,A_n$, we have</p><br />

$P\biggl(\bigcup_{i=1}^n A_i\biggr) =\sum_{i=1}^n P(A_i)-\sum_{i < j}p(a_i\cap="" a_j)="" $="" 
$="" \hspace{32pt}="" +\sum_{i="" />< j="" />< k}p(a_i\cap="" a_j\cap="" a_k)-\="" \cdots\="" +(-1)^{n-1}\,="" p\biggl(\bigcap_{i="1}^n" a_i\biggr)$="" /><hr />

I've tried using the following:

  • htmlDoc.OptionWriteEmptyNodes = true;
  • htmlDoc.OptionAutoCloseOnEnd = false;
  • htmlDoc.OptionCheckSyntax = false;
  • htmlDoc.OptionFixNestedTags = false;

with no luck.


Solution

  • I updated my HtmlAgilityPack to version 1.8.9, and the problem disappeared.