I came across this nice integerological fact:

Define \(\operatorname{ord}_p(n)\) to be the power of \(p\) in the prime factorisation of \(n\).


\[ \sum_{k=1}^n\gcd(n,k) = \prod_{p|n} \left(1+\left(1-\frac{1}{p}\right) \cdot \operatorname{ord}_p(n)\right) \]

I don't know why you'd want to do this, and all the references I've found to it talk about it as a special case of some more general identities, but for some reason it appealed to me.

· · Web · 2 · 2 · 5

@christianp This is what your post looks like on Chrome for me. Console message "Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self' 'unsafe-inline' 'nonce-8y+JBue0utk/qEmjcn+/CA=='". Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list." Math has been rendered like this for months, and the last time I said anything the only response was more or less "works for me". Any idea how to fix?

@11011110 @christianp
I've been seeing the same. I checked the console and get the same error (~50 times), with different alphanumeric strings after "nonce-" at each reload (but the same in each of the errors for a given reload).

@11011110 @christianp AFAICT from a quick search, the only way to fix this without requiring major changes to MathJax would be to stop the HTTP server from sending the "style-src 'nonce-*'" policy in the "content-security-policy" response header, while keeping the "style-src 'unsafe-inline'" policy.

That would disable a mitigation against CSS injection, incompatible with MathJax on non Firefox browsers. On Firefox MathJax doesn't need inline CSS for rendering it seems.

@11011110 @christianp I'm not sure whether Mastodon relies on that mitigation. I would certainly consider it bad practice to do so, but it does provide an extra layer of defense in case of bugs in the Mastodon code base, so disabling it might not be desirable either.

In theory the 'nonce-*' policy would allow passing the nonce to MathJax, allowing it to tag the inline CSS as permitted, but in general that does not work for style attributes, only for style tags, and MathJax uses attributes.

Sorry, @11011110, I completely forgot about this!
Thanks for that info,@jix. It looks like I need to do some serious mathjax plumbing.

@mwt @11011110 @jix mathjax 3 does this weird thing where it makes up the styles for each bit of maths it typesets. I'm not sure what the optimisation is, but I think it's integral to how mathjax 3 works. I'll check, though

@mwt @11011110 @jix I'm looking at this today. I think I have a plan: I need to get MathJax to add the nonce value to the <style> tags it generates. Wish me luck!

(As a British person, I _really_ don't like writing the word 'nonce')

@christianp @mwt @11011110 I think you would also need to modify it to put all inline styles in <style> tags and not use any <other-element style="..."> attributes which don't support nonce values AFAICT. That's why I said passing the nonce value to MathJax would work only in theory... I assumed it would require too many changes to be practical.

@jix I don't think it's using style attributes, apart from on the top container element, and that style seems to be applied at the moment. I can't see any other style= attributes deeper in

@christianp Ah, makes sense, I didn't look any deeper than the top container where I saw the attribute :D

I think I've done it!

@mwt @11011110 @jix, can you check that MathJax displays properly for you? You might need to clear your cache, I'm not clear about how that works

@christianp It does render as formula now in chromium, but the alignment of most things isn't quite right (see screenshot). It seems that in Firefox that alignment is done using inline style attributes (e.g. on the mjx-over tag for the $n$ over the sum), but in chromium I don't see those attributes.

@christianp Wait, I do see the inline styles in chromium, I just got lost again in the tree of nodes MathJax generates, sorry for the confusion. Still it doesn't render them properly. If I disable and re-enable those styles in the style tab of the devtools, the alignment is fixed, so I assume the inline-style feature got more restrictive in newer versions. I'm on Chromium 89, and in Edge 91 I also see the alignment issues.

@jix ahhh, how annoying! I suppose MJ could make up a class for each thing that needs styling, and add it to the stylesheet?

@christianp Yeah, I think that should work AFAIUI and would also be what I'd try. Given that this is just for alignment, I'd hope that there is a single place in the MathJax code that needs to be changed for this.

@jix @christianp It's much much prettier than before for me. If there are minor alignment issues as @jix reports, I don't really notice them. Thanks for all the work!!

@christianp @11011110 @jix It looks great in Firefox and a little broken in Chrome. Maybe it works in Firefox because of native MathML styling?

@mwt thanks. It turns out my version of chrome was old, and now all style attributes on elements are ignored. You've probably got the latest version

@christianp yes these security updates can certainly make webapp maintenance a nightmare

Sign in to participate in the conversation

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!