# Using same module multiple times to write single line output

**URL:** <https://community.wolfram.com/t/using-same-module-multiple-times-to-write-single-line-output/22550>\
**Category:** Questions\
**Created:** [July 26, 2023, 3:00pm UTC](https://community.wolfram.com/t/using-same-module-multiple-times-to-write-single-line-output/22550 "2023-07-26T15:00:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishkumarkundan](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@vishkumarkundan](https://community.wolfram.com/u/vishkumarkundan)\
**Post date:** [July 26, 2023, 3:00pm UTC](https://community.wolfram.com/t/using-same-module-multiple-times-to-write-single-line-output/22550/1 "2023-07-26T15:00:52Z")

</div>

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

```
Print[angsym[n1,s1,l1,j1], "->", angsym[n2,s2,l2,j2]]

```

This does not work.

---

<div class="post-metadata">

**Author:** ![eric3](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/eric3/32/12760_2.png) [@eric3](https://community.wolfram.com/u/eric3)\
**Post date:** [July 26, 2023, 3:58pm UTC](https://community.wolfram.com/t/using-same-module-multiple-times-to-write-single-line-output/22550/2 "2023-07-26T15:58:06Z")

</div>

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:

```
angsym2[n_, s_, l_, j_] :=
 With[
  {lsym = Switch[l, 0, "S", 1, "P", 2, "D", 3, "F", _, 0]},
  Row[{Superscript[n + 1, 2 s + 1], Subscript[lsym, j]}]]

```

You also don’t need `Print` to display your rule example:

```
angsym2[n1, s1, l1, j1] -> angsym2[n2, s2, l2, j2]

```

---

<div class="post-metadata">

**Author:** ![vishkumarkundan](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@vishkumarkundan](https://community.wolfram.com/u/vishkumarkundan)\
**Post date:** [July 26, 2023, 4:39pm UTC](https://community.wolfram.com/t/using-same-module-multiple-times-to-write-single-line-output/22550/3 "2023-07-26T16:39:23Z")

</div>

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]]

```

And the output can be taken in same manner.

---

<div class="post-metadata">

**Author:** ![eric3](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/eric3/32/12760_2.png) [@eric3](https://community.wolfram.com/u/eric3)\
**Post date:** [July 26, 2023, 4:51pm UTC](https://community.wolfram.com/t/using-same-module-multiple-times-to-write-single-line-output/22550/4 "2023-07-26T16:51:51Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![eric3](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/eric3/32/12760_2.png) [@eric3](https://community.wolfram.com/u/eric3)\
**Post date:** [July 26, 2023, 4:55pm UTC](https://community.wolfram.com/t/using-same-module-multiple-times-to-write-single-line-output/22550/5 "2023-07-26T16:55:33Z")

</div>

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`?

---

<div class="post-metadata">

**Author:** ![vishkumarkundan](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@vishkumarkundan](https://community.wolfram.com/u/vishkumarkundan)\
**Post date:** [July 26, 2023, 5:28pm UTC](https://community.wolfram.com/t/using-same-module-multiple-times-to-write-single-line-output/22550/6 "2023-07-26T17:28:18Z")

</div>

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.
