pgf
pgf copied to clipboard
Loading of libraries in an `expl3` context
Brief outline of the proposed feature
When expl3-syntax is activated you can nevertheless load other packages without problems. This here does "the right thing":
\ExplSyntaxOn
....
\usepackage{tikz}
....
\ExplSyntaxOff
But the same is not true when loading package “libraries”. You can't use e.g. \usetikzlibrary{calc} without getting errors.
There are workarounds discussed here.
Usage example
The compilation of the following MCE fails:
\begin{filecontents*}[overwrite]{myclass.cls}
\ProvidesExplClass
{myclass}
{2022/11/01}
{0.1}
{
My Nice Class
}
\NeedsTeXFormat{LaTeX2e}
\LoadClass { article }
%
\RequirePackage{tikz}
\usetikzlibrary{calc}
\end{filecontents*}
\documentclass{myclass}
\begin{document}
Foo.
\end{document}
with the following error:
! Package pgfkeys Error: I do not know the key '
/tikz/cs/point/.storein', to which you passed '\tikz@cs@point', and I am going to ignore it. Perhaps you misspelled it.
due to the category regime induced by the implicit \ExplSyntaxOn introduced by \ProvidesExplClass, which drops the keyboard spaces.
Please test the following patch. Please also keep in mind that you can only sensibly use TikZ with the traditional (initex) catcodes.
diff --git a/tex/generic/pgf/utilities/pgfkeys.code.tex b/tex/generic/pgf/utilities/pgfkeys.code.tex
index f24557f8..989f47d0 100644
--- a/tex/generic/pgf/utilities/pgfkeys.code.tex
+++ b/tex/generic/pgf/utilities/pgfkeys.code.tex
@@ -1213,7 +1213,10 @@
\catcode`\|=12
\catcode`\$=3
\pgfkeys@IfFileExists{pgfkeyslibrary\[email protected]}{%
+ \csname @pushfilename\expandafter\endcsname
+ \expandafter\xdef\csname @currname\endcsname{pgfkeyslibrary\[email protected]}%
\input pgfkeyslibrary\[email protected]
+ \csname @popfilename\endcsname
}{%
\pgfkeys@error{I did not find the pgfkeys library '\pgf@temp'. I looked for the
file named pgfkeyslibrary\[email protected], but could not find it in the
diff --git a/tex/generic/pgf/utilities/pgfutil-common.tex b/tex/generic/pgf/utilities/pgfutil-common.tex
index 0ecdc688..275f4189 100644
--- a/tex/generic/pgf/utilities/pgfutil-common.tex
+++ b/tex/generic/pgf/utilities/pgfutil-common.tex
@@ -244,7 +244,13 @@
\fi
\closein\pgfutil@inputcheck}
-\def\pgfutil@InputIfFileExists#1#2#3{\pgfutil@IfFileExists{#1}{\input #1\relax#2}{#3}}%
+\def\pgfutil@InputIfFileExists#1#2#3{%
+ \pgfutil@IfFileExists{#1}{%
+ \csname @pushfilename\expandafter\endcsname
+ \expandafter\xdef\csname @currname\endcsname{#1}%
+ \input #1\relax
+ \csname @popfilename\endcsname
+ #2}{#3}}%
% pgfutil@loop (from plain.tex)
Please test the following patch.
Quite weird: with an up to date TeX Live 2022, the pgfkeys.code.tex file contains only 1160 lines:
$ wc -l /home/bitouze/texlive/2022/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex
1160 /home/bitouze/texlive/2022/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex
so doesn't contain any \pgfkeys@IfFileExists{pgfkeyslibrary\[email protected]}{% line.
Just to be sure:
$ wget -q http://mirrors.ctan.org/graphics/pgf/base/tex/pgfkeys.code.tex && wc -l pgfkeys.code.tex
1160 pgfkeys.code.tex
I think Henri's patch is based on the latest pgfkeys.code.tex, which contains some not-yet-released changes. Nevertheless the key is to patch \pgfkeys@IfFileExists in pgfkeys.code.tex and \pgfutil@InputIfFileExists in pgfutil-common.tex.
I think Henri's patch is based on the latest
pgfkeys.code.tex, which contains some not-yet-released changes.
@muzimuzhi That's what I wanted to stress out :smile:
Nevertheless the key is to patch
\pgfkeys@IfFileExistsinpgfkeys.code.texand\pgfutil@InputIfFileExistsinpgfutil-common.tex.
The point is, at least \pgfkeys@IfFileExists doesn't exist in current pgfkeys.code.tex.
Nevertheless the key is to patch
\pgfkeys@IfFileExistsinpgfkeys.code.texand\pgfutil@InputIfFileExistsinpgfutil-common.tex.The point is, at least
\pgfkeys@IfFileExistsdoesn't exist in currentpgfkeys.code.tex.
Sorry, my bad. \pgfkeys@IfFileExists is added for the unreleased feature---pgfkeys library, so you can omit the patch to it for now.