[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 14 KB, 799x344, latex.gif [View same] [iqdb] [saucenao] [google]
3866642 No.3866642 [Reply] [Original]

Hey guys,

I'm always annoyed by writing my "math" tags with backslashes instead of slashes, by being unable to properly read what I write in /sci/'s editbox, or to copy-paste it from an editor in which I have LaTeX code due to the difference between the delimiters of regular LaTeX and jsMath's.

Thus, I started making a small GreaseMonkey script to convert single dollars into math tags and double dollars into eqn tags. Some kind anon pointed to me that a script existed already to allow previewing of jsMath before posting, so I used it as a base (it's from another /sci/borg and can be downloaded from http://userscripts.org/scripts/show/81801 ).

Anyway, here's my version: http://userscripts.org/scripts/show/114958

Feel free to suggest features, there's a non-zero probability that I won't be lazy all week-end. Also, little demo (if this fails, you're allowed to throw stones at me):

<div class="math">e^{i\pi}+1=0</div>

>> No.3866651

>>3866642
why don't you just code a solution that craps out solutions in copy and pastable jsmath and latex,

three text boxes.

>> No.3866671

>>3866651
I'm sorry, I don't get it. Do you just mean WYSIWYG? If so, it's hard to do without being a bit resource-consuming, I think. If you just use jsMath's built-in functions on the whole input text (which is the simple way to do it), it'll be consuming if someone types say 5 characters per second. And if you want to refresh only when a dollar or a math tag is typed, you need to do some more serious coding. It's possible, but it's not a simple little hack anymore, you need to think it through a little and to actually write some lines of code. I'll be too lazy for that.

>> No.3866676

>>3866671
that's why it'd be written in javascript or another scripting language executed clientside

>> No.3866685

A script to render the jsmath to check formatting before posting would be useful.

>> No.3866706

>>3866676
Hmm, yes, that's what GreaseMonkey scripts are. JS is a bit slow even if browsers are getting better at interpreting it. Look at how long it takes for jsMath to parse all the math tags in a page: sometimes more than a second when you have a few dozens of math tags. If you have a post with a few math tags itself, and you want to reprocess it every time you type a character in the box, it'll be very slow.

If you just want a preview button, then the original script already did it, and obviously my mod kept that feature. You have to press the button by yourself to start processing the jsMath though. But it's indeed done client-side, as everything jsMath does. The only thing the server does is proving the JS files more or less on the fly.

>> No.3866731

>>3866706
consolidation into one universal translator is a bit different.

>> No.3866739

>>3866706
Alt+P shortcut for preview would be superb, instead of having to use a mouse. I hate using the mouse.

>> No.3866744

>>3866731
>You're trolling
>I'm really dumb
>You should make an effort to make people understand what you mean
Pick (at least) 1 (and up to 3).

>> No.3866745

>>3866739
I'll try that. I'm not sure if javascript's hotkeys work when the user is typing into a textarea. But I'll give it a look anyway and I'll let you know.

>> No.3866750

>>3866745
I'm pretty sure it does *somehow* as vimperator can catch ESC. But that doesn't mean it is totally trivial, I know basically nothing of javascript.

>> No.3866765

can you try to place it somewhere that the 4chan x script might grab it into the quick-reply window, that would be nice.

>> No.3866771

>>3866765
Give me a link to that script. I'll do the alt+p first and I'll try to do what you suggest after.

>> No.3866780

>>3866744
>aspie detected
if you cannot derive even the faintest idea of what is meant by a universal translator of jsmath, latex, and regular math conventions, you shouldn't be coding shit.

>> No.3866785

>>3866765
it used to be on userscripts, but author decided to prune distribution channels, now available on

http://aeosynth.github.com/4chan-x/

>> No.3866825

>>3866780
I understand what you meant by universal conversion. I still don't get what you mean by "it's different". You're quoting a 4-lines post and I'm not going to try interpreting which exact word you're talking about because I just don't fucking care. I'm open to discussion, remarks, and suggestions, but really if you want to give me enigmas, give me mathematical enigmas, not interpretation bullshit.

>>3866750
Alt+P now toggles the preview on and off. Link in OP should work.

>>3866785
I'll have a look.

>> No.3866847

>>3866825
fucking wonderful, thanks, much more sensible behavior

>> No.3866864

>>3866847
Glad it helps.

I'm having a look at the quick reply of 4chan X right now. It's probably possible to do something. Give me like 15 or 20 minutes, I'll keep you udpated. Hopefully it won't be too hard.

>> No.3866971

>>3866864
Okay, it looks like it works. I'm typing this with dollars in the quickreply textarea of 4chanX: $\frac{1+\sqrt{5}}{2}$.

There are some little artifacts around the image in the preview on the QR box but it's not really a huge problem and I'm too lazy to fix it. I haven't tested it extensively, tell me if you encounter any bug.

>> No.3866981

>>3866971
Okay, so it doesn't use the "submit" method to submit the form, but probably a XMLHttpRequest or something. Anyway, my script didn't see that 4chanX was sending it. The preview works, and of course if you use the regular math and eqn tags it'll work well. Wait a bit for the dollars in the QR box.

>> No.3866982

>>3866971
heh, seems like you found one!

<div class="math">derp~test</div>

>> No.3867007

>>3866981
Actually I think it was just a stupid mistake in my code. Testing in motherfucking sage mode:
<span class="math">\frac{1+\sqrt{5}}{2}[/spoiler].

>>3866982
Indeed!

>> No.3867025

>>3867007
Okay, seems like it's more or less working with the QR box now. Last version is uploaded to userscripts.org.

I'll probably go to bed soon, but if someone has yet another idea, I might do it tomorrow.

>> No.3867093

>>3867025
something is not quite right with your regex. If you have two lines in a row using $ then it flubs the preview.

>> No.3867122

>>3867093
Care to give me an example (e.g. by disabling GM and posting it raw)?

>> No.3867126

Nvm, I know what it is. I'll try to find a workaround.

>> No.3867154

>>3867126
Replace lines 47 and 48 by
html = html.replace(/([^\$])\$\$([^\$]+?)\$\$(?=[^\$])/g,"$1<div class="math">$2</div>");
html = html.replace(/([^\$])\$([^\$]+?)\$(?=[^\$])/g,"$1<span class="math">$2[/spoiler]");

I'll also upload it in a minute. I didn't know JS had a (?=...) regexp tag. If it's new, I'm glad they finally did that. Else, I hate myself for using shitty workarounds all the time before now...

>> No.3867197

That seemed to get it, nice.

>> No.3867669

What about 4chan change from jsmath to mathjax? :D

http://mathjax.org