https://wiki.contextgarden.net/api.php?action=feedcontributions&user=Dain88&feedformat=atom
Wiki - User contributions [en]
2024-03-29T13:27:04Z
User contributions
MediaWiki 1.34.1
https://wiki.contextgarden.net/index.php?title=determinenoflines&diff=32500
determinenoflines
2021-03-20T00:30:35Z
<p>Dain88: </p>
<hr />
<div><inputbox><br />
type=create<br />
width=100<br />
break=no<br />
buttonlabel=Create new article<br />
default=determinenoflines<br />
</inputbox><br />
<br />
[[determinenoflines]] calculates the number of lines of the given text. For example,<br />
<br />
<texcode><br />
\startbuffer<br />
\input tufte<br />
\stopbuffer<br />
<br />
\starttext<br />
\determinenoflines{\getbuffer}<br />
<br />
The number of the lines given text is $\the\noflines$.<br />
\stoptext<br />
</texcode><br />
<br />
<context mode=lmtx><br />
\startbuffer<br />
\input tufte<br />
\stopbuffer<br />
<br />
\startTEXpage<br />
\determinenoflines{\getbuffer}<br />
<br />
The number of the lines given text is $\the\noflines$.<br />
\stopTEXpage<br />
</context><br />
<br />
<br />
<br />
== interesting example of Hans using \determinenoflines. ==<br />
<br />
<texcode> <br />
\def\determinednoflines#1%<br />
{\localcontrolled{\determinenoflines{#1}}\noflines}<br />
<br />
\startbuffer<br />
\input tufte<br />
\stopbuffer<br />
<br />
\starttext<br />
<br />
%\fillinrules[n=\determinednoflines{\getbuffer},<br />
%width=fit]{first}<br />
%\fillinrules[n=\determinednoflines{\getbuffer},<br />
%width=broad]{first}<br />
%\fillinrules[n=\determinednoflines{\getbuffer},<br />
%width=3cm]{first}<br />
\fillinrules[n=\determinednoflines{\getbuffer},<br />
width=3cm,distance=.5em,separator=:]{first}<br />
\fillinrules[n=\determinednoflines{\getbuffer}]{first}{last}<br />
<br />
\stoptext<br />
<br />
</texcode> <br />
<br />
<br />
<context mode=lmtx> <br />
\def\determinednoflines#1%<br />
{\beginlocalcontrol\determinenoflines{#1}\endlocalcontrol\noflines}<br />
<br />
\startbuffer<br />
\input tufte<br />
\stopbuffer<br />
\startTEXpage[width=15cm]<br />
%\fillinrules[n=\determinednoflines{\getbuffer},<br />
%width=fit]{first}<br />
%\fillinrules[n=\determinednoflines{\getbuffer},<br />
%width=broad]{first}<br />
%\fillinrules[n=\determinednoflines{\getbuffer},<br />
%width=3cm]{first}<br />
\fillinrules[n=\determinednoflines{\getbuffer},<br />
width=3cm,distance=.5em,separator=:]{first}<br />
\fillinrules[n=\determinednoflines{\getbuffer}]{first}{last}<br />
\stopTEXpage<br />
<br />
</context></div>
Dain88
https://wiki.contextgarden.net/index.php?title=determinenoflines&diff=32499
determinenoflines
2021-03-19T22:30:56Z
<p>Dain88: Created page with "<inputbox> type=create width=100 break=no buttonlabel=Create new article default=determinenoflines </inputbox> determinenoflines calculates the number of lines of the giv..."</p>
<hr />
<div><inputbox><br />
type=create<br />
width=100<br />
break=no<br />
buttonlabel=Create new article<br />
default=determinenoflines<br />
</inputbox><br />
<br />
[[determinenoflines]] calculates the number of lines of the given text. For example,<br />
<br />
<texcode><br />
\startbuffer<br />
\input tufte<br />
\stopbuffer<br />
<br />
\starttext<br />
\determinenoflines{\getbuffer}<br />
<br />
The number of the lines given text is $\the\noflines$.<br />
\stoptext<br />
</texcode><br />
<br />
<context mode=lmtx><br />
\startbuffer<br />
\input tufte<br />
\stopbuffer<br />
<br />
\startTEXpage<br />
\determinenoflines{\getbuffer}<br />
<br />
The number of the lines given text is $\the\noflines$.<br />
\stopTEXpage<br />
</context><br />
<br />
<br />
<br />
== interesting example of Hans using \determinenoflines. ==<br />
Unfortunately, it is not compiled in this wiki.<br />
If you run the following code with the latest LMTX(ConTeXt ver: 2021.03.17 LMTX), then you will see the lines.<br />
<br />
<texcode> <br />
\def\determinednoflines#1%<br />
{\localcontrolled{\determinenoflines{#1}}\noflines}<br />
<br />
\startbuffer<br />
\input tufte<br />
\stopbuffer<br />
<br />
\starttext<br />
<br />
\fillinrules[n=\determinednoflines{\getbuffer},<br />
width=fit]{first}<br />
\fillinrules[n=\determinednoflines{\getbuffer},<br />
width=broad]{first}<br />
\fillinrules[n=\determinednoflines{\getbuffer},<br />
width=3cm,distance=.5em,separator=:]{first}<br />
\fillinrules[n=\determinednoflines{\getbuffer}]{first}{last}<br />
<br />
\stoptext<br />
<br />
</texcode> <br />
<br />
<br />
<context mode=lmtx> <br />
\def\determinednoflines#1%<br />
{\localcontrolled{\determinenoflines{#1}}\noflines}<br />
<br />
\startbuffer<br />
\input tufte<br />
\stopbuffer<br />
<br />
\startTEXpage<br />
<br />
%\fillinrules[n=\determinednoflines{\getbuffer},<br />
% width=fit]{first}<br />
%\fillinrules[n=\determinednoflines{\getbuffer},<br />
% width=broad]{first}<br />
%\fillinrules[n=\determinednoflines{\getbuffer},<br />
% width=3cm]{first}<br />
%\fillinrules[n=\determinednoflines{\getbuffer},<br />
% width=3cm,distance=.5em,separator=:]{first}<br />
\fillinrules[n=\determinednoflines{\getbuffer}]{first}{last}<br />
<br />
\stopTEXpage<br />
</context></div>
Dain88
https://wiki.contextgarden.net/index.php?title=Pascal%27s_Triangle&diff=31739
Pascal's Triangle
2020-09-13T23:09:55Z
<p>Dain88: Created page with " Pascal's triangle is a triangula array of numbers which is well-known in mathematics. The number at the n-th row and r-th column in the array is the value of combination..."</p>
<hr />
<div><br />
<br />
[[Pascal's triangle]] is a triangula array of numbers which is well-known in mathematics. The number at the n-th row and r-th column in the array is the value of combination :<texcode> {n \choose k} </texcode> or <texcode> \binom{n}{k} </texcode>. <br />
More detailed explanation, you may read wikipedia.<br />
* '''[https://en.wikipedia.org/wiki/Pascal%27s_triangle Pascal's Triangle in Wikipedia]'''<br />
<br />
We draw Pascal's triangle using MetaFun and Lua. It can be done by the help of Hans.<br />
<br />
First, we define a function to calculate the combination with Lua.<br />
<br />
== lua code for calculation ==<br />
<br />
The functions MP.p_ncr(n,r) and MP.p_ncr_x() are provided for better and simpler code.<br />
<br />
<context source=yes mode=mkiv><br />
\startluacode<br />
local function fact (n)<br />
if n <= 0 then<br />
return 1<br />
else<br />
return n * fact(n-1)<br />
end<br />
end<br />
<br />
local function ncr(n,r)<br />
return fact(n)/(fact(r)*fact(n-r))<br />
end<br />
userdata.P = {<br />
fact = fact,<br />
ncr = ncr,<br />
}<br />
function MP.p_ncr(n, r)<br />
mp.print(ncr(n,r))<br />
end<br />
function MP.p_ncr_x()<br />
mp.print(ncr(mp.scan.pair()))<br />
end<br />
\stopluacode<br />
</context><br />
<br />
== Drawing Pascal's triangle with lines ==<br />
<br />
There are 3 different ways of calculating the value of combination tt.<br />
<br />
<context source=yes><br />
\startMPcode<br />
numeric n,r,u,dx,dy,tt,final; u := 1.8cm;<br />
<br />
path p, q;<br />
pair A,now;<br />
<br />
A := dir(210)*u;<br />
dy := ypart A;<br />
dx := -2*(xpart A);<br />
<br />
for n=0 upto 4:<br />
for r=0 upto n: <br />
% tt := lua("mp.print(P.ncr(" & decimal n & "," & decimal r & " ))");<br />
% tt := lua.MP.p_ncr(n,r);<br />
tt := runscript("MP.p_ncr_x()") (n,r) ;<br />
now := n*A + (r*dx,0);<br />
dotlabel(textext("$\displaystyle {" & decimal n & "\choose" & decimal r & "} = "& decimal tt & "$"),now);<br />
draw (now+A) -- now -- (now+A+(dx,0));<br />
endfor;<br />
endfor;<br />
\stopMPcode<br />
</context><br />
<br />
== Drawing Pascal's triangle of numbers ==<br />
<br />
<context source=yes><br />
\startMPcode<br />
numeric n,r,u,dx,dy,tt,final; u := 1.2cm;<br />
<br />
path p, q;<br />
pair A,now;<br />
<br />
A := dir(210)*u;<br />
dy := ypart A;<br />
dx := -2*(xpart A);<br />
<br />
for n=0 upto 8:<br />
for r=0 upto n:<br />
% tt := lua("mp.print(P.ncr(" & decimal n & "," & decimal r & " ))");<br />
% tt := lua.MP.p_ncr(n,r);<br />
tt := runscript("MP.p_ncr_x()") (n,r) ;<br />
now := n*A + (r*dx,0);<br />
label(textext("$" & decimal tt & "$"),now);<br />
endfor;<br />
endfor;<br />
\stopMPcode<br />
</context></div>
Dain88