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.


\newglossaryentry{value}{name={0.022}, first={0.022}, description={0.022} }


\NewDocumentCommand{\findLargest}{ om }
   {% 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 }


\findLargest{1, 2 ,3, 6, 3,1} \\
\findLargest[;]{ 1.5 ; sqrt(2) ; pi/2 } \\
\findLargest{0.00001,\glsentryname{value}} \\

  • Can you please clarify what you are trying to do? As it stands \glsentryname{value} is being expanded before the test is applied and it is correctly printing the largest value. – Andrew Swann Apr 12 '15 at 9:28
  • @AndrewSwann The expansion and logic in the function work perfectly. I am just trying to automate the recognition of the gls label so that I don't have to include it in the function call itself. My labels are extremely complicated strings and these functions are nested very deep, it would be helpful to move the \glsentryname addition to the function and dynamically apply it. – EngBIRD Apr 12 '15 at 16:15
  • OK. Have a look at tex.stackexchange.com/q/7180/15925 – Andrew Swann Apr 13 '15 at 10:12
  • @AndrewSwann Thanks for the link - I had allready bookmarked this one away because it was likely more appropriate to test for a number than a gls label. It wasn't so much the test that is problematic, but how to apply it to a given element of a list. For example unlike a C for loop, I don't believe I have access to the individual elements of the list as they are iterated through. Maybe this is where I am wrong, but in the example above the iteration seems to be handled internally by max() – EngBIRD Apr 13 '15 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.