Graphics, Figures & Tables ⇒ TikZ: How can I add two pieces of text?
TikZ: How can I add two pieces of text?
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
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
TikZ: How can I add two pieces of text?

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!