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

Add support for subscript and superscript #224

Open
elinake opened this issue Mar 17, 2021 · 2 comments
Open

Add support for subscript and superscript #224

elinake opened this issue Mar 17, 2021 · 2 comments

Comments

@elinake
Copy link

elinake commented Mar 17, 2021

I need to use superscript and subscript like this

<p>This text contains <sub>subscript</sub> text.</p>
<p>This text contains <sup>superscript</sup> text.</p>

This text contains subscript text.

This text contains superscript text.

@KillyMXI
Copy link
Member

KillyMXI commented Mar 17, 2021

It is not as easy as it may sound.
Text is not HTML. You rely on HTML to present the examples for your issue.
To represent super~ and subscript in plain text we'd have to rely on Unicode capabilities.

Unicode is a huge mess.
Include universal modifiers? Not good enough;
Include super~ and subscript versions for whole character groups? Not good enough;
Include random characters out of particular order as it seem needed for some narrow use cases? Perfection!
There is some logic behind that, but it makes general purpose implementation impossible or hacky at best.

And even assuming a particular use case only requires available characters such as digits, we can't assume every output terminal is able to display them. Depending on the use case, some people might resort to notation such as x^2 and x_2 for super~ and subscript.

So there is no one-fits-all solution. And I don't want to include very limited solutions in the base package.

I'm considering to make a cookbook in the repo wiki to list custom formatter examples for common cases like this, so people can copy and customize them. The idea is on the back of my mind, but for now I'm focused on higher priority things. Some recipes are just not possible yet. Also, I think I'm not done yet with breaking changes, so I don't want to keep updating the cookbook too...

One variant of custom formatter for sub/sup might be the following:

{
  formatters: {
    'supFormatter': function (elem, walk, builder, formatOptions) {
      builder.pushWordTransform(str => sup(str));
      walk(elem.children, builder);
      builder.popWordTransform();
    }
  },
  tags: {
    'sup': { format: 'supFormatter' }
  }
}

where the sup() function comes from a package like https://github.com/msn0/subsup or a custom implementation.

@elinake
Copy link
Author

elinake commented Mar 17, 2021

Thanks for the explanation!

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

No branches or pull requests

2 participants