Graphics, Figures & TablesHow to define a matrix value within tikzmath

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
topsquark
Posts: 71
Joined: Wed Oct 05, 2022 10:30 pm

How to define a matrix value within tikzmath

Post by topsquark »

I am trying to set up a matrix that will give me a series of points and I want to store those values in a matrix. But I have to calculate the values and define the matrix that way, rather than use \newcommand or \def. I am having some difficulties.

Code: Select all

\usetikzlibrary{math}
\begin{tikzpicture}
     \tikzmath {
          \a[1]=5;
          \c=\a[1]; {\node at (0,0) {\c}; };
     };
\end{tikzpicture}
This returns the output 51 instead of the value a[1] =5.0, which is, I suspect, the text 5 with a 1 from the [1]. (When I change the line to \c=\a[3] I get "53".) Due to a similar problem I was having I reset the \c definition as
\c=\pgfmathparse{\ax[1]}\pgfmathresult;
but I keep getting the error "extra \else".

Any thoughts?

Thanks!

-Dan

Addendum: By the way. That TikZ manual isn't really helping me all that much anymore. It reads like Hamlet. Is the TikZ language based on a programming language that I could try to learn something about? What I would call the basics of TikZ has been relatively easy to learn, but the stuff I've been doing recently is really stretching my abilities, and it shouldn't be that hard to learn. How to use matrices, for example. My last programming language is FORTRAN and I'm getting the feeling I'm missing three decades of programming changes.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

How to define a matrix value within tikzmath

Post by Stefan Kottwitz »

Hi Dan,

for TikZ, matrices (arrays) are macros. That doesn't make it easy. I know how to access an array element, but not how to assign a value to an element except redefining the macro (such as with a foreach loop). True array are possible with other packages or expl3 or Lua with LuaTeX.
topsquark wrote:Is the TikZ language based on a programming language that I could try to learn something about?
It's based on PGF (ok, you know that) and that's based on TeX, those lower layers are much more difficult than TikZ itself.
topsquark wrote:That TikZ manual isn't really helping me all that much anymore. It reads like Hamlet.
That's why I'm currently working on a TikZ book: LaTeX Graphics with TikZ.

Stefan
LaTeX.org admin
topsquark
Posts: 71
Joined: Wed Oct 05, 2022 10:30 pm

How to define a matrix value within tikzmath

Post by topsquark »

Thank you. Well, it's good to know that what I was trying to do is so hard. I was afraid I was getting slow. :)

I noticed that your link says the book is on sale. Is it complete, or are you saying you are working on a second edition?

-Dan
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

How to define a matrix value within tikzmath

Post by Stefan Kottwitz »

Hi Dan,

it's the book announcement, first edition, and it can be pre-ordered. At least I tested and could pre-order with the German Amazon, I don't see the option on amazon.com. But the price there is too high anyway, unrealistic, that may change.

It is announced to appear in June (EU) and July (US). I'm working on chapter 10 (of 16) now.

Stefan
LaTeX.org admin
Post Reply