I use the following answer in order to scale my tikzpictures.
I'd now like to turn to the issue of externalizing figures. The problem is that the autoscale autoid option sometimes need 2 compilations for the figure to be the right size, so the pdf image generated by the tikzexternal library is often the wrong size.
But now that the figures are externalized (and a pdf is generated for each of them), I don't think it's necessary to use autoscale autoid any more.
Is it possible to create a tikz environment that allows you to manage the size (0.5\columnwidth for example) of the imported pdf (corresponding to the tikz figure) ?
MWE
\documentclass[twocolumn,landscape]{article}
\usepackage{xparse}
\usepackage{tikz,tkz-fct}
\usetikzlibrary{calc}
\usetikzlibrary{external}
%\tikzexternalize
\makeatletter
\ExplSyntaxOn
\msg_new:nnn { nilcouv } { duplicate-figure-id }
{ duplicate~figure~identifier:~'#1'. }
% Sequence recording all figure identifiers (for the 'scale to max size' TikZ
% style) found so far
\seq_new:N \g__nilcouv_scale_to_max_style_figure_ids_seq
% Counter used when generating automatic figure identifiers for 'autoscale'
\int_new:N \g_nilcouv_last_autogenerated_figure_nb_int
\cs_new_protected:Npn __nilcouv_check_unique_id:n #1
{
\seq_if_in:NnTF \g__nilcouv_scale_to_max_style_figure_ids_seq {#1}
{ \msg_error:nnn { nilcouv } { duplicate-figure-id } {#1} }
{ \seq_gput_right:Nn \g__nilcouv_scale_to_max_style_figure_ids_seq {#1} }
}
% Automatic generation of figure ids (the pattern is defined here)
\cs_new:Npn __nilcouv_autogenerated_id:n #1 { nilcouv~autogenerated~id~#1 }
\cs_generate_variant:Nn __nilcouv_autogenerated_id:n { V }
\cs_new_protected:Npn __nilcouv_autoscale:nnn #1#2#3
{ \tikzset { scale~to~max~size={#1}{#2}{#3} } }
\cs_generate_variant:Nn __nilcouv_autoscale:nnn { x }
\cs_new_protected:Npn __nilcouv_autoscale_autoid:nn #1#2
{
% Increment the counter
\int_gincr:N \g_nilcouv_last_autogenerated_figure_nb_int
% Call the 'autoscale' style with the new id
__nilcouv_autoscale:xnn
{ __nilcouv_autogenerated_id:V
\g_nilcouv_last_autogenerated_figure_nb_int
}
{#1}
{#2}
}
% Set up aliases using LaTeX2e naming style
\cs_new_eq:NN \nilcouv@check@unique@id __nilcouv_check_unique_id:n
\cs_new_eq:NN \nilcouv@autoscale@autoid __nilcouv_autoscale_autoid:nn
\ExplSyntaxOff
% Autoscaling technique that doesn't affect font sizes in TikZ pictures.
% (based on code from marmot: <https://tex.stackexchange.com/a/497749/73317>)
%
% #1: unique per-picture id allowing several pictures to use this mechanism
% in a given document (it should contain no control sequence token nor
% active character)
% #2: target width
% #3: target height
\newcommand*{\nilcouv@ExportBB}[3]{%
\path let
\p1=($(current bounding box.north east)-(current bounding box.south west)$),
\n1={#2/\x1},\n2={#3/\y1}
in \pgfextra{\pgfmathsetmacro{\nilcouv@figscale}{min(\n1,\n2)}%
\expandafter\xdef\csname nilcouv@auto@figscale@#1\endcsname{%
\nilcouv@figscale}};
\immediate\write@mainaux{%
\string\expandafter
\gdef\string\csname\space nilcouv@auto@figscale@#1\string\endcsname{%
\csname nilcouv@auto@figscale@#1\endcsname}}%
}
\tikzset{
% Arguments: figure identifier, target width, target height
scale to max size/.style n args={3}{
execute at end picture={\nilcouv@ExportBB{#1}{#2}{#3}},
/utils/exec={\nilcouv@check@unique@id{#1}%
\ifcsname nilcouv@auto@figscale@#1\endcsname
\wlog{Found autoscale value for picture '#1'}%
\else
\typeout{Automatically-scaled pictures: please recompile
for picture '#1'.}%
\expandafter\gdef
\csname nilcouv@auto@figscale@#1\endcsname{1}%
\fi},
scale=\csname nilcouv@auto@figscale@#1\endcsname,
},
% Same style except the id is automatically generated using a counter
autoscale autoid/.style 2 args={%
/utils/exec={\nilcouv@autoscale@autoid{#1}{#2}}},
}
% End of the code based on <https://tex.stackexchange.com/a/497749/73317>
\makeatother
\begin{document}
\begin{tikzpicture}[autoscale autoid={0.3\columnwidth}{\maxdimen}]
\tkzInit[xmin=-1,xmax=3,ymin=-1,ymax=1.2]
\tkzDrawX
\tkzDrawY
% Fonction
\tkzClip
\tkzFct[thick,domain=0.55:5]{(\x\x+\x-1)/(\x*3)}
\tkzDefPointByFct(1.39)\tkzGetPoint{A}\tkzDrawPointsize=3
\draw[dotted,thick] (1.39,0) -- (1.39, 0.86) -- (0,0.86) node[left] {( f(x) )};
\draw[thick] (1.39,-0.1) node[below] {( x )} -- (1.39,0.1);
%Annotations
\draw[<->,ultra thick] (1,-0.35) -- (2,-0.35);
\node at (1.5,-0.45){(A)};
\draw[dashed] (1, 0) -- (1, 1) -- (0, 1);
\draw[dashed] (2, 0) -- (2, 0.625) -- (0, 0.625);
\draw[<->,ultra thick] (-0.6,0.625) -- (-0.6,1);
\end{tikzpicture}
\end{document}


auxfile and externalizing will be hard to make compatible. The externalization process has to check that value again the previous one as well. – Qrrbrbirlbel Oct 23 '23 at 14:30memoizecould do this, buttikzscaleis generally preferable for scaling. – cfr Oct 23 '23 at 16:23memoizedo the scaling ...? – cfr Oct 25 '23 at 18:57