TransWikia.com

Is it possible to have a generic newcommands for symbols generated by glossaries-extra?

TeX - LaTeX Asked by E. Seyma Kutluk on January 29, 2021

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}%
expandafternewcommandcsname #1endcsname{acs{#1}}}%

newcommand{acryntwo}[3]{%
newacronym{#1}{#2}{#3}%
expandafternewcommandcsname #1endcsname{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 Answers

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:

defsym*#1*{gls{#1}}

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

Answered by E. Seyma Kutluk on January 29, 2021

You can do it quite easily:

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

makeglossaries

newcommand{makenewsymbol}[3][]{%
  glsxtrnewsymbol[#1]{#2}{#3}%
  expandafternewcommandcsname #2endcsname{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.

Answered by egreg on January 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP