I want to redefine the glossaries
package’s \gls
commands to include an index entry and an optional argument for formatting the index entry. However, there are so many variants of this command (\gls
, \glspl
, \glstext
, etc. as well as many of my own defined keys), that I want to loop this command through a comma separated list. I am trying to use etoolbox
and its \docsvlist
command to accomplish this. My MWE is below:
\documentclass{report}
\usepackage{glossaries}
\usepackage{imakeidx}
\usepackage{etoolbox}
\usepackage{xargs}
\renewcommand{\do}[1]{%
\expandafter\newcommand%
\csname oldgls#1\endcsname%
\csname gls#1\endcsname%
\expandafter\renewcommandx%
\csname gls#1\endcsname%
[2][2]%
\csname oldgls#1\endcsname{##1}\index{##1##2}%
}
\docsvlist{pl,text}
\makeglossaries
\makeindex
\input{glossaryDefs} % A file defining myterm & anotherterm
\begin{document}
Some text \glspl{myterm}[|textbf] and some more text \glstext{anotherterm}.
\printglossary
\printindex
\end{document}
However, I get the error Missing \begin{document}.
I am pretty new to LaTeX and I suspect that there are probably a number of issues in this example. Any help would be appreciated.
\index
. What's with the optional parameter given by2
?\glspl{myterm}[|textbf]
should be equivalent to\oldglspl{myterm}\index{myterm|textbf}
.