12

In the example below I provided a small test package mytestpackage.sty which uses the syntax of expl3.

If I use the command \usetikzlibrary inside the package I will get the error: Runaway argument?

v\pgfversion ]$Header:/cvsroot/pgf/pgf/generic/pgf/frontendlayer/tikz\ETC.
! File ended while scanning use of \next.
<inserted text> 
                \par 

The MWE:

\documentclass{report}
\usepackage{filecontents}

\begin{filecontents}{mytestpackage.sty}
\RequirePackage{expl3}
\ProvidesExplPackage{mytestpackage}{2012/05/26} {0.1}{mytestpackage}
\RequirePackage{tikz}
\usetikzlibrary{calc,backgrounds,arrows,matrix}
\end{filecontents}
\usepackage{mytestpackage}
\begin{document}
foo bar
\end{document}

The first quick fix is:

\ExplSyntaxOff
\usetikzlibrary{calc,backgrounds,arrows,matrix}
\ExplSyntaxOn

How can I patch TikZ (\usetikzlibrary) to use it inside my package?

Based on this solution we can send a bug report.

5
  • 1
    Using TikZ in an expl3 context is quite hard, because it relies on the space being a space and probably also on : and _ having their normal category code.
    – egreg
    May 26, 2012 at 13:04
  • You could load tikz and the tikzlibraries before \ProvidesExplPackage
    – cgnieder
    May 26, 2012 at 13:05
  • @egreg: The reason is very simple -- to provide a package or class based on expl3 May 26, 2012 at 13:06
  • @cgnieder: This is the other solution. In the chat Joseph found the problem. May 26, 2012 at 13:06
  • @cgnieder: Joseph provided the answer. May 26, 2012 at 13:30

1 Answer 1

15

The issue arises not because of the catcode of : or _ but because of that of spaces: the code pgf uses to find versions from RCS-style data relies on the presence of a space. Perhaps the cleanest fix is to alter the behaviour of the internals of \usetikzlibary so that the LaTeX2e push/pop filename system is used. This is already updated by expl3 to deal correctly with \ExplSyntax...:

\documentclass{report}
\usepackage{filecontents}
\begin{filecontents}{mytestpackage.sty}
\RequirePackage{expl3}
\ProvidesExplPackage{mytestpackage}{2012/05/26} {0.1}{mytestpackage}
\RequirePackage{tikz}
\RequirePackage{etoolbox}
\ExplSyntaxOff
\patchcmd
  {\pgfutil@InputIfFileExists}
  {\input #1}
  {%
    \@pushfilename
    \xdef\@currname{#1}%
    \input #1 %
    \@popfilename
  }
  {}{}
\ExplSyntaxOn
\usetikzlibrary{calc,backgrounds,arrows,matrix}
\end{filecontents}
\usepackage{mytestpackage}
\begin{document}
foo bar
\end{document}

You could of course do the same 'directly' by copying the entire definition of \pgfutil@InputIfFileExists if you want to avoid using etoolbox, but that does not make the solution clearer so I've skipped it. (Note: this patch has been updated for v3 of pgf: the older version did much the same thing but targeting a macro no longer used internal by pgf.)


For tcolorbox's tcbuselibrary, patch its \tcb@input@library@in in a similar way:

\patchcmd
  {\tcb@input@library@in}
  {%
    \input\tcbpkgprefix#1\relax%
  }
  {%
    \@pushfilename
    \input\tcbpkgprefix#1\relax%
    \@popfilename
  }
  {}{}
1
  • Regarding the OP, the calc TikZ library is enough to points out an issue, which nowadays generates the following error: ! Package pgfkeys Error: I do not know the key '/tikz/cs/point/.storein [...] l.410 \tikzset{cs/point/.store in=\tikz@cs@point}'. The trouble clearly comes from the space in .store in ignored as usually with expl3 but I believed it was the case only between explicit \ExplSyntaxOn and \ExplSyntaxOff. Since 2012 (date of the OP), no progress on this subject? Jan 15, 2020 at 13:44

You must log in to answer this question.

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