What is wrong with my MathJax square bracket syntax? - mathjax

This mathjax expression (in an asciidoctor document in a VS Code preview using asciidoctor-vscode) fails to render correctly:
stem:[ = x_l = x_( ([m]+1) /2) ]
The ] after the m acts like a ) for the _, and ends it early. How can I force the parser to understand my brackets please?

If the inline stem equation contains a right square bracket, you must escape this character using a backslash.
Found in Equations and Formulas (STEM), see example 4. What you want to write is:
stem:[ = x_l = x_( ([m\]+1) /2) ]

MathJax is rubbish, rather use latexmath:[ = x_l = x_{\frac{[m\]+1}{2}} ]

Related

Pyparsing - matching the outermost set of nested brackets

I'm trying to use pyparsing to build a parser that will match on all text within an arbitrarily nested set of brackets. If we consider a string like this:
"[A,[B,C],[D,E,F],G] Random Middle text [H,I,J]"
What I would like is for a parser to match in a way that it returns two matches:
[
"[A,[B,C],[D,E,F],G]",
"[H,I,J]"
]
I was able to accomplish a somewhat-working version of this using a barrage of originalTextFor mashed up with nestedExpr, but this breaks when your nesting is deeper than the number of OriginalTextFor expressions.
Is there a straightforward way to only match on the outermost expression grabbed by nestedExpr, or a way to modify its logic so that everything after the first paired match is treated as plaintext rather than being parsed?
update: One thing that seems to come close to what I want to accomplish is this modified version of the logic from nestedExpr:
def mynest(opener='{', closer='}'):
content = (empty.copy()+CharsNotIn(opener+closer+ParserElement.DEFAULT_WHITE_CHARS))
ret = Forward()
ret <<= ( Suppress(opener) + originalTextFor(ZeroOrMore( ret | content )) + Suppress(closer) )
return ret
This gets me most of the way there, although there's an extra level of list wrapping in there that I really don't need, and what I'd really like is for those brackets to be included in the string (without getting into an infinite recursion situation by not suppressing them).
parser = mynest("[","]")
result = parser.searchString("[A,[B,C],[D,E,F],G] Random Middle text [H,I,J]")
result.asList()
>>> [['A,[B,C],[D,E,F],G'], ['H,I,J']]
I know I could strip these out with a simple list comprehension, but it would be ideal if I could just eliminate that second, redundant level.
Not sure why this wouldn't work:
sample = "[A,[B,C],[D,E,F],G] Random Middle text [H,I,J]"
scanner = originalTextFor(nestedExpr('[',']'))
for match in scanner.searchString(sample):
print(match[0])
prints:
'[A,[B,C],[D,E,F],G]'
'[H,I,J]'
What is the situation where "this breaks when your nesting is deeper than the number of OriginalTextFor expressions"?

Haskell syntax error for where statement [duplicate]

This question already has an answer here:
Why shouldn't I mix tabs and spaces?
(1 answer)
Closed 6 years ago.
I'm writing some Haskell code to learn the language, and I've run into the syntax error:
Vec2.hs:33:27: parse error on input '='
The code I've written here is below. The error is pointing at the 2nd term in vec2Normalize iLength = ... I don't see the syntax error
-- Get the inverse length of v and multiply the components by it
-- Resulting in the normalized form of v
vec2Normalize :: Vec2 -> Vec2
vec2Normalize v#(x,y) = (x * iLength, y * iLength)
where length = vec2Length v
iLength = if length == 0 then 1 else (1 / length)
Some guessing involved since you don’t provide the complete code, but this error could indicate that your line iLength = ... is not properly indented; actually, that the iLength starts to the right of the length = on the line before.
Does your original file use tabs instead of spaces for indentation? If so, be aware that Haskell always interprets a tab as spanning 8 columns. So, e.g.,
<TAB>where length = ...
<TAB><TAB><SPACE><SPACE>iLength = ...
would be interpreted as
where length = ...
iLength = ...
thus causing the error, even though your editor might show the lines properly aligned if it uses 4-column tabs.
You are using tabs for indentation, so the second definition in the where clause is actually not aligned with the first one. Haskell uses a tab width of 8 spaces, which may be different from your editor, leading to problems like this where the code looks okay, but really isn't.
I strongly recommend that you configure your editor to use spaces only when working with Haskell code.

Multiline string literal in Matlab?

Is there a multiline string literal syntax in Matlab or is it necessary to concatenate multiple lines?
I found the verbatim package, but it only works in an m-file or function and not interactively within editor cells.
EDIT: I am particularly after readbility and ease of modifying the literal in the code (imagine it contains indented blocks of different levels) - it is easy to make multiline strings, but I am looking for the most convenient sytax for doing that.
So far I have
t = {...
'abc'...
'def'};
t = cellfun(#(x) [x sprintf('\n')],t,'Unif',false);
t = horzcat(t{:});
which gives size(t) = 1 8, but is obviously a bit of a mess.
EDIT 2: Basically verbatim does what I want except it doesn't work in Editor cells, but maybe my best bet is to update it so it does. I think it should be possible to get current open file and cursor position from the java interface to the Editor. The problem would be if there were multiple verbatim calls in the same cell how would you distinguish between them.
I'd go for:
multiline = sprintf([ ...
'Line 1\n'...
'Line 2\n'...
]);
Matlab is an oddball in that escape processing in strings is a function of the printf family of functions instead of the string literal syntax. And no multiline literals. Oh well.
I've ended up doing two things. First, make CR() and LF() functions that just return processed \r and \n respectively, so you can use them as pseudo-literals in your code. I prefer doing this way rather than sending entire strings through sprintf(), because there might be other backslashes in there you didn't want processed as escape sequences (e.g. if some of your strings came from function arguments or input read from elsewhere).
function out = CR()
out = char(13); % # sprintf('\r')
function out = LF()
out = char(10); % # sprintf('\n');
Second, make a join(glue, strs) function that works like Perl's join or the cellfun/horzcat code in your example, but without the final trailing separator.
function out = join(glue, strs)
strs = strs(:)';
strs(2,:) = {glue};
strs = strs(:)';
strs(end) = [];
out = cat(2, strs{:});
And then use it with cell literals like you do.
str = join(LF, {
'abc'
'defghi'
'jklm'
});
You don't need the "..." ellipses in cell literals like this; omitting them does a vertical vector construction, and it's fine if the rows have different lengths of char strings because they're each getting stuck inside a cell. That alone should save you some typing.
Bit of an old thread but I got this
multiline = join([
"Line 1"
"Line 2"
], newline)
I think if makes things pretty easy but obviously it depends on what one is looking for :)

illegal string body character after dollar sign

if i define a groovy variable
def x = "anish$"
it will throw me error, the fix is
def x = "anish\$"
apart form "$" what are the blacklist characters that needs to be backslash,Is there a Groovy reference that lists the reserved characters. Most “language specifications” mention these details, but I don’t see it in the Groovy language spec (many “TODO” comments).
Just use single quotes:
def x = 'anish$'
If this isn't possible, the only thing that's going to cause you problems is $, as that is the templating char used by GString (see the GString section on this page -- about half way down)
Obviously, the backslash char needs escaping as well, ie:
def x = 'anish\\'
You can use octal representation. the character $ represents 044 in octal, then:
def x = 'anish\044'
or
def x = 'anish\044'
For example, in Java i did use like this:
def x = 'anish\044'
If you wants knows others letters or symbols converters, click here :)
The solution from tim_yates does not work in some contexts, e.g. in a Jasper report.
So if still everything with a $ sign wants to be interpreted as some variable (${varX}), e.g. in
"xyz".replaceAll("^(.{4}).{3}.+$", "$1...")
then simply make the dollar sign a single concatenated character '$', e.g.
"xyz".replaceAll("^(.{4}).{3}.+"+'$', '$'+"1...")
It might be a cheap method, but the following works for me.
def x = "anish" + '$'
Another alternative that is useful in Groovy templating is ${'$'}, like:
def x = "anish${'$'}" // anish$
Interpolate the Java String '$' into your GString.

How to string.find the square bracket character in lua?

So I'm trying to find square brackets inside a string:
s = "testing [something] something else"
x,y = string.find(s,"[")
which gives me an error: malformed pattern (missing ']').
I also tried:
x,y = string.find(s,"\[")
giving me the same error.
And this:
x,y = string.find(s,"\\[")
in this case x and y are nil.
Any thoughts on how to do this properly? Thanks in advance.
John's answer will work -- turning off pattern matching.
What you're trying to do -- escape the [ -- is done with the % character in Lua:
x,y = string.find(s,'%[')
Also strings in Lua all have the string module as their metatable, so you could just say:
x,y = s:find('%[')
or even:
x,y = s:find'%['
Use the fourth argument to string.find, which turns off pattern-matching.
x, y = string.find(s, "[", nil, true)

Resources