-
Notifications
You must be signed in to change notification settings - Fork 44
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
How to add context menu in Non-Component-Based Examples? #10
Comments
The
should do it. (Add your See if that does the trick. |
Thanks for the reply! I added that package and imported it as you said, but got another error at TypeError: Cannot read property '_' of undefined
...
if (window.MathJax._.a11y && window.MathJax._.a11y.explorer) {
... It seems that menu module requires MathJax object to be added to window. I'm puzzled about where I can get this object, do you have any idea? |
The menu system is fairly dependent on the components architecture, as it does dynamic loading of some components on demand (like the assistive tools, including the explorer that you are seeing this message about). The components architecture uses the global variable There are two possible options. One would be to subclass the Menu class and the MenuHandler (to use your new class) and override the methods that reference Alternatively, you could define
which should get you past this problem. A quick look through the code indicates that There is a pull request (mathjax/MathJax-src#458) that should resolve this, so another option would be to get a copy of the modified |
Thanks for your advice! I added window.MathJax = {_: {}}; and commented out menu.findID('Accessibility', 'Explorer').disable();
menu.findID('Accessibility', 'AutoCollapse').disable();
menu.findID('Accessibility', 'Collapsible').disable(); in menu.js as they raises error because if (this.state() < STATE.CONTEXT_MENU) {
document.menu.addMenu(this);
this.state(STATE.CONTEXT_MENU);
} the state code of current math item is 200, but STATE.CONTEXT_MENU is 170, so it was not getting added. After I commented the if statement, all the math disappeared. I dig down into public addMenu(math: HTMLMATHITEM) {
const element = math.typesetRoot;
element.addEventListener('contextmenu', () => this.menu.mathItem = math, true);
element.addEventListener('keydown', () => this.menu.mathItem = math, true);
element.addEventListener('click', (event: MouseEvent) => this.zoom(event, 'Click', math), true);
element.addEventListener('dblclick', (event: MouseEvent) => this.zoom(event, 'DoubleClick', math), true);
this.menu.getStore().insert(element);
} It seems that I'm not sure if I was using it the correct way. I just want a neat way to integrate MathJax in my project using Typescript+Webpack, but found litte information about it. |
The issue with Once that is taken care of, everything works for me. This is my setup: menu.js
menu.html
webpack.config.js
With these files, the menu works fine for me. So there must be something else going on in your situation. As for the state value, note that if you did something like If that's not it, then it could be that the MathItem has already been processed once, and you are trying to process its again. In that case, the state is 200 from the previous time through the typesetting process, and that doesn't change (unless you specifically set it down again). So depending on how you are calling MathJax's typesetting functions, that could be the issue you are seeing. Anyway, I'm not able to reproduce the problem you seem to be having, so can't get any further with it than this. Sorry not to be able to help more. |
Thank you very much! I figured out the remaining state code problem on my project: The project is a single page application that display new contents dynamically, so I call html.processed.clear('findMath')
html.processed.clear('compile')
html.processed.clear('getMetrics')
html.processed.clear('typeset')
html.processed.clear('updateDocument')
html.processed.clear('context-menu')
html.findMath()
.compile()
.getMetrics()
.typeset()
.updateDocument()
.addMenu() for each rendering. since html.processed.clear('findMath')
html.processed.clear('compile')
html.processed.clear('getMetrics')
html.processed.clear('typeset')
html.processed.clear('updateDocument')
html.processed.clear('context-menu')
html.render() works fine. Thanks again for your help! |
Glad you have it worked out. Note also that you can replace the multiple
which clears all the processed markers at once. |
That's elegant! 😄 |
Correct menu name being disabled. (mathjax/MathJax-demos-node#10)
Is there any documentation or a Node demo on how to add the contextual menu? |
@AustenLamacraft, it is best to start a new issue rather than ask a new question within a 2-year-old closed one.
Can you be clearer about what you are asking to do? Are you preprocessing pages on the server and want the menu in the result? Or are you making a web application (as in the example above) and are calling the MathJax modules directly? Or is it something else? As mentioned above, the menu is highly dependent on the component architecture, so calling MathJax modules directly will make it difficult to use the menu, though the discussion above gives the outline of how to do that (though some things have changed since then). It is best to use MathJax components rather than direct calls in this case. If you are doing preprocessing and your final pages just include the MathJax output, then there is not current method for adding the MathJax menu to that. |
Sorry, I wasn't too sure where to put this question. I'm doing static rendering (with eleventy static site generator) so I'm basically using the example of a direct call in this repo. So I guess there's no way to add the menu at this point. |
We have plans to make a stand-alone menu feature, but that hasn't been done yet. So I'm afraid that there is no menu option for this at the moment. |
I'm working on a front-end project with typescript and webpack, codes below worked fine:
Then I tried to add context menu on right-click, but I did not find documents about it, after reading some source code, I added
, however, I'm getting the following error:
. So, what's the corrent way of adding context menu in Non-Component-Based Examples ? Thanks!
The text was updated successfully, but these errors were encountered: