On Thu, 25 Oct 2012 20:02:22 +0200, Otared Kavian <ota...@gmail.com> wrote:
Hi Philipp, Thanks to you, Dalyoung and Hans for the nice example using luacode. I was wonedring how would you modify your code in order to be able to change the name of the matrix if necessary. For instance, how to modify your code in such a way that upon saying \ctxlua{document.print_matrix(b,3)} one gets a 3x3 matrix whos coefficients are b_{11},…b_{33}. Thanks in advance: OK
Something like this?
·································································
document.print_matrix = function (x, y, name) local name = name or "a" if not y then y = x end -- default to square context.startmatrix{left = "\\left(\\,", right = "\\,\\right)"} local schema = name .. "_{%d%d}" -- %d: prints integer part for i=1, x do for j=1, y do --- use the template defined above to print the --- row and column context.NC(string.format(schema, i, j)) end context.NR() end context.stopmatrix() end
·································································
Call with: \ctxlua{document.print_matrix(3, 3, "b")} Best regards, Lukas ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________