How to define custom macros in MathJax - macros

I'm trying to define custom macros used in LaTeX files in MathJax.
Can define simple macros (single parameter) without any issue such as;
\newcommand{\braket}[1]{\langle #1 \rangle}
as
Macros: {
braket: ['{\\langle #1 \\rangle}', 1]
}
But struggle with complicated ones;
\newcommand{\Abs}[2][]{\left\lvert#2\right\rvert_{\text{#1}}}
trying to define it like;
Macros: {
Abs: ['{\\left\\lvert#2\\rvert_{\\text{#1}}}', 2]
}
but no luck.
This is how it is used in LaTeX file
\begin{align}\nonumber
p_e = \Abs{\braket{e|\psi(t)}}^2 = \sin^2\Omega t\, .
\end{align}
Not sure where I did wrong.
I'm not a LaTeX expert, but just a developer trying to display LaTeX files on a web app (for Quantum Physics community), so I would greatly appreciate your help. thanks.
P.S this question was asked and closed on SE they redirected me to SO.

I've updated the codepen from my comment.
Primarliy, you forgot a \\right; I also modified your macro definition so that it has an optional parameter. In other words, something along the lines of:
Macros: {
braket: ['{\\langle #1 \\rangle}', 1],
Abs: ['\\left\\lvert #2 \\right\\rvert_{\\text{#1}}', 2, ""]
}},

Related

Example third person controler in Unity / StringToHash

I am trying to learn game development through different ways and sources and recently I have created a project in unity with example ThirdPersonController.
While looking through the code I came across one thing which I am finding difficult to wrap my mind around. It is "StringToHash". What is the purpose of this? Here is an example of variable with specified values set:
private void AssignAnimationIDs()
{
_animIDSpeed = Animator.StringToHash("Speed");
_animIDGrounded = Animator.StringToHash("Grounded");
_animIDJump = Animator.StringToHash("Jump");
_animIDFreeFall = Animator.StringToHash("FreeFall");
_animIDMotionSpeed = Animator.StringToHash("MotionSpeed");
}
and here is an example when this is used when being called:
if (_hasAnimator)
{
_animator.SetFloat(_animIDSpeed, _animationBlend);
_animator.SetFloat(_animIDMotionSpeed, inputMagnitude);
}
Welcome to Stack overflow.
Similar question already has been asked HERE . Unity Docs .
In your code below you changing values (parameters) of your animator. To find which values it should change it must compare the name of the value you gave in .SetFloat to the ones it has (in "parameters" section on "animator" tab).
You could do
.SetFloat("speed", _animationBlend);
But to get that milliseconds of time advantage (optimization) your "speed" is converted to integers first (like in your code above) and then you use it.

How to access the child nodes in a device tree (DTS) in Zephyr using DT_FOREACH_CHILD

I'm developing an application for an nRF52 SoC to access some external devices, kind of detectors in this case, so I have defined a custom format (and its corresponding yaml file) for my device access description node. It is kind of:
n: detectors {
compatible = "foo-detectors";
// Definition of first channel
det0: det_0 {
irq-pins = <13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Bar detector channel 1";
};
// Definition of second channel
det1: det_1 {
irq-pins = <17 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Bar detector channel 2";
};
};
Suppose I have a structure definition for holding data about the pins to which those devices are physically connected, say:
struct foo_detector_desc {
int irqpin;
int irqpin_flags;
}
Using Zephyr macros, I can use from my code the individual values for those nodes. For instance, DT_PROP_BY_IDX(DT_NODELABEL(det0), irq_pins, 0) expands to 13, DT_PROP_BY_IDX(DT_NODELABEL(det0), irq_pins, 1) expands to the value of OR'ed flags GPIO_PULL_UP | GPIO_ACTIVE_LOW.
But I don't want to create a ten-page code full of conditionals in the form DT_NODE_EXISTS(DT_ALIAS(det#)), but something more compact, flexible and maintainable.
I came across Zephyr macro DT_FOREACH_CHILD that is intended for being used in that scenario with which I can create a list with the labels, as showcased in the example embedded in the documentation:
#define LABEL_AND_COMMA(node_id) DT_LABEL(node_id),
const char *child_labels[] = {
DT_FOREACH_CHILD(DT_NODELABEL(n), LABEL_AND_COMMA)
};
Trying to use that for filling a static structures array, I tried following code but, yet it expands to two elements in the array, the structure fields are not initialised with desired values.
#define PIN_INFO_AND_COMMA(node_id) \
{ \
.pin=DT_PROP_BY_IDX(node_id, irq_pins, 0),\
.flags=DT_PROP_BY_IDX(node_id, irq_pins, 1),\
},
const struct detector_data _det_data[] = {
DT_FOREACH_CHILD(DT_NODELABEL(n), PIN_INFO_AND_COMMA)
};
I'm using Visual Studio Code with the nRF Connect plugin.
Is there a way to generate/see how those macros expand when compiled?
What is the correct way for initialising the structure fields (pins, flags)?
BR
It is possible to expand the macros one level at a time in VS Code. It is needed to click over the macro, then select it by double-clicking on it, and a bulb light will, eventually, show up. The option Insert Macro will replace the macro with its expansion.
Regarding using the DTS in code, the code I wrote in my previous post is OK, but I think I found a bug in the debugger. If I don't include any code using the value of _det_data, the debugger doesn't say the constant was optimised-out and displays wrong values when inspecting its content. That made me waste a lot of time.
For anyone interested on using DTS files for nRF devices in Zephyr, I posted all details in a thread in Nordic's developers forum (here).
BR

Can someone help me in Implementing XSSFilter

Can someone help me in Implementing XSSFilter, I need to check for XSS vulnerabilities in AEM code, I found that its method boolean check(ProtectionContext context, String src), checks for any XSS infected code, however what will be its context ? It would be nice if someone can share some example.
xssfilter=resourceResolver.adaptTo(XSSFilter.class);
String validjsonString = xssfilter.filter(jsonString);
LOGGER.debug("validjsonString:::::", validjsonString);
String[] uuidArray = getUUIDArray(validjsonString);
I am assuming that you are using the non-depracted Sling APIs here. In this case the ProtectionContext you are missing is coming from the following enum:
org.apache.sling.xss.ProtectionContext
The enum has two values:
HTML_HTML_CONTENT
Escape HTML for use inside element content (rules #6 and - to some degree - #1), using a policy to remove potentially malicous HTML
PLAIN_HTML_CONTENT
Escape plain text for use inside HTML content (rule #1)
Those rules mentioned in those definitions can be found here:
http://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet
So you could do either:
xssfilter.check(ProtectionContext.HTML_HTML_CONTENT, <your-string>);
xssfilter.check(ProtectionContext.PLAIN_HTML_CONTENT, <your-string>);
See: https://sling.apache.org/apidocs/sling11/org/apache/sling/xss/ProtectionContext.html#HTML_HTML_CONTENT

gwt gss lighten() and darken()

i was trying to use lighten() and darken() in GSS (i'm gwt 2.8 version and material-design rc4) like so:
#def MAIN_COLOR #64b5f6;
#def LIGHTER_COLOR lighter(MAIN_COLOR, 0.5);
.lighter {
color: LIGHTER_COLOR;
}
but the result is
.lighter {
color: lighter(#64b5f6,0.5)
}
i cannot find any sample of using those functions anywhere..
https://github.com/google/closure-stylesheets
i was expecting that those work like in SASS
$primary-color: #64b5f6;
$darken: darken($primary-color, 7%);
$lighten: lighten($primary-color, 20%);
thanks.
I can't reproduce your exact behaviour, but I have managed to get a working example and found the following:
The function name is lighten
The lighten function takes an integer number between 0 and 100 as the amount to lighten by. This is documented directly in the code on GitHub.
I've tried modifying your example as follows and it is working fine:
#def MAIN_COLOR #64b5f6;
#def LIGHTER_COLOR lighten(MAIN_COLOR, 5);
.lighter {
color: LIGHTER_COLOR;
}
This is evaluated, using the latest version of Closure Stylesheets (right now,
v1.4.0) to become the following:
.lighter{color:#7cc1f7}
I expect the number is a percentage lightness increase - that's the method I use in my own color software and is generally what other CSS preprocessor lightening/darkening functions use too - so you might need to play around to get the exact shade you're looking for.
I hope it works for you.

Mediawiki process tag after templates tranclusion

Is there any way to do something like that.
I have next wiki text:
{{template_open_tag}}
{{template_some_data}}
{{template_close_tag}}
And there are templates:
{{template_open_tag}}
<my-tag>
{{template_some_data}}
bla-bla-bla...
{{template_close_tag}}
</my-tag>
But tag '<bold>' processed already when first template transluded and wiki render this page like:
bla-bla-bla...
</my-tag>
But I want to see:
**bla-bla-bla...**
In my extension:
$wgHooks['ParserFirstCallInit'][] = 'myTagInit';
function myTagInit( &$parser ) {
$parser->setHook( 'my-tag', 'myTagRender' );
}
function myTagRender( $input, $args, $parser, $frame) {
return "**".$input."**";
}
Thank you.
P.S.
And don't ask me why I need this strange markup and don't want to use something like this:
{{template_tag|{{template_some_data}}}}
And {{template_open_tag}} like:
<my-tag>{{{1}}}</my-tag>
To warn you -- this sort of structure will likely be phased out entirely in future versions of MediaWiki, due to its inconsistent behavior and the difficulties it causes with structures like tags and sections.
The correct and future-proof way to do it is indeed to contain both your start and end in one template and pass the middle in as a parameter, eg {{template_tag|{{template_some_data}}}}
Set $wgUseTidy to true to make MediaWiki remove unclosed tags only after all the templates have been evaluated. Alternatively, you can use wikimarkup - as Adrian said - which does not suffer from this limitation.
Update: AFAIK XML-style extension tags are evaluated before way template including happens, so piecing them together from multiple templates is not possible. (Event <ext>{{{1}}}</ext> does not work pre-1.16, though you can make it work in 1.16 with recursiveTagParse.)
instead of using <bold> use ''' in both your {{template_open_tag}} and {{template_close_tag}} and it should render as bla-bla-bla...
Also, you can't do:
{{template_open_tag}}
{{template_some_data}}
{{template_close_tag}}
You have to do
{{template_open_tag}}{{template_some_data}}{{template_close_tag}}