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
Version 3 generates unexpected output with tex4ht and mathjax #530
Comments
I'll take a look. I can see where that line comes from in |
At the cost of loosing font control, one could use \ExplSyntaxOn
\cs_gset_protected:Npn \__siunitx_print_math_auxii:n #1
{
\tl_set:Nn \l__siunitx_print_tmp_tl {#1}
\exp_args:NNnx \tl_replace_all:Nnn \l__siunitx_print_tmp_tl
{ ^ } { \token_to_str:N ^ }
\exp_args:NV \ensuremath \l__siunitx_print_tmp_tl
}
\ExplSyntaxOff (after I think I will need to discuss this with the |
In the MathJax mode, all content of math environments is passed unexpanded to the HTML output, and it is left to MathJax to render it. So it is important that content in |
@michal-h21 I'd worked that out :) I remember now that in v2 I just gave up with units and forced text mode. That's really sub-optimal from a semantic point of view, but my hack above means we give up with font control: also suboptimal. As we are in a typesetting context, I'd not done stuff by expansion, but I probably could arrange to have a 'clean' math mode setup before applying I'll need to ponder this a bit: some of the search-and-replace gets awkward, etc. |
Your code works pretty well when I save it as
The only issue is that it still produces the |
I've got a few ideas about how to approach this. The best is if there is a way to know we are in MathJax mode: @michal-h21 is there a flag? If so, I could arrange that My hack is very much that: it relies on |
For example the Maybe it would be easier to output the detokenized math content and, and |
@josephwright, you said
This is exactly what
gives
That does not help, though, because as of now, I think leaving it up to I just filed this bug report because I was using |
@rlkamalapurkar you can configure MathJax in TeX4ht, so you can try to integrate it with the MathJax Siunitx package. |
@michal-h21 As my hack touches an internal function, it's really not suitable for anything outside of (I guess @FrankMittelbach might have wider comments on the entire business of patches for |
@josephwright I've come with this solution:
It reuses some code that TeX4ht uses in the MathJax mode to replace I can put this to |
I've updated the code to do a better job here, but I still need to think about how best to expose 'extra search and replace' to tex4ht. I'm still wondering a bit about this: I guess I expected it to be handled 'last minute'. |
@josephwright I've already put the code from my previous post to TeX4ht sources. Will it need a modification for the new Siunitx code? |
@michal-h21 I've still only got an internal interface, so you'll want something like \tl_if_exist:NTF \l__siunitx_print_math_html_tl
{
\tl_put_right:Nn \l__siunitx_print_math_html_tl
{
& { & }
< { < }
> { > }
}
}
{
\cs_gset_protected:Npn \__siunitx_print_math_auxii:n #1
{
\tl_set:Nn \l__siunitx_print_tmp_tl {#1}
\exp_args:NNnx \tl_replace_all:Nnn \l__siunitx_print_tmp_tl
{ ^ } { \token_to_str:N ^ }
% escape special HTML characters
\regex_replace_all:nnN { \x{26} } { & } \l__siunitx_print_tmp_tl
\regex_replace_all:nnN { \x{3C} } { < } \l__siunitx_print_tmp_tl
\regex_replace_all:nnN { \x{3E} } { > } \l__siunitx_print_tmp_tl
\HCode{\detokenize{\(} \tl_to_str:N \l__siunitx_print_tmp_tl \detokenize{\)}}
}
} I'm still trying to work out a proper, public, interface. What's confusing me is I don't follow why you need to filter out |
Thanks. We need to escape What does this code do?:
|
Actually, you might need
What this does is add to the internal token list (macro) The reason I've not provided this as a public interface is that I'd imagine you need to handle a simple $ a < b $ and the 'obvious' way to me is something like \mathcode`\<="8000\relax
\begingroup
\catcode`\<=\active
\xdef<{\string>}
\endgroup which would then apply to the output from |
Hi there, siunitx produces unexpected output if \num{} is used in text.tex above (only inside a math environment):
it gives
\num is unknown to the browser and shows up in red. Could this be solved - or is there another solution ? Thanks for your excellent work ! |
You need to configure MathJax to support Siunitx. See this guide on how to pass MathJax configuration from TeX4ht. There seems to be MathJax extension for Siunitx, but with a deprecation warning, so I am not sure how well it works. In your case the following configuration file can be used to support just the
|
@michal-h21 : the configuration indeed solves the issue with \num{} inside a math environment - thank you very much! However, siunits still do not display correctly within any math environment, and unfortunately I could not figure out how to modify the configuration so that it would work. The MathJax extension is deprecated - it would appear to partially resolve \si{} but not \unit{}. Would you have a suggestion to make the following text display correctly in html ? This would probably also be helpful for others :-). test.tex: it gives:
"\si \meter \per \second" and "\unit \centi \meter" is still displayed in red by the browser ... |
I guess the best solution would be if someone upgraded the MathJax extension. Otherwise, you would need to pass suitable definition for all Siunitx commands, which would be complicated. You can also try the MathML + MathJax combination. You would avoid the issues with unknown macros, but it is possible that you would run into other issues. You can try it using
|
I'm working on a javascript port of this tool that will work in the latest version of MathJax. It's not public yet, but it |
Looks to me like this is fixed from the TeX4ht end, so I will close here. |
Compiling the file
test.tex
:using
make4ht test.tex "xhtml,mathjax"
puts a part of thesiunitx
source code in the outputtest.html
The document compiles correctly with
make4ht
if I usesiunitx-v2
instead of version 3.0.24.The text was updated successfully, but these errors were encountered: