2

According to this topic How to design a command inquiring internally required packages? I am getting in trouble with the package storebox.

Have a look at this MWE example.

compiling with pdflatex, everything fine...

this example works
\documentclass{article}

\usepackage{storebox}
\usepackage{tcolorbox}

\begin{document}

test
\end{document}

compiling with pdflatex, everything fine, but storebox is disabled...

this example also works
\documentclass{article}


\usepackage{tcolorbox}
\usepackage[disable]{storebox}

\begin{document}
test

\end{document}

compiling this example, getting an error...

this example wont work
\documentclass{article}


\usepackage{tcolorbox}
\usepackage{storebox}

\begin{document}

test
\end{document}

but the following is the desired one...

\makeatletter
\let\req@onefilewithoptions\@onefilewithoptions
\def\@onefilewithoptions#1[#2][#3]#4{%
  \req@push{#1.#4}%
  \req@onefilewithoptions{#1}[{#2}][{#3}]{#4}%
  \req@pop
}

\let\req@list\@empty
\let\req@item\relax
\let\req@top\relax
\newcounter{req@count}
\def\req@push#1{%
  % \typeout{*** [#1]}% debug
  \ifcase\value{req@count}%
    \@ifundefined{req@#1}{%the file, whose package dependencies 
      \global\expandafter
      \let\csname req@#1\endcsname\@empty
      \xdef\req@list{%
        \req@list
        \req@item{#1}%
      }%
    }{}%
    \xdef\req@top{#1}%
    \edef\req@tmp{%
      \noexpand\AtBeginDocument{%
        \noexpand\stepcounter{req@count}%
        \xdef\noexpand\req@top{#1}%
      }%
    }%
    \req@tmp
  \else
    \expandafter\ifx\csname req@\req@top\endcsname\@empty
      \expandafter\xdef\csname req@\req@top\endcsname{#1}%
    \else
      \edef\req@tmp{%
        \noexpand\in@{,#1,}{,\csname req@\req@top\endcsname,}%
      }%
      \req@tmp
      \ifin@
      \else
        \expandafter\xdef\csname req@\req@top\endcsname{%
          \csname req@\req@top\endcsname
          ,#1%
        }%
      \fi
    \fi
  \fi
  \stepcounter{req@count}%
}
\def\req@pop{%
  \addtocounter{req@count}{-1}%
  \ifcase\value{req@count}%
    \global\let\req@top\relax
    \AtBeginDocument{%
      \addtocounter{req@count}{-1}%
      \global\let\req@top\relax
    }%
  \fi
}

\def\req@process{%
  \typeout{Requirement list}%
  \typeout{================}%
  \let\req@item\req@process@item
  \req@list 
  \typeout{================}%
}
\def\req@process@item#1{%
  \typeout{* #1\req@info{#1}}%
  \expandafter\@for\expandafter\req@tmp
  \expandafter:\expandafter=\csname req@#1\endcsname\do{%
    \typeout{ \space> \req@tmp\req@info{\req@tmp}}%
  }%
}
\def\req@info#1{%
  \@ifundefined{ver@#1}{}{ [\@nameuse{ver@#1}]}%
}
\AtEndDocument{\req@process}%
\makeatother

% this example also wont work because there is content in the page which should not appear
\documentclass{article}


\usepackage{tcolorbox}
\usepackage{storebox}

\begin{document}
test

\end{document}

At the one and only page I should read "test". But I can read "req@count-1test"

I like the code of generating the filelist, because I parse this file and include the resulting csv in reports (or I want to).

EDIT 1:

The problem egreg pointed out is the second one I determined during trying to find a solution for example 4. There is content in the first page of the pdf which should not be here.

I want to see "test" in the document but nothing else. What I can see ist "req@count-1test" which seems to me strange...

1 Answers1

4

The problem is a bug in storebox already described in Problems combining tikz and storebox: Missing number, treated as zero. With animate, page shipped out with text `graphicx`,

However, due to the code you add at the beginning, the workaround suggested in my answer there is ineffective, because the empty group is inserted too late. Instead of \ifdim, the \addtocounter instruction from \req@pop is gobbled, causing the printing of its argument.

You can fix the bug in this case with

\def\req@pop{%
  \addtocounter{req@count}{-1}%
  \ifcase\value{req@count}%
    \global\let\req@top\relax
    \AtBeginDocument{%
      \relax\addtocounter{req@count}{-1}% <---- ADDED \relax
      \global\let\req@top\relax
    }%
  \fi
}

The \relax will do nothing special for other included files, but in the case of storebox-pgf it will provide the “missing token” that will be gobbled.

egreg
  • 1,121,712