I'm trying to make the following code work correctly. I'm using command line call to python to check whether a number is in a list (no clue how to do this in pure LaTeX(?)). I then want to check whether the result is 'True' or 'False'.
\documentclass{article}
\newcommand{\mysequence}{[2,3,5,7,11,13,17,19,23,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101]}
\makeatletter
\newcommand\isprime[1]{\@@input|"python -c print((#1)in\mysequence)"}
\makeatother
\newcommand{\compare}[1]{%
\def\test{\isprime{#1}}
\def\true{True}
\def\false{False}
Test: \test\par
\ifx\test\true
#1 is PRIME! :D
\else
#1 is not prime ;(
\fi
\vspace{10pt}
}%
\begin{document}
\compare{3} % 3 is prime
\par
\compare{4} % 4 is not prime
\end{document}
As is, I get a correct value of \test, but the \ifx comparison does not seem to expand the \@@input and I get a wrong result. The output looks like that:
I believe I could fix this by using \edef instead of \def, but we I try i make LaTeX very angry and it goes a little bit too far past my knowlegde of it to fix it.



\compare{\thepage}(?). I realise its probably something to do with a completly different part of latex which I also don't understand. – MarcinKonowalczyk Jun 20 '19 at 17:25\thepagedoes not contain a number, but a command:\csname @arabic\endcsname \c@page. You need to do two extra things: 1) fully expand\thepageas in\edef\tmp{\thepage}and 2) Provide the number, not the macro to\compare, as in\expandafter\compare\expandafter{\tmp}. – Steven B. Segletes Jun 20 '19 at 17:30\expandafter\command\expandafter{\argument}, but I guess I'll go back to the \expandafter tutorial again. :) – MarcinKonowalczyk Jun 20 '19 at 17:42\expandafter\command\expandafter{\argument}executes the initial\expandafter, which, by definition, skips over the\commandand executes the next thing, which is another\expandafter. That 2nd\expandafterskips over the left brace and expands exactly once the value of\argument, which means it places the literal value of\argumentin its place. Then what is left?\command{<a literal number>}– Steven B. Segletes Jun 20 '19 at 17:47