2
$\begingroup$

I am using WriteString to avoid automatic line change. But it seems like the it does not work with Style, like the following

a = 7;
Style[WriteString["stdout", a], FontSize -> 47]

The FontSize seems to be not effective. Does WriteString not work with Style at all? If so, how can I even change the font size of a WriteString output?

It seems like my language is not very clear, so the reason why I ask this question is, I would like to print all possible arrangement of the some letters, say I define a function

f[i_] := Which[i == 1, "A", i == 2, "B", i == 3, "C"]

and Mathematica is expected to print

ABC
ACB
BAC
BCA
CAB
CBA
$\endgroup$
10
  • 1
    $\begingroup$ WriteString is designed for writing to streams, such as files. In what sense are you wanting to add a style in such a situation? What file format are you dealing with? And if you AREN’T trying to write to a file, then I think you want a different function than WriteString. $\endgroup$ Commented May 16, 2019 at 23:33
  • 1
    $\begingroup$ As a follow up, stdout only accepts text, not styles. This is described in the documentation: reference.wolfram.com/language/tutorial/… $\endgroup$ Commented May 16, 2019 at 23:35
  • $\begingroup$ What do you mean by "automatic line change"? $\endgroup$
    – m_goldberg
    Commented May 17, 2019 at 0:26
  • 1
    $\begingroup$ Paste[Style["Thing to display", 24]] $\endgroup$ Commented May 17, 2019 at 18:34
  • 1
    $\begingroup$ Instead of adding material to the answer below, add it to your question or submit a new answer of your own. $\endgroup$
    – bbgodfrey
    Commented May 19, 2019 at 3:25

3 Answers 3

3
$\begingroup$

I think there still deficiencies in my understanding of what the OP wants because of:

  • language difficulties
  • the OP's example does not involve "several outputs" as mentioned in comments

Despite this I will give the question a shot.

Mathematica has a number of output wrapping forms that will group multiple objects on one line. I think in your case Row might be the form you are looking for.

Using Row along with Style allows multiple objects of almost any kind, not just strings, to be placed and formatted on one line. You can wrap Row in a master style and override the master style for any of the individual objects.

For example

p = 1; q = 2;
Style[
  Row[
    {Subscript["t", Style[p, Plain]] + Subscript[t, Style[q, Plain]], 
     Style["→", Red], "F≡I"}],
  Bold, FontFamily -> "Times", 36]

output

$\endgroup$
3
$\begingroup$

If you must print your permutations, a more typical Mathematica style would be:

Do[
    Print @ Style[Row[perm], FontFamily->"Times", 46],
    {perm, Permutations[{"A", "B", "C"}]}
]

During evaluation of In[434]:= ABC

During evaluation of In[434]:= ACB

During evaluation of In[434]:= BAC

During evaluation of In[434]:= BCA

During evaluation of In[434]:= CAB

During evaluation of In[434]:= CBA

If you actually want to do something afterwards with the permutation, something like:

Table[
    Style[Row[perm], FontFamily->"Times",46],
    {perm,Permutations[{"A","B","C"}]}
]

{ABC,ACB,BAC,BCA,CAB,CBA}

might be more useful.

$\endgroup$
0
$\begingroup$

Thanks to m_goldberg's answer, I was able to figure out a solution based on his or her post

letter[i_] := Which[i == 1, "A", i == 2, "B", i == 3, "C"]

For[i = 1, i <= 3!, i++, 
 Print[Style[
   Row[{Style[letter[Permutations[{1, 2, 3}][[i]][[1]]], Plain], 
     Style[letter[Permutations[{1, 2, 3}][[i]][[2]]], Plain], 
     Style[letter[Permutations[{1, 2, 3}][[i]][[3]]], Plain]}], 
   FontFamily -> "Times", 46]]]

which will print all arrangement of letters A, B and C.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.