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.

  • 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 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. – E. Seyma Kutluk Sep 4 at 7:23
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.

  • Thank you @egreg ! This is exactly what i was looking for. Sorry for the grammar.. It should be something like "a space of minima". – E. Seyma Kutluk Sep 6 at 11:23
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.

  • 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 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 at 8:35
  • Hi @schtandard, I have edited my question, I hope it makes sense. – E. Seyma Kutluk Sep 6 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.