kramdown-rfc icon indicating copy to clipboard operation
kramdown-rfc copied to clipboard

Tips on math formatting

Open emanjon opened this issue 2 years ago • 4 comments

<sup> and <sub> often works great as in

p = 2<sup>256</sup> − 2<sup>224</sup> + 2<sup>192</sup> + 2<sup>96</sup> − 1

But in other cases like

(x<sup>3</sup> + a * x + b)<sup>((p + 1)/4)</sup>

log<sub>2</sub>

It works but not exactly as I would want my text formatted. I would like

log2 in HTML but log2 in TXT

Similarly I would like

(x3 + a * x + b)(p + 1)/4 in HTML and (x^3 + a * x + b)^((p + 1)/4) in TXT

Is there any way to achieve this? (Not prioritised otherwise)

emanjon avatar Nov 24 '22 07:11 emanjon

You can use

~~~ math
...
~~~

to invoke asciitex and tex2svg (display equations). Please see https://github.com/cabo/kramdown-rfc/wiki/SVG#math -- I probably should add an example there.

In today's xml2rfc, there is no way to have a plaintext/HTML switch in paragraph text, so you have to live with the decisions xml2rfc makes.

cabo avatar Nov 24 '22 07:11 cabo

Thanks

In today's xml2rfc, there is no way to have a plaintext/HTML switch in paragraph text,

True is it a xml2rfc limitation. That is very disappointing ....

Thinking more I would really like to also do

  • a * x in TXT and a ⋅ x in HTLM
  • x >= 0 in TXT and x ≥ 0 in HTML

Using asterisk for multiplication and >= for greater than or equal to in HTML looks like somebody wrote the text on a typewriter. It's a blast from the past in a bad way. HTML should not look like that in 2022...

emanjon avatar Nov 24 '22 07:11 emanjon

One draft that shows how math can be done today:

https://datatracker.ietf.org/doc/draft-ietf-tcpm-rfc8312bis/ https://ntap.github.io/rfc8312bis/draft-ietf-tcpm-rfc8312bis.html

The in-line plaintext is a bit hard to read as _ is used both for subscript and for italics.

The draft relies on a hack that will no longer be necessary once https://github.com/ietf-tools/xml2rfc/pull/895 is merged. Please see source code at https://github.com/NTAP/rfc8312bis.git -- α and β need to be written as {{{α}{}}} and {{{β}{}}} in paragraph text.

(An example for how we used to do math is in https://www.rfc-editor.org/rfc/rfc8698.html -- clearly we must move beyond that. One of the first drafts to use math properly was RFC 9100 -- see https://www.rfc-editor.org/rfc/rfc9100#figure-1 and https://datatracker.ietf.org/doc/html/rfc9100#section-2 for how this looks like with asciitex/tex2svg .)

cabo avatar Nov 24 '22 11:11 cabo

Oh, and the hack noted above lets you write a ⋅ x and x ≥ 0 in the plaintext version.

cabo avatar Nov 24 '22 11:11 cabo