[texhax] tabularx and titletoc/titlesec: harmful interaction? [workaround]
Susan Dittmar
Susan.Dittmar at gmx.de
Wed Jul 18 12:04:50 CEST 2012
Hi folks,
I still do not understand why the described problem arised, and in case
someone knows, I am still interested in an explanation.
Nonetheless using etoolbox and a macro instead of the counter I managed to
work around the problem (work-around appended for the archives). Btw, I
first used etoolbox's \numdef, which showed the same problem although
according to the docs it is a local definition!
Susan
\documentclass{article}
\usepackage{tabularx}
\usepackage{etoolbox}
\makeatletter
\newcommand{\mysecdepth}{0} % register to keep track of current section depth
\newenvironment*{mysection}{%
\begingroup%
\expandafter\numdef\expandafter\mysecdepth{\mysecdepth + 1} % locally add 1 to register \mysecdepth
\ifcase\value{mysecdepth}%
\immediate\write16{mysection: counter mysecdepth has value 0! This can't happen!}%
\expandafter\sectionI%
\or\expandafter\section%
\or\expandafter\subsection%
\else%
\immediate\write16{mysection: No more hierarchy levels!}%
\expandafter\subsection%
\fi%
}{%
\par%
\endgroup%
}%
\makeatother
\begin{document}
\begin{mysection}{first section}
text of first section
\begin{mysection}{first subsection of first section}
text of first subsection of first section
\end{mysection}
\end{mysection}
\begin{mysection}{second section}
text of second section
\end{mysection}
\begin{mysection}{third section}
text of third section
\begin{tabularx}{\linewidth}{X}
This is a tabularx \\
just to show my problem.\\
\end{tabularx}
\end{mysection}
\begin{mysection}{fourth section}
text of fourth section, which falsely was chosen to
be first subsection of section three, but now correctly
seen as section four
\end{mysection}
\end{document}
More information about the texhax
mailing list