Graphics, Figures & TablesTikZ: I have to define a variable twice?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
topsquark
Posts: 71
Joined: Wed Oct 05, 2022 10:30 pm

TikZ: I have to define a variable twice?

Post by topsquark »

I'm making a program to fill out a Clebsch-Gordon spin table. There are a few tweaks that still need to be done, but I'm almost there. One of them is this: I have the variables \j1 and \j2. I have to define them in the main block, and then I have to define them again in the function block for coeff. For some reason, if I don't redefine them, they turn into 01 and 02, respectively, instead of their previously defined values.

Here's the code. I have indicated the \j1 and \j2 lines with long arrows on the right.

Code: Select all

Code, edit and compile here:
\documentclass[tikz]{standalone}
\usepackage{fp}
\usetikzlibrary{math, fixedpointarithmetic}
\begin{document}
\begin{tikzpicture}[fixed point arithmetic]
% Variables
% j1, m1, j2, m2: Input spin vectors
% jtot, mtot: Input total spin vector
% jitot, mitot, mi1, mi2: Temporary spin vector values for the coeff function
% blocks: Number of coefficient boxes
% dw, dh: Number of cells per per box
% aoldx, aoldy: Coordinates of the top right of the last coeefficient grid
% anewx, anewy: Coordinates of the top right of the new coefficient grid
% num: Number to be converted to fraction
% r: Returned fraction
% w, h: Width and height of one cell
% n, d: Throw-away integers
% c, i, j, k, hm1, p, q, s, wjtot: Throw-away variables
% Program Block
\tikzmath {
% Convert A Decimal To A Fraction
function f(\num) {
integer \n, \d;
\stop=0;
for \k in {1,...,200} {
\a=\k*\num;
if \stop==0 then {
if int(abs(\a))==abs(\a) then {
if \k==1 then {\n=\num; let \r="\n"; \stop=1; }
else {\n=\a; \d=\k; let \r="\n/\d"; \stop=1; };
};
};
};
return \r;
};
function coeff(\jitot,\mitot,\mi1,\mi2) {
\j1=1/2; \j2=1/2; %<--------------------------------------------------------------------
\s=0;
for \ki in {0,...,0} {
\s=\s+1/((\ki)!*(\j1+\j2-\jitot-\ki)!*(\j1-\mi1-\ki)!*(\j2+\mi2-\ki)!*(\jitot-\j2+\mi1+\ki)!*(\jitot-\j1-\mi2+\ki)!);
};
 
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Thanks!

-Dan

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

topsquark
Posts: 71
Joined: Wed Oct 05, 2022 10:30 pm

TikZ: I have to define a variable twice?

Post by topsquark »

Okay, I figured it out. When I was testing things out I had shortened my loops to go from 0 to 0. What was happening was, inside the loop \j in {0,...,0}, I was getting \j1 = 01 because \j =0. I changed my for loop variable to \t and now I don't have to redefine anything.

I realize that TikZ isn't a strictly Mathematically driven programming language but some of this is just killing me!

-Dan
Post Reply