From: Philipp Gesang <Philipp.Gesang@alumni.uni-heidelberg.de>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: using variable for subscript in math+lua
Date: Thu, 25 Oct 2012 03:02:55 +0200 [thread overview]
Message-ID: <20121025010255.GB21449@phlegethon.router_intern> (raw)
In-Reply-To: <D9B1573E-D7DE-4B09-9DD9-9DFCA62EB714@me.com>
[-- Attachment #1.1: Type: text/plain, Size: 2467 bytes --]
···<date: 2012-10-25, Thursday>···<from: Jeong Dal>···
> Dear Hans, Lucas, Wolfgang, Aditya
>
> Now, I write a matrix using \startluacode by the helps of you.
> Also, I can do some operations in matrices which reduced my typing job.
> In this code, I have to give all the entries of a matrix as a table. It is good to use in many cases.
>
> I have one more question. If the given array is as the following and it works well.
>
> However, there might be a better way to do job using "for" iteration.
> I tired to use "i, j" in several ways but it doesn't work.
Inside a string the variables are just bytes. To print to a
string you can interpolate with string.format() [1].
[1] http://www.lua.org/manual/5.1/manual.html#pdf-string.format
·································································
\startluacode
document = document or { } -- recommended: use namespace
document.print_matrix = function (x, y)
if not y then y = x end -- default to square
context.startmatrix{left = "\\left(\\,", right = "\\,\\right)"}
local schema = "a_{%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
\stopluacode
\starttext
\startformula
\ctxlua{document.print_matrix(3)}
\stopformula
\startformula
\ctxlua{document.print_matrix(9,4)}
\stopformula
\startformula
\ctxlua{document.print_matrix(9)}
\stopformula
\stoptext
\endinput
·································································
>
> Is there a way to do such a job using "for" iteration?
>
> Thank you for reading.
>
> Best regards,
>
> Dalyoung
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
--
() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments
[-- Attachment #1.2: Type: application/pgp-signature, Size: 198 bytes --]
[-- Attachment #2: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
next prev parent reply other threads:[~2012-10-25 1:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-25 0:38 Jeong Dal
2012-10-25 1:02 ` Philipp Gesang [this message]
2012-10-25 7:52 ` Hans Hagen
2012-10-25 8:01 ` Philipp Gesang
2012-10-25 8:28 ` Hans Hagen
2012-10-25 18:02 ` Otared Kavian
2012-10-25 20:11 ` Hans Hagen
2012-10-25 21:27 ` Procházka Lukáš
2012-10-25 22:05 ` Philipp Gesang
2012-10-26 6:29 Jeong Dal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121025010255.GB21449@phlegethon.router_intern \
--to=philipp.gesang@alumni.uni-heidelberg.de \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).