how to display math formula with latex?is it a good idea?
I don’t know but maybe this helps you
https://www.ctan.org/pkg/lualatex-math
https://www.ctan.org/pkg/lualatex-doc
Or some kind of plotter.
http://stevedonovan.github.io/lua-flot/flot-lua.html
for example,
http.request(
http://latex.codecogs.com/eqneditor/editor.php
when i input textarea
\\sin^{-1}\\theta
i wanna download the png image
Well if you just want to display an image of a formula that’s easy. Copy the image generated by that site to the pasteboard, and then in Codea’s asset manager, use “add from pasteboard” to save it to your documents, Dropbox, the project’s local space, etc. Then there’s lots of ways to display an image, the easiest being to sprite it
img = "Documents:myFormula"
...
sprite(img,WIDTH*0.5,HEIGHT*0.5)
But typesetting a formula to the screen live is pretty hard I imagine!
TeX, as I’m sure you know, is primarily a typesetting language, for output to PDFs, rather than to the screen. I’ve used it for writing papers (not with math formulas though). I’m not sure what LuaTex is, even after reading their wiki page. I imagine it’s for additional scripting of TeX though, rather than a port of TeX to Lua.
How do websites do math formulas, nowadays? MathJax (which runs on JavaScript)? Or is there formula support in html5 now?
here is an example. You would have to write the editor to generate escaped text
--# Main
-- latex
function setup()
txt = "a%3D%5Csqrt%7Bt%7D"
img = image(10,10)
convert2png(txt)
end
function convert2png(txt)
local str = "http://latex.codecogs.com/png.download?" .. txt
http.request(str,function(data) img = data end)
end
function draw()
background(255)
spriteMode(CENTER)
sprite(img,WIDTH/2,HEIGHT/2)
end
thanks, couldnt it use latex string like this: \sin^{-1}\theta? and other setting options?
TeX, as I’m sure you know, is primarily a typesetting language, for output to PDFs, rather than to the screen. I’ve used it for writing papers (not with math formulas though). I’m not sure what LuaTex is, even after reading their wiki page. I imagine it’s for additional scripting of TeX though, rather than a port of TeX to Lua.
LuaTeX comprises of tex with lua embedded into it so that you can run lua scripts from within your tex document. You can feed lua bits of the document, if you like, or you can use lua to do some heavy calculation (which tex was not designed to do). You can see an example rendering the Sieve of Eratosthenes using lua to do the heavy lifting.
How do websites do math formulas, nowadays? MathJax (which runs on JavaScript)? Or is there formula support in html5 now?
MathML is the proper way to render mathematics on the web and it is part of HTML5. Unfortunately, not all browsers support it (Firefox is the best of the mainstream ones) so MathJaX is used to fill in the gap. The best way to get maths on the web with current technology is, therefore, an HTML5+MathML page which loads MathJaX for broken browsers.
All this is by-the-by as far as Codea is concerned. You can’t use luatex inside Codea. You could reimplement tex’s mathematical rendering, but that would be quite some task.
ok here is some more, doing the conversion of your string into hex format.
Then you send the string to the website and it returns this image:
https://pbs.twimg.com/media/CGxboHrXIAEY8uk.jpg
--# Main
-- latex
function setup()
-- note that you cant use "\", you must replace it by"\\\"
txt="\\\\sin^{-1}\\\\theta"
print(txt)
txt = toByte(txt)
print(txt)
img = image(10,10)
convert2png(txt)
end
--- Returns HEX representation of num
-- from http://snipplr.com/view.php?codeview&id=13086
function num2hex(num)
local hexstr = '0123456789ABCDEF'
local s = ''
while num > 0 do
local mod = math.fmod(num, 16)
s = string.sub(hexstr, mod+1, mod+1) .. s
num = math.floor(num / 16)
end
if s == '' then s = '0' end
return s
end
function toByte(txt)
t = {}
for i=1,txt:len() do
t[i] = num2hex(txt:byte(i))
end
return "%" .. table.concat(t,"%")
end
function convert2png(txt)
local str = "http://latex.codecogs.com/png.download?" .. txt
http.request(str,function(data) img = data end)
end
function draw()
background(255)
spriteMode(CENTER)
sprite(img,WIDTH/2,HEIGHT/2)
end
thanks?is there a way like your google answers code?
http.request("https://www.google.fr/search?q="..query, gotData,fail,{method="GET",
useragent=USER_AGENT})
your question is not clear…?
i mean input “\sin^{-1}\theta” in the web’s textarea, then get the download address
???
have you read my code? This is exactly what i am doing in
function convert2png(txt)
local str = "http://latex.codecogs.com/png.download?" .. txt
http.request(str,function(data) img = data end)
end
Or i still dont get your question right…
f(x) =
\\sum_{n=0}^\\infty a_n x^n =
a_0+a_1x+a_2x^2+\\cdots
f(n) =
\\begin{cases}
n/2, & \\text{if }n\\text{ is even} \\\\
3n+1, & \\text{if }n\\text{ is odd}
\\end{cases}
how to do?
--# Main
-- latex
function setup()
-- note that you cant use "\", you must replace it by"\\\"
txt1 = "f(x) =\\\\sum_{n=0}^\\\\infty a_n x^n = a_0+a_1x+a_2x^2+\\\\cdots"
txt2 = "f(n) =\\\\begin{cases} n/2, & \\\\text{if }n\\\\text{ is even} \\\\\\\\3n+1, & \\\\text{if }n\\\\text{ is odd}\\\\end{cases}"
imgs={
img1 = image(10,10),
img2 = image(10,10),
}
convert2png(txt1,"img1")
convert2png(txt2,"img2")
end
--- Returns HEX representation of num
function num2hex(num)
local hexstr = '0123456789ABCDEF'
local s = ''
while num > 0 do
local mod = math.fmod(num, 16)
s = string.sub(hexstr, mod+1, mod+1) .. s
num = math.floor(num / 16)
end
if s == '' then s = '0' end
return s
end
function toByte(txt)
t = {}
for i=1,txt:len() do
t[i] = num2hex(txt:byte(i))
end
return "%" .. table.concat(t,"%")
end
function convert2png(txt,img)
txt = toByte(txt)
local str = "http://latex.codecogs.com/png.download?" .. txt
http.request(str,function(data)
imgs[img] = data
pasteboard.image = data
print("received")
end)
end
function draw()
background(255)
spriteMode(CENTER)
sprite(imgs.img1,WIDTH/2,HEIGHT/4*3)
sprite(imgs.img2,WIDTH/2,HEIGHT/4*1)
end
thanks a million?i understand it