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

\textdegree macro not working #3170

Open
andersweinstein opened this issue Jan 31, 2024 · 10 comments
Open

\textdegree macro not working #3170

andersweinstein opened this issue Jan 31, 2024 · 10 comments
Labels
Accepted Issue has been reproduced by MathJax team Merged Merged into develop branch Test Needed v3
Milestone

Comments

@andersweinstein
Copy link

andersweinstein commented Jan 31, 2024

Issue Summary

MathJax showing \textdegree macro in red in math even though textcomp extension documented to contain it is required.
Also fails if textcomp explicitly loaded (though docs suggest require should be sufficient).

Steps to Reproduce:

Sample html file:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>textdegree test</title>
  <script>
  MathJax = {
    tex: {
      inlineMath: [['$', '$'], ['\\(', '\\)']],
      packages: ['base', 'ams', 'noerrors', 'noundefined', 'require', 'autoload', 'textcomp'],
      require: { defaultAllow: true, },
    },
    loader: {load: ['[tex]/textcomp']},
  };
  </script>
  <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
</head>
<body>
    <p>\[
    67 \require{textcomp}\textdegree F
    \]</p>
</body>
</html>

Technical details:

Seen in Chrome on MacOS.
Config details in sample file above.

Console shows
tex-chtml.html:12 Uncaught SyntaxError: Unexpected token ';'
though this does not appear to affect other equations from the demo.

Notes

I know many alternatives for showing a degree symbol so can rewrite the formula. However I have inherited content with legacy LaTex authored using the \textdegree macro and would like to understand why it does not work before changing all occurrences.

Documentation suggests \textdegree is included in the textcomp extension. Have not gotten any textcomp macro to render in these math expressions, suggesting perhaps something is wrong with the configuration, but can't see what the error is.

@pkra
Copy link
Contributor

pkra commented Feb 1, 2024

The tex: {}-block is missing its closing }.

@andersweinstein
Copy link
Author

Corrected; does not change problem.

@pkra
Copy link
Contributor

pkra commented Feb 1, 2024

works for me here https://jsbin.com/wokumonuti/1/edit?html,output

@andersweinstein
Copy link
Author

Ah, OK thanks. (Though note your example has the require:{...} outside the tex{...} block. )

Is there no way to get it through the \require{textcomp} alone, without explicitly including textcomp the loader list? You can see that taking out the loader line breaks it again (even after fixing require placement).

@dpvc
Copy link
Member

dpvc commented Feb 1, 2024

The textcomp package relies on the textmacros package, and although the \require macro is supposed to handle those dependencies, it looks like something isn't being set up properly when \require{textcomp} is used on its own. Adding [tex]/textcomp to the loader.load array means that both textcomp and its dependencies (i.e., textmacros) will be loaded, then \textdegree will work properly when either textcomp is included in the tex.packages list, or when \require{textcomp} is used (you don't need both).

I will be looking into why \require{textcomp} doesn't configure textmacros properly, but textmacros is a pretty complicated extension, so something subtle may be happening.

As for the require:{} block, the defaultAllow: true is the default, so the fact that it is misplaced didn't affect Peter's example. It is the fact that loader.load includes [tex]/textcomp that makes it work.

@andersweinstein
Copy link
Author

Thanks for the help. BTW I also tried including autoload: { textcomp: ['textdegree'], }, but that did not work by itself either.

@dpvc
Copy link
Member

dpvc commented Feb 1, 2024

autoload: { textcomp: ['textdegree'], } That uses the same mechanism as \require{textcomp}, and since that is what is not working, autoload won't help either. I haven't had the chance to track this down, but will let you know what I find when I do.

@dpvc
Copy link
Member

dpvc commented Feb 6, 2024

I figured out what was causing the \require{textcomp} to fail, while including it in the loader.load works. It turns out that when the required extension has dependencies, and one of those dependencies installs a pre-filter for the typesetting, the expression must be restarted so that those pre-filters will run. That gets done by the code throwing an error that is trapped higher up to force the expression to be re-typeset. But that error caused the configuring of the textcomp extension to be interrupted, and that was before the macros were defined, s when the expression was restarted, that resulted in the undefined macro.

I have made a PR to resolve the issue.

@andersweinstein
Copy link
Author

Thanks, and apologies for my errors. Trying to add \require{textcomp} or autoload config were my first attempts and then I flailed a bit tinkering with the config, but I guess there was a genuine issue.

@dpvc
Copy link
Member

dpvc commented Feb 8, 2024

No apologies needed. Your report lead me to fix an important issue in the require/autoload processing.

dpvc added a commit to mathjax/MathJax-src that referenced this issue Feb 12, 2024
Fix \require to properly handle retries in dependencies.  (mathjax/MathJax#3170)
@dpvc dpvc added Test Needed Merged Merged into develop branch and removed Ready for Review labels Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Merged Merged into develop branch Test Needed v3
Projects
None yet
Development

No branches or pull requests

3 participants