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

Macros do not persist despite gdef and globalGroup #2513

Open
3 tasks done
recmo opened this issue Sep 14, 2020 · 2 comments
Open
3 tasks done

Macros do not persist despite gdef and globalGroup #2513

recmo opened this issue Sep 14, 2020 · 2 comments

Comments

@recmo
Copy link

recmo commented Sep 14, 2020

Before reporting a bug

Describe the bug:
Macros are forgotten between invocations of renderToString (and possibly render), even when globalGroup is set and \gdef is used.

katex.renderToString(String.raw`\gdef\foo{1}`);
katex.renderToString(String.raw`\foo`); // Fails
katex.renderToString(String.raw`\gdef\foo{1}`, { globalGroup: true });
katex.renderToString(String.raw`\foo`); // Fails

To Reproduce:
Steps to reproduce the behavior:

  1. Go to 'https://katex.org.'
  2. Open javascript console
  3. Enter either of the two examples above
  4. See error Uncaught ParseError: KaTeX parse error: Undefined control sequence: \foo at position 1: \̲f̲o̲o̲

Expected behavior:
Foo macro to expand because it was defined globally.

Screenshots:
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • KaTeX Version: 0.12.0
  • Device: Desktop
  • OS: MacOS 10.15.6 (19G2021)
  • Browser: Firefox
  • Version: 80.0.1 (64-bit)

Additional context:
I'm trying to define some globally available macros that require arguments. Doing this through the macros option seems extremely complicated and I can not find a working example, I'd much prefer parsing some \gdef statements. Unfortunately this does not work either.

@recmo recmo added the bug label Sep 14, 2020
@recmo
Copy link
Author

recmo commented Sep 14, 2020

After digging some more, the following seems to work:

var macros = {};
katex.renderToString(String.raw`\gdef\foo{1}`, { macros });
katex.renderToString(String.raw`\foo`, { macros })

This solves it for me, but it took me many hours to figure out.

@edemaine
Copy link
Member

Right, that's the intended behavior -- sorry it took you hours to figure out! Do you have a suggestion on where we (or you via PR) could mention this in the documentation that would have helped you find it sooner?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants