Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have defined a command for adding a new symbol to the glossaries as follows:

\newcommand{\NewSymb}[4]{
    \newglossaryentry{#1}{
        name=#2,
        description={\nopostdesc #3}, 
        sort=#4,
        type=los,
        nonumberlist=true
    }
}

which can then be used for example like this:

\NewSymb{s:lattice}{\ensuremath{\Lambda}}{A Lattice}{lattice}

Now, in the text I can refer to this entry via

\gls[hyper=false]{s:lattice} 

but this is a bit too long for my taste. Therefore I have defined a command via

\newcommand{\LA}{{\gls[hyper=false]{s:lattice}}}

but I was wondering if it is somehow possible to integrate this \newcommand into the \NewSymb command, such that, after executing, say

\NewSymb{s:lattice}{\ensuremath{\Lambda}}{A Lattice}{lattice}{LA}

I automatically have access to an abbreviated command \LA. The name of the abbreviated command would be provided as a parameter of the NewSymb command.

share|improve this question
    
Please enclose your inline code with `. –  xport Jun 2 '11 at 19:23

1 Answer 1

up vote 3 down vote accepted
\newcommand{\NewSymb}[5]{
    \newglossaryentry{#1}{
        name=#2,
        description={\nopostdesc #3}, 
        sort=#4,
        type=los,
        nonumberlist=true
    }
   \newcommand#5{\gls[hyper=false]{#1}}
}

\NewSymb{s:lattice}{\ensuremath{\Lambda}}{A Lattice}{lattice}{\LA}

The fifth argument is the control sequence for calling \gls. It would be possible to express the argument without the backslash, but it's overkill.

It's possible to avoid the check made by \newcommand by changing it into \def. However it's a very risky behavior to redefine existing commands. For example, try to redefine \fi. An acceptable compromise might be

\newcommand{\NewSymb}[6][\newcommand]{
    \newglossaryentry{#2}{
        name=#3,
        description={\nopostdesc #4}, 
        sort=#5,
        type=los,
        nonumberlist=true
    }
   #1#6{\gls[hyper=false]{#2}}
}

after which

\NewSymb{s:lattice}{\ensuremath{\Lambda}}{A Lattice}{lattice}{\LA}

would work as before. But

\NewSymb[\renewcommand]{x}{y}{z}{X}{\fi}

would redefine \fi. (DON'T do it!)

share|improve this answer
    
works like a charm! thanks!! –  Christian Jun 2 '11 at 19:34
    
@Christian In order that the question doesn't remain among the unanswered ones, it's necessary to mark an answer as accepted. There's no hurry, however. –  egreg Jun 2 '11 at 19:40
    
@egreg: Actually, one upvote is sufficient. ;-) –  lockstep Jun 2 '11 at 19:41
    
@lockstep: nice to know. –  egreg Jun 2 '11 at 20:00
1  
@Christian: It's very dangerous to automatically redefine commands. See the edited answer. –  egreg Jun 4 '11 at 8:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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