MathQuill and set operators - latex

When using MathQuill one needs to type \nsub to get the ⊈ symbol. The latex you get back is \not\subset, which is fine.
But when you try to set back the same \not\subset expression to the MathQuill field, you get a different result : \neg\subset, which translates to a different rendering.
The problem can be reproduced directly on the MathQuill page (http://mathquill.com/) using the browser console :
Any ideas on how to handle or work around this ?

MathQuill will accept \nsub while typing, but also \notsubset, which got me to a simple find-and-replace solution, which does not require any other code change.
Not the best, but it works; the only downside is that the list of text replacements is fixed; the set operators are the one I found; could be more.
// special math pre-processing
var mathFix = {
"\\not\\subset" : "\\notsubset",
"\\not\\supset" : "\\notsupset"
}
var mathTextFixed = '<your latex here>';
Object.keys(mathFix).forEach(function(t1) {
mathTextFixed = mathTextFixed.replace(t1, mathFix[t1]);
});
mathField.latex(mathTextFixed);

Related

Nesting extra Span in Pandoc filter disappears the image

I am currently working on massaging the HTML output of a Pandoc filter due to some annoying restrictions in the CMS that is the eventual beneficiary of my hard work.
My working filter (now with the obvious declarations) is as follows:
local List = require 'pandoc.List'
local Emph = pandoc.Emph
local Quoted = pandoc.Quoted
local Span = pandoc.Span
local Str = pandoc.Str
local Strong = pandoc.Strong
local image_base = "http://my.website.example/images/"
local image_author = "Someone Not Stigma"
function process_images(el)
el.src = el.src:gsub("^file:images/", image_base)
el.caption = {
Strong( Quoted( "DoubleQuote", el.caption ) ),
Str(" by "),
Emph(image_author)
}
return el
end
return {{Image = process_images}}
In the eventual HTML, this gives me a nice figure with img and figcaption element inside of it. Wonderful. Unfortunately, my CMS destroys the figcaption (like it tends to destroy other stuff), and as such I figured I'd wrap everything in an extra span so I can style that one instead.
function process_images(el)
el.src = el.src:gsub("^file:images/", image_base)
el.caption = {
Span(
{
Strong( Quoted( "DoubleQuote", el.caption ) ),
Str(" by "),
Emph(image_author)
},
{ class="img-caption" }
)
}
return el
end
And yet somehow, this causes Pandoc to completely delete the image from the resulting HTML.
I have tried replacing the table syntaxes with List({}) syntaxes, but that just gives me upvalue complaints. I looked at the manual, but for as far I can tell I am doing everything right.
What am I missing here?
I call pandoc as follows:
pandoc --from=markdown-tex_math_dollars "Content.pure.txt" --lua-filter=".\pandoc-filter.lua" --to=html5 --template=".\pandoc-template.txt" -o "Content.txt"
Extensions are .txt (because these files are not browser ready). The template being used is rather lengthy (there's a fair bit of YAML variables and related markup), but be assured: $body$ can be found in there.
I am not a wise man. Always update to the latest version before posting questions, folks.
I was running an older version of Pandoc (v2.6), and upgrading to v2.9.1.1 suddenly made the output appear again. That's a lot of versions released in the span of about a year!
(In my defense, my Pandoc-filter-fu is not particularly strong, so it makes sense to assume user error rather than program bug. Why is it that every time you assume bug, it is user error, and every time you assume user error, it is an outright bug?)

Dart Markdown package, how to handle new lines

I am trying to make a WYSIWYG internal tool. And we decided to implement this feature with contentEditable. However, we save data to our databases in markdown. So I have to be able to parse from html to md and back. For html to md I use package html2md and for the other way around I use Markdown package.
The issue i've been having is that when you write to my editor text like
HEY
After many lines some text
It produces this in md
HEY
After many lines some text
Notably it uses 2 whitespace and 2 LF characters (or atleast i think so but i might be slightly wrong.) I solved this issue by parsing it like this
markdownToHtml(data.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>'), inlineSyntaxes: [TextSyntax(String.fromCharCodes([32,32,10,10]),sub: "<div><br></div>")],inlineOnly: true );
The inline only parameter was neccesary because without it the text syntax wasnt applied for some reason. However this inline only then bit me in the arse when I tried to implement parsing of unordered lists, which are parsed as blocks. So I need a way to correctly parse these empty lines without using inline only.
class EmptyLineBlockSyntax extends BlockSyntax{
RegExp get pattern => RegExp(r'^(?:[ \t][ \t]+)$');
const EmptyLineBlockSyntax();
Node parse(BlockParser parser) {
parser.encounteredBlankLine = true;
parser.advance();
return Element('p',[Element.empty('br')]);
}
}
return markdownToHtml(data.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>'), blockSyntaxes: [EmptyLineBlockSyntax()]);

How to fix JSLint insecure ^ error?

I have following function. What this does is filters character that is allowed in a subdomain. In JSLint I got following error. Is there any way I can do this without JSLint showing error. I know I can ignore error in JSLint settings but Is there any other way I can improve my code to not show JSLint error.
function filterSubDomain(value) {
return value.replace(/[^a-z0-9\-]/ig, '')
.replace(/^[\-]*/, '')
.replace(/[\-]*$/, '')
.toLowerCase();
}
I think this is easy enough -- just a quick head rethread. I'll repeat the comment from above quickly: JSLint wants you to say what you do want rather than what you don't, because saying what you don't want always leaves room for a superset of what you do want to sneak in. That is, JSLint's intention is to force you to code explicitly/precisely.
So instead of replace, you want to use match here. Here's one way, I believe (stealing from MDN's match code a little):
/*jslint sloppy:true, white:true, devel:true */
function filterSubDomain(value) {
var out = value,
re = /[a-z0-9\-]+/gi,
found;
found = value.match(re);
out = found.join("");
// There are better ways to `trim('-')`.
while (0 === out.indexOf("-")) {
out = out.substr(1);
}
while (out.length === out.lastIndexOf("-")+1) {
out = out.slice(0,out.length-1);
}
return out;
}
console.log(filterSubDomain('---For more inform--ation, - see Chapter 3.4.5.1---'));
// Formoreinform--ation-seeChapter3451
There are other ways to trim, but you get the point. No not's in JavaScript regular expressions with JSLint!

jQuery Mobile Filtered List - only match beginning of string

Im using the jQuery mobile search filter list:
http://jquerymobile.com/test/docs/lists/lists-performance.html
Im having somer performance issues, my list is a little slow to filter on some phones. To try and aid performance I want to change the search so only items starting with the search text are returned.
So 'aris' currently finds the result 'paris' but I want this changed. I can see its possible from the documentation below but I dont know how to implement the code.
http://jquerymobile.com/test/docs/lists/docs-lists.html
$("document").ready( function (){
$(".ui-listview").listview('option', 'filterCallback', yourFilterFunction)
});
This seems to demonstrate how you write and call your own function, but ive no idea how to write it! Thanks
http://blog.safaribooksonline.com/2012/02/14/jquery-mobile-tip-write-your-own-list-view-filter-function/
UPDATE - Ive tried the following in a seperate js file:
$("document").ready( function (){
function beginsWith( text, pattern) {
text= text.toLowerCase();
pattern = pattern.toLowerCase();
return pattern == text.substr( 0, pattern.length );
}
$(".ui-listview").listview('option', 'filterCallback', beginsWith)
});
might look something like this:
function beginsWith( text, pattern) {
text= text.toLowerCase();
pattern = pattern.toLowerCase();
return pattern == text.substr( 0, pattern.length );
}
Basically you compare from 0 to "length" of what you're matching to the source. So if you pass in "test","tester" it will see you're passing in a string of length 4 and then substr "tester" from 0,4, which gives you "test". Then "test" is equal to "test"... so return true. Lowercase them to make it case insensitive.
Another trick to improve filter performance, only filter once they've entered more than 1 character.
edit it appears jQueryMobile's filter function expects that "true" means it was not found... so it needs to be backwards. return pattern != text.substr( 0, pattern.length );
This worked for me. I am using regular expression here so sort of different way to achieve the same thing.
But the reason why my code didn't work initially was that the list item had a lot of spaces at the beginning and at the end (found that it got added on it's own while debugging).
So I do a trim on the text before doing the match. I have a feeling Jonathan Rowny's implementation will also work if we do text.trim() before matching.
$(".ui-listview").listview('option', 'filterCallback', function (text, searchValue) {
var matcher = new RegExp("^" + searchValue, "i");
return !matcher.test(text.trim());
});

How to edit the BibTeX .bst FUNCTION {format.names}?

After trying several .bst files I am still mostly satisfied with the layout of the ChicagoReedWeb.bst file. However, I don't like the handling of entries by the same author, eg:
If have looked at the ChicagoReedWeb.bst file but only understand some of the basics.
So how can I edit the code of the ChicagoReedWeb.bst file in such a way that it will print the author's full reference instead of the "--------" ?
OK, this is well outside my previous experience with BibTeX, but looking at the file, I get the impression that the name.or.dash section is replacing the name with a dash if it's the same as the previous one. I suggest trying replacing this code:
FUNCTION {name.or.dash}
{ 's :=
oldname empty$
{ s 'oldname := s }
{ s oldname =
{ "\rule[.6ex]{3em}{.05ex}"}
{ s 'oldname := s }
if$
}
if$
}
with this:
FUNCTION {name.or.dash}
{
}
If my understanding of the syntax is correct, this should simply remove the comparison and optional change, and leave the name as you want it.
A slightly tidier approach might be to take out the calls to name.or.dash in the places which you don't want them. That will give you more flexibility about whether you want a dash in place of, for example, a repeated book name.

Resources