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.
\documentclass{article}
\usepackage[utf8]{inputenc}
\setlength\parindent{0pt}
\usepackage[nogroupskip,toc,acronym]{glossaries}
\usepackage{scrwfile}
\usepackage{calculator}
\usepackage{fp}
\usepackage{calc}
\usepackage{pgf}
\usepackage{siunitx}
\newglossary[datag]{data}{datat}{datan}{Data}
\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} }
\newcommand{\foldfp}[3]{
\FPeval{result}{round(#1/#2,#3)}
\result
}
\newcommand{\foldcalculator}[3]{
\DIVIDE{#1}{#2}{\dsol}
\dsol
%\DIVIDE{\gls*{#1}}{\gls*{#2}}{\dsol}
%\DIVIDE{{#1}}{{#2}}{\dsol}
%\ROUND[#3]{\dsol}{\rsol}
%\rsol
}
\begin{document}
\begin{itemize}
\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}
\end{itemize}
\end{document}
\gls*
isprotected
, therefore not expandable, unfortunately. Nice question, anyway\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 protectinggls
calls because they are dynamic, however theglsentry
equivalents are constants... Is there any potential to adapt the question with these calls as shown in\item
three of the original question?\glsentryfirst
isn't protected, but I am not really familiar withglossaries
, 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)\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.)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
?