I have written this small module to write the n(2S+1)LJ symbol
angsym[n1_, s1_, l1_, j1_] := Module[{n = n1, s = s1, l = l1, j = j1},
lsym = Piecewise[{{"S", l == 0}, {"P", l == 1}, {"D", l == 2}, {"F",
l == 3}}];
Print[Superscript[n + 1, 2 s + 1], Subscript[lsym, j1]]]
This code is working fine.
But I want this code to write a single output to symbolize a reaction like:
n1(2 S1+1)L1 J1 → n2 (2 S2 +1)L2 J2
by using this module.
I have tried
It would help to understand how you actually want to use these structures, but here’s my initial suggestion. You don’t need Module and you don’t need Print. Try something like this:
Thanks for the answer. It works fine. I didn’t know about the Switch command. Using the Print inside module was not working. Using Row and Return is working. Below is the code
angsym[n1_, s1_, l1_, j1_] := Module[{n = n1, s = s1, l = l1, j = j1},
lsym = Piecewise[{{"S", l == 0}, {"P", l == 1}, {"D", l == 2}, {"F",
l == 3}}];
rowout = Row[{Superscript[n + 1, 2 s + 1], Subscript[lsym, j1]}];
Return[rowout]]
The Print was actually working, you just didn’t understand what was happening. Also, you don’t need the Return in your Module. The resulting value of a Module is simply the last expression in the Module.
Also, you’re free to write your code however you want, of course, but I’m curious… After learning about Switch, and after acknowledging that my simpler code works, why do you revert back to using Piecewise, Module, and Print?
I was being lazy about changing Piecewise to Switch. But I needed to understand modules better because I have to use Module functions made by others and I wanted to change them according to my needs. So, I am sticking to Module. Print is an odd command to use, but I didn’t know about the use of Row like that.
Plus I am using Return because in the other Module, I have many output statements and I need different statements at different times as written output.