Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math support (Simple) #16

Closed
bennyboer opened this issue Jul 20, 2020 · 14 comments
Closed

Math support (Simple) #16

bennyboer opened this issue Jul 20, 2020 · 14 comments
Labels
enhancement New feature or request math
Projects
Milestone

Comments

@bennyboer
Copy link
Owner

bennyboer commented Jul 20, 2020

We need support for a #MATH# Thingy allowing to enter LaTeX formatted formulas that will be properly renderered in the document.

Maybe we want to convert LaTeX first to MathML using SnuggleTeX and then rather typeset MathML.

@bennyboer bennyboer created this issue from a note in v0.1 (To do) Jul 20, 2020
@bennyboer bennyboer added this to the v0.1 milestone Jul 20, 2020
@bennyboer bennyboer moved this from To do to In progress in v0.1 Jul 21, 2020
@bennyboer bennyboer self-assigned this Jul 21, 2020
@bennyboer
Copy link
Owner Author

Branch is math

@bennyboer bennyboer added the math label Jul 21, 2020
@bennyboer
Copy link
Owner Author

The considered SnuggleTex and JEuclid seem to be pretty old which will most certainly cause problems with current Java versions with module support. Thus we'll write our own LaTeX math parser + converter to MathML + MathML typesetter

@bennyboer bennyboer added the enhancement New feature or request label Jul 21, 2020
@bennyboer
Copy link
Owner Author

bennyboer commented Jul 23, 2020

We are restricting the supported MathML element types (See https://developer.mozilla.org/de/docs/Web/MathML/Element) to a specific subset, that most common math expressions will work with v0.1.

Element types to support for v0.1:

  • math (Partial support - no attributes currently supported)
    • Basic rendering
  • mrow
    • Basic rendering
  • msup
    • Basic rendering
    • Attribute superscriptshift
  • msub
    • Basic rendering
    • Attribute subscriptshift
  • msubsup
    • Basic rendering
    • Attribute subscriptshift
    • Attribute superscriptshift
  • mroot
    • Basic rendering
  • msqrt
    • Basic rendering
  • mi
    • Basic rendering
    • Attribute mathsize
    • Attribute mathvariant
  • mn
    • Basic rendering
    • Attribute mathsize
    • Attribute mathvariant
  • mtext
    • Basic rendering
    • Attribute mathsize
    • Attribute mathvariant
  • mfrac
    • Basic rendering
    • Attribute bevelled
    • Attributes numalign and denomalign
    • Attribute linethickness
  • mover
    • Basic rendering
    • Attribute align
  • munder
    • Basic rendering
    • Attribute align
  • munderover
    • Basic rendering
    • Attribute align
  • mspace
    • Basic rendering
    • Attributes depth, height and width
  • mpadded
    • Basic rendering
  • mo
    • Basic rendering
    • Attribute lspace, rspace
    • Attribute mathsize
    • Attribute mathvariant
    • Attribute stretchy

Other Tasks

That way we will allow most use-cases while some special cases may remain to be done in later releases.

@bennyboer
Copy link
Owner Author

Thingy ideas:

Thingy should be allowed both inline and as its own paragraph.
Note that we won't adjust line heights depending on the size of the math expression.
If the expression is too big to be displayed inline, you will have to create its own paragraph for it.
When displayed inline the math expression should be fit to the line height. So if you have an extremely verbose expression it should be scaled to fit the line height.

Name: #MATH#
Arguments: Either MathML or TeX style math expressions (Should be determined automatically)
Options:

  • caption: Caption for the math (only for math thingies in their own paragraph)
  • number: Whether to number the expression
  • label: Internal document reference label (Is already working for all thingies)

@bennyboer
Copy link
Owner Author

First end-to-end process draft is finished supporting MathML with math, mi, mn and mo nodes.
For example the following is already working:

#MATH,
<math>
	<mi>a</mi>
	<mo>+</mo>
	<mn>1</mn>
</math>
#

@bennyboer
Copy link
Owner Author

Now supporting mfrac and mrow as well as the attribute mathvariant for mi, mo, mn to display for example set identifiers (N, R, C, ...)

@bennyboer
Copy link
Owner Author

bennyboer commented Jul 28, 2020

Currently already possible is something like:

grafik

Compared to Firefox:

grafik

<math>
	<msubsup>
		<mo>&#x222B;</mo>
		<mn>0</mn>
		<mn>1</mn>
	</msubsup>
	<mroot>
		<mfrac>
			<mrow>
				<mi>sin</mi>
				<mo>(</mo>
				<mi>&#x3C0;</mi>
				<mo>)</mo>
			</mrow>
			<mn>2</mn>
		</mfrac>
		<mn>3</mn>
	</mroot>
	<mroot>
		<mi>x</mi>
		<mn>3</mn>
	</mroot>
	<mo>+</mo>
	<mn>42</mn>
	<msqrt>
		<mrow>
			<msubsup>
				<mo>&#x222B;</mo>
				<mn>0</mn>
				<mn>1</mn>
			</msubsup>
			<mroot>
				<mfrac>
					<mrow>
						<mi>sin</mi>
						<mo>(</mo>
						<mi>&#x3C0;</mi>
						<mo>)</mo>
					</mrow>
					<mn>2</mn>
				</mfrac>
				<mn>3</mn>
			</mroot>
			<mroot>
				<mi>x</mi>
				<mn>3</mn>
			</mroot>
			<mo>+</mo>
			<mn>42</mn>
		</mrow>
	</msqrt>
</math>

@bennyboer
Copy link
Owner Author

Support for the bevelled and linethickness attributes of the <mfrac> node:

grafik

#MATH, '
<math>
	<mfrac bevelled="true" linethickness="1.0">
		<mrow>
			<mfrac>
				<msqrt>
					<mn>2</mn>
				</msqrt>
				<mn>42</mn>
			</mfrac>
			<mo>-</mo>
			<mi>y</mi>
		</mrow>
		<mfrac>
			<mroot>
				<mrow>
					<mn>42</mn>
					<mo>*</mo>
					<mi>x</mi>
				</mrow>
				<mn>3</mn>
			</mroot>
			<mrow>
				<mi>sin</mi>
				<mo>(</mo>
				<mn>2.43</mn>
				<mo>)</mo>
			</mrow>
		</mfrac>
	</mfrac>
	<mo>+</mo>
	<mn>1</mn>
</math>
'#

@bennyboer
Copy link
Owner Author

#MATH# thingy now also working in-line with text.

@bennyboer bennyboer mentioned this issue Jul 30, 2020
15 tasks
@bennyboer
Copy link
Owner Author

Just checked whether we can use the STIX 2.0 font for math. License seems to be OK, needs to be documented in the third party notice file in the root of the repository.

Also checked whether Apache PDFBox does support OpenType fonts and it works just fine by using something like:

OTFParser otfParser = new OTFParser();
OpenTypeFont otf = otfParser.parse(new File("C:/Users/beder/Downloads/code/CODE Light.otf"));

PDFont font = PDType0Font.load(document, otf, false);

When calling the PDType0Font.load method we have to set the third parameter to false as PDFBox does currently not support OTF font subsetting (See https://issues.apache.org/jira/browse/PDFBOX-3758).

@bennyboer
Copy link
Owner Author

LaTeX to MathML converter will not be done in the context of this issue, instead see issue #23.

@bennyboer
Copy link
Owner Author

There is already an issue about the extended math support where we will implement more sophisticated and less usefull MathML features: #22

@bennyboer
Copy link
Owner Author

STIX 2 font added.

@bennyboer bennyboer changed the title Math support Math support (Simple) Aug 25, 2020
@bennyboer bennyboer moved this from In progress to Done in v0.1 Aug 25, 2020
@bennyboer bennyboer removed their assignment Aug 25, 2020
@bennyboer
Copy link
Owner Author

math branch has been merged to master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request math
Projects
v0.1
  
Done
Development

No branches or pull requests

1 participant