Skip to content

Comments

MathML elements svg class for styling and filters#87

Open
biojet1 wants to merge 1 commit intocdelker:mainfrom
biojet1:svg_class
Open

MathML elements svg class for styling and filters#87
biojet1 wants to merge 1 commit intocdelker:mainfrom
biojet1:svg_class

Conversation

@biojet1
Copy link
Contributor

@biojet1 biojet1 commented Mar 19, 2025

Added to config .svg_classes .svg_def .svg_style for easy svg styling and filters.
see test/classes.ipynb for example to generate this svg

import ziamath as zm
zm.config.svg2 = False
zm.config.math.fontsize = 50
zm.config.svg_classes = True
zm.config.svg_style = r'''
.mrow { fill:blue }
.mn { fill:magenta ;   }
.mo { fill:yellow ; stroke:grey;   stroke-width:1px;}
.mi { fill:url(#grad1) ; stroke:darkslategrey;   stroke-width:1px;}
.background { fill:violet ; stroke:none}
.hline {fill:green}
'''
zm.config.svg_defs = r'''
    <linearGradient id="grad1" x1="0%" x2="100%" y1="0%" y2="100%">
      <stop offset="0%" stop-color="yellow" />
      <stop offset="100%" stop-color="red" />
    </linearGradient>
'''
mml = '''
<math display="block">
<mrow>
  <mrow>
    <mo>(</mo>
    <mfrac linethickness="1px">
      <mi>p</mi>
      <mn>2</mn>
    </mfrac>
    <mo>)</mo>
  </mrow>
  <msup>
    <mi>x</mi>
    <mn>2</mn>
  </msup>
  <msup>
    <mi>y</mi>
    <mrow>
      <mi mathcolor="DarkSlateGray">p</mi>
      <mo>-</mo>
      <mn>2</mn>
    </mrow>
  </msup>
  <mo>-</mo>
  <mfrac>
    <mn>1</mn>
    <mrow>
      <mn>1</mn>
      <mo>-</mo>
      <mi>x</mi>
    </mrow>
  </mfrac>
  <mfrac>
    <mn>1</mn>
    <mrow>
      <mn>1</mn>
      <mo>-</mo>
      <msup>
        <mi mathbackground="">x</mi>
        <mn mathbackground="orange">2</mn>
      </msup>
    </mrow>
  </mfrac>
</mrow>
</math>
'''
zm.Math(mml)

math

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant