1
$\begingroup$

I am working with the Article-style. How can I change globally the output of Print command?

For example typing

x=3;
Print["x", x]

will produce the same output with

x = 3;
Print[Style["x=", Red], x]

without the need to specify the Style.

Thanks.

EDIT 2

I apologize for the inconvenience. I thought that I could get what I want with a minimal example. I should have been more specific from the very beginning.

In reality I have my definitions (below is just a part).

ruls = {Nc0 -> 35.794, Nc1 -> 509.74, Ns0 -> 18.275, 
   Ns1 -> 27.971, β -> 0.8, m -> 0.0304, τ -> 1.4503, 
   zp0 -> 1000, zp1 -> 1, 
       α -> 5.3/10^3, χ -> 1., Tref -> 298.15, 
   C1 -> 45.685, C2 -> 245.06, η0 -> 0.2343, 
   Tinit -> 294.75, Δt -> 0.003}; 
elstrain = {0.00005, 0, 0, 0, 0, 0}; 
Δelstrain = {0.00005, 0, 0, 0, 0, 0}; 
Δstrain = {0.00005, 0, 0, 0, 0, 0}; 

equivStrainRate = 
  Sqrt[2/3 Δstrain.Δstrain]/\
Δt /. ruls;
aT[T_] := 10^(-C1 (T - Tref)/(C2 + (T - Tref)));
aTinit = aT[Tinit] /. ruls;
λ = aT[Tinit] equivStrainRate /. ruls;
η = η0 /. ruls;
DaTDT = D[aT[T], T] /. T -> Tinit /. ruls;
DλDT = DaTDT equivStrainRate;

Print[Style["Values of Quantities\n", Blue, 
  Bold], "equivStrainRate=", equivStrainRate, "\n", \
"equivStrainRateStar=", equivStrainRateStar, "\n", "aT=", aTinit, "\n\
", "\[Lambda]=", \[Lambda], "\n", "\[Eta]=", \[Eta], "\n", "DaTDT=", \
DaTDT, "\n", "D\[Lambda]DT=", D\[Lambda]DT]

enter image description here

I want the equivStrainRate=, equivStrainRateStar=, etc in above output to appear Red.

$\endgroup$
  • $\begingroup$ Ok! I will redit it. $\endgroup$ – Dimitris Jan 26 '16 at 13:54
  • $\begingroup$ Thanks. What Article style has to do with the problem? $\endgroup$ – Kuba Jan 26 '16 at 13:59
  • $\begingroup$ @Kuba: I wanted to clarify the I don't use the Default style. I am not sure if this affects really the question. $\endgroup$ – Dimitris Jan 26 '16 at 14:01
  • $\begingroup$ So you want to confine it to a single stylesheet? $\endgroup$ – Jason B. Jan 26 '16 at 14:01
  • 1
    $\begingroup$ So why not creating myPrint[name_, rest___]:=Print[Style[name<>"=", Red], rest] like in 104839 $\endgroup$ – Kuba Jan 26 '16 at 14:04
3
$\begingroup$
myPrint[lbl_, x__] := Print@Grid[
   Join[{{Style[lbl, Blue], SpanFromLeft}}, 
    Partition[Riffle[{x}, "=", {2, -2, 3}], 3]],
   ItemStyle -> {{{Red}, {Red}, {}}, {}}
   ]

myPrint["title", "x", 1, "y", 2]

enter image description here

$\endgroup$
2
$\begingroup$

This hardly seems like a shortcut to just typing it all out longhand, but try this

names = {"equivStrainRate", "equivStrainRateStar", "aT", "λ", 
   "η", "DaTDT", "DλDT"};
vals = {equivStrainRate, equivStrainRateStar, 
   aTinit, λ, η, DaTDT, DλDT};
Grid[Transpose[
   {Style[#, Red] & /@ names, ConstantArray[Style["=", Red], 7], 
    vals}]~Prepend~{Style["Values of Quantities", Blue, Bold], 
   SpanFromLeft}]

enter image description here

$\endgroup$
  • $\begingroup$ Very close but I guess I am very bizarre! I want the very name, e.g., equivStrainRate= in Red; but not the value of the variable itself (here 0.0136083). $\endgroup$ – Dimitris Jan 26 '16 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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