I want to write a mathematical formula along my text that includes alpha and beta values. How can I do so? If I copy paste the formula of polynomial linear regression from wikipedia to my code, I get this:
{\displaystyle y=\beta _{0}+\beta _{1}x+\beta _{2}x^{2}+\varepsilon .\,}
https://en.wikipedia.org/wiki/Polynomial_regression#:~:text=In%20statistics%2C%20polynomial%20regression%20is,nth%20degree%20polynomial%20in%20x.&text=For%20this%20reason%2C%20polynomial%20regression,case%20of%20multiple%20linear%20regression.
I read that there's a library 'react-mathjax' but I couldn't figure out how to use alpha beta symbols.
You can check out a new library called better-react-mathjax that I have written. It is written with the latest standards of React in mind.
The following code accomplishes what you want:
<MathJaxContext config={config}>
<h2>MathJax use with Latex</h2>
<MathJax dynamic>
{"$$y=\\beta _{0}+\\beta _{1}x+\\beta _{2}x^{2}+\\varepsilon$$"}
</MathJax>
</MathJaxContext>
I don't know for what you wanted to keep the last part (.\,) so I removed it but you can put it back if you want to.
I have prepared a sandbox for you, check it out and hope you like it!
Link: https://codesandbox.io/s/user-example-1-zu5vb
Related
HTML+CSS+Javascript tools offer a great way to create beautiful presentations (e.g. reveal.js + MathJax). However, I usually need to add citations to my presentations, and I would like to do that in a systematic way (so the bibliography is organized and the references are well-formatted). This is something that get's handled quite easily in LaTeX through BibTeX.
The best solution I've found so far comes from a library called bibtex-js. It seems to do a good job on rendering BiBTeX files in HTML as a bibliography listing, which is partially what I want. However, I don't only need to render bibliography listings, but also, I need to refer to entries in that bibliography by some index, and get a uniformly formatted reference marker. Take, for example, how LaTeX usually handles this problem:
%In thebibliography.bib
#article{darwin1859origins,
title={On the origins of species by means of natural selection},
author={Darwin, Charles},
journal={London: Murray},
year={1859}
}
%In mydocument.tex
As \cite{darwin1859origins} sustains in his ground-breaking book...
The previous code would be rendered as something like "As Darwin(1859) sustains in his ground-breaking book". Moreover, the formatting in which the citation is rendered could also be customizable (e.g. "Darwin,1859", "(Darwing,1859)", "[DWN59]", "[1]", etc.).
So the question is, how do you handle a similar task on a HTML document?
Thank you all in advance!
Yes, there is an emacs extension called org-mode, which is text processing with a markdown like syntax.
This can export to reveal-js trough this: https://github.com/yjwen/org-reveal
Or in my case I use the spacemacs extension: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Bemacs/org#revealjs-support
So org mode is an intermediate format that compiles to whatever you want, ie reveal-js, html, or even latex.
This includes a reference management system: https://github.com/jkitchin/org-ref
I'm unhappy with this for reveal.js, if we use this with reveal.js we end up having all the citation being presented as the link (whatever we type after cite:) and the full format citations are grouped on whatever slide you place them (so if you have more than 3 you can't read it correctly, although I guess its in the HTML). What I want is either the numbers I get in latex or footnote based citations, because in case of slides footnotes work kind off good.
This will of course work for just HTML pages, however you probably want to have presentations like me. I was searching for a solution for this when I stumbled upon this unanswered question so I guess here is your answer.
I made a project, incidentally also called bibtex-js. Available on npm.
I made it because most BibTeX parsers out there take considerable shortcuts in parsing. This one aligns closely with the authoritative document on BibTeX, Tame the BeaST and so works pretty well in terms of references and parsing author names, which seems what you are after.
I would say, based on some bibliographic standard, roll your own inline citation function:
import {parseBibFile, normalizeFieldValue} from "bibtex";
// Parse bib file
const bibFile = parseBibFile(bibtexString); // insert the darwin1859origins example as a string
// Sanity check: print all ids of entries in the bibfile
console.log(Object.keys(bibFile.entries$));
// Get the entry we are after
const entry = bibFile.getEntry("darwin1859origins");
// Get the relevant fields
// normalizeFieldValue turns a BibTeX string into a Javascript string
const year = normalizeFieldValue(entry.getField("year"));
// get first author
// "author" is a special kind of BibTeX field
const author = entry.getField("author").authors$[0];
function inlineCite(author){
return "("
+ (author.firstNames
.concat(author.vons)
.concat(author.lastNames)
.concat(author.jrs)).join(" ")
+ "," + year
+ ")";
}
console.log(inlineCite(author)); // (Charles Darwin, 1859)
You can do something complicated with et al. if you have multiple authors.
I am attempting to use the autoNumeric jQuery plug-in which helps with the conversion of various currencies in jQuery.
The plug-in itself works when I use it in a jsFiddle example.
$(function () {
$('.money').autoNumeric('init', {
aSign: '$',
vMin: '-999999999.99',
nBracket: '(,)'
});
});
However, as soon as I integrate it into a big, legacy project, I start receiving the above error on line 194. I know why I'm getting the error - a string is not being passed into the negativeBracket function (negativeBracket(s, nBracket, oEvent) is the signature). Instead, it seems to be a jQuery object - e.fn.init1. I'm confused on how this might be happening. I realize the community may not be able to give a direct answer, but I would love (and will accept as an answer) being pointed in the right direction as nothing has jumped out at me so far.
Update
So, have some additional info that may be of help. It still has me stumped how it's happening (unfortunately, the answers below didn't help to provide any additional insight). When I link in autoNumeric, I key it off of any text field with the class money. It does work as I am typing in the box. I can see see formatting. However, when I tab into a new box, the box I just finished typing in clears itself completely after hitting line 152 in autoNumeric with the same exact error.
#Carlos487 was correct in his answer when he said I have an object that is not a string. I instead have an object that, I believe, is a function. Here's what I'm seeing in Chrome debugger tools:
e.fn.init[1]
> 0: input#price.money required
> context: input#price.money required
length: 1
selector: ""
> __proto__: Object[0]
The "arrowed" items can be further expanded out. I don't know if this provides any more clues, but it's at least something a bit different.
The errors like
no method XXXXX in Object
are produced because you are trying to call obj.XXXX() and obj is not of the desired type, in your particular case a string.
Have you tried in another browser because older or IE can be a little troublesome. I would recomend using chrome developer tools with your legacy app to see if anything else is conflicting or producing the error
I will bet money that you are using a second library which is interfering with jQuery. It has probably overridden $ with its own function.
Try using jQuery instead of $:
jQuery(function () {
jQuery('.money').autoNumeric('init', {
aSign: '$',
vMin: '-999999999.99',
nBracket: '(,)'
});
});
It turns out that the issue was a myriad of issue compounding into the error I saw. A couple things that was happening:
The validator plug-in was wrapping the jQuery object in its own structure (hence the charAt issue).
Once I fixed that, I also learned that some homegrown code was also wiping and rewriting data into the field to provide formatting (which is what autoNumeric is also doing), so autoNumeric would bomb out because it would get a null value and attempt to format it.
There was some other random craziness that also needed cleaned up. So...issue resolved! Still more to work on, but at least this hurdle is past. Thanks all for your help.
I don't need anything super fancy, but some scope aware refactoring would be nice.
Refactoring something in function scope is one of the most common scenarios for me:
var funyfun = function(arg1, arg2) {
arg1 = ...arg2;
arg2....();
}
Is there a vim plugin that would allow me to refactor arg1, for ex, in the scope of that function or do I have to invent my own "select block, find, replace" shortcut.
For extra kudos, something that would "refactor on the fly" as I type, so I can see where changes are being made. Netbeans does an excellent job of this.
This is not limited to a certain block, but this how I would do it with plain Vim:
Move cursor on top of arg1 and type *N
Type ciw and insert replacement.
Now you can use n and N to navigate the occurrences and by pressing . Vim will redo the replacement on the current match
Here's a shortcut for it:
" Simple word refactoring shortcut. Hit <Leader>r<new word> on a word to
" refactor it. Navigate to more matches with `n` and `N` and redo refactoring
" by hitting the dot key.
map <Leader>r *Nciw
Sound a bit like you only want renaming instead of refactoring. Full refactoring is tricky for Javascript, though some IDEs provide approximations. Since the question is about Vim specifically, and hacks aren't excluded, I'll just jump on the scope-aware aspect:
I've got a modified DoctorJS to generate scope-aware tags, with a Vim plugin for scope-aware navigation based on those tags (see blog post/screencast).
The hacky part comes in how navigation is implemented for Vim: I generate a search pattern that includes the scope of the variable and excludes all nested scopes for the same name. So, you could use that search pattern (function scoped_tags#FindTagInScope) to implement renaming (only if all uses are in the same file, and it doesn't exclude comments and the like..). Or you could use the scoped navigation to jump through variable occurrences manually and use '.' to rename them..
A few JavaScript-aware commands for Vim are provided by tern_for_vim, such as :TernRename for scope-aware renaming of variables, :TernDef for jumping to the definition of the thing under the cursor, and so on. You will need to have nodejs and npm installed, make sure to read the installation instructions in the repo.
As a partial solution you can use Eclim with JSDT, which allows you to use power of Eclipse refactoring/debugging/auto-completion/plugins with Vim.
In my experience, it may be a bit slow on older machines, but it's worth giving it a try.
In addition to doing actual scope-aware refactoring and the like, consider :%s/varName/newNav/gc. Per :help :s_c, the c flag passed to :s enters a quick confirmation mode for find/replace operations that prompts you (y/n) on whether each match should be replaced or not.
you can do:
:.,/^}/ s/\<arg1\>/new_name/g
the .,/^}/ is a range that many Ex commands accept: from cursor line to next line starting with a closing brace.
Benoit and Epeli has some good points, however, I find it a bit tedious to write .,/^}/ before my substitute statement, and since it only modifies code from the cursor position to the next line starting with a }, it depends on having the cursor position at the beginning of the function or block (and it will not work for an entire function with an if statement).
So instead I use visual mode in combination with textobjects. For instance, typing vi{ will select all the code inside the closest matching pair of {}, va{ will include the {} characters, and if you do this with visual line (vi{V), you'll get the entire function declaration as well. Then you can just do a :s/\<arg1\>/new_name/g to rename arg1 to new_name, including function parameters.
I'm using js2-mode for working with javascript in emacs and for the most part it's very useful. However, the indenting methods are terribly frustrating when working with jQuery, closures, and JSON... for instance, code that I wish to be indented like this:
var foo = jQuery('#mycontainer ul li').each(function(el){
var bar = el.html();
});
Turns out as:
var foo = jQuery('#mycontainer ul li').each(function(el){
var bar = el.html();
});
Is there a way I can just switch off all the indenting "helpers" and just have emacs insert N spaces when I hit the tab key? I know manual-indentation is a step backwards, but having readable code is, IMHO, more useful than a tool that doesn't work as expected.
Not a direct answer to your question, but here is a fork of js2-mode that has improved indenting.
One of the improvements is that your example code is indented the way you ask here.
I guess I will make this a full answer instead of a comment; espresso-mode is included with Emacs, and is designed to be a Javascript mode for Emacs (instead of a Javascript mode that happens to run inside of Emacs). It works like regular programming modes, and also happens to indent things the way you like.
Check out this solution, maps indentation function in js2-mode to partially use indentation from esresso-mode (now known as js-mode included in emacs 23.2 and newer):
http://mihai.bazon.net/projects/editing-javascript-with-emacs-js2-mode
Works exactly as I expect indentation in emacs to work and you still get the parsing awesomeness from js2-mode.
Have you tried new versions of js2-mode? It looks like there's a fix out: http://code.google.com/p/js2-mode/issues/detail?id=94
js2-mode supports "bounce" indenting; you can press tab multiple times to choose different likely indenting levels, so you might be able to get the effect you want that way:
(setq js2-bounce-indent-p t)
You can simply bind TAB to insert itself:
(add-hook 'js2-mode-hook 'my-js2-mode-hook)
(defun my-js2-mode-hook ()
(define-key js2-mode-map [tab] 'self-insert-command))
(But the better solution would, of course, be to find out why the mode thinks it needs so much indentation for anonymous functions, and fix it.)
One other alternative is js3-mode. It indents like this by default, but there seems to be some options that might enable you to tweak it for your liking.
var foo = jQuery('#mycontainer ul li').each(function(el){
var bar = el.html();
});
I'm trying to help a friend to figure out if it's possible to implement DSP algorithms in Max/MSP javascript. He was told so in class, and he asked for my help but I can't find any way to process actual samples.
TL;DR
Is it possible to get samples in and return them out in Max/MSP using javascript?
Thanks
No, it's not, as it's made only for processing messages and not signal vectors. Probably you mixed JavaScript with Java — there is a mxj~ object which allows you to use Java 6 (not higher!) for developing signal processing algorithms. Check out the tutorial, which everyone starts to learn how to use Java with: http://pcm.peabody.jhu.edu/~gwright/stdmp/docs/WritingMaxExternalsInJava.pdf
You can write DSP algorithms using Max’s gen~ and codebox, the syntax for which resembles JavaScript or C.
DSP in Max runs at high priority to avoid audio dropouts, which the js object does not, but it is possible to generate code using JavaScript and load that into a gen~ instance. You can find an example of this bundled with Max itself: search for a file called gen~.dynamicexpr.maxpat
They released a node.js API with Max 8. You can now.
Though not using javascript, like delucis said you can now use gen~ to write dsp code.
Here's a distortion gen~ function using tanh for my own project:
tanh_dist(input, amp, offset)
{
pass1 = input + offset;
pass2 = pass1 * amp;
pass3 = tanh(pass2);
return(dcblock(pass3));
}
I also made a sample patch to show you how to use it (in the codebox). Just copy the following text and paste into an empty max patch window:
----------begin_max5_patcher----------
1168.3ocyW8tbiZCD+y3mBF9TROWOHAXG2qsyzGf9Db4FOxfLVWAACH74bYx
8r2U+ALXv13j3zlOPFu+jzt6uc0tZedhky5r8zRG6ey9K1VVOOwxRIRJvx7a
KmTx9vDRoZYNgYooTtvYpFSP2KTxy1rojJdjWCjSDgaY73UEzPgVA3kAybmZ
iWH+hBbk+yyelq8WM6gWkx3ITgRSnCBypD0RcMRYQZst9a+Jx0QJ6kISjel9
F8CRZ94cBWzAmve9rf2EeX9qwE1jjAGbsstIqHknLx4FIfgvRgEHU4rZkBmv
AgnKFrl6K+piUX704m3994xCLaAIkJnEqnbx5DZadQeDhmxoZSwwYpsyZBO1
w9q2ZZJnOMgOPdCvSnkKj4.uy7zh+C3IN86fp6cgH7ovD5OsQv0ryvBttGxV
lGbdV.OHKf5yBANmxSKYwbRxqyOiIL9Ouru3gvp5TK0+J3RwzzpDAKbKgyoI
6HEL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