I’m sorry for the imprecision of my question but I couldn’t find a way to describe my problem correctly.
I created a new package and in the “lua” part, I use two classes, one for points and the other for lines. Two tables z
and L
are associated to these classes. In the first one are stored the points and in the second the lines.
For example for points z.a = point: new (1,2)
. This defines the point a
whose affix (complex number) is 1+2i
. In the table here the key is a
and the value 1+2i
. In the same way if a
and b
are defined, I can define a line with for example L.a__b = line: new (z.a,z.b)
. This is a bit more complicated because tables are stored in a table.
I may be wrong but I think my problem can be translated like this:
If x=a and y=b then how do I define a function that gives me L.a__b = line: new (z.a,z.b)
, L.x__y
etc. gives nothing.
The package can be found on this page tkz-elements. You will find in the archive the code of tkz-elements a readme and a small documentation and several examples. All this is still experimental!
Here is the more complete code:
documentclass{article}
usepackage{tkz-euclide}
usepackage{tkz-elements}
begin{document}
parindent = 0pt
begin{elements}
z.a = point: new (0, -1)
z.b = point: new (4, 2)
z.c = point: new (1, 2)
z.d = point: new (-1, 3)
L.a__b = line: new (z.a,z.b)
L.a__d = line: new (z.a,z.d)
L.d__b = line: new (z.d,z.b)
-- L.c__d = line: new (z.c,z.d)
-- z.i =intersection_ll_ (L.a__b,L.c__d)
va = tostring(c__d)
for i in pairs(L) do
if i == va then
else
_, _,ft, sd = string.find( "c__d", "(.+)__(.+)" )
L["ft__sd"] = line: new (z.ft,z.sd) -- wrong !
-- tex.print(ft..'__'..sd) -- to show the values of ft and sd
break
end
end
-- the next code is here to show the different values
for i,k in pairs(L) do
tex.print(tostring(k)..";"..tostring(i))
for u,v in pairs(k)
do
tex.print(tostring(v))
end
tex.print('\\')
end
end{elements}
begin{tikzpicture}
tkzGetNodes
tkzDrawLines[add=1 and 1](a,b c,d)
tkzDrawPoints(a,b,c,d)
tkzLabelPoints(a,b,c,d)
end{tikzpicture}
end{document}
Some explanations: 4 points are defined then 4 lines but I commented the last one L.c__d
to show my problem.
The code allows to get the intersection of two lines if they are defined. I would like to find a test to know if one of them is not defined and in this case create it automatically.
Having commented L.c__d = line: new (z.c,z.d)
this line is no longer defined. So I parse the expression representing this line with the string.find
function and get ft
and sd
which point to c
and d
.
Question: How can I use ft
and sd
to get L.c__d = line: new (z.c,z.d)
?
