1

Sometimes there is only one item in the array list, and array access operator seems to get only the first character of the element in this case. How to fix it?

\documentclass[tikz, border=1cm]{standalone}

\begin{document}
\begin{tikzpicture}
  \node at (0, 0) {\pgfmathparse{{0.3}[0]}\pgfmathresult};
  \node at (1, 0) {\pgfmathparse{{13}[0]}\pgfmathresult};
  \node at (2, 0) {\pgfmathparse{{"abc"}[0]}\pgfmathresult};
  \node at (3, 0) {\pgfmathparse{{12pt}[0]}\pgfmathresult};
\end{tikzpicture}
\end{document}

enter image description here

ZhiyuanLck
  • 4,516
  • 2
    (1) Add extra braces {{"abc"}}[0]. (2) Don't use PGF (or LaTeX in general) for that. – Henri Menke Jun 01 '20 at 09:53
  • @HenriMenke would you care to expand a bit your suggestion not to use LaTeX this way ? It feels interesting (though I don't know why LaTeX should not be used this way ^^). – BambOo Jun 01 '20 at 13:02
  • If you want to process strings, use xstring (admittedly the manual is unreadable, literally). pgfmath is constantly converting from text to lengths to FPU registers and back, and tends to convert 1cm into 1pt (see section 95.1.2 on page 1028). – John Kormylo Jun 01 '20 at 14:51
  • @BambOo I mean by this to do your data processing outside of LaTeX in languages that implement proper array operations. – Henri Menke Jun 02 '20 at 06:46
  • @HenriMenke, I can only agree with you on that point :) – BambOo Jun 02 '20 at 07:56

0 Answers0