I want to represent a graph where the labels for each node are obtained computing a modulo computation. The first and easy way to do it is as follow :
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs,graphs.standard}
\begin{document}
\begin{tikzpicture}
\def \n {3}
\graph[clockwise=\n,radius=3cm] {
\foreach \x [evaluate=\x as \xn using {int(mod(\x+1,\n))}] in {0,...,\the\numexpr\n-1} {
\foreach \y [evaluate=\y as \yn using {int(mod(\y+1,\n))}] in {\x,...,\the\numexpr\n-1} {
\x / {$a_\x, a_\xn$} --
\y / {$a_\y, a_\yn$};
};
};
};
\end{tikzpicture}
\end{document}
Then I found out about pgfmathtruncatemacro and wrote
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs,graphs.standard}
\begin{document}
\begin{tikzpicture}
\def \n {3}
\graph[clockwise=\n,radius=3cm] {
\foreach \x in {0,...,\the\numexpr\n-1} {
\pgfmathtruncatemacro{\xn}{mod(\x+1,\n)}%
\foreach \y in {\x,...,\the\numexpr\n-1} {
\pgfmathtruncatemacro{\yn}{mod(\y+1,\n)}%
\x / {$a_\x, a_\xn$} --
\y / {$a_\y, a_\yn$};
};
};
};
\end{tikzpicture}
\end{document}
And strangely it gives me these errors :
! Undefined control sequence. \pgfmathsetcount ... \pgfmath@onquick #2\pgfmath@ {\afterassignment \pgfmath... l.16 } ; The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g.,
\hobx'), typeI' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.! Undefined control sequence. \tikz@lib@graph@handle@node@cont ...kzgraphnodeas \tikzgraphnodeas@default ... l.16 } ; The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g.,
\hobx'), typeI' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.! Undefined control sequence. \tikz@lib@graph@typesetter ->\tikzgraphnodetext l.16 } ; The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g.,
\hobx'), typeI' and the correct spelling (e.g., `I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.) ! Incomplete \iffalse; all text was ignored after line 16. \fi
And I really can't understand why it wouldn't work.
[EDIT] I wrote my second code based on this answer. The part where I write \n - 1 without \the\numexpr is not needed when working in Overleaf so it's NOT the problem here. And I don't want to have \pgfmathtruncatemacro in the labelling of the node since the answer I linked works perfectly for me too without needing it. My problem is that it looks buggy when using it in the \graph environment.
[EDIT 2] Added \the\numexpr since it would not compile on every installation of TL and since it was not this that made the program not work.


\pgfmathtruncatemacrobut the\n-1in the\foreachloop, and can be solved e.g. with\the\numexpr\n-1. However, even your first example does not compile. – Oct 14 '19 at 13:52parse=trueoption to the\foreach... – Paul Gaborit Oct 14 '19 at 13:59\graphmacro changes the syntax : you can't use TeX code directly. Here, you must use[/utils/exec={\pgfmathtruncatemacro{\xn}{mod(\x+1,\n)}}]instead of\pgfmathtruncatemacro{\xn}{mod(\x+1,\n)}... – Paul Gaborit Oct 15 '19 at 06:07[parse=true]it tells me it doesn't know this command. The image I put was obtained with the first code on Overleaf. – Lhooq Oct 15 '19 at 09:13