I'm trying to patch the package tikzscale. Specifically, I want to remove the following lines from the package, as it does not constitute a useful error in my usecase[1].
\tikzscale@ifSizeDifference{\measuredFirst - \measuredSecond}{%
}{%
\PackageError{tikzscale}{Requested to scale unscalable graphic}{Do not set width or height for graphic in\MessageBreak #3}%
}%
I am additionally attempting to do this without editing the package itself, as I expect to share this document with other people (and on Overleaf) in such a situation that I cannot request others to edit their installs on the package, so I'm trying to do this with regexpatch, or xpatch.
xpatch fails with:
File: etoolbox.def 2018/02/11 v2.5e etoolbox debug messages (JAW)
)
[debug] tracing \patchcmd on input line 19
[debug] analyzing '\tikzscale@scaleTikzpictureTo'
[debug] ++ control sequence is defined
[debug] ++ control sequence is a macro
[debug] -- macro cannot be retokenized cleanly
[debug] -> the macro may have been defined under a category
[debug] code regime different from the current one
[debug] -> the replacement text may contain special control
[debug] sequence tokens formed with \csname...\endcsname;
[debug] -> the replacement text may contain carriage return,
[debug] newline, or similar characters
regexpatch fails with:
File: etoolbox.def 2018/02/11 v2.5e etoolbox debug messages (JAW)
)
*************************************************
* xpatch message
* `\tikzscale@scaleTikzpictureTo' is not especially defined
*************************************************
*************************************************
* xpatch message
* Macro`\tikzscale@scaleTikzpictureTo' is NOT patchable
* (Check if it contains `@' commands)
*************************************************
Is there a way in which this can work? Here is an MWE (while this will compile with no issues, inspecting the log will reveal the failure to patch).
\documentclass[twocolumn,twoside]{article}
\usepackage{regexpatch}
\usepackage{tikzscale}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\tracingpatches
\tracingxpatches
\makeatletter
\regexpatchcmd{\tikzscale@scaleTikzpictureTo} % Command to patch
{\PackageError{tikzscale}{Requested to scale unscalable graphic}.*} % Content to be replaced
{\relax} % Replacement content
{\message{Succesfully patched tikzscale!}} % Success message
{\message{Failed to patch tikzscale!}} % Failure message
\makeatother
\begin{document}
\lipsum
\end{document}
[1] My usecase is this, if it matters: I am writing .tikz files which themselves have \includegraphics, annotated in tikz. When I attempt to include them in my main document, they throw me the error Requested to scale unscalable graphic, however, the document compiles correctly, however, it fails on Overleaf.
An example of the .tikz I'm trying to include:
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0){
\includegraphics[width=0.95\linewidth]{figure2.pdf}
};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
% (a) (b) (c) (d) labels
\node at (0.02,0.97){\textbf{(a)}};
\node at (0.40,0.97){\textbf{(b)}};
\node at (0.67,0.97){\textbf{(c)}};
\node at (0.21,0.66){\textbf{(d)}};
\node at (0.02,0.39){\textbf{(e)}};
% Inset label
\fill [white] (0.23,0.53) rectangle (0.30,0.62);
\fill [white] (0.65,0.53) rectangle (0.75,0.62);
\node at (0.67,0.41) {Diffraction losses};
\node[anchor=south west] at (0.23,0.53) {$\bm{|\psi\rangle}$};
\node[anchor=south west] at (0.65,0.53) {$\bm{T|\psi\rangle}$};
% Optical component labels
\node at (0.14,0.35){\small Laser};
% \node at (0.07,0.32){\small Fiber};
\node at (0.14,0.01){\small Pol$_1$};
\node at (0.23,0.01){\small HWP};
\node at (0.31,0.01){\small BS};
\node at (0.30,0.32){\small Det$_B$};
% \node at (0.40,0.01){\small Lens};
% \node at (0.46,0.35){\small Metasurface};
% \node at (0.53,0.01){\small Lens};
\node at (0.46,-0.02){\small Metasurface};
\node at (0.70,0.01){\small Fourier lens};
\node at (0.74,0.20){\small QWP};
\node at (0.83,0.20){\small Pol$_2$};
\node at (0.95,0.03){\small Det$_A$};
%\draw[red,ultra thick,rounded corners] (0.62,0.65) rectangle (0.78,0.75);
\end{scope}
\end{tikzpicture}
\regexpatchcmdrequires a very different syntax; but that's not the problem: the macro\tikzscale@scaleTikzpictureTodoes not contain the tokens you'd like to replace, because it's defined with\NewDocumentCommand(and so patching it is not covered byregexpatch). – egreg Jun 08 '18 at 06:26tikzpictures ought not be done and can always (?) be avoided. – cfr Jun 09 '18 at 03:05\includegraphicsto include a.tikzfile, which has an\includegraphicsof a.pdffile. I've edited my post with an example. – Firnagzen Jun 12 '18 at 02:48xparse. Doing this violates the LaTeX 3 philosophy. That is, it can be done but the developers don't want it done. In any case, there is a surely a better way of addressing the problem. – cfr Jun 13 '18 at 03:05