Can I parse the text returned from \gls*{...} and get latex to recognize it as a numerical variable so that I can use it in a calculation? This calculation could be done using calculator, fp, calc or pgf depending what I run into concerning package conflicts. I am compiling in XeLaTeX and TeX4HT.

The primary reason why I turned to the glossaries package to manage was because of the presence of symbols such as . _ + - etc in the names of the variables. The presence of these precludes the possibility that they will be suitable names for newcommands. I will likely post another question later trying to figure out if it's possible to import a table from a csv file and iterate through it until the matching string argument is found, and then return the value on the same line in a specific column, within a newcommand, but I am hoping it's easier to parse a number from a string returned by a gls call.

In the MWE below the different approaches I have tried are commented out to permit compilation to show the success of the glossaries definition and calculation functions.




    \newglossaryentry{d.A_Control-0}{ type={data},  name={1.1}, first={1.1}, description={1.1} }

    \newglossaryentry{d.B_Sample-2}{ type={data},  name={1.08059784043081}, first={1.08059784043081}, description={1.08059784043081} }




            \item \gls*{d.A_Control-0}
            \item \gls*{d.B_Sample-2}
            \item \glsentryfirst{d.A_Control-0}
            \item \foldfp{33}{2}{2} - proof that the calculation function works fine.
            \item \foldcalculator{33}{2}{2} - proof that the calculation function works fine.
            %\item \num{\gls*{d.A_Control-0}}
            %\item \number{\gls*{d.A_Control-0}}
            %\item \foldfp{\gls*{d.A_Control-0}}{\gls*{d.B_Sample-2}}{2}
            %\item \foldcalculator{\gls*{d.A_Control-0}}{\gls*{d.B_Sample-2}}{2}            

  • 1
    \gls* is protected, therefore not expandable, unfortunately. Nice question, anyway – user31729 Feb 23 '15 at 18:17
  • @ChristianHupfer Thanks for your comment. Are \glsentryfirst or any of the other \glsentryxxx fields also protected? Might I be able to use one of these macros to define a custom macro that would parse this constant value? I think I understand the purpose behind protecting gls calls because they are dynamic, however the glsentry equivalents are constants... Is there any potential to adapt the question with these calls as shown in \item three of the original question? – EngBIRD Feb 23 '15 at 18:28
  • Quick check for your first question (in comment): \glsentryfirst isn't protected, but I am not really familiar with glossaries, so I don't know the various \glsentryxxx commands. Try yourself (in a terminal) texdef -t latex -p glossaries glsentryxxx (replace glsentryxxx with the real macro name) – user31729 Feb 23 '15 at 18:33
  • 1
    The expandable commands are the non-case-changing \glsentryxxx commands listed in Using Glossary Terms Without Links. (It's also possible to use \glsletentryfield to assign to contents of a particular field to a command, which you could then use in an expandable context.) – Nicola Talbot Feb 23 '15 at 20:57
  • @NicolaTalbot Much thanks for your comment, not to mention the glossaries package itself. I have solved my question using \glsentryname{#n} instead of \gls*{#n} inside the newcommand performing the ratio. Could have sworn I had tried that in the form of \glsentryfirst{#n}. I am having some trouble visualizing how \glsletentryfield would improve this because from what I understand, I still have to assign a custom function name. In macro form this would be overwritten with each call, but how is that different than using the call to the field using \glsentryxxx? – EngBIRD Feb 24 '15 at 2:49

Thanks to all who commented, here is my summary of the problem evolution and solution:

  1. I was mistaken in interpreting the unexpanded \gls*{} entries as a numerical parse problem. Thanks to @ChristianHupfer
  2. I can use \glsentryname{} to grab the expanded definition. Thanks to @NicolaTalbot
  3. Now that I am using an expanded variable correctly, there isn't actually a problem recognizing the defined term (a number in excel - rather than use LaTeX to parse and evaluate my content, I use a formula in excel to control the digits/rounding of the raw data stored as gls entry outputs). Thanks to @cfr.
  4. Lastly I couldn't continue to use the calculator package because it uses a modified division algorithm that does not return sufficiently accurate results. Instead I used the following code.

fold command:

    \ifboolexpr{test {\ifdimgreater{\glsentryname{#1} pt}{\glsentryname{#2} pt}}}%
    }% true
    }% false

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.