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

Mimicking LaTeX Physics Package #16

Merged
merged 6 commits into from
Oct 28, 2015
Merged

Mimicking LaTeX Physics Package #16

merged 6 commits into from
Oct 28, 2015

Conversation

ickc
Copy link
Contributor

@ickc ickc commented Feb 12, 2015

In LaTeX, when you \usepackage{physics}, you used the LaTeX Physics Package.
This extension is to mimick that in MathJax.

@pkra
Copy link
Contributor

pkra commented Feb 12, 2015

Very cool! This is an awesome addition and looks good to me.

There's only a small, formal problem: you should add licensing information to both the packed and the unpacked extension. Otherwise, your code has no actual license :-( You might want to compare how the other extensions do it.

@ickc
Copy link
Contributor Author

ickc commented Feb 12, 2015

Thanks! This is the first time I submitted anything open source so I missed that. I thought the license.txt is enough.

I also want to ask a question: in the Physics package in LaTeX, some commands are defined with optional arguments.
e.g. \dv (differentials) have the following possibilities:

  • optional boolean: \dv or \dv*,
  • and each of them can have an optional [] like \dv[]{} or \dv{},
  • and then it can also have variable no. of arguments like \dv{} and \dv{}{}.

Are there a way to write MathJax Macro like this too? Thanks!

@pkra
Copy link
Contributor

pkra commented Feb 16, 2015

Sorry for the delay, I was travelling. Thanks for updating the PR.

Regarding the questions,

@ickc
Copy link
Contributor Author

ickc commented Feb 18, 2015

Thanks for the reply. I tried to follow the first link and write something like:
Macros: {
vb: ['\mathbf'],
'vb*': ['\boldsymbol']
}
But it seems it doesn't work. The difference is in the AMSmath the * appears in an environment, but I want to include it in a Macros. What did I miss?
Thanks again.

@pkra
Copy link
Contributor

pkra commented Feb 18, 2015

Hm. I'm not sure what's happening. @dpvc could you help out?

@dpvc
Copy link
Member

dpvc commented Feb 18, 2015

Macro names in TeX are either a single character (like \{) or a string or alphabetic characters (like \sum). You can't mix non-alphabetic with alphabetic characters, and that even includes numbers (technically, it can be done, but requires changing the category codes of the non-alphabetic characters, which MathJax doesn't support). So you can't define \vb* separately from \vb even in true TeX.

What \vb does in TeX is look at the next character after the macro to see if it is an asterisk and does one thing if it is and a different thing if it isn't. You can do that in MathJax, but must do so through javascript code. This is how most of the macros are defined in MathJax, and Peter was trying to point you to the code where this is done. He actually pointed to where environments are defined instead, which is a bit misleading, since the starred and unstarred versions are handled separately. A better example might be to look at operatorname, which is defined by the javascript function HandleOperatorName. This uses the GetStar() function to determine if there is a star following the control sequence or not. This also might be a good one to look at because it does a string substitution (like a macro) rather than building the internal MathML structure directly.

I notice that a number of the macros in the physics package allow arguments in parentheses as well as braces. For that, you would need to do something like the GetStar() function, but look for parentheses instead, and then search ahead for the closing parenthesis to get the argument. This can be done using the GetUpTo() function. There are several other service routines in the same area (like GetArgument(), GetBrackets(), ParseArg() and ParseUpTo()) that you will find useful if you want to implement more of the physics package functionality.

At some point, you will probably need to produce the internal MathML rather than just do string substitutions. You should look at the functions in the TeX input jax, like Frac, and the others nearby for examples of how that is done. See also the Extension Authoring wiki page for some more details.

It would be great to have some more good examples of this, so if you want to extend the functionality of your physics extension, that would be great. You can ask questions here, or on the MathJax Development Forum.

@pkra
Copy link
Contributor

pkra commented Mar 18, 2015

@kolencheung did you want to work on this some more or should I merge it?

pkra added a commit that referenced this pull request Oct 28, 2015
@pkra pkra merged commit d9c4f8c into mathjax:master Oct 28, 2015
@ickc ickc deleted the patch-1 branch January 19, 2016 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants