I want to label a family of curves representing mathematical functions by writing at some place of the curve the formula directly on the trace. More specifically, my family of curves is the very simple x -> x²+c where c will take various values between -4 and 4. As this family of functions will be difficult to label the usual way (with formula next to the curve), I want to superpose the label directly on the curve (thus interrupting the trace - with a little white space to help the reading).
I tried with TikZ, and failed. The following code is OK with decorations like "bumps", but not with "text along path".
\documentclass[11pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{arrows, arrows.meta, decorations.text, decorations.pathmorphing}
\begin{document}
\begin{center}
\begin{tikzpicture}[>=Stealth ]
\def\xmin{-4}
\def\xmax{4}
\def\ymin{-6}
\def\ymax{6}
\draw[thin, opacity=0.2] (\xmin, \ymin) grid (\xmax, \ymax);
\draw[very thick, ->] (\xmin,0) -- (\xmax,0) node[below left] {$x$} ;
\draw[very thick, ->] (0,\ymin) -- (0,\ymax) node[below left] {$y$} ;
\clip (\xmin, \ymin) rectangle (\xmax, \ymax) ;
\draw[very thick, dashed, domain=-3:3,samples=200] plot (\x, {(\x)^2} ) ;
\draw[very thick, domain=\xmin:\xmax,samples=200, red, decorate,
decoration={bumps} % OK
%decoration={text along path, text={\small test}} % Not OK
]
plot (\x, {(\x)^2+3} ) ;
\draw[decorate, decoration={text along path, text={Some long text along a ridiculously long curve that could yet be longer}} ] (-4,3) to[in=180,out=0] (0,0) to[in=180,out=0] (4,3) ; % OK too
\end{tikzpicture}
\end{center}
\end{document}
This code does not compile, in an odd way : the compilation never ends ! I use LuaLaTeX with the latest TexLive (on Ubuntu 18.04, but this is pointless).
Additionally, I found something near to my needs here : Pgfplots: plot text along function. But this approach uses PGFplots syntax which I do not master - and don't have enough time to begin mastering now.
Does someone have any idea ? Thanks in advance !
Update
Thanks to Schrödinger's Cat, who seems to be quite alive, I'm close to what I have in mind. But I have major difficulties to surround the label on each curve to mask the curve, in order to improve its readbility. Here a code showing where I am :
\documentclass[11pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{arrows, arrows.meta, decorations.text, decorations.pathmorphing} % decoration.markings
\begin{document}
\begin{tikzpicture}[scale=.8,>=Stealth]
\def \xmin {-4}
\def \xmax {4}
\def \ymin {-6}
\def \ymax {6}
\draw[thin, opacity=0.2] (\xmin, \ymin) grid (\xmax, \ymax);
\draw[very thick, ->] (\xmin,0) -- (\xmax,0) node[below left] {$x$} ;
\draw[very thick, ->] (0,\ymin) -- (0,\ymax) node[below left] {$y$} ;
\clip (\xmin, \ymin) rectangle (\xmax, \ymax) ;
\draw[very thick, dashed, domain=-3:3,samples=200] plot (\x, {(\x)^2} ) ;
\foreach \c [evaluate=\c as \pc using {100-(\c+6)*9}, evaluate=\c as \ic using {abs(\xmax-\c)+.5}] in {-6,-4,-2,2,4} {
\draw[very thick, domain=\xmin:\xmax,samples=200, blue!\pc!red,
% text effects={path from text, characters={text along path, fill=gray!50}},
postaction={decorate,
decoration={text along path,
raise=-.5ex,
% fill=green % Let (Lua)LaTeX hang
text={|\scriptsize| $x {\mapsto} {x^2}+(\c)$},
text color=blue!\pc!red,
text align={align=right, right indent=\ic cm}
},
text effects={path from text, characters={text along path, fill=gray!50}},
} ]
plot (\x, {(\x)^2+\c} ) ;
} ;
\draw (0,0) node[shift={(-.3cm,-.3cm)}, fill=white, circle, inner sep=-.5pt] {$O$} ;
\coordinate (I) at (1,0); \draw (I) node {\small $|$} node[yshift=-.3cm, fill=white, inner sep=.5pt] {$1$} ;
\coordinate (J) at (0,1); \draw (J) node {$-$} node[xshift=-.2cm, fill=white, inner sep=.5pt] {$1$} ;
\end{tikzpicture}
\end{document}
\small
in|
s:decoration={text along path, text={|\small| test}}
.