hypbmsec compatibility / redefinition



Hello Mr Oberdiek again,


Sometimes I want a \section with an option like :

\section {title}[my special option]

With the current definition of \hbs@process, it is not possible to test
with \@ifnextchar after the arguments checking because \hbs@seccmd is
nested inside \if...\fi conditionals.


I propose the following :

% --------- minimal example ----------------------------------------
\documentclass[a4paper,11pt]{book}
\usepackage {etex,hypbmsec}

\makeatletter
%% \mysection definition
\def\mysection {\secdef \my@section \my@ssection }
\long\def\my@section [#1]#2{\@ifnextchar [{\my@section@withoption {#1}{#2}}
{\my@section@ {#1}{#2}}%
}% \my@section
\long\def\my@section@withoption #1#2[#3]{1=#1\par 2=#2\par 3=#3\par }
\long\def\my@section@ #1#2{1=#1\par 2=#2\par }
\long\def\my@ssection #1{1=#1 \par}

%% plugin: \mysection into hypbmsec processor
\let\hbs@mysection \mysection
\renewcommand \mysection {\hbs@do \hbs@mysection }

%% \hbs@process redefinition in order to get out of the conditionnals:
\long\def\hbs@process #1{\begingroup \long
\ifx \hbs@tocstring\relax
\ifx \hbs@mbstring\relax \def\x ##1##2{\endgroup \hbs@seccmd {#1}}%
\else \def\x ##1##2{\endgroup \hbs@seccmd {\texorpdfstring {#1}{##1}}}\fi
\else\ifx \hbs@bmstring\relax \def\x ##1##2{\endgroup \hbs@seccmd [{##2}]{#1}}%
\else \def\x ##1##2{\endgroup \hbs@seccmd [\texorpdfstring {##2}{##1}]{#1}}\fi\fi
\expandafter \expandafter \expandafter \x
\expandafter \expandafter \expandafter {\expandafter \hbs@bmstring
\expandafter}\expandafter {\hbs@tocstring }%
}% \hbs@process


\begin{document}

\loggingall
\mysection (bookmark)[mark]{title}[option]

\vskip5mm

\mysection {title}[option]
\tracingnone

\end{document}\endinput
% ------------------------------------------------------------------------

Thanks in avance.
.