This is now part three of what will most likely be a several part questions, first of which was answered here, second of which was answered here. Now that I've begun to start using expl3 more extensively in my document, I'd like to know how to work with multiple variables within a new document command. The example I'm working with, for instance, is trying to write an expression that will ultimately go under a square root radical. Given by:
\documentclass[12pt]{article}
\usepackage{xfp}
\ExplSyntaxOn
\NewDocumentCommand{\underradical}{}
{
% Attempting: Setting a value to correspond to || or nothing
\int_set:Nn \l_tmpa_int_abs { \int_rand:nn { 1 } { 2 } }
% if odd indicator, use |, else do nothing
\int_if_odd:nTF \l_tmpa_int_abs { | } {}
% the variable
x
% Attempting: Setting a variable to correspond to an x shift or not
\int_set:Nn \l_tmpa_int_val { \int_rand:nn { 1 } { 2 } }
% Attempting: Setting a variable to correspond to a left or right shift
\int_set:Nn \l_tmpa_int_dir { \int_rand:nn { 1 } { 2 } }
% a random sign
\int_if_odd:nTF \l_tmpa_int_val {
\int_if_odd:nTF \l_tmpa_int_dir { + } { - }
} {}
% the absolute value of the summand
\int_if_odd:nTF \l_tmpa_int_val { \int_rand:nn { 1 } { 3 } }
% if odd exponent use |, else do nothing
\int_if_odd:nTF \l_tmpa_int_abs { | } {}
}
\ExplSyntaxOff
\begin{document}
\underradical
\end{document}
Where there are three distinct variables being used here, \l_tmpa_int_abs, \l_tmpa_int_val, and \l_tmpa_int_dir. However, this does not yield a desired output it gives an output of 2x22, or 1x22, or any combination as such where each 2 also has an equal likelihood of being a 1. I thought I was implementing the naming scheme correctly based off page 3 and 4 of the expl3 documentation, but obviously this is unlikely as my output is not correct. I can at least, get one of the 2s or 1s to actually being printed as the desired symbol or number, but only if I change their variable to be \l_tmpa_int. Naturally, I cannot have all three variables declared this to work as the compiler won't know which one I'm referring to. I would like to know how to work with multiple variables within a given new document command to allow me to fix my issue.
\int_new:N <var>), it seems you are missing the false branch in the\int_if_odd:nTFbelowthe absolute value of the summand– Phelype Oleinik Oct 15 '20 at 23:46