我为 glossarie-package 创建了一个新命令。特别是对于符号...
\newcommand*{\nsymbol}[4]{\newglossaryentry{#1}{
type=symbols,
name={#2},
description={\nopostdesc},
symbol={{#3}},
user1={#4},
sort={#1}}}
这里的主要问题(我猜)是下面的一行工作正常,但第二行给了我一个“未定义的控制序列”,我无法确定问题是什么。
\nsymbol{abc}{alphabet}{$A_.{bc}$}{$\si{cm}$}
\nsymbol{abc}{alphabet}{$A_.{bc}$}{$\si{\metre}$}
我只能猜测,但似乎新命令与 siunitx 配合得不太好,因为错误内容如下:
! 未定义控制序列。 \@glo@useri ->$\si {\metre }$ l.38 ...alphabet}{$A_.{bc}$}{$\si{\metre}$}
如果“\si”和“{\metre}”之间有空格,这可能是问题所在……无论是否是数学模式,都没有区别。提前谢谢,这可能很愚蠢,但我会很感激任何有用的答案。
编辑:这是一个最小的例子,不太确定这里的问题是什么,所以我复制了很多。
\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}
答案1
就是\protect
这样,就像\nsymbol{abc1}{alphabet1}{$A_.{bc1}$}{$\si{\protect\metre}$}
更新:Nicola 刚刚提供了 Rosetta Stone...添加\glsnoexpandfields
到序言中可以减轻保护参数的需要。它的作用是“防止在设置条目的内部命令时发生扩展。”
\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}