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.

This question follows a previous question of mine: Prepend different stuffs to starred and unstarred \chapter commands.

In some circumstances, a starred macro in definition of another starred/unstarred macro doesn't work as expected. The following MCE works like a charm but, as soon as the glossaries packages is loaded, the star of \resetsecnumdepth looks like disconnected: it appears in the text.

\documentclass{book}
\usepackage{xparse}
\usepackage{tocvsec2}
% \usepackage{glossaries}
%
\let\ORIchapter\chapter%
\RenewDocumentCommand\chapter{som}{%
  \IfBooleanTF{#1}
    {
     \setsecnumdepth{none}%
    }
    {%
     \resetsecnumdepth*
    }
  \IfNoValueTF{#2}
    {\ORIchapter{#3}}
    {\ORIchapter[#2]{#3}}%
}
%
\setsecnumdepth{chapter}
\begin{document}
\chapter{A chapter}
\end{document}

The problem doesn't come from xparse package, as the following MCE, using only LaTeX macros, has the same trouble.

\documentclass{book}
\usepackage{tocvsec2}
\usepackage{glossaries}
%
\let\ORIchapter\chapter%
\makeatletter%
\renewcommand\chapter{%
  \@ifstar{\starred@chapter}{\unstarred@chapter}%
}
\newcommand{\starred@chapter}{%
  \setsecnumdepth{none}%
  \ORIchapter%
}%
\newcommand{\unstarred@chapter}{%
  \resetsecnumdepth*
  \ORIchapter%
}%
%
\makeatother%
%
\setsecnumdepth{chapter}
\begin{document}

\chapter{A chapter}
\end{document}

I had a look of the glossaries' code, and made some tests (patching the glossaries macros involving \chapter in order they use \ORIchapter instead) but I didn't succeed to debug the trouble (neither warning nor error in the .log file).

share|improve this question
1  
glossaries doesn't explicitly redefine \@ifstar so it must load something else that does. –  Nicola Talbot Mar 9 at 19:59
1  
It's amsgen that redefines it. –  Nicola Talbot Mar 9 at 20:00
1  
@NicolaTalbot I identified wrongly the source of the problem; the bug is indeed in tocvsec2. Sorry. –  egreg Mar 9 at 20:36
2  
@egreg Drat those pesky spurious spaces :-) –  Nicola Talbot Mar 9 at 20:49
    
Note that tocvsec2 (2014/03/10 v1.3a) should have solved the issue. –  egreg Mar 11 at 0:11

1 Answer 1

up vote 10 down vote accepted

It's another case of a spurious space!

\documentclass{book}
\usepackage{xparse}
\usepackage{tocvsec2}
\usepackage{glossaries}

\makeatletter
\renewcommand\resetsecnumdepth{%
  \@ifstar{%
    \setcounter{secnumdepth}{\value{max@secnumdepth}}%
    \edef\stack@secnumdepth{\the\c@secnumdepth\relax}%
  }{%
    \ifx\stack@secnumdepth\@empty
      \PackageWarning{tocvsec2}{There is no previous value for secnumdepth}%
    \else
      \afterassignment\gobble@secnumdepth
      \expandafter\c@secnumdepth\expandafter\numexpr\stack@secnumdepth\@nil
    \fi
  }%<--- Was missing
}
\makeatother

\let\ORIchapter\chapter
\RenewDocumentCommand\chapter{som}{%
  \IfBooleanTF{#1}
    {
     \setsecnumdepth{none}%
    }
    {%
     \resetsecnumdepth*
    }
  \IfNoValueTF{#2}
    {\ORIchapter{#3}}
    {\ORIchapter[#2]{#3}}%
}

\setsecnumdepth{chapter}
\begin{document}
\chapter{A chapter}
\end{document}

What happens? In amsgen.sty, \@ifstar receives a new definition based on \new@ifnextchar, which does not ignore spaces like it happens for \@ifnextchar.

The missing % in the definition causes \new@ifnextchar not seeing the * as the next character, but a space.

The problem shows because glossaries loads amsgen via amsmath.

share|improve this answer
    
OK.I'll let know Will Robertson, the current tocvsec2 maintainer. –  Denis Bitouzé Mar 9 at 21:08
    
Who would guess: you found a missing % :-) –  David Carlisle Mar 10 at 0:54
    
@DavidCarlisle: not me, for sure! :) –  Denis Bitouzé Mar 11 at 7:17

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.