5

I have created a new command for the glossarie-package. Especcially for symbols...

\newcommand*{\nsymbol}[4]{\newglossaryentry{#1}{
            type=symbols,
            name={#2},
            description={\nopostdesc},
            symbol={{#3}}, 
            user1={#4}, 
            sort={#1}}}

The main issue here (i guess) the following line works fine, but the second one gives me an 'Undefiened Control Sequence' and I can't determine whats the problem.

\nsymbol{abc}{alphabet}{$A_.{bc}$}{$\si{cm}$}
\nsymbol{abc}{alphabet}{$A_.{bc}$}{$\si{\metre}$}

I can only guess, but it seems the newcommand doesnt work quite well with siunitx, since the error says something like:

! Undefined control sequence. \@glo@useri ->$\si {\metre }$ l.38 ...alphabet}{$A_.{bc}$}{$\si{\metre}$}

Where there is a space between '\si' and '{\metre}', maybe this is the problem... It doesn't make any difference in, whether its mathmode or not. Thanks in advance, its probably stupid, but I would appreciate any helpful answer.

EDIT:that's kind of a minimal example, not quite sure, what's the problem here, so I copied a lot.

\documentclass{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[locale=DE]{siunitx}
    \sisetup{detect-mode = false,
    detect-family=true,
    mode=math,
    %               output-decimal-marker={,},
    binary-units=true,
    group-separator={\,},group-minimum-digits=3%
}

        % upright indices-shortcut
\mathcode`\.="8000
\begingroup\lccode`~=`.
\lowercase{\endgroup\def~}#1{\mathrm{#1}}

\usepackage{hyperref}

\usepackage[acronym, symbols, nomain, toc]{glossaries}
\usepackage{booktabs}
\usepackage{tabu}

%%% new glossary styl
\newglossarystyle{symblongtabu}{
    \renewenvironment{theglossary}{
        \begin{longtabu}spread 0pt[l]{ccc<{\strut}l}
        }{
    \end{longtabu}}
    \renewcommand*{\glsgroupheading}[1]{}
    \renewcommand*{\glsgroupskip}{}
    \renewcommand*{\glossaryheader}{
        \toprule
        \bfseries Formelzeichen & \bfseries Bezeichnung &
        \bfseries Einheit & \bfseries Seite(n)
        \tabularnewline\midrule\endhead
        \bottomrule\endfoot}
    \renewcommand*{\glossentry}[2]{
        \glsentryitem{##1}
        % Entry number if required
        \glstarget{##1}{\glossentrysymbol{##1}} &
        \glossentryname{##1} &
        \glsentryuseri{##1} &
        ##2\tabularnewline}}

\makenoidxglossaries

%%% newsymb macro
\newcommand*{\nsymbol}[4]{\newglossaryentry{#1}{
        type=symbols,
        name={#2},
        description={\nopostdesc},
        symbol={{#3}}, 
        user1={#4}, 
        sort={#1}}}
\defglsentryfmt[symbols]{\ifmmode
    \glssymbol{\glslabel}
    \else
    \glsgenentryfmt~\glsentrysymbol{\glslabel}
    \fi}
%%% entries
\nsymbol{abc}{alphabet}{$A_.{bc}$}{$\si{cm}$}
\nsymbol{abc1}{alphabet1}{$A_.{bc1}$}{$\si{\metre}$}

\begin{document}

    \printnoidxglossary[type = symbols, style = symblongtabu]

    \gls{abc} \\
    \gls{abc1}

\end{document}
  • 2
    Welcome to TeX.SX! Please help us (and also you) and add a minimal working example (MWE), that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}. Try \SI{}{\metre} – Bobyandbob Sep 7 '17 at 16:19
  • Done, hope it is good enough. To make it work zou need to comment both second lines... – Pratched Sep 7 '17 at 16:36
  • Nearly missed your other advice...\SI{}{} doesnt make any difference...white space again before the curly bracket – Pratched Sep 7 '17 at 16:41
5

Just \protect it, as in \nsymbol{abc1}{alphabet1}{$A_.{bc1}$}{$\si{\protect\metre}$}

UPDATE: Nicola just provided the Rosetta Stone...adding \glsnoexpandfields to the preamble alleviates the need to protect the arguments. It works to "prevent expansion occurring when the entry's internal commands are set."

\documentclass{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[locale=DE]{siunitx}
    \sisetup{detect-mode = false,
    detect-family=true,
    mode=math,
    %               output-decimal-marker={,},
    binary-units=true,
    group-separator={\,},group-minimum-digits=3%
}

        % upright indices-shortcut
\mathcode`\.="8000
\begingroup\lccode`~=`.
\lowercase{\endgroup\def~}#1{\mathrm{#1}}

\usepackage{hyperref}

\usepackage[acronym, symbols, nomain, toc]{glossaries}
\usepackage{booktabs}
\usepackage{tabu}

%%% new glossary styl
\newglossarystyle{symblongtabu}{
    \renewenvironment{theglossary}{
        \begin{longtabu}spread 0pt[l]{ccc<{\strut}l}
        }{
    \end{longtabu}}
    \renewcommand*{\glsgroupheading}[1]{}
    \renewcommand*{\glsgroupskip}{}
    \renewcommand*{\glossaryheader}{
        \toprule
        \bfseries Formelzeichen & \bfseries Bezeichnung &
        \bfseries Einheit & \bfseries Seite(n)
        \tabularnewline\midrule\endhead
        \bottomrule\endfoot}
    \renewcommand*{\glossentry}[2]{
        \glsentryitem{##1}
        % Entry number if required
        \glstarget{##1}{\glossentrysymbol{##1}} &
        \glossentryname{##1} &
        \glsentryuseri{##1} &
        ##2\tabularnewline}}

\makenoidxglossaries

%%% newsymb macro
\newcommand*{\nsymbol}[4]{\newglossaryentry{#1}{
        type=symbols,
        name={#2},
        description={\nopostdesc},
        symbol={{#3}}, 
        user1={#4}, 
        sort={#1}}}
\defglsentryfmt[symbols]{\ifmmode
    \glssymbol{\glslabel}
    \else
    \glsgenentryfmt~\glsentrysymbol{\glslabel}
    \fi}
%%% entries
\nsymbol{abc}{alphabet}{$A_.{bc}$}{$\si{cm}$}
\nsymbol{abc1}{alphabet1}{$A_.{bc1}$}{$\si{\protect\metre}$}

\begin{document}

    \printnoidxglossary[type = symbols, style = symblongtabu]

    \gls{abc} \\
    \gls{abc1}

\end{document}

enter image description here

  • well, that did the trick. Thanks a lot. Any suggestions on how to solve the issue if I define the units in the newcommand with user1={$\si{#4}$} and only write \nsymbol{abc}{alphabet}{$A_.{bc}$}{\metre} ? Reason here would be the time to add new ones... – Pratched Sep 7 '17 at 18:21
  • @Djiwahwah I am sorry, but I have no direct workaround for the requirement to \protect the argument of \si. – Steven B. Segletes Sep 7 '17 at 18:29
  • 1
    @Djiwahwah except that neither \p1 nor \p2 are valid macro names since 1 and 2 are not an alphabetic catcode. I think this might be a case of "the cure is worse than the ailment" – Steven B. Segletes Sep 7 '17 at 19:14
  • 3
    It's simpler to just add \glsnoexpandfields to prevent expansion occurring when the entry's internal commands are set then you don't need \protect. – Nicola Talbot Sep 7 '17 at 19:14
  • 1
    One last thing, this solution does make it possible to use only the unit-token within \nsymb such as \ampere if you set user1={$\si{#4}$} - might be helpful to somebody – Pratched Sep 7 '17 at 19:34

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.