MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

\textdegree macro not working

Open andersweinstein opened this issue 2 years ago • 10 comments

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.

andersweinstein avatar Jan 31 '24 01:01 andersweinstein

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

pkra avatar Feb 01 '24 16:02 pkra

Corrected; does not change problem.

andersweinstein avatar Feb 01 '24 17:02 andersweinstein

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

pkra avatar Feb 01 '24 18:02 pkra

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).

andersweinstein avatar Feb 01 '24 19:02 andersweinstein

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.

dpvc avatar Feb 01 '24 19:02 dpvc

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

andersweinstein avatar Feb 01 '24 19:02 andersweinstein

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 avatar Feb 01 '24 19:02 dpvc

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.

dpvc avatar Feb 06 '24 21:02 dpvc

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.

andersweinstein avatar Feb 06 '24 23:02 andersweinstein

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

dpvc avatar Feb 08 '24 01:02 dpvc