I am trying to include a TikZ figure in a French-language presentation. The Beamer script, without specifying the language, is as follows:
\documentclass{beamer}
\usetheme[progressbar=frametitle]{metropolis}
\setbeamertemplate{frame numbering}[fraction]
\useoutertheme{metropolis}
\useinnertheme{metropolis}
\usefonttheme[onlymath]{serif}
\usecolortheme{spruce}
\setbeamercolor{background canvas}{bg=white}
%\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{ragged2e,mathtools,tikz,amsfonts}
\addtobeamertemplate{block begin}{}{\justifying}
\metroset{block=fill}
\useinnertheme{tcolorbox}
\justifying
\title{Probabilité}
\subtitle{Lois Continues}
\date[]{}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage[outline]{contour}
\contourlength{1.2pt}
\tikzset{>=latex}
\usetikzlibrary{positioning, calc}
\pgfmathdeclarefunction{gauss}{3}{%
\pgfmathparse{1/(#3sqrt(2pi))exp(-((#1-#2)^2)/(2#3^2))}%
}
% to fill an area under function
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\AtEndPreamble{
\pgfplotsset{compat=1.12}
}
\begin{document}
\begin{frame}{Frame Title}
\begin{figure}[h]
\caption{\large Densité de la loi normale $N(\mu, \sigma)$}
\centering
\begin{tikzpicture}[scale=1.2]
\def\N{50}
\def\B{11}
\def\Bs{3.0}
\def\xmax{\B+3.2\Bs}
\def\ymin{{-0.1gauss(\B,\B,\Bs)}}
\def\h{0.08*gauss(\B,\B,\Bs)}
\begin{axis}[
every axis plot post/.append style={
mark=none,
domain={-0.05*(\xmax)}:{1.08*\xmax},
samples=\N,
smooth
},
xmin={-0.1*(\xmax)}, xmax=\xmax,
ymin=\ymin, ymax={1.1*gauss(\B,\B,\Bs)},
axis y line*=left,
axis x line*=bottom,
axis line style={draw=none},
ticks=none,
every axis x label/.style={
at={(current axis.right of origin)},
anchor=north
},
width=0.85*\textwidth,
height=0.55*\textwidth,
y=700pt,
clip=false
]
% PLOTS
\addplot[blue, thick, name path=B] {gauss(x,\B,\Bs)};
% FILL
\path[name path=xaxis]
(0,0) -- (\pgfkeysvalueof{/pgfplots/xmax},0);
\addplot[blue!50] fill between[of=xaxis and B, soft clip={
domain={\B-3*\Bs}:{\B+3*\Bs}}
];
\addplot[blue!25] fill between[of=xaxis and B, soft clip={
domain={\B-2*\Bs}:{\B+2*\Bs}}
];
\addplot[blue!10] fill between[of=xaxis and B, soft clip={
domain={\B-1*\Bs}:{\B+1*\Bs}}
];
% LINES
\addplot[black, dotted, thick]
coordinates {({\B-3*\Bs},{1*gauss(\B-3*\Bs,\B,\Bs)}) ({\B-3*\Bs},{-\h})}
node[below=-3pt, scale=0.8] {\strut$\mu-3\sigma$};
\addplot[black, dotted, thick]
coordinates {({\B-2*\Bs},{1*gauss(\B-2*\Bs,\B,\Bs)}) ({\B-2*\Bs},{-\h})}
node[below=-3pt, scale=0.8] {\strut$\mu-2\sigma$};
\addplot[black, dotted, thick]
coordinates {({\B-1*\Bs},{1*gauss(\B-\Bs,\B,\Bs)}) ({\B-1*\Bs},{-\h})}
node[below=-3pt, scale=0.8] at ({\B-\Bs},{-\h}) {\strut$\mu-\sigma$};
\addplot[black, dotted, line width=0.7pt]
coordinates {(\B,{1*gauss(\B,\B,\Bs)}) (\B,{-\h})}
node[below=-3pt, scale=0.8] {\strut$\mu$};
\addplot[black, dotted, thick]
coordinates {({\B+1*\Bs},{1*gauss(\B+\Bs,\B,\Bs)}) ({\B+1*\Bs},{-\h})}
node[below=-3pt, scale=0.8] at ({\B+\Bs},{-\h}) {\strut$\mu+\sigma$};
\addplot[black, dotted, thick]
coordinates {({\B+2*\Bs},{1*gauss(\B+2*\Bs,\B,\Bs)}) ({\B+2*\Bs},{-\h})}
node[below=-3pt, scale=0.8] at ({\B+2*\Bs},{-\h}) {\strut$\mu+2\sigma$};
\addplot[black, dotted, thick]
coordinates {({\B+3*\Bs},{1*gauss(\B+3*\Bs,\B,\Bs)}) ({\B+3*\Bs},{-\h})}
node[below=-3pt, scale=0.8] at ({\B+3*\Bs},{-\h}) {\strut$\mu+3\sigma$};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
This code as you see works as intended, but once I specify the language by uncommenting the following line:
%\usepackage[french]{babel}
it gives me this error message:
I tried to circumvent the problem by including \shorthandoff{;} after \begin{tikzpicture}, as recommended in this answer, but the problem persists; the figure does not appear. I also tried this answer, but it also doesn't work for me.
Any clue as to how to fix this problem would be appreciated.



\usepackage[french]{babel}uncommented so one does not need to search for it just to remove the%sign. This way one could directly reproduce your problem. – samcarter_is_at_topanswers.xyz Dec 13 '23 at 22:59