1
$\begingroup$

I have the following expression:

enter image description here

I initalize the variables:

capital = 1200; rate = 0.02; time = 6; period = 12; 

and then run for second term, for example:

HoldForm[c (1 + r*t)] /. {c -> capital, r -> rate, 
  t -> Internal`RationalNoReduce[n, m] /. {n -> time, m -> period}}

I get

enter image description here

I receive the same result if I use Inactivate or Unevaluated beforehand. It is necesary that the fraction 6/12 does not get simplified to 1/2. This result is not exactly what I want but it is enough for me. But when I enter that instruction in a Row function, I get a different output:

enter image description here

First multiplication symbol × disappears, better, but second make easier to read expression. I have tried with FractionBox, but no difference. I use version 12.3.1 for Windows and Linux

$\endgroup$
2
  • 2
    $\begingroup$ Welcome to Mathematica StackExchange! Does this answer your question? HoldForm does not Hold Form for fractions sometimes For you this means: HoldForm[c (1 + HoldForm[r] HoldForm[t])] /. {c -> capital, r -> rate, t -> Internal`RationalNoReduce[n, m] /. {n -> time, m -> period}} And if you are bothered by ×, see Getting rid of the horrible Times x in Mathematica 12.3. $\endgroup$
    – Domen
    Commented Apr 3, 2023 at 8:22
  • $\begingroup$ It's not clear to me what you actually want to achieve. However, if you want fine level control over the presentation of arithmetic expressions (so you can override Mathematica's standard, normalized presentation), I've found TemplateExpression to be very helpful. $\endgroup$
    – lericr
    Commented Apr 3, 2023 at 12:57

2 Answers 2

3
$\begingroup$

You're looking for AutoMultiplicationSymbol:

Row@{
  Style[
   HoldForm[1200 (1 + (0.02 6)/12)],
   AutoMultiplicationSymbol -> {"Numbers"}
   ]
  }

enter image description here

Note how this solves both the missing symbol inside Row, and the unwanted symbol before the parentheses (you can check the documentation page for other settings for where to include the symbol).

$\endgroup$
0
$\begingroup$

You did not write what your aim is. Depending on that, one selects the solution. I guess that you need it for some demonstration. If this is right, I propose instead of HoldForm, using the figures in the form of strings. Then they do not cancel with one another. For example, this is the definition of your parameters:

capital = 1200; rate = 0.02; time = 6; period = 12;

Let us introduce a rule:

rule = {c -> capital, r -> rate, n -> time, m -> period} /. 
  Rule[a_, b_] :> Rule[a, ToString[b]]

(*  {c -> "1200", r -> "0.02", n -> "6", m -> "12"}  *)

Here it is clearly seen that each figure is s string. However, this is not visible in Mathematica. There they look as usual figures.

Here is your calculation

c (1 + r*n/m) /. rule

(*  "1200" (1 + ("0.02" "6")/("12"))  *)

Again, in Mathematica, the output looks as follows:

enter image description here

I hope it helps. Have fun!

$\endgroup$
1
  • $\begingroup$ Thank so very much for yours fast and useful answers!! $\endgroup$ Commented Apr 5, 2023 at 10:33

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