Uncategorized

Python: Replacing numbers in an HTML document


I have an HTML document that contains mathematical equations enclosed by a pair of \( (opening) and \) (closing) or by a pair of \[ and \]. For example:

We have \( a + b = c + 1.5 \) ...
We have \[ a + b = c + 1.5 \] ...

What I would like to do is to detect all numbers in this document and put them into \( ... \).

There are two tricky things:

  1. If a number is already inside an equation, then we should ignore it. For example, if we have the following text:
An equation \( a + b = c + 1.5 \), then a number 2.5, then another equation \( x + y = z + 1 \).

then it should be replaced with

An equation \( a + b = c + 1.5 \), then a number \( 2.5 \), then another equation \( x + y = z + 1 \).
  1. The conversion should be applied only to visible content. For example, numerical values inside HTML tags, such as <svg width="2.699ex" height="2.509ex"> should remain unchanged.

Thank you very much in advance for helping me achieve this!



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *