Macaulay2 / M2

The primary source code repository for Macaulay2, a system for computing in commutative algebra, algebraic geometry and related fields.
https://macaulay2.com
347 stars 231 forks source link

non-Hypertext inside Hypertext, validate discussion #2757

Closed pzinn closed 1 year ago

pzinn commented 1 year ago

This is not so much an issue as a call for discussion about the following. Ever since #1288 (2.5 years ago), the role of html has changed quite a bit. It used to be that html would only accept instances of Hypertext as argument, and would produce the corresponding HTML code. After a series of PRs following #1288, html now accepts any type and converts it to HTML code according to the following recipe: by default (in particular for all mathematical types), it does something like htmlLiteral @@ tex where htmlLiteral makes sure characters that have a special meaning in HTML are encoded (the implicit assumption is that something like KaTeX will be running and concert it); for some other types (including, but not limited to, Hypertext) it just produces HTML code directly. There's one problem with this new paradigm which I uncovered as part of my current improvements to locate, code, listSymbols (in relation to #2655 and #2375, among other things): it can lead to Hypertext which is considered illegal by validate. Let me give an example (which is relevant to my new, improved, listSymbols): suppose you want to create an HTML TABLE whose contents can have some mathematical stuff, say a ring QQ[x]. Currently the only way to produce this is with something roughly like

TABLE {{QQ[x]}}

(note that you can't write TABLE {{ html(QQ[x]) }} -- that would doubly htmlLiteral the stuff inside html(...) which in general will not produce the desired result). Now this will work perfectly fine -- except if you tried to validate this (e.g., to include it in documentation), it will tell you QQ[x] has an invalid type inside a Hypertext element. Which is a valid point -- with the "old" logic that is still enforced by validate, one can't have non Hypertext inside Hypertext (well, except strings and options, obviously). So at some point in the near future we will have to make a choice:

Any thoughts? I'll probably provide a truncated version of my upgrades mentioned above as a PR, but I'm definitely stuck in moving forward because of the issue I've just described.

mahrud commented 1 year ago

I don't think I understand this:

(note that you can't write TABLE {{ html(QQ[x]) }} -- that would doubly htmlLiteral the stuff inside html(...) which in general will not produce the desired result).

What's an example? It seems to me like the simpler solution is for TABLE, SPAN, etc. to convert non-hypertext stuff in its input by passing them through tex or html.

Alternatively, validate can make small changes as it reads the input and return corrected output in cases like this. One example would be running html on non-hypertext objects.

pzinn commented 1 year ago

fine, here's another example:

SPAN {<|a|>}

this will work, but SPAN {html(<|a|>)} will fail.

As to changing validate, this might work, but how would you avoid the problem I mention at the end? How can conversion to net work correctly? (without replacing say <|a|> with its TeX version?

mahrud commented 1 year ago

Ahh I see what you mean. Maybe SPAN { tex <|a|> } (or texMath) is the right way to go then?

As to changing validate, this might work, but how would you avoid the problem I mention at the end? How can conversion to net work correctly? (without replacing say <|a|> with its TeX version?

As far as I know, validate is only called in the context of html validate X; that is, right before being converted to html. After all, there are no validation rules for nets, only html files, so we would never pass the output of validate to net.

pzinn commented 1 year ago

OK sounds good -- then maybe I'm worrying about nothing, maybe just relaxing slightly validate along the lines of what you said would be good enough. not closing yet this thread, will keep experimenting.

pzinn commented 1 year ago

BTW, just to give an idea of what I'm trying to achieve and why it involves a lot of non-Hypertext inside Hypertext, see https://www.unimelb-macaulay2.cloud.edu.au/?user=xxx (this is an experimental build) The difference is particularly visible in WebApp mode (note all the clickable links), but should work equally well in Standard mode.

DanGrayson commented 1 year ago

re: "accept non-Hypertext inside Hypertext"

The name "Hypertext" implies that the object should consist just of hyper-text.

mahrud commented 1 year ago

The name "Hypertext" implies that the object should consist just of hyper-text.

Except TEX, ExampleItem, LATER, LITERAL, MENU, TO, etc., so probably an incorrect implication.