I would like to make the function calls \findLargest in the MWE below a little more dynamic and compact.
As demonstrated in the example below, I can store glossaries values and include them in the comparison.
I would like to change it however so that the call: \findLargest{0.001,value} can test if the elements of the list are numeric or are gls labels.
To do this I think the code below would require a command or step implemented before the largest number search call that would apply an if statement that would carry out if is numeric type logic. (if such a thing is possible). If false (not numeric) I would want the index element of the list to be replaced by the result of \glsentryname{i}
This is tough for me to visualize as I am used to programming in languages that have manually defined loops and thus it's easy for me to insert decision structures and new variables within the loop.
\documentclass{article}
\usepackage{xparse}
\usepackage{glossaries}
\usepackage{siunitx}
\newglossaryentry{value}{name={0.022}, first={0.022}, description={0.022} }
\ExplSyntaxOn
\NewDocumentCommand{\findLargest}{ om }
{
\IfNoValueTF{#1}
{% separator is a comma, directly use \fp_eval:n { max ( #2 ) }
\engbird_compute_max:n { #2 }
}
{% we need to pass the separator
\engbird_find_largest:nn { #1 } { #2 }
}
}
\seq_new:N \l_engbird_largest_seq
\tl_new:N \l_engbird_largest_tl
\cs_new_protected:Npn \engbird_find_largest:nn #1 #2
{
% split the input at the stated separator
\seq_set_split:Nnn \l_engbird_largest_seq { #1 } { #2 }
% build a comma separated list
\tl_set:Nx \l_engbird_largest_tl { \seq_use:Nn \l_engbird_largest_seq {,} }
% compute the max
\engbird_compute_max:V \l_engbird_largest_tl
}
% syntactic sugar
\cs_new:Npn \engbird_compute_max:n #1
{
\fp_eval:n { max (#1) }
}
\cs_generate_variant:Nn \engbird_compute_max:n { V }
\ExplSyntaxOff
\begin{document}
\noindent
\findLargest{1, 2 ,3, 6, 3,1} \\
\findLargest[;]{ 1.5 ; sqrt(2) ; pi/2 } \\
\findLargest{0.00001,\glsentryname{value}} \\
\end{document}
\glsentryname{value}is being expanded before the test is applied and it is correctly printing the largest value. – Andrew Swann Apr 12 '15 at 09:28\glsentrynameaddition to the function and dynamically apply it. – EngBIRD Apr 12 '15 at 16:15