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
SCDoc: add MathJax for rendering math #6260
SCDoc: add MathJax for rendering math #6260
Conversation
Converted PDF from the corresponding reference in SCDoc included in this PR: |
Thanks for your work on this @prko! In the doc renderer, Would it make more sense to implement a new modal tag, such as In that case, the user would specify, e.g., I can't comment on the how the new library is included because I'm unfamiliar with how that can/should work. |
In the original PR (#6254), the maths parsing was in `*renderToFile': As I read @Nathn's review:
I was not sure what the following sentence meant:
I interpreted it to mean that the parser should be inside appropriate modal tags. (Whether the maths parser should be inside \strong and \soft tags is not clear, but I think strong and soft might be needed sometimes). By moving the maths parser to
Yes, this is true! The parser
You are absolutely right, but adding a new SCDoc modal tag is hard coded, and it seems to require adding a lexer in some So the current way works best from my amateur programming level. Unless someone who can modify the appropriate parts of the source file wants to implement MathJax in SCDoc, I think a soft-coded implementation similar to the way suggested in this PR seems to be the only way to implement this feature.
I want to say four things:
Anyway. I will think about how to reduce unnecessary parsing attempts... |
My honest opinion is that this is a really bad idea from the get-go. SC is already tremendously bloated in terms of dependencies. This makes the problem worse. It makes every SC download from now on bundle MathJax with it. (Also much better to make it a git submodule than check in all the files, but that's beside the point.) SCDoc is not a professional markup language, it's a simple and lightweight system fulfilling the basic needs of SC and its users. (If you need a full-featured markup language, use any reStructuredText or Markdown parser out there.) I am completely unconvinced of the demand for MathJax as a feature and I recommend that this PR be closed. I am strongly opposed to the addition of MathJax to SCDoc at all, in any form. |
@nhthn
So I included MathJax.... Now you say again that including MathJax is a bad idea. This is sad to hear, but I still want to learn and find a better way.
Could you let me know if there is a way to use the git submodule within SCDoc?
It is sad for me. I have already written more than 800 pages with SCDoc... For me, SC-Doc is not bad because I can create teaching material for online access from SuperCollider HelpBrowser and for PDF. I think I can combine these PDFs as one and use it for a book publication. The problem with SCDoc is that it lacks readability and some features. So I am trying to improve the SCDoc feature. If you think I am making a wrong attempt, could you please tell me a good markup language to do it like SCDoc with a good feature to print as a paper book? I do not think it is such a good idea to convert more than 800 pages into another language, but I should change if I am doing completely wrong things (for me and also for the development of SC. I thought it might be a good idea to help improve SCDoc.).
OK, I see what you think, but I'd like to keep this open for at least a couple of weeks to see what other people think. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
FWIW I think there are a number of people that would find math rendering support very useful. We knew that the devil would be in the details of how MathJax could be supported offline/static, how heavy it is, and what the maintenance overhead would be. This was an important proof-of-concept to show what can be done, and I appreciate the work that @prko has put into this! I think it's worth keeping the PR open to hear more thoughts if people have them, especially if someone can detail why this specific library can or cannot be maintained—I'm unfamiliar with this in practice and I'm not gaining any insight so far from the argument that "dependencies are bad". Is it all or nothing?
Is this the case? It looks like only a subset is required, as reflected in @prko's implementation. |
maybe i'm missing something, but why not just insert the math formulas as png images? like for example in the Shaper helpfile. |
@redFrik 1. The use of various mathematical symbols in sclang is currently very limited.The pi symbol can be used by copying it from the internet or a character map, but other symbols can only be used via an image, but the image cannot be placed in a paragraph with text. 2. Mathematical expressions in sclang are not so ideal for readability when inline with the flow of text in a paragraph.3. Images cannot be inline with the text flow in a paragraph.4. Using LaTeX via MathJax in sclang dramatically reduces the amount of work and makes the workflow more flexible.I have already created about 750 image files for use in various SCDocs:
Taking screenshots and saving them as images requires extra work:
It takes extra time and increases the number of image files. Some operations were not too bad. However, some were very time consuming and it is a big barrier to writing documents. If mathematical expressions can be done in sclang, we can use that time for something else, because using LaTeX via MathJax in sclang dramatically reduces the amount of work and makes the workflow more flexible: |
Just to echo @prko that it's great you've put so much work into this, and even if it doesn't go forward, I hope it's at least been useful in developing your skills. I think I agree that we should be careful about adding a new dependency. It might be better as some have suggested to look at converting the doc to a different format that provides builtin support for math symbols. If you're interested in that, I think it would be best to agree a strategy before investing too much effort. This would necessarily involve a lot of automated conversion. I think we'd need to provide simple tools for Quark authors etc to convert to minimise friction. If that could be done in a way which reduced overall maintenance demands, I think you'd have a runner. |
@smoge Thanks for considering the specifics of the proposal more closely. The sooner we can arrive at an optimal way to include the library, the conversation can be grounded in the practical issues of maintenance. Implementation on the SCDoc renderer side is secondary.
Could you elaborate with regard to the way this PR is currently including the library?
I'm unfamiliar with web rendering tech. What aspects of this library might require updating in the future? Given that it's rendering to HTML, I'd imagine this doesn't evolve much over time, and we might even be able to pin to a particular version/submodule and it will "just work" into the future? (i.e. no updates needed?) |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
|
We can make one file just with what we will need. That will be the most efficient way. It does not need anything more. No node.js, no internet connection, nothing, just the help browser. @prko already did a proof-of-concept, so we know it works. |
On the MathJax version of this PR
The MathJax version of this PR is version 3. According to the following link: I downloaded it by running the following command in a terminal:
Basically, we may only need the following two files, which are referenced in this PR:
However, I am not sure if I can delete all the other files as I seem to have found some links to other folders in the file I think we need to inspect the inside of this file, but I do not understand javascript. Maintaining MathJaxAs far as I understand, there is only one thing to maintain to implement MathJax into SuperCollider: Linking the updated version of the updated version of MathJax if we want. The current official version of MathJax is 3, but MathJax 2 is still hosted online by the MathJax development team. They have also released version 4 beta. MathJax will be included in the SC release if this PR is approved. Then, in theory, we won't have to do any maintenance, unless at least one user wants to upgrade the MathJax in SC from version 3 to any future version, or the use of version 3 is forbidden by the MathJax development team. As a composer and music theorist, MathJax 3 is already too rich for me. So, at least for me, I won't want to upgrade MathJax from 3 to 4, because I don't know the deep level of mathematics. On removing MathML support
I also thought it would be better to remove MathML, because it is too long to type and too complicated to use with a reference manual. The reason I did not remove it is only because of the time I spent investigating it: when I could not configure LaTeX to use teletype text, MathML worked. So I added the necessary code to make MathML work with
By removing MathML support, I basically need just the following lines:
to
Also the following code and its related parts are needed to write the documentation as SCDoc:
On using LaTeX in SCDoc
On the need to implement MathJax in SuperCollider
I would say that there are many advantages to implementing MathJax in SuperCollider. However, I would shorten the list of advantages of implementing MathMax in SC by mentioning only the first one: it is possible to write beautiful and readable help documents.
As @JordanHendersonMusic mentioned, teaching SC is already a huge task, but I think it would be more enjoyable if we could have a "readability-improved" help document. Please see the attached images below, comparing the left (using LaTeX via MathJax) and the right (current help documents) on each image. Which style would be better for SC newcomers? |
@prko I think we agreed on all the important points. Right? We need to discuss the implementation. I think we can clean up and simplify a lot. I've written about it above. Let's keep just Also, use the asynchronous configuration for the library, it will make the pages load as fast as they do today, and the math will be rendered with lower priority. The code will be more beautiful, trust me and see. No regexp, no replace. Just write as any other SCDoc markup, and the library will do the hard work for you. I can't see why we would need anything more complicated than that. |
@prko Another thing. Let's try not to change too many help files. Let's just add this new feature in pages where it is important, for example, all digital filters and chaotic equations, etc. Don't try to change every square root and exponent in every file. No need for that. Try to be more minimalistic now. Let me know if you need anything. If you want I'm available to review as well. Good luck, comrade. |
This comment was marked as resolved.
This comment was marked as resolved.
I suggest we then support only LaTeX. (We can expand in the future if there is interest.)
Even better. But anyway I think rendering LaTeX is not necessary in these styling modal tags, and removing it should lower the number of times the latex parser is called. (Again, could be added later if desired.) I suggest we keep this PR minimally viable. Relatedly:
In fact, I'd say just do the Help file instructing on the use of the feature, and maybe one other Help file as an example. Leave other documentation changes to a future PR.
Can this be reflected in an update to this PR?
If you need help, I hope some others in this conversation who understand the details can assist! |
Here is a summary of the main opposition before getting a response from the lead developer of MathJax:
|
I am sorry to hear this and I can relate to your frustration. I still would really like and invite you to be part of participation as your input in discussion, code and motivation is really valuable and appreciated! I just want to find a good modus operandi together to tackle "controversial" topics such as this b/c I believe that just maintaining a status quo will just lead to a decay of contributions. Yet we should find and settle for a way that new features don't generate problems later down the road - we should be aware of them so we can make hopefully a good decision on this. As this was a feature before which was removed because of issues, people voiced concerns. Thank you for this summary! Maybe edit the top post to include it so others are able to catch up with the current state?
I think the direct use and embedding of MathML is indeed a bit strange and would limit schelp to HTML output. But that's where transpilers such as could
From my understanding the objection was regarding the necessity for online access in order to view the documentation properly.
I think you refer to the MathML export?
Although npm-world is a rather short-living environment, once something runs in the browser it gets broken or deprecated if we have a static js file. We are still using a 6 year old jquery and codemirror and it is still working and not generating (many) problems.
To which I somehow would somehow agree regarding to follow the unix philosophy, but I don't have the feeling that SC is pursuing this philosophy. Having SCDoc in the first place would be an example. I think having Math support within SCDoc would be a good feature and I would vouch for it, especially as you are so passionate about it. I yesterday went into the debian IRC and they said that most likely we have to modify the debian packaging - they suggested that we should get in contact with the package maintainer, which I will do today. I also tried out a small build with Temml yesterday with mixed results - it seems the used chromium engine (qt 5.15 is using chromium 87) is currently too old to render MathML properly (which is a pity) - it would have allowed to simply add 3 files which were together not exceeding 400kb. Simple things like inline vs Qt WebEngine |
Thank you for your response, @capital-G. To be clear, I was not refering to my participation and contribution to the SC community/project. When I see sensible people, with knoledge and openness, I'm more than happy to do teamwork on easy, medium, or hard tasks. I think my motivation to participate in this discussion, is because it's not a fair interchange as other situations. I see a lot of ideas circulating without arguments but imposed as dogmas (as if we were a Church). I'm not refering to you, or @mtmccrea. But some ex-developers in the last years created a "CREDO" and believe it's some kind of obvious "good practice in CS". But everyone knows that when you just repeat something without argumentation and debate, it's just a tautology, you're imposing something arbitrary. Besides, the way those strange opposition (without real arguments) did not follow The Code of Conduct, which I reproduce a relevant passage: --
-- I don't see here as a place for confrontation. I would much prefer to see Supercollider's GitHub a place of TUTORING, where knowledge circulates. A coder with less experience can grow much faster with senior developers pointing things here and there. The practical result of those attitudes of a very small number of people is pushing the project more and more into conservatism, and eventually, it will just lose its relevance. I don't want to see this. During the situation involving my name, I wrote a long letter about ethics in the SuperCollider community. I planned to make it public but to avoid more turbulence, I gave a copy only to the moderators. But I still believe ethical introspection must happen in this community until it becomes a very different place. |
@smoge thanks for your text. I think we should dissect and re-visit (edit: the social dynamics and interactions of this) thread/PR at another time and space in order to find a more fluent experience for everyone with less friction. This is very important. On the topic, as temml does not work, I tried to implement tex support via kaTeX, see develop...capital-G:supercollider:scdoc-katex kaTeX and MathJax have some different priorities and technical capabilities, but I think they are not too important here. More important to me seems that kaTeX is much easier to build and bundle b/c it does not require to load modules on-demand. Although there is a debian package for katex (https://packages.debian.org/sid/katex), the package is used to install katex as a CLI, therefore it is not applicable to the same/shared library approach within debian (at least to my understanding), eliminating this problem as well. |
Suggestion @capital-G: new PR, we will have a small team to help you One suggestion. I think your main expertise is probably HTML/JavaScript/web services. (Just a guess). Am I right? All information is available here in this thread, including primary information from communications with MathJax developers. All problems were solved. Most of the unknowns are not problems anymore. Just some elements, such as Debian packaging, still need some conclusions. I think you are a very good candidate to lead this project. You're at home in technical terms and can have a team with expertise in other things. We can design a plan in no time with the information available. Since you're already working with small changes in the SCDoc parser, that would be a good task to be coupled together anyway. Again, if you are willing to lead a team like this, with respect among comrades, I would very glad to help if needed. |
One suggestion regarding packaging: what if we package MathJax exactly as it's provided on CDNs (e.g. I believe a single, minified js file), and treat the copy in our sclang build as more or less a cached version of the CDN copy, for cases where a user either doesn't have internet, or chooses to use a local copy for other reasons (there can be an SCDoc flag for this). We don't need to include MathJax at all in the SuperCollider repo, we can simply pull down the version we want via e.g. cmake |
Done!
@smoge already mentioned it, and I told him that as far as I know, MathJax's result is better than KaTeX's... However,
Anyway, I think the Debian policy problem is currently the most important and the last problem to be solved. Including a script that installs the MathJax package in If you want to continue with KaTeX, I can close this PR, If someone implements the following
I will be happy to use it and I will be satisfied that my engagement has moved an expert mind.
Please compare the images below (one of them shows how the page looks like when the MathJax library is missing): |
Re mathjax caching, the cmake is relatively easy:
As well as including this in the files that are copied during install, along with our various .css files etc. Re the mathjax vs katex choice, Id suggest that a big priority here should be long-term stability - our documentation doesn't get updated much, and the SCDoc also doesn't get updated much (for good reason! these are the kinds of things you do right once and then leave alone, hopefully). One concern with Katex is that it's not yet 1.0 - it's explicitly using semantic versioning, which means we have no real guarantee of API stability at all. I guess it's worth considering what it would look like if, 1 or 2 years from now, Katex changes their API significantly, which would mean we would need to rewrite any Javascript code that touches it. This may not be a big deal, maybe we barely need to touch the library, but I think the "what would it take to update" is a really important thought experiment. |
Only advanced DSP, or some plugins for block signal notation or something like this, which we would not import anyway. Let's start with the simplest solution. The only thing I think is important is the LaTex synthax. Let's stick to it whatever library. |
In the post (#6260 (comment)), an image was not included correctly and has been fixed. Please compare the two images again to see what happens when the MahJax package is missing or broken.
In this PR, LaTeX code can be used in https://github.com/prko/supercollider/blob/18348356dfa3709ff0b7b13ab0fbc53a8652bb44/SCClassLibrary/SCDoc/SCDocRenderer.sc#L255 Does KaTex is known for faster rendering than MathJax, but KaTex does not render all LaTeX code. https://www.intmath.com/cg5/katex-mathjax-comparison.php There is some code that KaTeX does not render (arrows and symbols): The quality of both is not that different, and the speed is KaTex does not seem to be really faster than MathJax on my end, if I understand the table entitled Timings. Thanks for your response! I think your suggestion seems to resolve all the problems. However, according to @capital-G, your solution seems to be based on online access to MathJax server. Then, I think some developers who pointed out that the MathMax package should be shipped with SC would not accept it even though it is limited to Debian... Do I understand it correctly? As my knowledge regarding this is not enough, I should rely on the interpretation of other developers. I am sorry for that. @smoge |
Um... As far as I am concerned, the decision to close this PR and wait for @capital-G's PR is not up to me, but that of the other developers. As I am not a professional developer, I do not know all the underlying issues. So if @capital-G still writes that KaTex is better than MathJax for SC after reading this post, I should believe him until some other developer has an opinion that supports this PR with enough convincing reasons. Please keep in mind the following four things:
My verdict: What is your verdict? |
Update MathJax_LaTeX_MathML.schelp: typo correction
local functions within `.renderSubTree` are converted to methods and the corresponding parts are modified.
reflected the review by @smoge
remove unnecessary and wrong comments
Updated according to the old MathJax support version (before 16 July 2013).
Updated according to the old MathJax support version (before 16 July 2013). - `lex.scdoc.cpp`, `SCDoc.tab.cpp` and `SCDoc.tab.hpp` are reproduced with the restored `SCDoc.l` and `SCDoc.y`.
Updated according to the old MathJax support version (before 16 July 2013).
1834835
to
878fe65
Compare
Oh, I did `rebase' the branch linked to this PR to reflect the new changes from the merged commits, as this is the recommended way to do a branch update. Um... this seems to delete all the commit history. I cannot see what I have been doing for a month..... |
I am closing this PR since @capital-G suggested #6317. I think I think the way to do it for Debian policy in this PR does not cause any problems, but as I am not an expert in this area, I follow the opinion of @capital-G. Thanks to @capital-G for implementing KaTeX, and I am glad that my involvement at least got you to implement the math feature for SCDoc! |
MathJax has some more features than kaTeX, but I really think that these are not really common or not part of the LaTeX standard at all, like the mentioned schematic diagram. For a full list of available functions see https://katex.org/docs/support_table The graphic could suggest that evergreens such as On the other hand, the output of kaTeX actually matches the typesetting of LaTeX, so you also have features in kaTeX that you don't have in mathJaX.
I am really grateful for your dedication to implementing this feature, which was the reason I sat down and tried it once again kaTeX which I think has more chances against the mentioned opposition. Personally, I am not too interested in TeX support, although I support adding this feature, and thought I could use my expertise to get this in. I hope I didn't create any bad feelings by creating the 2nd PR :/ |
I just wanted to say a big thank you for the extra info. With this info, I'm fully happy now! I hope your PR gets the green light as soon as possible! Your hard work, effort and time for the needs of all users are much appreciated! |
ADDED :
As this PR has been modified several times, along with many discussions and some reviews, please read the following post on this PR:
SCDoc: add MathJax for rendering math #6260 (comment)
A summary of the main objection to the initial commit of this PR and the author's reaction:
SCDoc: add MathJax for rendering math #6260 (comment)
The state as of around 17 May 2024:
SCDoc: add MathJax for rendering math #6260 (comment)
math::
is restored(done by adding code to CMakeLists.txt and tested successfully)
A MathJax package that does not conflict with Debian policy should be automatically installed when building.
Currently, using
npm
is the easiest way, at least from the point of view of the author of this PR.INITIAL POST:
With this PR, we can represent mathematical expressions using LaTeX and MathML without an internet connection.
Purpose and Motivation
I have spent a lot of time using SC-Doc to write course material for my Digital Sound Production lecture, as SuperCollider is one of the key tools in the course. My students have suffered from the lack of a reader friendly layout in SCdoc and I have also found that there are some editing features missing in SCdoc. One of these is the lack of mathematical expressions. Currently, to include reader-friendly mathematical expressions, we have to use graphics from other software such as LaTeX, but this is time consuming and tedious to edit. With this PR, we can save a lot of time and energy, and productivity will increase.
In the following thread are some reactions to the idea of implementing LaTeX and MathML in SCdoc:
https://scsynth.org/t/scdoc-schelp-style-add-on-latex-mathml-subsubsection-multimedia-file-iframe-sub-sup-small-line-height-hr/9242
This PR is a revised PR of the relevant part of the following PR #6254
I think I have incorporated all the opinions of @nhthn and @jrsurge in this new PR.
Types of changes
To-do list