1

I redefined \chapter* but when I use acronyms from the glossaries package, I get a bunch of errors. A minimal (non-)working example:

\documentclass{memoir}

\usepackage[acronym]{glossaries}
\makeglossaries
\loadglsentries{acronym_file}

\makeatletter
\let\stdchapter\chapter
\renewcommand*\chapter{%
    \if@star{\starchapter}{\stdchapter}
\def\starchapter[#1]#2{%
    \stdchapter*[{#1}]{#2}}
\makeatother

\begin{document}
\printacronyms
\end{document}

This gives me the error message ! Use of \starchapter doesn't match its definition.

If I remove \printacronyms or if I use \printglossary instead of \printacronyms, I don't get the error message.

Also, if I replace \def\starchapter[#1]#2{\stdchapter*[{#1}]{#2}} by \newcommand*\starchapter[1]{\stdchapter*{#1}}, I don't get the error message (note that this doesn't work for me, since I want the optional parameter in \chapter[foo]{bar})

Is there a (hopefully easy) way to change my chapter definition so that I don't get this problem with acronyms?

10
  • 1
    Your \starchapter doesn't have an optional argument with square brackets but a mandatory one because you defined it with \def. You'd want to do \newcommand*\startchapter[2][]{... #1 is optional and #2 is mandatory ... }
    – cgnieder
    Nov 6, 2015 at 13:46
  • 1
    There's another issue here: memoir provides \chapter[][]{}, i.e. with two optional arguments
    – user31729
    Nov 6, 2015 at 13:54
  • 1
    @ChristianHupfer only in the unstarred variant IIRC. There are more things: there's a closing brace missing, \if@star is undefined (it's \@ifstar) and the redefinition \renewcommand*\chapter{\@ifstar{\starchapter}{\chapter}} used as \chapter{foo} causes and endless loop…
    – cgnieder
    Nov 6, 2015 at 14:03
  • @clemens: True, but the heading [...] argument is for the starred available too
    – user31729
    Nov 6, 2015 at 14:04
  • what is the goal of the redefinition? If your redefinition were working it just calls the original \chapter with the same arguments… this seems kind of pointless.
    – cgnieder
    Nov 6, 2015 at 14:08

2 Answers 2

2

I suggest to use \NewDocumentCommand to check for the multiple cases:

\chapter[][]{}

and \chapter*[]{}

Fill in the new definitions of your own chapter - style then.

My definition here will fail for \chapter*[][]{} -> what should be done there?

\documentclass{memoir}

\usepackage[acronym]{glossaries}

\usepackage{xparse}

\makeglossaries
%\loadglsentries{acronym_file}

\newacronym{LaTeX}{\LaTeX}{LaTeX is fun}

\makeatletter
\let\stdchapter\chapter

\RenewDocumentCommand{\chapter}{soom}{%
  \IfBooleanTF{#1}{% Is it starred -> yes, so check for #2.
    \IfValueTF{#2}{%
      \stdchapter*[#2]{#4}% -> #2 is heading title 
    }{%
      \stdchapter*{#4}%     
    }%
  }{%
    \IfValueTF{#2}{%
      \IfValueTF{#3}{%
        \stdchapter[#2][#3]{#4}% -> #2 is toc title, #3 is head title
      }{%
        \stdchapter[#2]{#4}% No head title #3
      }%
    }{%
      % Do not check for #3 since #2 isn't here!
      \stdchapter{#4}%     
    }%
  }%
}

\begin{document}

\tableofcontents
\chapter{First}

\chapter[Another one]{Second}

\chapter[Yet Another one][My nice title]{Third}

\gls{LaTeX}

\chapter*{Not in Toc}

\chapter*[Head of unnumbered chapter]{Also not in toc}



\printacronyms
\end{document}
4
  • you don't need \LetLtxMacro I believe. \chapter itself does not have any arguments whatsoever
    – cgnieder
    Nov 6, 2015 at 14:10
  • @clemens: Yes, it's a moving one. I'll keep it anyway
    – user31729
    Nov 6, 2015 at 14:11
  • \chapter has no arguments – moving or not (check with \show\chapter). If you were to copy the internal \@m@mchapter then \LetLtxMacro would help avoiding \\@m@mchapter
    – cgnieder
    Nov 6, 2015 at 14:21
  • @clemens: Alright, alright, I removed \LetLtxMacro
    – user31729
    Nov 6, 2015 at 14:23
1

I found something that works:

\makeatletter
\let\stdchapter\chapter
\renewcommand*\chapter{%
    \if@star{\@dblarg\starchapter}{\stdchapter}
\def\starchapter[#1]#2{%
    \stdchapter*[{#1}]{#2}}
\makeatother

This seems to do the trick (though I'm not so sure it's the best way to do things given the comments by clemens and Christian Hupfer)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .