@@ -147,10 +147,10 @@ def latex_to_html(latex_str: str) -> str:
147147 # Special cases that don't follow the pattern (optional overrides)
148148 special_replacements = {
149149 "ċ" : "·" ,
150- "<sup>" : '<tspan dy="-7%" font-size="10 ">' ,
151- "</sup>" : "</tspan>" ,
152- "<sub>" : '<tspan dy="7%" font-size="10">' ,
153- "</sub>" : "</tspan>" ,
150+ # "<sup>": '<tspan dy="-7%" font-size="70% ">',
151+ # "</sup>": "</tspan>",
152+ # "<sub>": '<tspan dy="7%" font-size="10">',
153+ # "</sub>": "</tspan>",
154154 }
155155
156156 for entity , replacement in special_replacements .items ():
@@ -159,6 +159,42 @@ def latex_to_html(latex_str: str) -> str:
159159 return s
160160
161161
162+ def html_to_svg (text : str , baseline : str ) -> str :
163+ """Convert HTML text to SVG-compatible text using tspan for subscripts/superscripts.
164+
165+ Parameters
166+ ----------
167+ text:
168+ The input HTML text.
169+ baseline:
170+ The dominant baseline alignment for the text ('hanging', 'middle', 'baseline').
171+
172+ Returns
173+ -------
174+ str
175+ The SVG-compatible text.
176+ """
177+ replacements = {
178+ "hanging" : {
179+ "<sup>" : '<tspan dy="-7%" font-size="70%">' ,
180+ "</sup>" : "</tspan>" ,
181+ "<sub>" : '<tspan dy="7%" font-size="70%">' ,
182+ "</sub>" : "</tspan>" ,
183+ },
184+ "middle" : {
185+ "<sup>" : '<tspan dy="-2%" font-size="70%">' ,
186+ "</sup>" : "</tspan>" ,
187+ "<sub>" : '<tspan dy="2%" font-size="70%">' ,
188+ "</sub>" : "</tspan>" ,
189+ },
190+ }
191+
192+ for entity , replacement in replacements [baseline ].items ():
193+ text = text .replace (entity , replacement )
194+
195+ return text
196+
197+
162198# def html_tags_to_svg(text: str) -> str:
163199# """Convert <sup> and <sub> HTML tags to SVG superscript/subscript using tspan."""
164200
0 commit comments