Mathjax is incorrectly rendered - mathjax

I noticed that MathJax is incorrectly rendered.
Here https://www.emathhelp.net/calculators/calculus-2/integral-calculator/?f=xsinx&var=&steps=on
under "the integral of the cosine is ..." only integral of cosine on left-hand-side and sine on the right-hand side should be red, not equal sign and -xcos(x).
However, when I click "show math as tex commands", I get - x \cos{\left(x \right)} + \color{red}{\int{\cos{\left(x \right)} d x}} = - x \cos{\left(x \right)} + \color{red}{\sin{\left(x \right)}} and this is the string without any errors.
What is causing incorrect color rendering?

The site you link to uses the color extension for MathJax, which redefines the \color macro to be compatible with the LaTeX version. In LaTeX, \color is a switch that changes the color from there on, rather than MathJax's version where \color takes an argument that is what to be colored. So something like \color{red}{x} + y usually would produce a red "x" and a black "+ y", but with the color extension would produce red "x + y". This is why you are seeing completely red expressions in the website you linked to.

Related

plotshape - text colour displayed incorrectly with user defined input variables

There seems to be a bug in the compiler of Pine Script, in this below example the use of a variable called transp sets a user definable input value for the transparency of a given colour.
Yet when using plotshape and bgcolor it has inconsistent results. bgcolour works as expected, plotshape however behaves very oddly. It sets the colour correctly for the plotted shape using style=shape.cross, but it fails to understand the colour instruction for the text = ‘hi’ or text = ‘lo’. In this case it uses the default colour of blue.
If you change transp to a set integer like transp = 80, it then works correctly and displays both the shape and text in the given colour. This is incredibly bogus, if it merely didn’t accept variables assigned to user inputs for transparency then it would affect both shape and text. You could also just enter the color.new expression straight into plotshape, and this works in the same way, use a variable for transparency that has a user input associated to it and it will not work correctly, use a hardcoded integer assignment and it works fine.
//#version=5
indicator(title='RSI and test colour variable', shorttitle='Colour test', overlay=false)
transp = input.int(60, minval=0, maxval=100, title='Transparency:')
blue = color.new(color.blue, 0)
green = color.new(color.green, transp)
red = color.new(color.red, transp)
white = color.new(color.white, 0)
lower = 30
higher = 60
Len = input(title='RSI Length:', defval=10)
Src = input(title='RSI Source:', defval=close)
rsi = ta.rsi(Src, Len)
plot(rsi, color=white)
plot(lower, color=blue)
plot(higher, color=blue)
plotshape (rsi > higher, location=location.top, color=green, style=shape.cross, text='Hi', size=size.tiny)
bgcolor (rsi > higher ? green : na)
plotshape (rsi < lower, location=location.top, color=red, style=shape.cross, text='Lo', size=size.tiny)
bgcolor (rsi < lower ? red : na)
I have looked over this and tried every conceivable permutation to the code to get around this, and it always responds in the same incoherent manner. It took sometime to actually realise what the issue was, this is clearly a bug, not overly fatal, but it’s not an ideal presentation, and I can’t move on with this bug looking at me, still bugging me. ;o\
Any work-arounds?
Although it might not be the reason, it does not necessarily need to be a user defined input. The value needs to be known at compile time.
If you try transp=close > 2 ? 40 : 80, you will get the same behavior.
Some more info.
As a workaround, use the textcolor parameter.
plotshape (rsi > higher, location=location.top, color=green, textcolor=green, style=shape.cross, text='Hi', size=size.tiny)
plotshape (rsi < lower, location=location.top, color=red, textcolor=red, style=shape.cross, text='Lo', size=size.tiny)

How to tell if a color is imaginary/impossible?

Short version
How can I tell if a color (e.g. XYZ) is impossible? (Wikipedia: Imposible color)
For example, this color is impossible:
XYZ: (15.96, 84.04, 0)
xyY: (0.1595, 0.8404, 0.8404)
Lab: (93, -196, 161) (D65 whitepoint)
It's impossible because it lies outside of the chromacity diagram:
How can I know that?
Incorrect code
The goal is for someone to fill in the function:
Boolean IsImaginaryColor(Single X, Single Y, Single Z)
{
//...TODO: Get someone to answer the question.
}
Right now we know that if any of the components of a corresponding LMS color are negative, then the color is imaginary.
That is a necessary, but not sufficient, condition for a color to be real. You can have all three components of LMS be positive, but it still be an imaginary color.
Boolean IsImaginaryColor(Single X, Single Y, Single Z)
{
//If any component of LMS color is negative,
//then the color is definitely imaginary.
LMSColor lms = XYZtoLMS(X, Y, Z);
if ((lms.L < 0) or (lms.M < 0) or (lms.S < 0))
return true;
//The color may still be imaginary,
//but i don't know how to solve that problem
//So as a first approximation i'll say it's real
return false;
}
LMSColor XYZtoLMS(Single X, Single Y, Single Z)
{
//perform Matrix multiplication:
//
// LMS = M * XYZ
//
// Where M is the M_CAT02 transformation matrix from CIECAM02
//
// 0.7328, 0.4296, -0.1624
// -0.7036, 1.6975, 0.0061
// 0.0030, 0.0136, 0.9834
LMSColor result;
result.L = 0.7328*X + 0.4296*Y + -0.1624*Z
result.M = -0.7036*X + 1.6975*Y + 0.0061*Z
result.S = 0.0030*X + 0.0136*Y + 0.9834*Z
}
In the xy color plane, this gives a good first-approximation (and nice visual indication) of impossible colors:
But the calculation still gives colors outside the chromacity diagram *(technically they're outside the "spectral locus"). So obviously only checking for negative components in LMS is incomplete.
Long Version
I am rendering a color picker. For example:
to pick an Lab color
you pick an ab color
for a given L plane
This is similar to what you can already do in Photoshop:
So in this case I've picked the color:
Lab: (72, -58, 119)
That color (assuming the D65 whitepoint) corresponds to the XYZ color:
Lab: (72, -58, 119)
XYZ: (25.22, 43.66, 0.36)
You can tell if a real color is outside the sRGB color gamut if one of its components is either:
less than 0
greater than 255
This XYZ color lies outside of the sRGB color space because one of it's components is negative:
XYZ: (25.22, 43.66, 0.36)
Lab: (72, -58, 119) (D65)
RGB: (106.1, 199.6, -234.7) (sRGB)
Photoshop already knows if a color is outside the sRGB color gamut, and will display a gumut warning:
But I'd like to go one step further
I can already know if a color is outside the sRGB color gamut.
But now i want to know if a color is imaginary, so i can continue to show the gamut, but hide completely impossible colors. A conceptual mockup might be:
Warning: I have no idea which of those colors actually are impossible. This is only the idea of the concept.
So what I need to know is if a color is impossible.
Background Theory - What is an example of an impossible color?
The Wikipedia page on Impossible colors notes that while the primaries for the sRGB color space all lie inside the spectral locus - and so are all real colors:
The ProPhotoRGB color space does use some primaries that are impossible:
The ProPhoto RGB color space uses imaginary green and blue primaries to obtain a larger gamut (space inside the triangle) than would be possible with three real primaries. However, some real colors are still irreproducible.
So now I have a concrete example of an impossible color: the green primary of the ProPhoto RGB color space:
| Color | CIE x | CIE y |
|-------|--------|--------|
| red | 0.7347 | 0.2653 |
| green | 0.1596 | 0.8404 | <--- this one
| blue | 0.0366 | 0.0001 |
| white | 0.3457 | 0.3585 |
This impossible color, given different color spaces, is:
xyY: (0.1596, 0.8404, 0.8404)
XYZ: (15.96, 84.04, 0)
LMS: (47.80, 131.43, 1.19)
Lab: (93.4679, -195.9973, 161.1515)
LCHab: (93.4679, 253.7415, 140.5725)
How can I tell that this color is impossible?
Given an XYZ color, how can I tell that it is impossible? E.g.:
XYZ: 15.96, 84.04, 0
Bonus Chatter
It's important to note the difference between
colors existing outside some gamut
and imaginary colors
A quick single-image primer would be:
Gamut: a color may not be displayable on your monitor, or printer, or phone, but it is still a real color - you could get a combination of Electromagnetic Waves of various wavelengths and intensities to generate the color
Imaginary: No combination of EM waves, of any intensities, of any wavelengths, can generate that response in the Long, Medium, and Short human cones
I already know how to tell if a color exists outside a particular color gamut.
I want to know if a color also exists outside the spectral locus.
In other words: i want to know if it is imaginary.
Bruce Lindbloom has a nice graphic that raises the issues of colors outside the Lab color space when you arbitrary choose to arbitrarily limit the a and b component values to +- 128:
Bonus Reading
https://physics.stackexchange.com/q/94375/
Determine that a Luv Color is non-imaginary
https://physics.stackexchange.com/questions/420614
This is a duplicate of the answer I gave here: Determine that a Luv Color is non-imaginary which relate to https://stackoverflow.com/a/48396021/931625
I think the safe way is to compute the XYZ volume boundaries and check if you are within or outside.

how to display numbers in scientific notation in plot legends in Matlab?

I have two float variables, let's say they are phi = 1.34e8 and beta = -2.7e-6. How do I display both results in a plot label in latex scientific notation over two lines? I want the plot label to look like (in latex font):
\phi = 1.34 x 10^8
\beta = -2.7 x 10^-6
And what about I have other variables for error, e.g. phi_err = 7.1e7, and I want the legend to look like:
\phi = (1.34 +/- 0.71) x 10^8
Edit:
My current Matlab code:
txt1 = texlabel(['n2=',num2str(n2)]);
txt2 = texlabel(['beta=',num2str(beta)]);
figure(1)
plot(...)
text(0.7,0.8,{txt1,txt2},'Units','normalized')
And the plot text looks like the upper part of the attached figure. How do I display the text in scientific notation with the multiply sign and the base 10 instead of e? Also, if I want to add the error (let's say I set in Matlab beta=[-2.7e-6, 1.2e-6] where beta(1) is the value and beta(2) is the error), then show should I modify the above code so that the result looks like the lower part of the attached figure? For the example I give, how do I extract 2.7 and 1.2 before the e? And what if they are of different order of magnitude, e.g. the error is 1.2e-7, which means in the displayed text I have to change it from 1.2e-7 to 0.12e-6 and combine the error and the beta value.

How to get colors with the same perceived brightness?

Is there a tool / program / color system that enables you to get colors of the same luminance (perceived brightness)?
Say I pick a color (determine RGB values) and the program gives me all the colors around the color wheel with the same luminance but different hues?
I haven't seen such tool yet, all I came across were three different algorithms for color luminance:
(0.2126*R) + (0.7152*G) + (0.0722*B)
(0.299*R + 0.587*G + 0.114*B)
sqrt( 0.241*R^2 + 0.691*G^2 + 0.068*B^2 )
Just to be clear, I'm talking about color luminance / perceived brightness or whatever you want to call it - the attribute that encounters that we perceive red hue brighter than blue for example. (So 255,0,0 has higher luminance value than 0,0,255.)
P.S.: Does anyone know which algorithm is used to determine color luminence on this website: http://www.workwithcolor.com/hsl-color-picker-01.htm
It looks like they used none of the posted algorithms.
In the HSL color picker you linked to, it looks like they are using the 3rd Lightness equation given here, and then making it a percentage. So the equation is:
L = (100 * 0.5 * (max(r,g,b) + min(r,g,b))) / 255
Edit: Actually, I just realized that they have an L value and a Lum value shown on that color picker. The equation above applies to the L value, but I don't know how they are arriving at the Lum value. It doesn't seem to follow any of the standard equations.

How does one define double-lines for edge and node shapes in graphviz dot?

How can edges and nodes be styled using graphviz dot with doubled lines as shown the in the "LEGAL" and "TAX DISC" nodes of the following diagram?
Doubled shapes can be done by using [peripheries=2] on the node
Doubled edges can be done by specifying more than one colour for the edge, separated by a colon. In this case use the same colour twice: [color="black:black"] (or, to separate them slightly more, do [color="black:invis:black"])
I got there eventually! Sorry for the "evolutionary" nature of this answer :-)
So for example
graph G {
Foo [peripheries=2]
Foo -- Bar [color="black:white:black"]
}
The accepted answer is correct about using the peripheries attribute for multiple node outlines.
However, using the color white to draw widely-separated double edges between nodes is not ideal. If such an edge is drawn over a non-white background or crosses non-white objects, a white line will be visible. It is much better to use one of the colors none or invis. To update part of the example from the accepted answer:
graph G {
Foo [peripheries = 2]
Foo -- Bar [color = "black:invis:black"]
}
See the Graphviz color documentation for more information.
(See other answers about normal edges and nodes)
The three color solution does not work with directed edges with dir="back".
digraph A {
foo -> bar [dir = "back", color = "black:invis:black"];
}
results in this output:
I tried wrapping it with invis layers outside. Looks a bit weird compared to normal arrows because of the increased edge width, but at least it is understandable to readers:
digraph A {
foo -> bar [dir = "back", color = "invis:black:invis:black:invis"];
}
However this won't work with forward edges.

Resources