0

I am defining symbols in my document with glossaries-extra package such as:

\glsxtrnewsymbol[description={Lagrangian}]{lag}{\ensuremath{\mathit{L}}}

However I will be referring to this in my document very often -mostly inside equations-. Normally if I wouldnt have to have a list of symbols I would define

\newcommand{\lag}{\mathit{L}}

and simply write \lag everywhere inside the equation. Now I either need to use \gls{lag} everytime, or for each glossary-symbol entry I should use the \newcommand as above. My question is isnt there a way to tell latex to print \gls{label} whenever I type \label ?

....editing after @schtandard's comments.....

So a MWE is this

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[symbols,nonumberlist]{glossaries-extra}
 
\makeglossaries
 

\glsxtrnewsymbol[description={Field on Minima spce}]{minfield}{\ensuremath{\varphi}}
\glsxtrnewsymbol[description={General Field}]{field}{\ensuremath{\phi}}
\newcommand{\field}{\gls{field}}
\newcommand{\minfield}{\gls{minfield}}

\begin{document}
 
I have a configuration space with fields $\field$ that has a minima. Fields on the minima space are called $\minfield$. 
\begin{equation}
\delta V (\field=\minfield)=0
\end{equation}
 
\clearpage
 
\printglossaries
 
\end{document}

This produces this: enter image description here

What I want is not to have to define \newcommand s at all, but still be able get the result I get with the exact same code in between \begin{document} and end{document}. Probably what I want is something like,

\newsymbol{#1,#2,#3}
{
 \glsxtrnewsymbol[description={#1}]{#2}{#3},
\newcommand{\#2}{#3}
}

I dont know if something like that already exists or possible, I am new to this level of latex.

...edit 2... I have been using the solution suggested by @egreg happily and i think it helped me quite a lot. I have tried to use the same thing for acronyms, however I come across a small problem. Let me explain. Consider the following code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[acronyms,nomain,shortcuts]{glossaries-extra}
   
\newcommand{\acryn}[3]{%
\newacronym{#1}{#2}{#3}%
\expandafter\newcommand\csname #1\endcsname{\acs{#1}}}%

\newcommand{\acryntwo}[3]{%
\newacronym{#1}{#2}{#3}%
\expandafter\newcommand\csname #1\endcsname{\acs{#1}~}}%
  
\makeglossaries

\acryn{gr}{GR}{General Relativity}
\acryntwo{grtwo}{GR}{General Relativity}
     
\begin{document}
  
If I use the glossary package command I can say \acs{gr} and it prints nicely. But if I use the command I define when I say \gr unfortunately no gap appears.\\

I could add tilde to the command and this problem would be solved \grtwo as one can see, but now the gap appears where I do not want it to appear: (\grtwo). Note that this does not happen with the built-in command: (\acs{gr}).

\printglossary[type=\acronymtype]
   
     
\end{document}

which produces this:

enter image description here

2
  • 1
    Welcome to TeX.SX! Do you mean \newcommand\lag{\gls{lag}}? Please add an MWE that shows the current behavior and that we can use to provide a solution for you.
    – schtandard
    Sep 3, 2019 at 19:06
  • Hi @schtandard, thanks! Well I mean something that does that generically for an arbitrary glossary entry. Maybe I should've said "My question is isnt there a way to tell latex to print \gls{label} whenever I type \label for an arbitrary label of glossary?" . I will try to come up with a minimally working example. Sep 4, 2019 at 7:23

2 Answers 2

1

You can do it quite easily:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[symbols,nonumberlist]{glossaries-extra}

\makeglossaries

\newcommand{\makenewsymbol}[3][]{%
  \glsxtrnewsymbol[#1]{#2}{#3}%
  \expandafter\newcommand\csname #2\endcsname{\gls{#2}}%
}

\makenewsymbol[description={Field on Minima space}]{minfield}{\ensuremath{\varphi}}
\makenewsymbol[description={General Field}]{field}{\ensuremath{\phi}}

\begin{document}

I have a configuration space with fields $\field$ that has a minima. 
Fields on the minima space are called $\minfield$. 
\begin{equation}
\delta V (\field=\minfield)=0
\end{equation}

\printglossaries

\end{document}

enter image description here

From a grammatical point of view, “a minima” looks quite odd.

2
  • Thank you @egreg ! This is exactly what i was looking for. Sorry for the grammar.. It should be something like "a space of minima". Sep 6, 2019 at 11:23
  • Hi again. I have been using this happily and i think it helped me quite a lot, so thank you for this again. I have tried to use the same thing for acronyms, however I come across a small problem. Could you please take a look at the end of my question where I have explain this? Thank you.. Aug 3, 2020 at 10:33
0

Ok, I got my answer reading through some deeper discussion of Latex macros on overleaf website:

How TeX macros actually work

Answer to my question is no ofcourse. But I can avoid {}'s, which was actually what I wanted to because they are harder to write on my keyboard (alt+0 and alt+7). I can do the following definition:

\def\sym*#1*{\gls{#1}}

and write \sym*label* . Yeah maybe not too big difference, but at least I learned how TeX works better.

3
  • I would strongly recommend against this! While it may not cause any problems in this specific case, it most probably will in general. It is best to stick with the LaTeX syntax, there is a reason why we use this standardized form.
    – schtandard
    Sep 5, 2019 at 8:32
  • Also, the answer to your actual question (if I understand it correctly) is not really no. While you can't make TeX replace any \macro with \gls{macro} (which you would not want to do in any case), it is easy to automatically create the appropriate macros when defining the symbol. But as I said, you will have to provide an MWE.
    – schtandard
    Sep 5, 2019 at 8:35
  • Hi @schtandard, I have edited my question, I hope it makes sense. Sep 6, 2019 at 9:48

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.