Sorry about the thread title but I've learned that I no longer know the technical term. It used to be called "concatenation of strings." But strings are now something completely different.
Anyway, what I'm up to is to tack a number onto a piece of text. Normally this would be easy. But the text is "/2". Any time I put a number on the front to make a fraction it's no longer a piece of text, it's a fraction and it gets evaluated. I'm working on a quick routine to take the number 0.5 and change it to the text "1/2". And similarly 1.5 to "3/2". But if I run 1 and /2 together I just get 0.5 again.
I can do this by using nested if statements if I have to but there ought to be a way to do this. I suspect that part of my problem in looking up a solution is that I don't know what to call this process anymore!
Thanks!
-Dan
Graphics, Figures & Tables ⇒ TikZ: How can I add two pieces of text?
NEW: TikZ book now 40% off at Amazon.com for a short time.

TikZ: How can I add two pieces of text?
Please add a
minimal working example marked with code tags to your explanation, so that one can see why your input is evaluated.

TikZ: How can I add two pieces of text?
I didn't include the code because it was simply \b = 0.5; \let \a = "\b/2"; and various other attempts.Bartman wrote:Please add aminimal working example marked with code tags to your explanation, so that one can see why your input is evaluated.
Anyway, you're right, I should have included it. My apologies.
I did finally find an answer.
Code: Select all
\begin{tikzpicture}
\tikzmath {
int \b;
function f(\n) {
if int(\n)<\n then {\b=2*\n; let \r="\b/2"; }
else {let \r=1; };
return \r;
};
\p = 0.5; \a = f(\p);
{ \node at (0,0) {\a}; };
};
\end{tikzpicture}
I appreciate the response.
-Dan
Addendum: It works on my system. I have no idea why it isn't working here. Sorry about that!